Search in sources :

Example 6 with MethodResult

use of com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult in project azure-iot-sdk-java by Azure.

the class DeviceMethodIT method invokeMethod_defaultResponseTimeout_succeed.

@Test
public void invokeMethod_defaultResponseTimeout_succeed() throws Exception {
    // Arrange
    TestDevice testDevice = devices.get(0);
    // Act
    MethodResult result = methodServiceClient.invoke(testDevice.getDeviceId(), METHOD_DELAY_IN_MILLISECONDS, null, CONNECTION_TIMEOUT, "100");
    testDevice.waitIotHub(1, 10);
    // Assert
    assertNotNull(result);
    assertEquals((long) METHOD_SUCCESS, (long) result.getStatus());
    assertEquals(METHOD_DELAY_IN_MILLISECONDS + ":succeed", result.getPayload());
    assertEquals(0, testDevice.getStatusError());
}
Also used : MethodResult(com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult) Test(org.junit.Test)

Example 7 with MethodResult

use of com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult in project azure-iot-sdk-java by Azure.

the class DeviceMethodIT method invokeMethod_throws_NumberFormatException_failed.

@Test
public void invokeMethod_throws_NumberFormatException_failed() throws Exception {
    // Arrange
    TestDevice testDevice = devices.get(0);
    // Act
    MethodResult result = methodServiceClient.invoke(testDevice.getDeviceId(), METHOD_DELAY_IN_MILLISECONDS, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, PAYLOAD_STRING);
    testDevice.waitIotHub(1, 10);
    // Assert
    assertNotNull(result);
    assertEquals((long) METHOD_THROWS, (long) result.getStatus());
    assertEquals("java.lang.NumberFormatException: For input string: \"" + PAYLOAD_STRING + "\"", result.getPayload());
    assertEquals(0, testDevice.getStatusError());
}
Also used : MethodResult(com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult) Test(org.junit.Test)

Example 8 with MethodResult

use of com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult in project azure-iot-sdk-java by Azure.

the class DeviceMethodIT method invokeMethod_unknown_failed.

@Test
public void invokeMethod_unknown_failed() throws Exception {
    // Arrange
    TestDevice testDevice = devices.get(0);
    // Act
    MethodResult result = methodServiceClient.invoke(testDevice.getDeviceId(), METHOD_UNKNOWN, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, PAYLOAD_STRING);
    testDevice.waitIotHub(1, 10);
    // Assert
    assertNotNull(result);
    assertEquals((long) METHOD_NOT_DEFINED, (long) result.getStatus());
    assertEquals("unknown:" + METHOD_UNKNOWN, result.getPayload());
    assertEquals(0, testDevice.getStatusError());
}
Also used : MethodResult(com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult) Test(org.junit.Test)

Example 9 with MethodResult

use of com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult in project azure-iot-sdk-java by Azure.

the class DeviceMethodIT method invokeMethod_recoverFromTimeout_succeed.

@Test
public void invokeMethod_recoverFromTimeout_succeed() throws Exception {
    // Arrange
    TestDevice testDevice = devices.get(0);
    try {
        methodServiceClient.invoke(testDevice.getDeviceId(), METHOD_DELAY_IN_MILLISECONDS, (long) 5, CONNECTION_TIMEOUT, "7000");
        assert true;
    } catch (IotHubGatewayTimeoutException expected) {
    //Don't do anything. Expected throw.
    }
    // Act
    MethodResult result = methodServiceClient.invoke(testDevice.getDeviceId(), METHOD_DELAY_IN_MILLISECONDS, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, "100");
    testDevice.waitIotHub(1, 10);
    // Assert
    assertNotNull(result);
    assertEquals((long) METHOD_SUCCESS, (long) result.getStatus());
    assertEquals(METHOD_DELAY_IN_MILLISECONDS + ":succeed", result.getPayload());
    assertEquals(0, testDevice.getStatusError());
}
Also used : IotHubGatewayTimeoutException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubGatewayTimeoutException) MethodResult(com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult) Test(org.junit.Test)

Example 10 with MethodResult

use of com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult in project azure-iot-sdk-java by Azure.

the class DeviceMethodIT method invokeMethod_succeed.

@Test
public void invokeMethod_succeed() throws Exception {
    // Arrange
    TestDevice testDevice = devices.get(0);
    // Act
    MethodResult result = methodServiceClient.invoke(testDevice.getDeviceId(), METHOD_LOOPBACK, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, PAYLOAD_STRING);
    testDevice.waitIotHub(1, 10);
    // Assert
    assertNotNull(result);
    assertEquals((long) METHOD_SUCCESS, (long) result.getStatus());
    assertEquals(METHOD_LOOPBACK + ":" + PAYLOAD_STRING, result.getPayload());
    assertEquals(0, testDevice.getStatusError());
}
Also used : MethodResult(com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult) Test(org.junit.Test)

Aggregations

MethodResult (com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult)17 Test (org.junit.Test)16 DeviceMethod (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod)2 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)2 IotHubGatewayTimeoutException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubGatewayTimeoutException)2 IOException (java.io.IOException)2 IotHubNotFoundException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubNotFoundException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 LinkedList (java.util.LinkedList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1