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);
}
Aggregations