Search in sources :

Example 1 with RetryDecision

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

the class NoRetryTest method VerifyShouldRetryResult.

// Tests_SRS_NORETRY_28_001: [The function shall return the false and 0 as the RetryDecision despite on inputs.]
@Test
public void VerifyShouldRetryResult() {
    // arrange
    RetryDecision expected = new RetryDecision(false, 0);
    // act
    RetryDecision actual = retryNoRetry.getRetryDecision(this.currentRetryCount, this.lastException);
    // assert
    assertEquals(expected.shouldRetry(), actual.shouldRetry());
    assertEquals(expected.getDuration(), actual.getDuration());
}
Also used : RetryDecision(com.microsoft.azure.sdk.iot.device.transport.RetryDecision) Test(org.junit.Test)

Example 2 with RetryDecision

use of com.microsoft.azure.sdk.iot.device.transport.RetryDecision 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 RetryDecision

use of com.microsoft.azure.sdk.iot.device.transport.RetryDecision 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 RetryDecision

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

the class RetryDecisionTest method constructorSavesParameters.

// Tests_SRS_RETRYDECISION_28_001: [The constructor shall save the duration and getRetryDecision]
// Tests_SRS_RETRYDECISION_28_002: [The function shall return the value of getRetryDecision]
// Tests_SRS_RETRYDECISION_28_003: [The function shall return the value of duration]
@Test
public void constructorSavesParameters() {
    // act
    final RetryDecision retryDecisionTest = new RetryDecision(true, 10);
    // assert
    assertTrue(retryDecisionTest.shouldRetry());
    assertEquals(10, retryDecisionTest.getDuration());
}
Also used : RetryDecision(com.microsoft.azure.sdk.iot.device.transport.RetryDecision) Test(org.junit.Test)

Example 5 with RetryDecision

use of com.microsoft.azure.sdk.iot.device.transport.RetryDecision 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

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