Search in sources :

Example 1 with RetryState

use of org.springframework.retry.RetryState 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()));
}
Also used : DefaultRetryState(org.springframework.retry.support.DefaultRetryState) RetryState(org.springframework.retry.RetryState) Test(org.junit.Test)

Example 2 with RetryState

use of org.springframework.retry.RetryState 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()));
}
Also used : DefaultRetryState(org.springframework.retry.support.DefaultRetryState) RetryState(org.springframework.retry.RetryState) Test(org.junit.Test)

Example 3 with RetryState

use of org.springframework.retry.RetryState 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()));
}
Also used : DefaultRetryState(org.springframework.retry.support.DefaultRetryState) RetryState(org.springframework.retry.RetryState) Test(org.junit.Test)

Example 4 with RetryState

use of org.springframework.retry.RetryState in project spring-integration by spring-projects.

the class RequestHandlerRetryAdvice method doInvoke.

@Override
protected Object doInvoke(final ExecutionCallback callback, Object target, final Message<?> message) throws Exception {
    RetryState retryState = null;
    retryState = this.retryStateGenerator.determineRetryState(message);
    messageHolder.set(message);
    try {
        return this.retryTemplate.execute(context -> callback.cloneAndExecute(), this.recoveryCallback, retryState);
    } catch (MessagingException e) {
        if (e.getFailedMessage() == null) {
            throw new MessagingException(message, "Failed to invoke handler", e);
        }
        throw e;
    } catch (Exception e) {
        throw new MessagingException(message, "Failed to invoke handler", unwrapExceptionIfNecessary(e));
    } finally {
        messageHolder.remove();
    }
}
Also used : MessagingException(org.springframework.messaging.MessagingException) MessagingException(org.springframework.messaging.MessagingException) RetryState(org.springframework.retry.RetryState)

Example 5 with RetryState

use of org.springframework.retry.RetryState in project spring-integration by spring-projects.

the class SpelExpressionRetryStateGeneratorTests method testForceRefreshElvis.

@Test
public void testForceRefreshElvis() {
    SpelExpressionRetryStateGenerator generator = new SpelExpressionRetryStateGenerator("headers['foo']", "headers['noHeader']?:true");
    RetryState state = generator.determineRetryState(message);
    assertEquals("bar", state.getKey());
    assertTrue(((DefaultRetryState) state).isForceRefresh());
    assertTrue(state.rollbackFor(new RuntimeException()));
}
Also used : DefaultRetryState(org.springframework.retry.support.DefaultRetryState) RetryState(org.springframework.retry.RetryState) Test(org.junit.Test)

Aggregations

RetryState (org.springframework.retry.RetryState)7 Test (org.junit.Test)6 DefaultRetryState (org.springframework.retry.support.DefaultRetryState)6 MessagingException (org.springframework.messaging.MessagingException)1