use of com.ctrip.xpipe.command.DefaultCommandFuture in project x-pipe by ctripcorp.
the class OneThreadTaskExecutorTest method testClose.
@Test
public void testClose() throws Exception {
CommandFuture<Void> future = new DefaultCommandFuture<>();
when(command.execute()).thenReturn(future);
future.setFailure(new Exception());
RetryCommandFactory<Void> retryCommandFactory = DefaultRetryCommandFactory.retryForever(scheduled, 0);
OneThreadTaskExecutor oneThreadTaskExecutor = new OneThreadTaskExecutor(retryCommandFactory, executors);
oneThreadTaskExecutor.executeCommand(command);
sleep(100);
logger.info("[testClose][destroy]");
oneThreadTaskExecutor.destroy();
retryCommandFactory.destroy();
sleep(50);
verify(command, new AtLeast(1)).execute();
verify(command, new AtLeast(1)).reset();
logger.info("[testClose][sleep verify no more interactions]");
sleep(100);
verifyNoMoreInteractions(command);
}
use of com.ctrip.xpipe.command.DefaultCommandFuture 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