Search in sources :

Example 1 with CorrelationDetailsLoggingAssert.buildExceptionMessage

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

the class TransportClientTests method uploadToBlobAsyncSingleFileAndTelemetry.

@Test
@ContinuousIntegrationTest
public void uploadToBlobAsyncSingleFileAndTelemetry() throws Exception {
    // arrange
    testInstance.setup(false);
    setUpFileUploadState();
    testInstance.transportClient.open();
    ExecutorService executor = Executors.newFixedThreadPool(2);
    // act
    for (int j = 0; j < testInstance.clientArrayList.size(); j++) {
        for (int i = 1; i < MAX_FILES_TO_UPLOAD; i++) {
            final int indexI = i;
            final int indexJ = j;
            executor.submit(() -> {
                try {
                    ((DeviceClient) testInstance.clientArrayList.get(indexJ)).uploadToBlobAsync(testInstance.fileUploadState[indexI].blobName, testInstance.fileUploadState[indexI].fileInputStream, testInstance.fileUploadState[indexI].fileLength, new FileUploadCallback(), testInstance.fileUploadState[indexI]);
                } catch (IOException e) {
                    Assert.fail(buildExceptionMessage(e.getMessage(), testInstance.clientArrayList.get(indexJ)));
                }
            });
            executor.submit(() -> testInstance.clientArrayList.get(indexJ).sendEventAsync(new Message(testInstance.messageStates[indexI].messageBody), new FileUploadCallback(), testInstance.messageStates[indexI]));
            // assert
            FileUploadNotification fileUploadNotification = testInstance.fileUploadNotificationReceiver.receive(MAXIMUM_TIME_TO_WAIT_FOR_IOTHUB_MILLISECONDS);
            Assert.assertNotNull(buildExceptionMessage("file upload notification was null", testInstance.clientArrayList.get(indexJ)), fileUploadNotification);
            verifyNotification(fileUploadNotification, testInstance.fileUploadState[i], testInstance.clientArrayList.get(indexJ));
            Assert.assertTrue(buildExceptionMessage("File upload callback was not triggered for file upload attempt " + i, testInstance.clientArrayList.get(indexJ)), testInstance.fileUploadState[i].isCallBackTriggered);
            Assert.assertEquals(buildExceptionMessage("File upload status was not successful on attempt " + i + ", status was: " + testInstance.fileUploadState[i].fileUploadStatus, testInstance.clientArrayList.get(indexJ)), testInstance.fileUploadState[i].fileUploadStatus, SUCCESS);
            Assert.assertEquals(buildExceptionMessage("Message status was not successful on attempt " + i + ", status was: " + testInstance.messageStates[i].messageStatus, testInstance.clientArrayList.get(indexJ)), testInstance.messageStates[i].messageStatus, SUCCESS);
        }
    }
    executor.shutdown();
    if (!executor.awaitTermination(MULTITHREADED_WAIT_TIMEOUT_MILLISECONDS, TimeUnit.MILLISECONDS)) {
        executor.shutdownNow();
    }
    for (int i = 1; i < MAX_FILES_TO_UPLOAD; i++) {
        Assert.assertEquals(CorrelationDetailsLoggingAssert.buildExceptionMessage("File" + i + " has no notification", testInstance.clientArrayList), testInstance.fileUploadState[i].fileUploadNotificationReceived, SUCCESS);
    }
    testInstance.transportClient.closeNow();
    tearDownFileUploadState();
}
Also used : Message(com.microsoft.azure.sdk.iot.device.Message) CorrelationDetailsLoggingAssert.buildExceptionMessage(tests.integration.com.microsoft.azure.sdk.iot.helpers.CorrelationDetailsLoggingAssert.buildExceptionMessage) 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) StandardTierHubOnlyTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)

Aggregations

Message (com.microsoft.azure.sdk.iot.device.Message)1 IOException (java.io.IOException)1 ExecutorService (java.util.concurrent.ExecutorService)1 CorrelationDetailsLoggingAssert.buildExceptionMessage (tests.integration.com.microsoft.azure.sdk.iot.helpers.CorrelationDetailsLoggingAssert.buildExceptionMessage)1 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)1 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)1 StandardTierHubOnlyTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.StandardTierHubOnlyTest)1