@Test public void sendMessagesOverAmqpsWs() throws URISyntaxException, IOException, InterruptedException { TransportClient transportClient = new TransportClient(AMQPS_WS); ArrayList<InternalClient> clientArrayList = new ArrayList<>(); for (int i = 0; i < MAX_DEVICE_MULTIPLEX; i++) { clientArrayList.add(new DeviceClient(clientConnectionStringArrayList[i], transportClient)); } openTransportClientWithRetry(transportClient, clientArrayList); for (int i = 0; i < clientArrayList.size(); i++) { sendMessagesMultiplex(clientArrayList.get(i), IotHubClientProtocol.AMQPS_WS, NUM_MESSAGES_PER_CONNECTION, RETRY_MILLISECONDS, SEND_TIMEOUT_MILLISECONDS); } transportClient.closeNow(); }
if (this.transportClient.getTransportClientState() == TransportClient.TransportClientState.OPENED) if (this.transportClient.getTransportClientState() == TransportClient.TransportClientState.OPENED) if (this.transportClient.getTransportClientState() == TransportClient.TransportClientState.OPENED)
TransportClient transportClient = new TransportClient(protocol); transportClient.open(); System.out.format("Connection opened with multiplexing"); transportClient.setSendInterval(42); transportClient.closeNow(); System.out.println("Shutting down..."); transportClient.closeNow();
@Test public void invokeMethodAMQPSWSInvokeParallelSucceed() throws Exception TransportClient transportClient = new TransportClient(AMQPS_WS); transportClient.open(); ArrayList<InternalClient> clientArrayList = new ArrayList<>(); transportClient.closeNow();
private void tearDownTwin(TransportClient transportClient) { try { transportClient.closeNow(); } catch (Exception e) { e.printStackTrace(); fail("Encountered exception during tearDownTwin: " + Tools.getStackTraceFromThrowable(e)); } sCDeviceTwin = null; }
this.getConfig().setProtocol(this.transportClient.getIotHubClientProtocol()); this.transportClient.registerDeviceClient(this);
transportClient = new TransportClient(IotHubClientProtocol.AMQPS);
@Test public void sendMessagesOverAmqps() throws URISyntaxException, IOException, InterruptedException { TransportClient transportClient = new TransportClient(AMQPS); ArrayList<InternalClient> clientArrayList = new ArrayList<>(); for (int i = 0; i < MAX_DEVICE_MULTIPLEX; i++) { clientArrayList.add(new DeviceClient(clientConnectionStringArrayList[i], transportClient)); } openTransportClientWithRetry(transportClient, clientArrayList); for (int i = 0; i < clientArrayList.size(); i++) { sendMessagesMultiplex(clientArrayList.get(i), IotHubClientProtocol.AMQPS, NUM_MESSAGES_PER_CONNECTION, RETRY_MILLISECONDS, SEND_TIMEOUT_MILLISECONDS); } transportClient.closeNow(); }
if (this.transportClient.getTransportClientState() == TransportClient.TransportClientState.OPENED)
@Test public void sendMessagesOverAmqpsMultithreaded() throws InterruptedException, URISyntaxException, IOException { TransportClient transportClient = new TransportClient(AMQPS); ArrayList<InternalClient> clientArrayList = new ArrayList<>(); for (int i = 0; i < MAX_DEVICE_MULTIPLEX; i++) { clientArrayList.add(new DeviceClient(clientConnectionStringArrayList[i], transportClient)); } CountDownLatch cdl = new CountDownLatch(clientArrayList.size()); IotHubServicesCommon.openTransportClientWithRetry(transportClient, clientArrayList); for (int i = 0; i < clientArrayList.size(); i++) { new Thread( new MultiplexRunnable( deviceListAmqps[i], clientArrayList.get(i), NUM_MESSAGES_PER_CONNECTION, NUM_KEYS_PER_MESSAGE, SEND_TIMEOUT_MILLISECONDS, cdl)) .start(); } cdl.await(); if(!succeed.get()) { Assert.fail(CorrelationDetailsLoggingAssert.buildExceptionMessage("Sending message over AMQP protocol in parallel failed", clientArrayList)); } transportClient.closeNow(); }
/** * Starts asynchronously sending and receiving messages from an IoT Hub. If * the client is already open, the function shall do nothing. * * @throws IOException if a connection to an IoT Hub cannot be established. */ public void open() throws IOException { if (this.ioTHubConnectionType == IoTHubConnectionType.USE_TRANSPORTCLIENT) { if (this.transportClient.getTransportClientState() == TransportClient.TransportClientState.CLOSED) { // Codes_SRS_DEVICECLIENT_12_007: [If the client has been initialized to use TransportClient and the TransportClient is not opened yet the function shall throw an IOException.] throw new IOException("Calling open() when using the TransportClient is not supported. Use TransportClient.open() instead."); } else { // Codes_SRS_DEVICECLIENT_12_019: [If the client has been initialized to use TransportClient and the TransportClient is already opened the function shall do nothing.] logger.LogInfo("Connection already opened by TransportClient."); } } else { // Codes_SRS_DEVICECLIENT_21_006: [The open shall invoke super.open().] super.open(); } logger.LogInfo("Connection opened with success, method name is %s ", logger.getMethodName()); }
@Test public void sendMessagesOverAmqpsWsMultithreaded() throws InterruptedException, URISyntaxException, IOException { TransportClient transportClient = new TransportClient(AMQPS_WS); ArrayList<InternalClient> clientArrayList = new ArrayList<>(); for (int i = 0; i < MAX_DEVICE_MULTIPLEX; i++) { clientArrayList.add(new DeviceClient(clientConnectionStringArrayList[i], transportClient)); } CountDownLatch cdl = new CountDownLatch(clientArrayList.size()); IotHubServicesCommon.openTransportClientWithRetry(transportClient, clientArrayList); for (int i = 0; i < clientArrayList.size(); i++) { new Thread( new MultiplexRunnable( deviceListAmqps[i], clientArrayList.get(i), NUM_MESSAGES_PER_CONNECTION, NUM_KEYS_PER_MESSAGE, SEND_TIMEOUT_MILLISECONDS, cdl)) .start(); } cdl.await(); if(!succeed.get()) { Assert.fail(CorrelationDetailsLoggingAssert.buildExceptionMessage("Sending message over AMQP protocol in parallel failed", clientArrayList)); } transportClient.closeNow(); }
if (this.transportClient.getTransportClientState() == TransportClient.TransportClientState.OPENED)
@Test public void receiveMessagesOverAmqpWSIncludingProperties() throws Exception { TransportClient transportClient = new TransportClient(AMQPS); final ArrayList<InternalClient> clientArrayList = new ArrayList<>(); for (int i = 0; i < MAX_DEVICE_MULTIPLEX; i++) { clientArrayList.add(new DeviceClient(clientConnectionStringArrayList[i], transportClient)); } IotHubServicesCommon.openTransportClientWithRetry(transportClient, clientArrayList); for (int i = 0; i < clientArrayList.size(); i++) { Success messageReceived = new Success(); com.microsoft.azure.sdk.iot.device.MessageCallback callback = new MessageCallback(); ((DeviceClient)clientArrayList.get(i)).setMessageCallback(callback, messageReceived); sendMessageToDevice(deviceListAmqps[i].getDeviceId(), "AMQPS_WS"); waitForMessageToBeReceived(messageReceived, "AMQPS_WS", clientArrayList.get(i)); Thread.sleep(200); } transportClient.closeNow(); }
@Test public void receiveMessagesOverAmqpsIncludingProperties() throws Exception { TransportClient transportClient = new TransportClient(AMQPS); final ArrayList<InternalClient> clientArrayList = new ArrayList<>(); for (int i = 0; i < MAX_DEVICE_MULTIPLEX; i++) { clientArrayList.add(new DeviceClient(clientConnectionStringArrayList[i], transportClient)); } IotHubServicesCommon.openTransportClientWithRetry(transportClient, clientArrayList); for (int i = 0; i < clientArrayList.size(); i++) { Success messageReceived = new Success(); com.microsoft.azure.sdk.iot.device.MessageCallback callback = new MessageCallback(); ((DeviceClient)clientArrayList.get(i)).setMessageCallback(callback, messageReceived); sendMessageToDevice(deviceListAmqps[i].getDeviceId(), "AMQPS"); waitForMessageToBeReceived(messageReceived, "AMQPS", clientArrayList.get(i)); Thread.sleep(200); } transportClient.closeNow(); }
@Test public void invokeMethodAMQPSWSSucceed() throws Exception { TransportClient transportClient = new TransportClient(AMQPS_WS); ArrayList<InternalClient> clientArrayList = new ArrayList<>(); for (int i = 0; i < MAX_DEVICE_MULTIPLEX; i++) { clientArrayList.add(new DeviceClient(clientConnectionStringArrayList[i], transportClient)); } IotHubServicesCommon.openTransportClientWithRetry(transportClient, clientArrayList); for (int i = 0; i < clientArrayList.size(); i++) { ((DeviceClient)clientArrayList.get(i)).subscribeToDeviceMethod(new SampleDeviceMethodCallback(), null, new DeviceMethodStatusCallBack(), null); CountDownLatch countDownLatch = new CountDownLatch(1); RunnableInvoke runnableInvoke = new RunnableInvoke(methodServiceClient, deviceListAmqps[i].getDeviceId(), METHOD_NAME, METHOD_PAYLOAD, countDownLatch); new Thread(runnableInvoke).start(); countDownLatch.await(); MethodResult result = runnableInvoke.getResult(); Assert.assertNotNull(buildExceptionMessage(runnableInvoke.getException() == null ? "Runnable returns null without exception information" : runnableInvoke.getException().getMessage(), clientArrayList.get(i)), result); Assert.assertEquals(buildExceptionMessage("result was not success, but was: " + result.getStatus(), clientArrayList.get(i)), (long)METHOD_SUCCESS,(long)result.getStatus()); Assert.assertEquals(buildExceptionMessage("Received unexpected payload", clientArrayList.get(i)), runnableInvoke.getExpectedPayload(), METHOD_NAME + ":" + result.getPayload().toString()); } transportClient.closeNow(); }
@Test public void invokeMethodAMQPSSucceed() throws Exception { TransportClient transportClient = new TransportClient(AMQPS); ArrayList<InternalClient> clientArrayList = new ArrayList<>(); for (int i = 0; i < MAX_DEVICE_MULTIPLEX; i++) { clientArrayList.add(new DeviceClient(clientConnectionStringArrayList[i], transportClient)); } IotHubServicesCommon.openTransportClientWithRetry(transportClient, clientArrayList); for (int i = 0; i < clientArrayList.size(); i++) { ((DeviceClient)clientArrayList.get(i)).subscribeToDeviceMethod(new SampleDeviceMethodCallback(), null, new DeviceMethodStatusCallBack(), null); CountDownLatch countDownLatch = new CountDownLatch(1); RunnableInvoke runnableInvoke = new RunnableInvoke(methodServiceClient, deviceListAmqps[i].getDeviceId(), METHOD_NAME, METHOD_PAYLOAD, countDownLatch); new Thread(runnableInvoke).start(); countDownLatch.await(); MethodResult result = runnableInvoke.getResult(); Assert.assertNotNull(buildExceptionMessage(runnableInvoke.getException() == null ? "Runnable returns null without exception information" : runnableInvoke.getException().getMessage(), clientArrayList.get(i)), result); Assert.assertEquals(buildExceptionMessage("result was not success, but was: " + result.getStatus(), clientArrayList.get(i)), (long)METHOD_SUCCESS,(long)result.getStatus()); Assert.assertEquals(buildExceptionMessage("Received unexpected payload", clientArrayList.get(i)), runnableInvoke.getExpectedPayload(), METHOD_NAME + ":" + result.getPayload().toString()); } transportClient.closeNow(); }
@Test public void invokeMethodAMQPSInvokeParallelSucceed() throws Exception TransportClient transportClient = new TransportClient(AMQPS); ArrayList<InternalClient> clientArrayList = new ArrayList<>(); transportClient.closeNow();