private void tearDownTwin(TransportClient transportClient) { try { transportClient.closeNow(); } catch (Exception e) { e.printStackTrace(); fail("Encountered exception during tearDownTwin: " + Tools.getStackTraceFromThrowable(e)); } sCDeviceTwin = null; }
@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(); }
@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(); }
@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(); }
@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(); }
client.closeNow();
@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(); }
transportClient.closeNow();
transportClient.closeNow();
transportClient.closeNow(); tearDownFileUploadState();
transportClient.closeNow(); tearDownFileUploadState();
this.transportClient.closeNow(); this.transportClient.open();