@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); }
public void executeCommand(Command<?> command) { logger.debug("[executeCommand][offer it in pool]{}", command); boolean offer = false; synchronized (this) { offer = tasks.offer(command); } if (!offer) { throw new IllegalStateException("pool full:" + tasks.size()); } doExecute(); }
OneThreadTaskExecutor implements Destroyable { public void executeCommand(Command<?> command) { logger.debug("[executeCommand][offer it in pool]{}", command); boolean offer = false; synchronized (this) { offer = tasks.offer(command); } if (!offer) { throw new IllegalStateException("pool full:" + tasks.size()); } doExecute(); } }
OneThreadTaskExecutor implements Destroyable { public void executeCommand(Command<?> command) { logger.debug("[executeCommand][offer it in pool]{}", command); boolean offer = false; synchronized (this) { offer = tasks.offer(command); } if (!offer) { throw new IllegalStateException("pool full:" + tasks.size()); } doExecute(); } OneThreadTaskExecutor(Executor executors);  OneThreadTaskExecutor(RetryCommandFactory<?> retryCommandFactory, Executor executors); }
OneThreadTaskExecutor implements Destroyable { public void executeCommand(Command<?> command) { logger.debug("[executeCommand][offer it in pool]{}", command); boolean offer = false; synchronized (this) { offer = tasks.offer(command); } if (!offer) { throw new IllegalStateException("pool full:" + tasks.size()); } doExecute(); } OneThreadTaskExecutor(Executor executors);  OneThreadTaskExecutor(RetryCommandFactory<?> retryCommandFactory, Executor executors); void executeCommand(Command<?> command); @Override void destroy(); }
OneThreadTaskExecutor implements Destroyable { public void executeCommand(Command<?> command) { logger.debug("[executeCommand][offer it in pool]{}", command); boolean offer = false; synchronized (this) { offer = tasks.offer(command); } if (!offer) { throw new IllegalStateException("pool full:" + tasks.size()); } doExecute(); } OneThreadTaskExecutor(Executor executors);  OneThreadTaskExecutor(RetryCommandFactory<?> retryCommandFactory, Executor executors); void executeCommand(Command<?> command); @Override void destroy();  }