Java Code Examples for org.springframework.retry.context.RetryContextSupport#registerThrowable()

The following examples show how to use org.springframework.retry.context.RetryContextSupport#registerThrowable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlRetryPolicyTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void testRetryTransientExceptions() throws Exception {
	SqlRetryPolicy sqlRetryPolicy = new SqlRetryPolicy();
	RetryContextSupport retryContext = new RetryContextSupport(null);

	retryContext.registerThrowable(new SQLTransientException("foo"));
	assertThat(sqlRetryPolicy.canRetry(retryContext)).isTrue();

	retryContext.registerThrowable(new TransientDataAccessResourceException("foo"));
	assertThat(sqlRetryPolicy.canRetry(retryContext)).isTrue();
}
 
Example 2
Source File: SqlRetryPolicyTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void testNoRetryPersistentExceptions() throws Exception {
	SqlRetryPolicy sqlRetryPolicy = new SqlRetryPolicy();
	RetryContextSupport retryContext = new RetryContextSupport(null);

	retryContext.registerThrowable(new SQLException("foo"));
	assertThat(sqlRetryPolicy.canRetry(retryContext)).isFalse();

	retryContext.registerThrowable(new DataAccessResourceFailureException("foo"));
	assertThat(sqlRetryPolicy.canRetry(retryContext)).isFalse();
}
 
Example 3
Source File: SqlRetryPolicyTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void testWithNestedException() throws Exception {
	SqlRetryPolicy sqlRetryPolicy = new SqlRetryPolicy();
	RetryContextSupport retryContext = new RetryContextSupport(null);

	retryContext.registerThrowable(new TransactionSystemException(
			"Could not commit JDBC transaction", new SQLTransientException("foo")));
	assertThat(sqlRetryPolicy.canRetry(retryContext)).isTrue();
}
 
Example 4
Source File: SqlRetryPolicyTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void testMaxRetriesReached() throws Exception {
	SqlRetryPolicy sqlRetryPolicy = new SqlRetryPolicy();
	sqlRetryPolicy.setMaxNumberOfRetries(3);
	RetryContextSupport retryContext = new RetryContextSupport(null);
	retryContext.registerThrowable(new SQLTransientException("foo"));
	assertThat(sqlRetryPolicy.canRetry(retryContext)).isTrue();
	retryContext.registerThrowable(new SQLTransientException("foo"));
	assertThat(sqlRetryPolicy.canRetry(retryContext)).isTrue();
	retryContext.registerThrowable(new SQLTransientException("foo"));
	assertThat(sqlRetryPolicy.canRetry(retryContext)).isTrue();
	retryContext.registerThrowable(new SQLTransientException("foo"));
	assertThat(sqlRetryPolicy.canRetry(retryContext)).isFalse();
}
 
Example 5
Source File: ApiExceptionRetryPolicy.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Override
public void registerThrowable(RetryContext context, Throwable throwable) {
    RetryContextSupport contextSupport = RetryContextSupport.class.cast(context);
    contextSupport.registerThrowable(throwable);
    if (throwable != null) {
        LOGGER.warn("Exception occurred during CM API call.", throwable);
    }
}
 
Example 6
Source File: JerseyClientRetryPolicy.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Override
public void registerThrowable(RetryContext context, Throwable throwable) {
    RetryContextSupport contextSupport = RetryContextSupport.class.cast(context);
    contextSupport.registerThrowable(throwable);
    if (throwable != null) {
        LOGGER.warn("Exception occurred during a REST API call.", throwable);
    }
}