Search in sources :

Example 11 with DeviceTestManager

use of tests.integration.com.microsoft.azure.sdk.iot.helpers.DeviceTestManager in project azure-iot-sdk-java by Azure.

the class DeviceMethodTests method invokeMethodRecoverFromTimeoutSucceed.

@Test
@StandardTierHubOnlyTest
@ContinuousIntegrationTest
public void invokeMethodRecoverFromTimeoutSucceed() throws Exception {
    // Arrange
    super.openDeviceClientAndSubscribeToMethods();
    DeviceTestManager deviceTestManger = this.testInstance.deviceTestManager;
    try {
        if (testInstance.identity instanceof TestModuleIdentity) {
            testInstance.methodServiceClient.invoke(testInstance.identity.getDeviceId(), ((TestModuleIdentity) testInstance.identity).getModuleId(), DeviceEmulator.METHOD_DELAY_IN_MILLISECONDS, (long) 5, CONNECTION_TIMEOUT, "7000");
        } else {
            testInstance.methodServiceClient.invoke(testInstance.identity.getDeviceId(), DeviceEmulator.METHOD_DELAY_IN_MILLISECONDS, (long) 5, CONNECTION_TIMEOUT, "7000");
        }
        assert true;
    } catch (IotHubGatewayTimeoutException expected) {
    // Don't do anything. Expected throw.
    }
    // Act
    MethodResult result;
    if (testInstance.identity instanceof TestModuleIdentity) {
        result = testInstance.methodServiceClient.invoke(testInstance.identity.getDeviceId(), ((TestModuleIdentity) testInstance.identity).getModuleId(), DeviceEmulator.METHOD_DELAY_IN_MILLISECONDS, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, "100");
    } else {
        result = testInstance.methodServiceClient.invoke(testInstance.identity.getDeviceId(), DeviceEmulator.METHOD_DELAY_IN_MILLISECONDS, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, "100");
    }
    deviceTestManger.waitIotHub(1, 10);
    // Assert
    assertNotNull(buildExceptionMessage("method result was null", testInstance.deviceTestManager.client), result);
    assertEquals(buildExceptionMessage("Expected SUCCESS but got " + result.getStatus(), testInstance.deviceTestManager.client), (long) DeviceEmulator.METHOD_SUCCESS, (long) result.getStatus());
    assertEquals(buildExceptionMessage("Expected " + DeviceEmulator.METHOD_DELAY_IN_MILLISECONDS + ":succeed" + " But got " + result.getPayload(), testInstance.deviceTestManager.client), DeviceEmulator.METHOD_DELAY_IN_MILLISECONDS + ":succeed", result.getPayload());
    Assert.assertEquals(buildExceptionMessage("Unexpected status errors occurred", testInstance.deviceTestManager.client), 0, deviceTestManger.getStatusError());
}
Also used : DeviceTestManager(tests.integration.com.microsoft.azure.sdk.iot.helpers.DeviceTestManager) IotHubGatewayTimeoutException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubGatewayTimeoutException) TestModuleIdentity(tests.integration.com.microsoft.azure.sdk.iot.helpers.TestModuleIdentity) MethodResult(com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) Test(org.junit.Test) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)

Aggregations

DeviceTestManager (tests.integration.com.microsoft.azure.sdk.iot.helpers.DeviceTestManager)11 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)6 MethodResult (com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult)6 Test (org.junit.Test)6 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)6 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)6 JobResult (com.microsoft.azure.sdk.iot.service.jobs.JobResult)5 Date (java.util.Date)5 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)4 IotHubUnathorizedException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubUnathorizedException)4 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 ExecutorService (java.util.concurrent.ExecutorService)4 Ignore (org.junit.Ignore)4 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)4 TestModuleIdentity (tests.integration.com.microsoft.azure.sdk.iot.helpers.TestModuleIdentity)3