protected void setConnectionStatusCallBack(final List<Pair<IotHubConnectionStatus, Throwable>> actualStatusUpdates) { IotHubConnectionStatusChangeCallback connectionStatusUpdateCallback = new IotHubConnectionStatusChangeCallback() { @Override public void execute(IotHubConnectionStatus status, IotHubConnectionStatusChangeReason statusChangeReason, Throwable throwable, Object callbackContext) { actualStatusUpdates.add(new Pair<>(status, throwable)); } }; this.testInstance.deviceTestManager.client.registerConnectionStatusChangeCallback(connectionStatusUpdateCallback, null); }
protected void setConnectionStatusCallBack(final List<com.microsoft.azure.sdk.iot.device.DeviceTwin.Pair<IotHubConnectionStatus, Throwable>> actualStatusUpdates) { IotHubConnectionStatusChangeCallback connectionStatusUpdateCallback = new IotHubConnectionStatusChangeCallback() { @Override public void execute(IotHubConnectionStatus status, IotHubConnectionStatusChangeReason statusChangeReason, Throwable throwable, Object callbackContext) { actualStatusUpdates.add(new com.microsoft.azure.sdk.iot.device.DeviceTwin.Pair<>(status, throwable)); } }; this.internalClient.registerConnectionStatusChangeCallback(connectionStatusUpdateCallback, null); }
public static void sendMessagesExpectingConnectionStatusChangeUpdate(InternalClient client, IotHubClientProtocol protocol, List<MessageAndResult> messagesToSend, final long RETRY_MILLISECONDS, final long SEND_TIMEOUT_MILLISECONDS, final IotHubConnectionStatus expectedStatus, int interMessageDelay, AuthenticationType authType) throws IOException, InterruptedException { final List<Pair<IotHubConnectionStatus, Throwable>> actualStatusUpdates = new ArrayList<>(); client.registerConnectionStatusChangeCallback(new IotHubConnectionStatusChangeCallback() { @Override public void execute(IotHubConnectionStatus status, IotHubConnectionStatusChangeReason statusChangeReason, Throwable throwable, Object callbackContext) { actualStatusUpdates.add(new Pair<>(status, throwable)); } }, new Object()); sendMessages(client, protocol, messagesToSend, RETRY_MILLISECONDS, SEND_TIMEOUT_MILLISECONDS, interMessageDelay, actualStatusUpdates); Assert.assertTrue(buildExceptionMessage(protocol + ", " + authType + ": Expected connection status update to occur: " + expectedStatus, client), actualStatusUpdatesContainsStatus(actualStatusUpdates, expectedStatus)); }
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(); }
public void errorInjectionTestFlow(com.microsoft.azure.sdk.iot.device.Message errorInjectionMessage) throws IOException, IotHubException, InterruptedException testInstance.client.registerConnectionStatusChangeCallback(new IotHubConnectionStatusChangeCallback()