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"));
}
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());
}
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());
}
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);
}
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);
}
Aggregations