DatastoreStorage implements Closeable { static void sleepMillis(long sleepMillis) { try { Thread.sleep(sleepMillis); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); } } DatastoreStorage(CheckedDatastore datastore); @VisibleForTesting  DatastoreStorage(CheckedDatastore datastore,
                   Function<CheckedDatastoreTransaction, DatastoreStorageTransaction> storageTransactionFactory,
                   ExecutorService executor, Logger log); @Override void close(); void updateNextNaturalTrigger(WorkflowId workflowId, TriggerInstantSpec triggerSpec); Map<WorkflowId, Workflow> workflows(); Map<WorkflowId, Workflow> workflows(Set<WorkflowId> workflowIds); List<Workflow> workflows(String componentId); T runInTransactionWithRetries(TransactionFunction<T, E> f);  }
@Test public void sleepShouldBeInterruptible() throws Exception { var running = new CompletableFuture<String>(); var future = executor.submit(() -> { running.complete(null); DatastoreStorage.sleepMillis(Long.MAX_VALUE); return "foobar"; }); running.join(); executor.shutdownNow(); var result = future.get(30, SECONDS); assertThat(result, is("foobar")); }