use of com.microsoft.azure.sdk.iot.device.transport.ExponentialBackoffWithJitter in project azure-iot-sdk-java by Azure.
the class ExponentialBackoffWithJitterTest method shouldRetryResultRetry1stTime.
// 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 shouldRetryResultRetry1stTime() {
// arrange
final RetryPolicy exp = new ExponentialBackoffWithJitter(10000, 10, 100, 10, true);
final double deltaBackoffLowBound = 10 * 0.8;
final int count = 2;
Deencapsulation.setField(exp, "random", mockedRandom);
new NonStrictExpectations() {
{
mockedRandom.nextInt(anyInt);
result = 0;
}
};
// act
RetryDecision actual = exp.getRetryDecision(count, null);
// assert
int expected = (int) ((Math.pow(2.0, (double) count) - 1.0) * deltaBackoffLowBound) + 10;
assertTrue(actual.shouldRetry());
assertEquals(expected, actual.getDuration());
}
use of com.microsoft.azure.sdk.iot.device.transport.ExponentialBackoffWithJitter in project azure-iot-sdk-java by Azure.
the class ExponentialBackoffWithJitterTest method shouldRetryResultWithOnlyCurrentRetryCount.
// 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 shouldRetryResultWithOnlyCurrentRetryCount() {
// arrange
final RetryPolicy exp = new ExponentialBackoffWithJitter(10, 0, 0, 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(0, actual.getDuration());
}
use of com.microsoft.azure.sdk.iot.device.transport.ExponentialBackoffWithJitter in project azure-iot-sdk-java by Azure.
the class ExponentialBackoffWithJitterTest method constructorSavesParameterToLocal.
// Tests_SRS_EXPONENTIALBACKOFF_28_002: [Constructor should save retryCount, minBackoff, maxBackoff, deltaBackoff and firstFastRetry]
@Test
public void constructorSavesParameterToLocal() {
// act
final RetryPolicy exp = new ExponentialBackoffWithJitter(10, 2 * 1000, 2 * 1000, 2 * 1000, false);
// assert
assertEquals(10, Deencapsulation.getField(exp, "retryCount"));
assertEquals(2 * 1000L, Deencapsulation.getField(exp, "minBackoff"));
assertEquals(2 * 1000L, Deencapsulation.getField(exp, "maxBackoff"));
assertEquals(2 * 1000L, Deencapsulation.getField(exp, "deltaBackoff"));
assertFalse((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 shouldRetryResultWithFirstFastRetry.
// Tests_SRS_EXPONENTIALBACKOFF_28_003: [The function shall indicate immediate retry on first retry if firstFastRetry is true]
@Test
public void shouldRetryResultWithFirstFastRetry() {
// arrange
final RetryPolicy exp = new ExponentialBackoffWithJitter(10, 100, 10 * 1000, 100, true);
RetryDecision expected = new RetryDecision(true, 0);
// act
RetryDecision actual = exp.getRetryDecision(0, null);
// assert
assertTrue(actual.shouldRetry());
assertEquals(0, actual.getDuration());
}
use of com.microsoft.azure.sdk.iot.device.transport.ExponentialBackoffWithJitter in project azure-iot-sdk-java by Azure.
the class InternalClientTest method setRetryPolicySetPolicy.
// Tests_SRS_INTERNALCLIENT_28_001: [The function shall set the device config's RetryPolicy .]
@Test
public void setRetryPolicySetPolicy() throws URISyntaxException {
// arrange
final IotHubClientProtocol protocol = IotHubClientProtocol.AMQPS;
InternalClient client = Deencapsulation.newInstance(InternalClient.class, new Class[] { IotHubConnectionString.class, IotHubClientProtocol.class, long.class, long.class, ClientOptions.class }, mockIotHubConnectionString, protocol, SEND_PERIOD, RECEIVE_PERIOD, null);
Deencapsulation.setField(client, "config", mockConfig);
// act
Deencapsulation.invoke(client, "setRetryPolicy", new ExponentialBackoffWithJitter());
// assert
new Verifications() {
{
mockConfig.setRetryPolicy((RetryPolicy) any);
times = 1;
}
};
}
Aggregations