org.springframework.retry.context.RetryContextSupport Java Examples
The following examples show how to use
org.springframework.retry.context.RetryContextSupport.
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: DatabaseInstanceStatusRetryPolicyTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void canRetry_noExceptionRegistered_returnsTrue() throws Exception { // Arrange AmazonRDS amazonRDS = mock(AmazonRDS.class); DatabaseInstanceStatusRetryPolicy policy = new DatabaseInstanceStatusRetryPolicy( amazonRDS, "test"); RetryContext retryContext = new RetryContextSupport(null); // Act policy.open(retryContext); // Assert assertThat(policy.canRetry(retryContext)).isTrue(); }
Example #2
Source File: DatabaseInstanceStatusRetryPolicyTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void canRetry_retryNotPossibleDueToNoDatabase_returnsFalse() throws Exception { // Arrange AmazonRDS amazonRDS = mock(AmazonRDS.class); DatabaseInstanceStatusRetryPolicy policy = new DatabaseInstanceStatusRetryPolicy( amazonRDS, "test"); when(amazonRDS.describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) .thenThrow(new DBInstanceNotFoundException("test")); RetryContext retryContext = policy.open(new RetryContextSupport(null)); // Act policy.registerThrowable(retryContext, new TransientDataAccessResourceException("not available")); // Assert assertThat(policy.canRetry(retryContext)).isFalse(); policy.close(retryContext); }
Example #3
Source File: DatabaseInstanceStatusRetryPolicyTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void canRetry_retryPossibleDueToAvailableDatabase_returnsTrue() throws Exception { // Arrange AmazonRDS amazonRDS = mock(AmazonRDS.class); DatabaseInstanceStatusRetryPolicy policy = new DatabaseInstanceStatusRetryPolicy( amazonRDS, "test"); when(amazonRDS.describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) .thenReturn(new DescribeDBInstancesResult().withDBInstances( new DBInstance().withDBInstanceStatus("available"))); RetryContext retryContext = policy.open(new RetryContextSupport(null)); // Act policy.registerThrowable(retryContext, new TransientDataAccessResourceException("not available")); // Assert assertThat(policy.canRetry(retryContext)).isTrue(); policy.close(retryContext); }
Example #4
Source File: JerseyClientRetryPolicy.java From cloudbreak with Apache License 2.0 | 5 votes |
@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); } }
Example #5
Source File: ApiExceptionRetryPolicy.java From cloudbreak with Apache License 2.0 | 5 votes |
@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: DatabaseInstanceStatusRetryPolicyTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void canRetry_multipleDatabasesFoundForInstanceIdentifier_reportsException() throws Exception { // Arrange AmazonRDS amazonRDS = mock(AmazonRDS.class); DatabaseInstanceStatusRetryPolicy policy = new DatabaseInstanceStatusRetryPolicy( amazonRDS, "test"); DescribeDBInstancesResult describeDBInstancesResult = new DescribeDBInstancesResult() .withDBInstances(new DBInstance(), new DBInstance()); when(amazonRDS.describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) .thenReturn(describeDBInstancesResult); RetryContext retryContext = policy.open(new RetryContextSupport(null)); // Act policy.registerThrowable(retryContext, new TransientDataAccessResourceException("not available")); // Assert assertThatThrownBy(() -> policy.canRetry(retryContext)) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("Multiple databases found for same identifier"); }
Example #7
Source File: DatabaseInstanceStatusRetryPolicyTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void canRetry_withResourceIdResolver_returnsTrue() throws Exception { // Arrange AmazonRDS amazonRDS = mock(AmazonRDS.class); ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class); DatabaseInstanceStatusRetryPolicy policy = new DatabaseInstanceStatusRetryPolicy( amazonRDS, "foo"); when(amazonRDS.describeDBInstances( new DescribeDBInstancesRequest().withDBInstanceIdentifier("test"))) .thenReturn(new DescribeDBInstancesResult().withDBInstances( new DBInstance().withDBInstanceStatus("available"))); when(resourceIdResolver.resolveToPhysicalResourceId("foo")).thenReturn("test"); policy.setResourceIdResolver(resourceIdResolver); RetryContext retryContext = policy.open(new RetryContextSupport(null)); // Act policy.registerThrowable(retryContext, new TransientDataAccessResourceException("not available")); // Assert assertThat(policy.canRetry(retryContext)).isTrue(); policy.close(retryContext); }
Example #8
Source File: SqlRetryPolicyTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@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 #9
Source File: SqlRetryPolicyTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@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 #10
Source File: SqlRetryPolicyTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@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 #11
Source File: SqlRetryPolicyTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@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 #12
Source File: DatabaseInstanceStatusRetryPolicy.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Override public void registerThrowable(RetryContext context, Throwable throwable) { ((RetryContextSupport) context).registerThrowable(throwable); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Registered Throwable of Type {} for RetryContext", throwable.getClass().getName()); } }
Example #13
Source File: DatabaseInstanceStatusRetryPolicy.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Override public RetryContext open(RetryContext parent) { RetryContextSupport context = new RetryContextSupport(parent); context.setAttribute(DB_INSTANCE_ATTRIBUTE_NAME, getDbInstanceIdentifier()); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Starting RetryContext for database instance with identifier {}", getDbInstanceIdentifier()); } return context; }
Example #14
Source File: ApiExceptionRetryPolicy.java From cloudbreak with Apache License 2.0 | 4 votes |
@Override public RetryContext open(RetryContext parent) { return new RetryContextSupport(parent); }
Example #15
Source File: SqlRetryPolicy.java From spring-cloud-aws with Apache License 2.0 | 4 votes |
@Override public void registerThrowable(RetryContext context, Throwable throwable) { ((RetryContextSupport) context).registerThrowable(throwable); }
Example #16
Source File: JerseyClientRetryPolicy.java From cloudbreak with Apache License 2.0 | 4 votes |
@Override public RetryContext open(RetryContext parent) { return new RetryContextSupport(parent); }
Example #17
Source File: SqlRetryPolicy.java From spring-cloud-aws with Apache License 2.0 | 4 votes |
@Override public RetryContext open(RetryContext parent) { return new RetryContextSupport(parent); }