use of com.microsoft.azure.sdk.iot.device.transport.ExponentialBackoffWithJitter 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.ExponentialBackoffWithJitter 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.ExponentialBackoffWithJitter 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.ExponentialBackoffWithJitter 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());
}
use of com.microsoft.azure.sdk.iot.device.transport.ExponentialBackoffWithJitter 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