use of org.springframework.retry.support.DefaultRetryState in project spring-integration by spring-projects.
the class SpelExpressionRetryStateGeneratorTests method testBasic.
@Test
public void testBasic() {
SpelExpressionRetryStateGenerator generator = new SpelExpressionRetryStateGenerator("headers['foo']");
RetryState state = generator.determineRetryState(message);
assertEquals("bar", state.getKey());
assertFalse(((DefaultRetryState) state).isForceRefresh());
assertTrue(state.rollbackFor(new RuntimeException()));
}
use of org.springframework.retry.support.DefaultRetryState in project spring-integration by spring-projects.
the class SpelExpressionRetryStateGeneratorTests method testForceRefreshTrue.
@Test
public void testForceRefreshTrue() {
SpelExpressionRetryStateGenerator generator = new SpelExpressionRetryStateGenerator("headers['foo']", "headers['trueHeader']");
RetryState state = generator.determineRetryState(message);
assertEquals("bar", state.getKey());
assertTrue(((DefaultRetryState) state).isForceRefresh());
assertTrue(state.rollbackFor(new RuntimeException()));
}
use of org.springframework.retry.support.DefaultRetryState in project spring-integration by spring-projects.
the class SpelExpressionRetryStateGeneratorTests method testForceRefreshFalse.
@Test
public void testForceRefreshFalse() {
SpelExpressionRetryStateGenerator generator = new SpelExpressionRetryStateGenerator("headers['foo']", "headers['falseHeader']");
RetryState state = generator.determineRetryState(message);
assertEquals("bar", state.getKey());
assertFalse(((DefaultRetryState) state).isForceRefresh());
assertTrue(state.rollbackFor(new RuntimeException()));
}
use of org.springframework.retry.support.DefaultRetryState in project spring-integration by spring-projects.
the class AdvisedMessageHandlerTests method defaultStatefulRetrySucceedOnThirdTry.
@Test
public void defaultStatefulRetrySucceedOnThirdTry() {
final AtomicInteger counter = new AtomicInteger(2);
AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
if (counter.getAndDecrement() > 0) {
throw new RuntimeException("foo");
}
return "bar";
}
};
QueueChannel replies = new QueueChannel();
handler.setOutputChannel(replies);
RequestHandlerRetryAdvice advice = new RequestHandlerRetryAdvice();
advice.setRetryStateGenerator(message -> new DefaultRetryState(message.getHeaders().getId()));
List<Advice> adviceChain = new ArrayList<Advice>();
adviceChain.add(advice);
handler.setAdviceChain(adviceChain);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
Message<String> message = new GenericMessage<String>("Hello, world!");
for (int i = 0; i < 3; i++) {
try {
handler.handleMessage(message);
} catch (Exception e) {
assertTrue(i < 2);
}
}
assertTrue(counter.get() == -1);
Message<?> reply = replies.receive(10000);
assertNotNull(reply);
assertEquals("bar", reply.getPayload());
}
use of org.springframework.retry.support.DefaultRetryState in project spring-integration by spring-projects.
the class AdvisedMessageHandlerTests method defaultStatefulRetryRecoverAfterThirdTry.
@Test
public void defaultStatefulRetryRecoverAfterThirdTry() {
final AtomicInteger counter = new AtomicInteger(3);
AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
if (counter.getAndDecrement() > 0) {
throw new RuntimeException("foo");
}
return "bar";
}
};
QueueChannel replies = new QueueChannel();
handler.setOutputChannel(replies);
RequestHandlerRetryAdvice advice = new RequestHandlerRetryAdvice();
advice.setRetryStateGenerator(message -> new DefaultRetryState(message.getHeaders().getId()));
defaultStatefulRetryRecoverAfterThirdTryGuts(counter, handler, replies, advice);
}
Aggregations