Search in sources :

Example 1 with RetryPolicy

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

the class ExponentialBackoffWithJitterTest method constructorHaveDefaultValues.

// Tests_SRS_EXPONENTIALBACKOFF_28_006: [Constructor should have default values retryCount, minBackoff, maxBackoff, deltaBackoff and firstFastRetry]
@Test
public void constructorHaveDefaultValues() {
    // act
    final RetryPolicy exp = new ExponentialBackoffWithJitter();
    // assert
    assertEquals(Integer.MAX_VALUE, Deencapsulation.getField(exp, "retryCount"));
    assertEquals(100L, Deencapsulation.getField(exp, "minBackoff"));
    assertEquals(10 * 1000L, Deencapsulation.getField(exp, "maxBackoff"));
    assertEquals(100L, Deencapsulation.getField(exp, "deltaBackoff"));
    assertTrue((boolean) Deencapsulation.getField(exp, "firstFastRetry"));
}
Also used : RetryPolicy(com.microsoft.azure.sdk.iot.device.transport.RetryPolicy) ExponentialBackoffWithJitter(com.microsoft.azure.sdk.iot.device.transport.ExponentialBackoffWithJitter) Test(org.junit.Test)

Example 2 with RetryPolicy

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

the class ExponentialBackoffWithJitterTest method shouldRetryResultWithMinMaxBackOffReturnsMinBackOff.

// Tests_SRS_EXPONENTIALBACKOFF_28_005: [The function shall return waitTime according to
// F(x) = min(Cmin+ (2^(x-1)-1) * rand(C * (1 – Jd), C*(1-Ju)), Cmax) where  x is the xth retry.]
@Test
public void shouldRetryResultWithMinMaxBackOffReturnsMinBackOff() {
    // arrange
    final RetryPolicy exp = new ExponentialBackoffWithJitter(10, 10, 100, 0, true);
    Deencapsulation.setField(exp, "random", mockedRandom);
    new NonStrictExpectations() {

        {
            mockedRandom.nextInt(anyInt);
            result = 0;
        }
    };
    // act
    RetryDecision actual = exp.getRetryDecision(1, null);
    // assert
    assertTrue(actual.shouldRetry());
    assertEquals(10, actual.getDuration());
}
Also used : RetryDecision(com.microsoft.azure.sdk.iot.device.transport.RetryDecision) RetryPolicy(com.microsoft.azure.sdk.iot.device.transport.RetryPolicy) NonStrictExpectations(mockit.NonStrictExpectations) ExponentialBackoffWithJitter(com.microsoft.azure.sdk.iot.device.transport.ExponentialBackoffWithJitter) Test(org.junit.Test)

Example 3 with RetryPolicy

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

the class ExponentialBackoffWithJitterTest method shouldRetryResultWithLargeCurrentRetryCountReturnsMaxBackOff.

// Tests_SRS_EXPONENTIALBACKOFF_28_005: [The function shall return waitTime according to
// F(x) = min(Cmin+ (2^(x-1)-1) * rand(C * (1 – Jd), C*(1-Ju)), Cmax) where  x is the xth retry.]
@Test
public void shouldRetryResultWithLargeCurrentRetryCountReturnsMaxBackOff() {
    // arrange
    final RetryPolicy exp = new ExponentialBackoffWithJitter(10000, 10, 100, 10, true);
    Deencapsulation.setField(exp, "random", mockedRandom);
    new NonStrictExpectations() {

        {
            mockedRandom.nextInt(anyInt);
            result = 0;
        }
    };
    // act
    RetryDecision actual = exp.getRetryDecision(999, null);
    // assert
    assertTrue(actual.shouldRetry());
    assertEquals(100, actual.getDuration());
}
Also used : RetryDecision(com.microsoft.azure.sdk.iot.device.transport.RetryDecision) RetryPolicy(com.microsoft.azure.sdk.iot.device.transport.RetryPolicy) NonStrictExpectations(mockit.NonStrictExpectations) ExponentialBackoffWithJitter(com.microsoft.azure.sdk.iot.device.transport.ExponentialBackoffWithJitter) Test(org.junit.Test)

Example 4 with RetryPolicy

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

the class DeviceClientConfigTest method getRetryPolicyReturnsSavedPolicy.

// Tests_SRS_DEVICECLIENTCONFIG_28_004: [This function shall return the saved RetryPolicy object.]
@Test
public void getRetryPolicyReturnsSavedPolicy() {
    // arrange
    DeviceClientConfig config = Deencapsulation.newInstance(DeviceClientConfig.class, mockIotHubConnectionString);
    Deencapsulation.setField(config, "retryPolicy", mockRetryPolicy);
    // act
    RetryPolicy actual = config.getRetryPolicy();
    // assert
    assertEquals(mockRetryPolicy, actual);
}
Also used : RetryPolicy(com.microsoft.azure.sdk.iot.device.transport.RetryPolicy) Test(org.junit.Test)

Example 5 with RetryPolicy

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

the class ExponentialBackoffWithJitterTest method shouldRetryResultWithNoFirstFastRetry.

// Tests_SRS_EXPONENTIALBACKOFF_28_004: [The function shall return non-zero wait time on first retry if firstFastRetry is false]
@Test
public void shouldRetryResultWithNoFirstFastRetry() {
    // arrange
    final RetryPolicy exp = new ExponentialBackoffWithJitter(10, 100, 10 * 1000, 100, false);
    // act
    RetryDecision actual = exp.getRetryDecision(0, null);
    // assert
    assertTrue(actual.shouldRetry());
    assertTrue(actual.getDuration() > 0);
}
Also used : RetryDecision(com.microsoft.azure.sdk.iot.device.transport.RetryDecision) RetryPolicy(com.microsoft.azure.sdk.iot.device.transport.RetryPolicy) ExponentialBackoffWithJitter(com.microsoft.azure.sdk.iot.device.transport.ExponentialBackoffWithJitter) Test(org.junit.Test)

Aggregations

RetryPolicy (com.microsoft.azure.sdk.iot.device.transport.RetryPolicy)9 Test (org.junit.Test)9 ExponentialBackoffWithJitter (com.microsoft.azure.sdk.iot.device.transport.ExponentialBackoffWithJitter)8 RetryDecision (com.microsoft.azure.sdk.iot.device.transport.RetryDecision)6 NonStrictExpectations (mockit.NonStrictExpectations)4