use of cn.taketoday.retry.RetryOperations in project today-infrastructure by TAKETODAY.
the class RetryInterceptorBuilderTests method testWithCustomRetryTemplate.
@Test
public void testWithCustomRetryTemplate() {
RetryOperations retryOperations = new RetryTemplate();
StatefulRetryOperationsInterceptor interceptor = RetryInterceptorBuilder.stateful().retryOperations(retryOperations).build();
assertEquals(3, TestUtils.getPropertyValue(interceptor, "retryOperations.retryPolicy.maxAttempts"));
assertSame(retryOperations, TestUtils.getPropertyValue(interceptor, "retryOperations"));
}
use of cn.taketoday.retry.RetryOperations in project today-infrastructure by TAKETODAY.
the class StatefulRetryOperationsInterceptorTests method testKeyGeneratorReturningNull.
@SuppressWarnings("unchecked")
@Test
public void testKeyGeneratorReturningNull() throws Throwable {
this.interceptor.setKeyGenerator(mock(MethodArgumentsKeyGenerator.class));
this.interceptor.setLabel("foo");
RetryOperations template = mock(RetryOperations.class);
this.interceptor.setRetryOperations(template);
MethodInvocation invocation = mock(MethodInvocation.class);
when(invocation.getArguments()).thenReturn(new Object[] { new Object() });
this.interceptor.invoke(invocation);
ArgumentCaptor<DefaultRetryState> captor = ArgumentCaptor.forClass(DefaultRetryState.class);
verify(template).execute(any(RetryCallback.class), any(RecoveryCallback.class), captor.capture());
assertNull(captor.getValue().getKey());
}
use of cn.taketoday.retry.RetryOperations in project today-infrastructure by TAKETODAY.
the class StatefulRetryOperationsInterceptorTests method testKeyGeneratorAndRawKey.
@SuppressWarnings("unchecked")
@Test
public void testKeyGeneratorAndRawKey() throws Throwable {
this.interceptor.setKeyGenerator(item -> "bar");
this.interceptor.setLabel("foo");
this.interceptor.setUseRawKey(true);
RetryOperations template = mock(RetryOperations.class);
this.interceptor.setRetryOperations(template);
MethodInvocation invocation = mock(MethodInvocation.class);
when(invocation.getArguments()).thenReturn(new Object[] { new Object() });
this.interceptor.invoke(invocation);
ArgumentCaptor<DefaultRetryState> captor = ArgumentCaptor.forClass(DefaultRetryState.class);
verify(template).execute(any(RetryCallback.class), any(RecoveryCallback.class), captor.capture());
assertEquals("bar", captor.getValue().getKey());
}
use of cn.taketoday.retry.RetryOperations in project today-framework by TAKETODAY.
the class RetryInterceptorBuilderTests method testWithCustomRetryTemplate.
@Test
public void testWithCustomRetryTemplate() {
RetryOperations retryOperations = new RetryTemplate();
StatefulRetryOperationsInterceptor interceptor = RetryInterceptorBuilder.stateful().retryOperations(retryOperations).build();
assertEquals(3, TestUtils.getPropertyValue(interceptor, "retryOperations.retryPolicy.maxAttempts"));
assertSame(retryOperations, TestUtils.getPropertyValue(interceptor, "retryOperations"));
}
use of cn.taketoday.retry.RetryOperations in project today-framework by TAKETODAY.
the class StatefulRetryOperationsInterceptorTests method testKeyGeneratorAndRawKey.
@SuppressWarnings("unchecked")
@Test
public void testKeyGeneratorAndRawKey() throws Throwable {
this.interceptor.setKeyGenerator(item -> "bar");
this.interceptor.setLabel("foo");
this.interceptor.setUseRawKey(true);
RetryOperations template = mock(RetryOperations.class);
this.interceptor.setRetryOperations(template);
MethodInvocation invocation = mock(MethodInvocation.class);
when(invocation.getArguments()).thenReturn(new Object[] { new Object() });
this.interceptor.invoke(invocation);
ArgumentCaptor<DefaultRetryState> captor = ArgumentCaptor.forClass(DefaultRetryState.class);
verify(template).execute(any(RetryCallback.class), any(RecoveryCallback.class), captor.capture());
assertEquals("bar", captor.getValue().getKey());
}
Aggregations