/** * Ends the DeviceClient connection and destroy the thread. * @throws IOException if the DeviceClient cannot close the connection with the IoTHub. */ void stop() throws IOException { if (this.client != null) { this.client.closeNow(); } stopDevice = true; }
void start() throws InterruptedException { try { if (this.client != null) { this.client.closeNow(); } } catch (IOException e) { e.printStackTrace(); } clearStatistics(); if (this.client != null) { IotHubServicesCommon.openClientWithRetry(this.client); } }
protected void tearDownTwin(DeviceState deviceState) throws IOException { // tear down twin on device client if (deviceState.sCDeviceForTwin != null) { deviceState.sCDeviceForTwin.clearTwin(); } if (deviceState.dCDeviceForTwin != null) { deviceState.dCDeviceForTwin.clean(); if (deviceState.dCDeviceForTwin.getDesiredProp() != null) { deviceState.dCDeviceForTwin.getDesiredProp().clear(); } } if (internalClient != null) { internalClient.closeNow(); internalClient = null; } }
client.closeNow();
super.closeNow(); this.closeFileUpload();
public static void sendMessagesExpectingUnrecoverableConnectionLossAndTimeout(InternalClient client, IotHubClientProtocol protocol, Message errorInjectionMessage, AuthenticationType authType) throws IOException, InterruptedException { final List<Pair<IotHubConnectionStatus, Throwable>> statusUpdates = new ArrayList<>(); client.registerConnectionStatusChangeCallback(new IotHubConnectionStatusChangeCallback() { @Override public void execute(IotHubConnectionStatus status, IotHubConnectionStatusChangeReason statusChangeReason, Throwable throwable, Object callbackContext) { statusUpdates.add(new Pair<>(status, throwable)); } }, new Object()); openClientWithRetry(client); client.sendEventAsync(errorInjectionMessage, new EventCallback(null), new Success()); long startTime = System.currentTimeMillis(); while (!(actualStatusUpdatesContainsStatus(statusUpdates, IotHubConnectionStatus.DISCONNECTED_RETRYING) && actualStatusUpdatesContainsStatus(statusUpdates, IotHubConnectionStatus.DISCONNECTED))) { Thread.sleep(500); if (System.currentTimeMillis() - startTime > 30 * 1000) { break; } } Assert.assertTrue(buildExceptionMessage(protocol + ", " + authType + ": Expected notification about disconnected but retrying.", client), actualStatusUpdatesContainsStatus(statusUpdates, IotHubConnectionStatus.DISCONNECTED_RETRYING)); Assert.assertTrue(buildExceptionMessage(protocol + ", " + authType + ": Expected notification about disconnected.", client), actualStatusUpdatesContainsStatus(statusUpdates, IotHubConnectionStatus.DISCONNECTED)); client.closeNow(); }
testInstance.client.closeNow(); //close the device client connection Assert.assertTrue(buildExceptionMessage(testInstance.protocol + ", " + testInstance.authenticationType + ": Received messages don't match up with sent messages", testInstance.client), messageIdListStoredOnReceive.containsAll(messageIdListStoredOnC2DSend)); // check if the received list is same as the actual list that was created on sending the messages messageIdListStoredOnReceive.clear();
testInstance.client.closeNow();
this.testInstance.protocol); client.closeNow();
testInstance.client.closeNow();