Search in sources :

Example 11 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_standardTimeout_succeed.

@Test
public void invokeMethod_standardTimeout_succeed() throws Exception {
    // Arrange
    TestDevice testDevice = devices.get(0);
    // Act
    MethodResult result = methodServiceClient.invoke(testDevice.getDeviceId(), METHOD_LOOPBACK, null, null, 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)

Example 12 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_responseTimeout_failed.

@Test(expected = IotHubGatewayTimeoutException.class)
public void invokeMethod_responseTimeout_failed() throws Exception {
    // Arrange
    TestDevice testDevice = devices.get(0);
    // Act
    MethodResult result = methodServiceClient.invoke(testDevice.getDeviceId(), METHOD_DELAY_IN_MILLISECONDS, (long) 5, CONNECTION_TIMEOUT, "7000");
}
Also used : MethodResult(com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult) Test(org.junit.Test)

Example 13 with MethodResult

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

the class DeviceMethodSample method main.

/**
     * @param args
     * @throws IOException
     * @throws URISyntaxException
     */
public static void main(String[] args) throws Exception {
    System.out.println("Starting sample...");
    DeviceMethod methodClient = DeviceMethod.createFromConnectionString(iotHubConnectionString);
    try {
        // Manage complete Method
        System.out.println("Getting device Method");
        MethodResult result = methodClient.invoke(deviceId, methodName, responseTimeout, connectTimeout, payload);
        if (result == null) {
            throw new IOException("Method invoke returns null");
        }
        System.out.println("Status=" + result.getStatus());
        System.out.println("Payload=" + result.getPayload());
    } catch (IotHubException e) {
        System.out.println(e.getMessage());
    }
    System.out.println("Shutting down sample...");
}
Also used : IOException(java.io.IOException) DeviceMethod(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException) MethodResult(com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult)

Example 14 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_number_succeed.

@Test
public void invokeMethod_number_succeed() throws Exception {
    // Arrange
    TestDevice testDevice = devices.get(0);
    // 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 : MethodResult(com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult) Test(org.junit.Test)

Example 15 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_resetDevice_failed.

@Test
public void invokeMethod_resetDevice_failed() throws Exception {
    // Arrange
    TestDevice testDevice = devices.get(0);
    // Act
    try {
        MethodResult result = methodServiceClient.invoke(testDevice.getDeviceId(), METHOD_RESET, RESPONSE_TIMEOUT, CONNECTION_TIMEOUT, null);
        testDevice.restartDevice();
        throw new Exception("Reset device do not affect the method invoke on the service");
    } catch (IotHubNotFoundException expected) {
    // Don't do anything, expected throw.
    }
    testDevice.restartDevice();
}
Also used : IotHubNotFoundException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubNotFoundException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) IotHubGatewayTimeoutException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubGatewayTimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException) IotHubNotFoundException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubNotFoundException) 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