use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class SimpleRetryPolicyTests method testRetryCount.
@Test
public void testRetryCount() throws Exception {
SimpleRetryPolicy policy = new SimpleRetryPolicy();
RetryContext context = policy.open(null);
assertNotNull(context);
policy.registerThrowable(context, null);
assertEquals(0, context.getRetryCount());
policy.registerThrowable(context, new RuntimeException("foo"));
assertEquals(1, context.getRetryCount());
assertEquals("foo", context.getLastThrowable().getMessage());
}
use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class TimeoutRetryPolicyTests method testTimeoutPreventsRetry.
@Test
public void testTimeoutPreventsRetry() throws Exception {
TimeoutRetryPolicy policy = new TimeoutRetryPolicy();
policy.setTimeout(100);
RetryContext context = policy.open(null);
policy.registerThrowable(context, new Exception());
assertTrue(policy.canRetry(context));
Thread.sleep(200);
assertFalse(policy.canRetry(context));
policy.close(context);
}
use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class TimeoutRetryPolicyTests method testRetryCount.
@Test
public void testRetryCount() throws Exception {
TimeoutRetryPolicy policy = new TimeoutRetryPolicy();
RetryContext context = policy.open(null);
assertNotNull(context);
policy.registerThrowable(context, null);
assertEquals(0, context.getRetryCount());
policy.registerThrowable(context, new RuntimeException("foo"));
assertEquals(1, context.getRetryCount());
assertEquals("foo", context.getLastThrowable().getMessage());
}
use of cn.taketoday.retry.RetryContext in project today-infrastructure by TAKETODAY.
the class CircuitBreakerStatisticsTests method init.
@Before
public void init() {
this.callback = new MockRetryCallback();
this.recovery = new RecoveryCallback<Object>() {
@Override
public Object recover(RetryContext context) throws Exception {
return RECOVERED;
}
};
this.retryTemplate = new RetryTemplate();
this.cache = new MapRetryContextCache();
this.retryTemplate.setRetryContextCache(this.cache);
retryTemplate.setListeners(new RetryListener[] { listener });
this.callback.setAttemptsBeforeSuccess(1);
// No rollback by default (so exceptions are not rethrown)
this.state = new DefaultRetryState("retry", new BinaryExceptionClassifier(false));
}
use of cn.taketoday.retry.RetryContext 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());
}
}
Aggregations