Search in sources :

Example 1 with MethodInvocationRetryCallback

use of cn.taketoday.retry.interceptor.MethodInvocationRetryCallback in project today-infrastructure by TAKETODAY.

the class MethodInvocationRetryListenerSupportTests method testCloseWithRetryCallbackShouldntCallDoCloseMethod.

@Test
public void testCloseWithRetryCallbackShouldntCallDoCloseMethod() {
    final AtomicInteger callsOnDoCloseMethod = new AtomicInteger(0);
    MethodInvocationRetryListenerSupport support = new MethodInvocationRetryListenerSupport() {

        @Override
        protected <T, E extends Throwable> void doClose(RetryContext context, MethodInvocationRetryCallback<T, E> callback, Throwable throwable) {
            callsOnDoCloseMethod.incrementAndGet();
        }
    };
    RetryContext context = mock(RetryContext.class);
    RetryCallback callback = mock(RetryCallback.class);
    support.close(context, callback, null);
    assertEquals(0, callsOnDoCloseMethod.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RetryContext(cn.taketoday.retry.RetryContext) MethodInvocationRetryCallback(cn.taketoday.retry.interceptor.MethodInvocationRetryCallback) RetryCallback(cn.taketoday.retry.RetryCallback) MethodInvocationRetryCallback(cn.taketoday.retry.interceptor.MethodInvocationRetryCallback) Test(org.junit.Test)

Example 2 with MethodInvocationRetryCallback

use of cn.taketoday.retry.interceptor.MethodInvocationRetryCallback in project today-infrastructure by TAKETODAY.

the class MethodInvocationRetryListenerSupportTests method testOpenWithMethodInvocationRetryCallbackShouldCallDoCloseMethod.

@Test
public void testOpenWithMethodInvocationRetryCallbackShouldCallDoCloseMethod() {
    final AtomicInteger callsOnDoOpenMethod = new AtomicInteger(0);
    MethodInvocationRetryListenerSupport support = new MethodInvocationRetryListenerSupport() {

        @Override
        protected <T, E extends Throwable> boolean doOpen(RetryContext context, MethodInvocationRetryCallback<T, E> callback) {
            callsOnDoOpenMethod.incrementAndGet();
            return true;
        }
    };
    RetryContext context = mock(RetryContext.class);
    MethodInvocationRetryCallback callback = mock(MethodInvocationRetryCallback.class);
    assertTrue(support.open(context, callback));
    assertEquals(1, callsOnDoOpenMethod.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RetryContext(cn.taketoday.retry.RetryContext) MethodInvocationRetryCallback(cn.taketoday.retry.interceptor.MethodInvocationRetryCallback) Test(org.junit.Test)

Example 3 with MethodInvocationRetryCallback

use of cn.taketoday.retry.interceptor.MethodInvocationRetryCallback in project today-infrastructure by TAKETODAY.

the class MethodInvocationRetryListenerSupportTests method testCloseWithMethodInvocationRetryCallbackShouldCallDoCloseMethod.

@Test
public void testCloseWithMethodInvocationRetryCallbackShouldCallDoCloseMethod() {
    final AtomicInteger callsOnDoCloseMethod = new AtomicInteger(0);
    MethodInvocationRetryListenerSupport support = new MethodInvocationRetryListenerSupport() {

        @Override
        protected <T, E extends Throwable> void doClose(RetryContext context, MethodInvocationRetryCallback<T, E> callback, Throwable throwable) {
            callsOnDoCloseMethod.incrementAndGet();
        }
    };
    RetryContext context = mock(RetryContext.class);
    MethodInvocationRetryCallback callback = mock(MethodInvocationRetryCallback.class);
    support.close(context, callback, null);
    assertEquals(1, callsOnDoCloseMethod.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RetryContext(cn.taketoday.retry.RetryContext) MethodInvocationRetryCallback(cn.taketoday.retry.interceptor.MethodInvocationRetryCallback) Test(org.junit.Test)

Example 4 with MethodInvocationRetryCallback

use of cn.taketoday.retry.interceptor.MethodInvocationRetryCallback in project today-framework by TAKETODAY.

the class MethodInvocationRetryListenerSupportTests method testCloseWithMethodInvocationRetryCallbackShouldCallDoCloseMethod.

@Test
public void testCloseWithMethodInvocationRetryCallbackShouldCallDoCloseMethod() {
    final AtomicInteger callsOnDoCloseMethod = new AtomicInteger(0);
    MethodInvocationRetryListenerSupport support = new MethodInvocationRetryListenerSupport() {

        @Override
        protected <T, E extends Throwable> void doClose(RetryContext context, MethodInvocationRetryCallback<T, E> callback, Throwable throwable) {
            callsOnDoCloseMethod.incrementAndGet();
        }
    };
    RetryContext context = mock(RetryContext.class);
    MethodInvocationRetryCallback callback = mock(MethodInvocationRetryCallback.class);
    support.close(context, callback, null);
    assertEquals(1, callsOnDoCloseMethod.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RetryContext(cn.taketoday.retry.RetryContext) MethodInvocationRetryCallback(cn.taketoday.retry.interceptor.MethodInvocationRetryCallback) Test(org.junit.Test)

Example 5 with MethodInvocationRetryCallback

use of cn.taketoday.retry.interceptor.MethodInvocationRetryCallback in project today-framework by TAKETODAY.

the class MethodInvocationRetryListenerSupportTests method testOnErrorWithMethodInvocationRetryCallbackShouldCallDoOnErrorMethod.

@Test
public void testOnErrorWithMethodInvocationRetryCallbackShouldCallDoOnErrorMethod() {
    final AtomicInteger callsOnDoOnErrorMethod = new AtomicInteger(0);
    MethodInvocationRetryListenerSupport support = new MethodInvocationRetryListenerSupport() {

        @Override
        protected <T, E extends Throwable> void doOnError(RetryContext context, MethodInvocationRetryCallback<T, E> callback, Throwable throwable) {
            callsOnDoOnErrorMethod.incrementAndGet();
        }
    };
    RetryContext context = mock(RetryContext.class);
    MethodInvocationRetryCallback callback = mock(MethodInvocationRetryCallback.class);
    support.onError(context, callback, null);
    assertEquals(1, callsOnDoOnErrorMethod.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RetryContext(cn.taketoday.retry.RetryContext) MethodInvocationRetryCallback(cn.taketoday.retry.interceptor.MethodInvocationRetryCallback) Test(org.junit.Test)

Aggregations

RetryContext (cn.taketoday.retry.RetryContext)8 MethodInvocationRetryCallback (cn.taketoday.retry.interceptor.MethodInvocationRetryCallback)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 Test (org.junit.Test)8 RetryCallback (cn.taketoday.retry.RetryCallback)2