use of cn.taketoday.retry.RetryListener in project today-framework by TAKETODAY.
the class RetryListenerTests method testCloseInterceptors.
@Test
public void testCloseInterceptors() throws Throwable {
template.setListeners(new RetryListener[] { new RetryListener() {
public <T, E extends Throwable> void close(RetryContext context, RetryCallback<T, E> callback, Throwable t) {
count++;
list.add("1:" + count);
}
}, new RetryListener() {
public <T, E extends Throwable> void close(RetryContext context, RetryCallback<T, E> callback, Throwable t) {
count++;
list.add("2:" + count);
}
} });
template.execute(new RetryCallback<String, Exception>() {
public String doWithRetry(RetryContext context) throws Exception {
return null;
}
});
assertEquals(2, count);
assertEquals(2, list.size());
// interceptors are called in reverse order on close...
assertEquals("2:1", list.get(0));
}
use of cn.taketoday.retry.RetryListener in project today-framework by TAKETODAY.
the class RetryListenerTests method testOnError.
@Test
public void testOnError() throws Throwable {
template.setRetryPolicy(new NeverRetryPolicy());
template.setListeners(new RetryListener[] { new RetryListener() {
public <T, E extends Throwable> void onError(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) {
list.add("1");
}
}, new RetryListener() {
public <T, E extends Throwable> void onError(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) {
list.add("2");
}
} });
try {
template.execute(new RetryCallback<String, Exception>() {
public String doWithRetry(RetryContext context) throws Exception {
count++;
throw new IllegalStateException("foo");
}
});
fail("Expected IllegalStateException");
} catch (IllegalStateException e) {
assertEquals("foo", e.getMessage());
}
// never retry so callback is executed once
assertEquals(1, count);
assertEquals(2, list.size());
// interceptors are called in reverse order on error...
assertEquals("2", list.get(0));
}
use of cn.taketoday.retry.RetryListener in project today-framework by TAKETODAY.
the class RetryOperationsInterceptorTests method setUp.
@Before
public void setUp() throws Exception {
this.interceptor = new RetryOperationsInterceptor();
RetryTemplate retryTemplate = new RetryTemplate();
final AtomicBoolean calledFirst = new AtomicBoolean();
retryTemplate.registerListener(new RetryListener() {
@Override
public <T, E extends Throwable> boolean open(RetryContext context, RetryCallback<T, E> callback) {
calledFirst.set(true);
return true;
}
@Override
public <T, E extends Throwable> void close(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) {
RetryOperationsInterceptorTests.this.context = context;
}
});
retryTemplate.registerListener(new RetryListener() {
@Override
public <T, E extends Throwable> boolean open(RetryContext context, RetryCallback<T, E> callback) {
assertFalse(calledFirst.get());
return true;
}
}, 0);
this.interceptor.setRetryOperations(retryTemplate);
this.target = new ServiceImpl();
this.service = ProxyFactory.getProxy(Service.class, new SingletonTargetSource(this.target));
count = 0;
transactionCount = 0;
}
use of cn.taketoday.retry.RetryListener in project today-framework by TAKETODAY.
the class StatefulRetryOperationsInterceptorTests method setUp.
@BeforeEach
public void setUp() throws Exception {
interceptor = new StatefulRetryOperationsInterceptor();
retryTemplate.registerListener(new RetryListener() {
@Override
public <T, E extends Throwable> void close(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) {
StatefulRetryOperationsInterceptorTests.this.context = context;
}
});
interceptor.setRetryOperations(retryTemplate);
service = ProxyFactory.getProxy(Service.class, new SingletonTargetSource(new ServiceImpl()));
transformer = ProxyFactory.getProxy(Transformer.class, new SingletonTargetSource(new TransformerImpl()));
count = 0;
}
use of cn.taketoday.retry.RetryListener in project today-framework by TAKETODAY.
the class RetryListenerTests method testOpenInterceptors.
@Test
public void testOpenInterceptors() throws Throwable {
template.setListeners(new RetryListener[] { new RetryListener() {
public <T, E extends Throwable> boolean open(RetryContext context, RetryCallback<T, E> callback) {
count++;
list.add("1:" + count);
return true;
}
}, new RetryListener() {
public <T, E extends Throwable> boolean open(RetryContext context, RetryCallback<T, E> callback) {
count++;
list.add("2:" + count);
return true;
}
} });
template.execute(new RetryCallback<String, Exception>() {
public String doWithRetry(RetryContext context) throws Exception {
return null;
}
});
assertEquals(2, count);
assertEquals(2, list.size());
assertEquals("1:1", list.get(0));
}
Aggregations