InMemoryTimeoutManager implements TimeoutManager, AutoCloseable { @Override public TimeoutId requestTimeout(final ExecutionContext context, final String sagaId, final long delay, final TimeUnit timeUnit, @Nullable final String name, @Nullable final Object data) { checkNotNull(sagaId, "SagaId not allowed to be null."); UUIDTimeoutId id = UUIDTimeoutId.generateNewId(); TimeoutContext timeoutContext = new TimeoutContext(context.getAllHeaders()); SagaTimeoutTask timeoutTask = new SagaTimeoutTask(id, sagaId, name, timeout -> timeoutExpired(timeout, timeoutContext), clock, data); ScheduledFuture future = scheduledService.schedule(timeoutTask, delay, timeUnit); synchronized (sync) { openTimeouts.put(id, sagaId, future); } return id; } InMemoryTimeoutManager();  InMemoryTimeoutManager(final int timerThreadPoolSize);  InMemoryTimeoutManager(final ScheduledExecutorService scheduledService, final Clock clock); @Override void addExpiredCallback(final TimeoutExpired callback); @Override TimeoutId requestTimeout(final ExecutionContext context, final String sagaId, final long delay, final TimeUnit timeUnit, @Nullable final String name,
                               @Nullable final Object data); @Override void cancelTimeouts(final String sagaId); @Override void cancelTimeout(final TimeoutId id); @Override void close();  }
@Test public void requestTimeout_TimeoutMessage_schedulesTimeoutTask() { long timeoutInSec = 5; sut.requestTimeout(mockContext(), "anySagaId", timeoutInSec, TimeUnit.SECONDS, "anyName", null); ArgumentCaptor<SagaTimeoutTask> captor = ArgumentCaptor.forClass(SagaTimeoutTask.class); verify(executor).schedule(captor.capture(), eq(timeoutInSec), eq(TimeUnit.SECONDS)); assertThat("Scheduled task not of expected type.", captor.getValue(), instanceOf(SagaTimeoutTask.class)); }