Search in sources :

Example 1 with NoRetry

use of com.microsoft.azure.sdk.iot.device.transport.NoRetry in project azure-iot-sdk-java by Azure.

the class SendMessagesErrInjTests method sendMessagesWithTcpConnectionDropNotifiesUserIfRetryExpires.

@Test
@ContinuousIntegrationTest
public void sendMessagesWithTcpConnectionDropNotifiesUserIfRetryExpires() throws Exception {
    if (testInstance.protocol == HTTPS || (testInstance.protocol == MQTT_WS && testInstance.authenticationType != SAS) || testInstance.useHttpProxy) {
        // MQTT_WS + x509 is not supported for sending messages
        return;
    }
    this.testInstance.setup();
    testInstance.identity.getClient().setRetryPolicy(new NoRetry());
    Message tcpConnectionDropErrorInjectionMessageUnrecoverable = ErrorInjectionHelper.tcpConnectionDropErrorInjectionMessage(1, 100000);
    IotHubServicesCommon.sendMessagesExpectingUnrecoverableConnectionLossAndTimeout(testInstance.identity.getClient(), testInstance.protocol, tcpConnectionDropErrorInjectionMessageUnrecoverable, testInstance.authenticationType);
    // reset back to default
    testInstance.identity.getClient().setRetryPolicy(new ExponentialBackoffWithJitter());
}
Also used : NoRetry(com.microsoft.azure.sdk.iot.device.transport.NoRetry) ExponentialBackoffWithJitter(com.microsoft.azure.sdk.iot.device.transport.ExponentialBackoffWithJitter) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest) IotHubTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest) ErrInjTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ErrInjTest) Test(org.junit.Test) ContinuousIntegrationTest(tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)

Example 2 with NoRetry

use of com.microsoft.azure.sdk.iot.device.transport.NoRetry in project azure-iot-sdk-java by Azure.

the class SendMessagesErrInjTests method errorInjectionTestFlowNoDisconnect.

private void errorInjectionTestFlowNoDisconnect(Message errorInjectionMessage, IotHubStatusCode expectedStatus, boolean noRetry) throws IOException, IotHubException, URISyntaxException, InterruptedException, ModuleClientException, GeneralSecurityException {
    // Arrange
    if (noRetry) {
        testInstance.identity.getClient().setRetryPolicy(new NoRetry());
    }
    testInstance.identity.getClient().open();
    // Act
    MessageAndResult errorInjectionMsgAndRet = new MessageAndResult(errorInjectionMessage, IotHubStatusCode.OK_EMPTY);
    IotHubServicesCommon.sendMessageAndWaitForResponse(testInstance.identity.getClient(), errorInjectionMsgAndRet, RETRY_MILLISECONDS, SEND_TIMEOUT_MILLISECONDS, this.testInstance.protocol);
    // time for the error injection to take effect on the service side
    Thread.sleep(2000);
    MessageAndResult normalMessageAndExpectedResult = new MessageAndResult(new Message("test message"), expectedStatus);
    IotHubServicesCommon.sendMessageAndWaitForResponse(testInstance.identity.getClient(), normalMessageAndExpectedResult, RETRY_MILLISECONDS, SEND_TIMEOUT_MILLISECONDS, this.testInstance.protocol);
    testInstance.identity.getClient().closeNow();
}
Also used : NoRetry(com.microsoft.azure.sdk.iot.device.transport.NoRetry)

Example 3 with NoRetry

use of com.microsoft.azure.sdk.iot.device.transport.NoRetry in project azure-iot-sdk-java by Azure.

the class TransportClientTest method setRetryPolicySetIfOneRegisteredDeviceClient.

// Tests_SRS_TRANSPORTCLIENT_28_002: [The function shall set the retry policies to all registered device clients.]
@Test
public void setRetryPolicySetIfOneRegisteredDeviceClient() {
    // arrange
    IotHubClientProtocol iotHubClientProtocol = IotHubClientProtocol.AMQPS;
    TransportClient transportClient = new TransportClient(iotHubClientProtocol);
    ArrayList<DeviceClient> deviceClientList = new ArrayList<>();
    deviceClientList.add(mockDeviceClient);
    Deencapsulation.setField(transportClient, "deviceClientList", deviceClientList);
    new NonStrictExpectations() {

        {
            mockDeviceClient.getConfig();
            result = mockDeviceClientConfig;
        }
    };
    // act
    transportClient.setRetryPolicy(new NoRetry());
    // assert
    new Verifications() {

        {
            mockDeviceClientConfig.setRetryPolicy((RetryPolicy) any);
            times = 1;
        }
    };
}
Also used : NoRetry(com.microsoft.azure.sdk.iot.device.transport.NoRetry) ArrayList(java.util.ArrayList) Verifications(mockit.Verifications) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 4 with NoRetry

use of com.microsoft.azure.sdk.iot.device.transport.NoRetry in project azure-iot-sdk-java by Azure.

the class TransportClientTest method setRetryPolicyDoNothingIfNoRegisteredDeviceClient.

// Tests_SRS_TRANSPORTCLIENT_28_001: [The function shall throw UnsupportedOperationException if there is no registered device client]
@Test(expected = UnsupportedOperationException.class)
public void setRetryPolicyDoNothingIfNoRegisteredDeviceClient() {
    // arrange
    IotHubClientProtocol iotHubClientProtocol = IotHubClientProtocol.AMQPS;
    TransportClient transportClient = new TransportClient(iotHubClientProtocol);
    ArrayList<DeviceClient> deviceClientList = new ArrayList<>();
    Deencapsulation.setField(transportClient, "deviceClientList", deviceClientList);
    // act
    transportClient.setRetryPolicy(new NoRetry());
}
Also used : NoRetry(com.microsoft.azure.sdk.iot.device.transport.NoRetry) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

NoRetry (com.microsoft.azure.sdk.iot.device.transport.NoRetry)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 ExponentialBackoffWithJitter (com.microsoft.azure.sdk.iot.device.transport.ExponentialBackoffWithJitter)1 NonStrictExpectations (mockit.NonStrictExpectations)1 Verifications (mockit.Verifications)1 ContinuousIntegrationTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ContinuousIntegrationTest)1 ErrInjTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.ErrInjTest)1 IotHubTest (tests.integration.com.microsoft.azure.sdk.iot.helpers.annotations.IotHubTest)1