Search in sources :

Example 1 with RetryOperations

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"));
}
Also used : RetryTemplate(cn.taketoday.retry.support.RetryTemplate) RetryOperations(cn.taketoday.retry.RetryOperations) Test(org.junit.Test)

Example 2 with 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());
}
Also used : RecoveryCallback(cn.taketoday.retry.RecoveryCallback) DefaultRetryState(cn.taketoday.retry.support.DefaultRetryState) RetryOperations(cn.taketoday.retry.RetryOperations) MethodInvocation(org.aopalliance.intercept.MethodInvocation) RetryCallback(cn.taketoday.retry.RetryCallback) Test(org.junit.jupiter.api.Test)

Example 3 with RetryOperations

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());
}
Also used : RecoveryCallback(cn.taketoday.retry.RecoveryCallback) DefaultRetryState(cn.taketoday.retry.support.DefaultRetryState) RetryOperations(cn.taketoday.retry.RetryOperations) MethodInvocation(org.aopalliance.intercept.MethodInvocation) RetryCallback(cn.taketoday.retry.RetryCallback) Test(org.junit.jupiter.api.Test)

Example 4 with RetryOperations

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"));
}
Also used : RetryTemplate(cn.taketoday.retry.support.RetryTemplate) RetryOperations(cn.taketoday.retry.RetryOperations) Test(org.junit.Test)

Example 5 with 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());
}
Also used : RecoveryCallback(cn.taketoday.retry.RecoveryCallback) DefaultRetryState(cn.taketoday.retry.support.DefaultRetryState) RetryOperations(cn.taketoday.retry.RetryOperations) MethodInvocation(org.aopalliance.intercept.MethodInvocation) RetryCallback(cn.taketoday.retry.RetryCallback) Test(org.junit.jupiter.api.Test)

Aggregations

RetryOperations (cn.taketoday.retry.RetryOperations)6 RecoveryCallback (cn.taketoday.retry.RecoveryCallback)4 RetryCallback (cn.taketoday.retry.RetryCallback)4 DefaultRetryState (cn.taketoday.retry.support.DefaultRetryState)4 MethodInvocation (org.aopalliance.intercept.MethodInvocation)4 Test (org.junit.jupiter.api.Test)4 RetryTemplate (cn.taketoday.retry.support.RetryTemplate)2 Test (org.junit.Test)2