Search in sources :

Example 11 with ContinuousIntegrationTest

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

the class FileUploadTests method uploadToBlobAsyncMultipleFilesParallel.

@Test(timeout = MAX_MILLISECS_TIMEOUT_KILL_TEST)
@ContinuousIntegrationTest
public void uploadToBlobAsyncMultipleFilesParallel() throws URISyntaxException, IOException, InterruptedException, IotHubException, GeneralSecurityException {
    if (testInstance.withProxy) {
        // No need to do performance test both with and without proxy
        return;
    }
    // arrange
    DeviceClient deviceClient = setUpDeviceClient(testInstance.protocol);
    ExecutorService executor = Executors.newFixedThreadPool(2);
    // act
    for (int i = 1; i < MAX_FILES_TO_UPLOAD; i++) {
        final int index = i;
        executor.submit(() -> {
            try {
                deviceClient.uploadToBlobAsync(testInstance.fileUploadState[index].blobName, testInstance.fileUploadState[index].fileInputStream, testInstance.fileUploadState[index].fileLength, new FileUploadCallback(), testInstance.fileUploadState[index]);
            } catch (IOException e) {
                fail(buildExceptionMessage("IOException occurred during upload: " + Tools.getStackTraceFromThrowable(e), deviceClient));
            }
        });
        // assert
        waitForFileUploadStatusCallbackTriggered(i, deviceClient);
        assertEquals(buildExceptionMessage("Expected SUCCESS but file upload status " + i + " was " + testInstance.fileUploadState[i].fileUploadStatus, deviceClient), SUCCESS, testInstance.fileUploadState[i].fileUploadStatus);
        assertEquals(buildExceptionMessage("Expected SUCCESS but message status " + i + " was " + testInstance.messageStates[i].messageStatus, deviceClient), SUCCESS, testInstance.messageStates[i].messageStatus);
    }
    executor.shutdown();
    if (!executor.awaitTermination(10000, TimeUnit.MILLISECONDS)) {
        executor.shutdownNow();
    }
    tearDownDeviceClient(deviceClient);
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) IOException(java.io.IOException) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) Test(org.junit.Test) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)

Example 12 with ContinuousIntegrationTest

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

the class SendMessagesTests method sendMessagesWithUnusualApplicationProperties.

@Test
@ContinuousIntegrationTest
public void sendMessagesWithUnusualApplicationProperties() throws Exception {
    this.testInstance.setup();
    this.testInstance.identity.getClient().open();
    Message msg = new Message("asdf");
    // All of these characters should be allowed within application properties
    msg.setProperty("TestKey1234!#$%&'*+-^_`|~", "TestValue1234!#$%&'*+-^_`|~()<>@,;:\\\"[]?={} \t");
    // ()<>@,;:\"[]?={}
    IotHubServicesCommon.sendMessageAndWaitForResponse(this.testInstance.identity.getClient(), new MessageAndResult(msg, IotHubStatusCode.OK_EMPTY), RETRY_MILLISECONDS, SEND_TIMEOUT_MILLISECONDS, testInstance.protocol);
    this.testInstance.identity.getClient().closeNow();
}
Also used : MessageAndResult(tests.integration.com.microsoft.azure.sdk.iot.helpers.MessageAndResult) Message(com.microsoft.azure.sdk.iot.device.Message) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) Test(org.junit.Test) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)

Example 13 with ContinuousIntegrationTest

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

the class DeviceTwinWithVersionTests method testUpdateReportedPropertiesWithHigherVersionFailed.

@Test
@StandardTierHubOnlyTest
@ContinuousIntegrationTest
public void testUpdateReportedPropertiesWithHigherVersionFailed() throws IOException, InterruptedException, URISyntaxException, IotHubException {
    // arrange
    createDevice(testInstance.protocol);
    testInstance.deviceTwinWithVersionTestDevice.expectedProperties = new HashSet<>(PROPERTIES);
    // Create the first version of the reported properties.
    testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus = STATUS.UNKNOWN;
    testInstance.deviceTwinWithVersionTestDevice.deviceClient.sendReportedProperties(PROPERTIES);
    Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
    testInstance.deviceTwinWithVersionTestDevice.deviceClient.getDeviceTwin();
    long startTime = System.currentTimeMillis();
    while (!testInstance.deviceTwinWithVersionTestDevice.expectedProperties.isEmpty()) {
        if (System.currentTimeMillis() - startTime > EXPECTED_PROPERTIES_MAX_WAIT_MILLISECONDS) {
            fail(buildExceptionMessage("Timed out waiting for expected property change", testInstance.deviceTwinWithVersionTestDevice.deviceClient));
        }
        Thread.sleep(BREATHE_TIME);
        if (testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus == STATUS.IOTHUB_FAILURE) {
            throw new IOException("IoTHub send Http error code");
        }
        if (testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus == STATUS.BAD_ANSWER) {
            throw new IOException(testInstance.deviceTwinWithVersionTestDevice.exception);
        }
    }
    assertEquals(buildExceptionMessage("Expected 2, but reported properties version was " + testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion, testInstance.deviceTwinWithVersionTestDevice.deviceClient), 2, (int) testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion);
    // New values for the reported properties
    final Set<Property> newValues = new HashSet<Property>() {

        {
            add(new Property(PROPERTY_KEY_1, "newValue1"));
            add(new Property(PROPERTY_KEY_2, "newValue2"));
        }
    };
    testInstance.deviceTwinWithVersionTestDevice.expectedProperties = new HashSet<>(newValues);
    testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus = STATUS.UNKNOWN;
    testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion = null;
    testInstance.deviceTwinWithVersionTestDevice.receivedProperties = new HashSet<>();
    // act
    testInstance.deviceTwinWithVersionTestDevice.deviceClient.sendReportedProperties(newValues, 3);
    // assert
    // test device client
    Thread.sleep(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB);
    while ((testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus != STATUS.BAD_ANSWER) && (testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus != STATUS.IOTHUB_FAILURE)) {
        Thread.sleep(BREATHE_TIME);
    }
    testInstance.deviceTwinWithVersionTestDevice.expectedProperties = new HashSet<>(PROPERTIES);
    testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus = STATUS.UNKNOWN;
    testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion = null;
    testInstance.deviceTwinWithVersionTestDevice.receivedProperties = new HashSet<>();
    testInstance.deviceTwinWithVersionTestDevice.deviceClient.getDeviceTwin();
    startTime = System.currentTimeMillis();
    while (!testInstance.deviceTwinWithVersionTestDevice.expectedProperties.isEmpty()) {
        if (System.currentTimeMillis() - startTime > EXPECTED_PROPERTIES_MAX_WAIT_MILLISECONDS) {
            fail(buildExceptionMessage("Timed out waiting for expected property change", testInstance.deviceTwinWithVersionTestDevice.deviceClient));
        }
        Thread.sleep(BREATHE_TIME);
        if (testInstance.deviceTwinWithVersionTestDevice.deviceTwinStatus == STATUS.BAD_ANSWER) {
            throw new IOException(testInstance.deviceTwinWithVersionTestDevice.exception);
        }
    }
    assertEquals(buildExceptionMessage("Expected 2, but reported properties version was " + testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion, testInstance.deviceTwinWithVersionTestDevice.deviceClient), 2, (int) testInstance.deviceTwinWithVersionTestDevice.reportedPropertyVersion);
    // test service client
    DeviceTwinDevice deviceOnServiceClient = new DeviceTwinDevice(testInstance.deviceTwinWithVersionTestDevice.deviceId);
    testInstance.twinServiceClient.getTwin(deviceOnServiceClient);
    assertEquals(buildExceptionMessage("Expected reported properties version 2 but was " + deviceOnServiceClient.getReportedPropertiesVersion(), testInstance.deviceTwinWithVersionTestDevice.deviceClient), 2, (int) deviceOnServiceClient.getReportedPropertiesVersion());
    Set<Pair> reported = deviceOnServiceClient.getReportedProperties();
    assertSetEquals(PROPERTIES, reported);
}
Also used : DeviceTwinDevice(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice) IOException(java.io.IOException) Property(com.microsoft.azure.sdk.iot.device.DeviceTwin.Property) Pair(com.microsoft.azure.sdk.iot.service.devicetwin.Pair) 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) IntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest) 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)

Example 14 with ContinuousIntegrationTest

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

the class ServiceClientTests method serviceClientValidatesRemoteCertificateWhenGettingFileUploadFeedbackReceiver.

// The IoT Hub instance we use for this test is currently offline, so this test cannot be run
@Ignore
@Test
@ContinuousIntegrationTest
public void serviceClientValidatesRemoteCertificateWhenGettingFileUploadFeedbackReceiver() throws IOException {
    boolean expectedExceptionWasCaught = false;
    ServiceClient serviceClient = ServiceClient.createFromConnectionString(invalidCertificateServerConnectionString, testInstance.protocol);
    try {
        serviceClient.open();
        FileUploadNotificationReceiver receiver = serviceClient.getFileUploadNotificationReceiver();
        receiver.open();
        receiver.receive(1000);
    } catch (IOException e) {
        expectedExceptionWasCaught = true;
    } catch (Exception e) {
        fail(buildExceptionMessage("Expected IOException, but received: " + Tools.getStackTraceFromThrowable(e), hostName));
    }
    assertTrue(buildExceptionMessage("Expected an exception due to service presenting invalid certificate", hostName), expectedExceptionWasCaught);
}
Also used : FileUploadNotificationReceiver(com.microsoft.azure.sdk.iot.service.FileUploadNotificationReceiver) ServiceClient(com.microsoft.azure.sdk.iot.service.ServiceClient) IOException(java.io.IOException) IOException(java.io.IOException) IotHubUnathorizedException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubUnathorizedException) Ignore(org.junit.Ignore) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) IntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest) 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)

Example 15 with ContinuousIntegrationTest

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

the class ServiceClientTests method serviceClientValidatesRemoteCertificateWhenGettingFeedbackReceiver.

// The IoT Hub instance we use for this test is currently offline, so this test cannot be run
@Ignore
@Test
@ContinuousIntegrationTest
public void serviceClientValidatesRemoteCertificateWhenGettingFeedbackReceiver() throws IOException {
    boolean expectedExceptionWasCaught = false;
    ServiceClient serviceClient = ServiceClient.createFromConnectionString(invalidCertificateServerConnectionString, testInstance.protocol);
    try {
        serviceClient.open();
        FeedbackReceiver receiver = serviceClient.getFeedbackReceiver();
        receiver.open();
        receiver.receive(1000);
    } catch (IOException e) {
        expectedExceptionWasCaught = true;
    } catch (Exception e) {
        fail(buildExceptionMessage("Expected IOException, but received: " + Tools.getStackTraceFromThrowable(e), hostName));
    }
    assertTrue(buildExceptionMessage("Expected an exception due to service presenting invalid certificate", hostName), expectedExceptionWasCaught);
}
Also used : ServiceClient(com.microsoft.azure.sdk.iot.service.ServiceClient) FeedbackReceiver(com.microsoft.azure.sdk.iot.service.FeedbackReceiver) IOException(java.io.IOException) IOException(java.io.IOException) IotHubUnathorizedException(com.microsoft.azure.sdk.iot.service.exceptions.IotHubUnathorizedException) Ignore(org.junit.Ignore) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) IntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest) 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

ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)22 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)22 Test (org.junit.Test)20 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)15 IntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.IntegrationTest)14 IOException (java.io.IOException)9 Ignore (org.junit.Ignore)6 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)5 DeviceTwinDevice (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwinDevice)5 IotHubUnathorizedException (com.microsoft.azure.sdk.iot.service.exceptions.IotHubUnathorizedException)5 ExecutorService (java.util.concurrent.ExecutorService)4 DeviceTestManager (tests.integration.com.microsoft.azure.sdk.iot.helpers.DeviceTestManager)4 Device (com.microsoft.azure.sdk.iot.service.Device)3 ServiceClient (com.microsoft.azure.sdk.iot.service.ServiceClient)3 MethodResult (com.microsoft.azure.sdk.iot.service.devicetwin.MethodResult)3 Pair (com.microsoft.azure.sdk.iot.service.devicetwin.Pair)3 ArrayList (java.util.ArrayList)3 Property (com.microsoft.azure.sdk.iot.device.DeviceTwin.Property)2 Message (com.microsoft.azure.sdk.iot.device.Message)2 Module (com.microsoft.azure.sdk.iot.service.Module)2