use of cn.taketoday.retry.RetryStatistics in project today-infrastructure by TAKETODAY.
the class StatisticsListenerTests method testStatelessRecovery.
@Test
public void testStatelessRecovery() throws Throwable {
RetryTemplate retryTemplate = new RetryTemplate();
retryTemplate.setListeners(new RetryListener[] { listener });
for (int x = 1; x <= 10; x++) {
MockRetryCallback callback = new MockRetryCallback();
callback.setAttemptsBeforeSuccess(x + 1);
retryTemplate.setRetryPolicy(new SimpleRetryPolicy(x));
retryTemplate.execute(callback, new RecoveryCallback<Object>() {
@Override
public Object recover(RetryContext context) throws Exception {
return null;
}
});
assertEquals(x, callback.attempts);
RetryStatistics stats = repository.findOne("test");
// System.err.println(stats);
assertNotNull(stats);
assertEquals(x, stats.getRecoveryCount());
assertEquals((x + 1) * x / 2, stats.getStartedCount());
assertEquals(stats.getStartedCount(), stats.getErrorCount());
}
}
use of cn.taketoday.retry.RetryStatistics in project today-infrastructure by TAKETODAY.
the class StatisticsListenerTests method testStatelessSuccessful.
@Test
public void testStatelessSuccessful() throws Throwable {
RetryTemplate retryTemplate = new RetryTemplate();
retryTemplate.setListeners(new RetryListener[] { listener });
for (int x = 1; x <= 10; x++) {
MockRetryCallback callback = new MockRetryCallback();
callback.setAttemptsBeforeSuccess(x);
retryTemplate.setRetryPolicy(new SimpleRetryPolicy(x));
retryTemplate.execute(callback);
assertEquals(x, callback.attempts);
RetryStatistics stats = repository.findOne("test");
// System.err.println(stats);
assertNotNull(stats);
assertEquals(x, stats.getCompleteCount());
assertEquals((x + 1) * x / 2, stats.getStartedCount());
assertEquals(stats.getStartedCount(), stats.getErrorCount() + x);
}
}
use of cn.taketoday.retry.RetryStatistics in project today-infrastructure by TAKETODAY.
the class StatisticsListenerTests method testStatefulSuccessful.
@Test
public void testStatefulSuccessful() throws Throwable {
RetryTemplate retryTemplate = new RetryTemplate();
retryTemplate.setListeners(new RetryListener[] { listener });
RetryState state = new DefaultRetryState("foo");
for (int x = 1; x <= 10; x++) {
MockRetryCallback callback = new MockRetryCallback();
callback.setAttemptsBeforeSuccess(x);
retryTemplate.setRetryPolicy(new SimpleRetryPolicy(x));
for (int i = 0; i < x; i++) {
try {
retryTemplate.execute(callback, state);
} catch (Exception e) {
// don't care
}
}
assertEquals(x, callback.attempts);
RetryStatistics stats = repository.findOne("test");
// System.err.println(stats);
assertNotNull(stats);
assertEquals(x, stats.getCompleteCount());
assertEquals((x + 1) * x / 2, stats.getStartedCount());
assertEquals(stats.getStartedCount(), stats.getErrorCount() + x);
}
}
use of cn.taketoday.retry.RetryStatistics in project today-framework by TAKETODAY.
the class CircuitBreakerInterceptorStatisticsTests method testCircuitOpenWhenNotRetryable.
@Test
public void testCircuitOpenWhenNotRetryable() throws Throwable {
Object result = callback.service("one");
RetryStatistics stats = repository.findOne("test");
// System.err.println(stats);
assertEquals(1, stats.getStartedCount());
assertEquals(RECOVERED, result);
result = callback.service("two");
assertEquals(RECOVERED, result);
assertEquals("There should be two recoveries", 2, stats.getRecoveryCount());
assertEquals("There should only be one error because the circuit is now open", 1, stats.getErrorCount());
}
use of cn.taketoday.retry.RetryStatistics in project today-framework by TAKETODAY.
the class StatisticsListenerTests method testStatelessSuccessful.
@Test
public void testStatelessSuccessful() throws Throwable {
RetryTemplate retryTemplate = new RetryTemplate();
retryTemplate.setListeners(new RetryListener[] { listener });
for (int x = 1; x <= 10; x++) {
MockRetryCallback callback = new MockRetryCallback();
callback.setAttemptsBeforeSuccess(x);
retryTemplate.setRetryPolicy(new SimpleRetryPolicy(x));
retryTemplate.execute(callback);
assertEquals(x, callback.attempts);
RetryStatistics stats = repository.findOne("test");
// System.err.println(stats);
assertNotNull(stats);
assertEquals(x, stats.getCompleteCount());
assertEquals((x + 1) * x / 2, stats.getStartedCount());
assertEquals(stats.getStartedCount(), stats.getErrorCount() + x);
}
}
Aggregations