Search in sources :

Example 1 with RetryCommandFactory

use of com.ctrip.xpipe.command.RetryCommandFactory in project x-pipe by ctripcorp.

the class OneThreadTaskExecutorTest method testRetryTemplate.

@Test
public void testRetryTemplate() throws TimeoutException {
    int retryTimes = 10;
    CommandFuture<Void> future = new DefaultCommandFuture<>();
    when(command.execute()).thenReturn(future);
    future.setFailure(new Exception());
    RetryCommandFactory retryCommandFactory = DefaultRetryCommandFactory.retryNTimes(scheduled, retryTimes, 10);
    OneThreadTaskExecutor oneThreadTaskExecutor = new OneThreadTaskExecutor(retryCommandFactory, executors);
    oneThreadTaskExecutor.executeCommand(command);
    waitConditionUntilTimeOut(() -> {
        try {
            verify(command, times(retryTimes + 1)).execute();
            return true;
        } catch (Throwable e) {
        }
        return false;
    }, 2000);
}
Also used : DefaultCommandFuture(com.ctrip.xpipe.command.DefaultCommandFuture) TimeoutException(java.util.concurrent.TimeoutException) DefaultRetryCommandFactory(com.ctrip.xpipe.command.DefaultRetryCommandFactory) RetryCommandFactory(com.ctrip.xpipe.command.RetryCommandFactory) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Aggregations

AbstractTest (com.ctrip.xpipe.AbstractTest)1 DefaultCommandFuture (com.ctrip.xpipe.command.DefaultCommandFuture)1 DefaultRetryCommandFactory (com.ctrip.xpipe.command.DefaultRetryCommandFactory)1 RetryCommandFactory (com.ctrip.xpipe.command.RetryCommandFactory)1 TimeoutException (java.util.concurrent.TimeoutException)1 Test (org.junit.Test)1