use of cn.taketoday.retry.policy.MapRetryContextCache 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.policy.MapRetryContextCache in project today-infrastructure by TAKETODAY.
the class StatefulRecoveryRetryTests method testCacheCapacityNotReachedIfRecovered.
@Test
public void testCacheCapacityNotReachedIfRecovered() throws Throwable {
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(1);
this.retryTemplate.setRetryPolicy(retryPolicy);
this.retryTemplate.setRetryContextCache(new MapRetryContextCache(2));
final StringHolder item = new StringHolder("foo");
RetryState state = new DefaultRetryState(item);
RetryCallback<Object, Exception> callback = new RetryCallback<Object, Exception>() {
@Override
public Object doWithRetry(RetryContext context) throws Exception {
StatefulRecoveryRetryTests.this.count++;
throw new RuntimeException("Barf!");
}
};
RecoveryCallback<Object> recoveryCallback = new RecoveryCallback<Object>() {
@Override
public Object recover(RetryContext context) throws Exception {
return null;
}
};
try {
this.retryTemplate.execute(callback, recoveryCallback, state);
fail("Expected RuntimeException");
} catch (RuntimeException e) {
assertEquals("Barf!", e.getMessage());
}
this.retryTemplate.execute(callback, recoveryCallback, state);
RetryContext context = this.retryTemplate.open(retryPolicy, state);
// True after exhausted - the history is reset...
assertEquals(0, context.getRetryCount());
}
use of cn.taketoday.retry.policy.MapRetryContextCache in project today-infrastructure by TAKETODAY.
the class StatefulRecoveryRetryTests method testCacheCapacity.
@Test
public void testCacheCapacity() throws Throwable {
this.retryTemplate.setRetryPolicy(new SimpleRetryPolicy(1));
this.retryTemplate.setRetryContextCache(new MapRetryContextCache(1));
RetryCallback<Object, Exception> callback = context -> {
StatefulRecoveryRetryTests.this.count++;
throw new RuntimeException("Barf!");
};
try {
this.retryTemplate.execute(callback, new DefaultRetryState("foo"));
fail("Expected RuntimeException");
} catch (RuntimeException e) {
assertEquals("Barf!", e.getMessage());
}
try {
this.retryTemplate.execute(callback, new DefaultRetryState("bar"));
fail("Expected RetryException");
} catch (RetryException e) {
String message = e.getNestedMessage();
assertTrue("Message does not contain 'capacity': " + message, message.contains("capacity"));
}
}
use of cn.taketoday.retry.policy.MapRetryContextCache in project today-framework by TAKETODAY.
the class StatefulRecoveryRetryTests method testCacheCapacityNotReachedIfRecovered.
@Test
public void testCacheCapacityNotReachedIfRecovered() throws Throwable {
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(1);
this.retryTemplate.setRetryPolicy(retryPolicy);
this.retryTemplate.setRetryContextCache(new MapRetryContextCache(2));
final StringHolder item = new StringHolder("foo");
RetryState state = new DefaultRetryState(item);
RetryCallback<Object, Exception> callback = new RetryCallback<Object, Exception>() {
@Override
public Object doWithRetry(RetryContext context) throws Exception {
StatefulRecoveryRetryTests.this.count++;
throw new RuntimeException("Barf!");
}
};
RecoveryCallback<Object> recoveryCallback = new RecoveryCallback<Object>() {
@Override
public Object recover(RetryContext context) throws Exception {
return null;
}
};
try {
this.retryTemplate.execute(callback, recoveryCallback, state);
fail("Expected RuntimeException");
} catch (RuntimeException e) {
assertEquals("Barf!", e.getMessage());
}
this.retryTemplate.execute(callback, recoveryCallback, state);
RetryContext context = this.retryTemplate.open(retryPolicy, state);
// True after exhausted - the history is reset...
assertEquals(0, context.getRetryCount());
}
use of cn.taketoday.retry.policy.MapRetryContextCache in project today-framework by TAKETODAY.
the class StatefulRecoveryRetryTests method testCacheCapacity.
@Test
public void testCacheCapacity() throws Throwable {
this.retryTemplate.setRetryPolicy(new SimpleRetryPolicy(1));
this.retryTemplate.setRetryContextCache(new MapRetryContextCache(1));
RetryCallback<Object, Exception> callback = context -> {
StatefulRecoveryRetryTests.this.count++;
throw new RuntimeException("Barf!");
};
try {
this.retryTemplate.execute(callback, new DefaultRetryState("foo"));
fail("Expected RuntimeException");
} catch (RuntimeException e) {
assertEquals("Barf!", e.getMessage());
}
try {
this.retryTemplate.execute(callback, new DefaultRetryState("bar"));
fail("Expected RetryException");
} catch (RetryException e) {
String message = e.getNestedMessage();
assertTrue("Message does not contain 'capacity': " + message, message.contains("capacity"));
}
}
Aggregations