@Test public void simulationTest() { GuardRailBuilder<TimeoutableResult, SimulationRejected> builder = new GuardRailBuilder<TimeoutableResult, SimulationRejected>() .name("Simulation") .resultCounts(new TotalCounts<TimeoutableResult>(TimeoutableResult.class)) .rejectedCounts(new TotalCounts<>(SimulationRejected.class)) .resultLatency(new NoOpLatency<>(TimeoutableResult.class)); GuardRail<TimeoutableResult, SimulationRejected> guardRail = builder.build(); final ThreadPoolService<SimulationRejected> callService = new ThreadPoolService<>(5, 10, guardRail); Map<TimeoutableResult, Callable<Long>> resultToCallable = new HashMap<>(); resultToCallable.put(TimeoutableResult.SUCCESS, new Callable<Long>() { @Override public Long call() throws InterruptedException { try { PrecipiceFuture<TimeoutableResult, String> f = callService.submit(TestCallable.success()); f.await(); } catch (RejectedException e) { } return 1L; } }); resultToCallable.put(TimeoutableResult.ERROR, new Callable<Long>() { @Override public Long call() throws InterruptedException { try { PrecipiceFuture<TimeoutableResult, String> f = callService.submit(TestCallable.erred(new IOException())); f.await(); } catch (RejectedException e) { } return 1L; } }); resultToCallable.put(TimeoutableResult.TIMEOUT, new Callable<Long>() { @Override public Long call() throws InterruptedException { try { CountDownLatch latch = new CountDownLatch(1); PrecipiceFuture<TimeoutableResult, String> f = callService.submit(TestCallable.blocked(latch), 1L); f.await(); latch.countDown(); } catch (RejectedException e) { } return 1L; } }); Simulation<TimeoutableResult> simulation = new Simulation<>(guardRail); simulation.run(resultToCallable); }
public <T> PrecipiceFuture<TimeoutableResult, T> submit(Callable<T> callable) { PrecipicePromise<TimeoutableResult, T> promise = Asynchronous.acquirePermitsAndPromise(guardRail, 1L); internalComplete(callable, promise); return promise.future(); }
ThreadPoolService implements Precipice<TimeoutableResult, Rejected> { public <T> PrecipiceFuture<TimeoutableResult, T> submit(Callable<T> callable) { PrecipicePromise<TimeoutableResult, T> promise = Asynchronous.acquirePermitsAndPromise(guardRail, 1L); internalComplete(callable, promise); return promise.future(); } }
ThreadPoolService implements Precipice<TimeoutableResult, Rejected> { public <T> PrecipiceFuture<TimeoutableResult, T> submit(Callable<T> callable) { PrecipicePromise<TimeoutableResult, T> promise = Asynchronous.acquirePermitsAndPromise(guardRail, 1L); internalComplete(callable, promise); return promise.future(); } ThreadPoolService(int poolSize, int queueSize, GuardRail<TimeoutableResult, Rejected> guardRail);  ThreadPoolService(ExecutorService executorService, GuardRail<TimeoutableResult, Rejected> guardRail); }
ThreadPoolService implements Precipice<TimeoutableResult, Rejected> { public <T> PrecipiceFuture<TimeoutableResult, T> submit(Callable<T> callable) { PrecipicePromise<TimeoutableResult, T> promise = Asynchronous.acquirePermitsAndPromise(guardRail, 1L); internalComplete(callable, promise); return promise.future(); } ThreadPoolService(int poolSize, int queueSize, GuardRail<TimeoutableResult, Rejected> guardRail);  ThreadPoolService(ExecutorService executorService, GuardRail<TimeoutableResult, Rejected> guardRail); @Override GuardRail<TimeoutableResult, Rejected> guardRail(); PrecipiceFuture<TimeoutableResult, T> submit(Callable<T> callable); PrecipiceFuture<TimeoutableResult, T> submit(Callable<T> callable, long millisTimeout); void complete(Callable<T> callable, PrecipicePromise<TimeoutableResult, T> promise); void complete(Callable<T> callable, PrecipicePromise<TimeoutableResult, T> promise, long millisTimeout); ExecutorService getExecutor(); DelayQueueTimeoutService getTimeoutService(); void shutdown(); }
ThreadPoolService implements Precipice<TimeoutableResult, Rejected> { public <T> PrecipiceFuture<TimeoutableResult, T> submit(Callable<T> callable) { PrecipicePromise<TimeoutableResult, T> promise = Asynchronous.acquirePermitsAndPromise(guardRail, 1L); internalComplete(callable, promise); return promise.future(); } ThreadPoolService(int poolSize, int queueSize, GuardRail<TimeoutableResult, Rejected> guardRail);  ThreadPoolService(ExecutorService executorService, GuardRail<TimeoutableResult, Rejected> guardRail); @Override GuardRail<TimeoutableResult, Rejected> guardRail(); PrecipiceFuture<TimeoutableResult, T> submit(Callable<T> callable); PrecipiceFuture<TimeoutableResult, T> submit(Callable<T> callable, long millisTimeout); void complete(Callable<T> callable, PrecipicePromise<TimeoutableResult, T> promise); void complete(Callable<T> callable, PrecipicePromise<TimeoutableResult, T> promise, long millisTimeout); ExecutorService getExecutor(); DelayQueueTimeoutService getTimeoutService(); void shutdown();  }