Search in sources :

Example 1 with EventCallback

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

the class SendMessagesIT method SendMessagesOverHttps.

@Test
public void SendMessagesOverHttps() throws URISyntaxException, IOException {
    String messageString = "Java client e2e test message over Https protocol";
    Message msg = new Message(messageString);
    DeviceClient client = new DeviceClient(DeviceConnectionString.get(iotHubConnectionString, deviceHttps), IotHubClientProtocol.HTTPS);
    client.open();
    for (int i = 0; i < NUM_MESSAGES_PER_CONNECTION; ++i) {
        try {
            Success messageSent = new Success();
            EventCallback callback = new EventCallback();
            client.sendEventAsync(msg, callback, messageSent);
            Integer waitDuration = 0;
            while (!messageSent.getResult()) {
                Thread.sleep(RETRY_MILLISECONDS);
                if ((waitDuration += RETRY_MILLISECONDS) > SEND_TIMEOUT_MILLISECONDS) {
                    break;
                }
            }
            if (!messageSent.getResult()) {
                Assert.fail("Sending message over HTTPS protocol failed");
            }
        } catch (Exception e) {
            Assert.fail("Sending message over HTTPS protocol failed");
        }
    }
    client.closeNow();
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) DeviceClient(com.microsoft.azure.sdk.iot.device.DeviceClient) DeviceConnectionString(tests.integration.com.microsoft.azure.sdk.iot.device.DeviceConnectionString) EventCallback(tests.integration.com.microsoft.azure.sdk.iot.device.EventCallback) Success(tests.integration.com.microsoft.azure.sdk.iot.device.Success) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException) Test(org.junit.Test)

Example 2 with EventCallback

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

the class SendMessagesIT method SendMessagesOverAmqps.

@Test
public void SendMessagesOverAmqps() throws URISyntaxException, IOException, InterruptedException {
    String messageString = "Java client e2e test message over Amqps protocol";
    Message msg = new Message(messageString);
    DeviceClient client = new DeviceClient(DeviceConnectionString.get(iotHubConnectionString, deviceAmqps), IotHubClientProtocol.AMQPS);
    client.open();
    for (int i = 0; i < NUM_MESSAGES_PER_CONNECTION; ++i) {
        try {
            Success messageSent = new Success();
            EventCallback callback = new EventCallback();
            client.sendEventAsync(msg, callback, messageSent);
            Integer waitDuration = 0;
            while (!messageSent.getResult()) {
                Thread.sleep(RETRY_MILLISECONDS);
                if ((waitDuration += RETRY_MILLISECONDS) > SEND_TIMEOUT_MILLISECONDS) {
                    break;
                }
            }
            if (!messageSent.getResult()) {
                Assert.fail("Sending message over AMQPS protocol failed");
            }
        } catch (Exception e) {
            Assert.fail("Sending message over AMQPS protocol failed");
        }
    }
    client.closeNow();
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) DeviceClient(com.microsoft.azure.sdk.iot.device.DeviceClient) DeviceConnectionString(tests.integration.com.microsoft.azure.sdk.iot.device.DeviceConnectionString) EventCallback(tests.integration.com.microsoft.azure.sdk.iot.device.EventCallback) Success(tests.integration.com.microsoft.azure.sdk.iot.device.Success) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException) Test(org.junit.Test)

Example 3 with EventCallback

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

the class SendMessagesIT method SendMessagesOverMqtt.

@Test
public void SendMessagesOverMqtt() throws URISyntaxException, IOException {
    String messageString = "Java client e2e test message over Mqtt protocol";
    Message msg = new Message(messageString);
    DeviceClient client = new DeviceClient(DeviceConnectionString.get(iotHubConnectionString, deviceMqtt), IotHubClientProtocol.MQTT);
    client.open();
    for (int i = 0; i < NUM_MESSAGES_PER_CONNECTION; ++i) {
        try {
            Success messageSent = new Success();
            EventCallback callback = new EventCallback();
            client.sendEventAsync(msg, callback, messageSent);
            Integer waitDuration = 0;
            while (!messageSent.getResult()) {
                Thread.sleep(RETRY_MILLISECONDS);
                if ((waitDuration += RETRY_MILLISECONDS) > SEND_TIMEOUT_MILLISECONDS) {
                    break;
                }
            }
            if (!messageSent.getResult()) {
                Assert.fail("Sending message over MQTT protocol failed");
            }
        } catch (Exception e) {
            Assert.fail("Sending message over MQTT protocol failed");
        }
    }
    client.closeNow();
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) DeviceClient(com.microsoft.azure.sdk.iot.device.DeviceClient) DeviceConnectionString(tests.integration.com.microsoft.azure.sdk.iot.device.DeviceConnectionString) EventCallback(tests.integration.com.microsoft.azure.sdk.iot.device.EventCallback) Success(tests.integration.com.microsoft.azure.sdk.iot.device.Success) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) IotHubException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubException) Test(org.junit.Test)

Aggregations

DeviceClient (com.microsoft.azure.sdk.iot.device.DeviceClient)3 Message (com.microsoft.azure.sdk.iot.device.Message)3 IotHubException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubException)3 IOException (java.io.IOException)3 URISyntaxException (java.net.URISyntaxException)3 Test (org.junit.Test)3 DeviceConnectionString (tests.integration.com.microsoft.azure.sdk.iot.device.DeviceConnectionString)3 EventCallback (tests.integration.com.microsoft.azure.sdk.iot.device.EventCallback)3 Success (tests.integration.com.microsoft.azure.sdk.iot.device.Success)3