use of com.dtflys.forest.retryer.BackOffRetryer in project forest by dromara.
the class TestAsyncGetClient method testRetrySimpleGetTimeout.
@Test
public void testRetrySimpleGetTimeout() throws InterruptedException {
server.enqueue(new MockResponse().setHeadersDelay(10, TimeUnit.SECONDS).setBody(EXPECTED));
AtomicReference<BackOffRetryer> retryerAtomicReference = new AtomicReference<>(null);
CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean success = new AtomicBoolean(true);
getClient.retrySimpleGetTimeout((ex, request, response) -> {
success.set(false);
retryerAtomicReference.set((BackOffRetryer) request.getRetryer());
latch.countDown();
});
latch.await(30, TimeUnit.SECONDS);
assertThat(success.get()).isFalse();
BackOffRetryer retryer = retryerAtomicReference.get();
Assertions.assertThat(retryer).isNotNull();
Assertions.assertThat(retryer.getMaxRetryCount()).isEqualTo(2);
Assertions.assertThat(retryer.getMaxRetryInterval()).isEqualTo(500);
Assertions.assertThat(retryer.getWaitedTime()).isEqualTo(500 + 500);
}
use of com.dtflys.forest.retryer.BackOffRetryer in project forest by dromara.
the class TestAsyncGetClient method testRetrySimpleGetError.
@Test
public void testRetrySimpleGetError() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404));
AtomicReference<BackOffRetryer> retryerAtomicReference = new AtomicReference<>(null);
CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean success = new AtomicBoolean(true);
getClient.retrySimpleGetError((ex, request, response) -> {
retryerAtomicReference.set((BackOffRetryer) request.getRetryer());
success.set(false);
latch.countDown();
});
latch.await(10, TimeUnit.SECONDS);
assertThat(success.get()).isFalse();
BackOffRetryer retryer = retryerAtomicReference.get();
Assertions.assertThat(retryer).isNotNull();
Assertions.assertThat(retryer.getMaxRetryCount()).isEqualTo(2);
Assertions.assertThat(retryer.getMaxRetryInterval()).isEqualTo(500);
Assertions.assertThat(retryer.getWaitedTime()).isEqualTo(500 + 500);
}
use of com.dtflys.forest.retryer.BackOffRetryer in project forest by dromara.
the class TestErrorClient method testErrorGetWithRetry.
@Test
public void testErrorGetWithRetry() {
server.enqueue(new MockResponse().setResponseCode(400).setBody(EXPECTED));
AtomicReference<BackOffRetryer> retryerAtomicReference = new AtomicReference<>(null);
getClient.errorGetWithRetry((ex, request, response) -> {
retryerAtomicReference.set((BackOffRetryer) request.getRetryer());
});
BackOffRetryer retryer = retryerAtomicReference.get();
assertThat(retryer).isNotNull();
assertThat(retryer.getMaxRetryCount()).isEqualTo(3);
assertThat(retryer.getMaxRetryInterval()).isEqualTo(2000);
assertThat(retryer.getWaitedTime()).isEqualTo(1000 + 2000 + 2000);
assertThat(retryer.getCurrentRetryCount()).isEqualTo(3);
}
Aggregations