@Test public void ifNoServiceReturnedThenAllRejected() throws Exception { WritableSequence<ThreadPoolService<?>> iterable = prepIterable(); long millisTimeout = 100L; when(guardRail.acquirePermits(1L, submitTimeNanos)).thenReturn(null); when(pattern.getPrecipices(1L, submitTimeNanos)).thenReturn(iterable); try { poolPattern.submit(action, millisTimeout); fail("Should have been rejected"); } catch (RejectedException e) { assertEquals(PatternRejected.ALL_REJECTED, e.reason); } verify(guardRail).releasePermitsWithoutResult(1, submitTimeNanos); verify(rejectedCounts).write(PatternRejected.ALL_REJECTED, 1L, submitTimeNanos); verifyZeroInteractions(service1); verifyZeroInteractions(service2); verifyZeroInteractions(service3); }
public <T> PrecipiceFuture<TimeoutableResult, T> submit(final PatternCallable<T, C> action, long millisTimeout) { long nanoTime = acquirePermit(); Sequence<ThreadPoolService<?>> services = pattern.getPrecipices(1L, nanoTime); if (services.isEmpty()) { return handleAllReject(nanoTime); } PrecipicePromise<TimeoutableResult, T> promise = Asynchronous.getPromise(guardRail, 1L, nanoTime); long adjustedTimeout = DelayQueueTimeoutService.adjustTimeout(millisTimeout); for (ThreadPoolService<?> service : services) { PrecipicePromise<TimeoutableResult, T> internal = Asynchronous.getPromise(service.guardRail(), 1L, nanoTime, promise); final C context = serviceToContext.get(service); ExecutorService executor = service.getExecutor(); DelayQueueTimeoutService timeoutService = service.getTimeoutService(); Callable<T> callable = new CallableWithContext<>(action, context); CancellableTask<TimeoutableResult, T> task = TaskFactory.createTask(callable, internal); executor.execute(task); timeoutService.scheduleTimeout(new ThreadPoolTimeout<>(task), adjustedTimeout, nanoTime); } return promise.future(); }
ThreadPoolPattern implements Precipice<TimeoutableResult, PatternRejected> { public <T> PrecipiceFuture<TimeoutableResult, T> submit(final PatternCallable<T, C> action, long millisTimeout) { long nanoTime = acquirePermit(); Sequence<ThreadPoolService<?>> services = pattern.getPrecipices(1L, nanoTime); if (services.isEmpty()) { return handleAllReject(nanoTime); } PrecipicePromise<TimeoutableResult, T> promise = Asynchronous.getPromise(guardRail, 1L, nanoTime); long adjustedTimeout = DelayQueueTimeoutService.adjustTimeout(millisTimeout); for (ThreadPoolService<?> service : services) { PrecipicePromise<TimeoutableResult, T> internal = Asynchronous.getPromise(service.guardRail(), 1L, nanoTime, promise); final C context = serviceToContext.get(service); ExecutorService executor = service.getExecutor(); DelayQueueTimeoutService timeoutService = service.getTimeoutService(); Callable<T> callable = new CallableWithContext<>(action, context); CancellableTask<TimeoutableResult, T> task = TaskFactory.createTask(callable, internal); executor.execute(task); timeoutService.scheduleTimeout(new ThreadPoolTimeout<>(task), adjustedTimeout, nanoTime); } return promise.future(); } }
ThreadPoolPattern implements Precipice<TimeoutableResult, PatternRejected> { public <T> PrecipiceFuture<TimeoutableResult, T> submit(final PatternCallable<T, C> action, long millisTimeout) { long nanoTime = acquirePermit(); Sequence<ThreadPoolService<?>> services = pattern.getPrecipices(1L, nanoTime); if (services.isEmpty()) { return handleAllReject(nanoTime); } PrecipicePromise<TimeoutableResult, T> promise = Asynchronous.getPromise(guardRail, 1L, nanoTime); long adjustedTimeout = DelayQueueTimeoutService.adjustTimeout(millisTimeout); for (ThreadPoolService<?> service : services) { PrecipicePromise<TimeoutableResult, T> internal = Asynchronous.getPromise(service.guardRail(), 1L, nanoTime, promise); final C context = serviceToContext.get(service); ExecutorService executor = service.getExecutor(); DelayQueueTimeoutService timeoutService = service.getTimeoutService(); Callable<T> callable = new CallableWithContext<>(action, context); CancellableTask<TimeoutableResult, T> task = TaskFactory.createTask(callable, internal); executor.execute(task); timeoutService.scheduleTimeout(new ThreadPoolTimeout<>(task), adjustedTimeout, nanoTime); } return promise.future(); } ThreadPoolPattern(Map<ThreadPoolService<?>, C> serviceToContext, GuardRail<TimeoutableResult,
            PatternRejected> guardRail, PatternStrategy strategy);  ThreadPoolPattern(Map<ThreadPoolService<?>, C> serviceToContext,
                             GuardRail<TimeoutableResult, PatternRejected> guardRail,
                             Pattern<TimeoutableResult, ThreadPoolService<?>> pattern); }
ThreadPoolPattern implements Precipice<TimeoutableResult, PatternRejected> { public <T> PrecipiceFuture<TimeoutableResult, T> submit(final PatternCallable<T, C> action, long millisTimeout) { long nanoTime = acquirePermit(); Sequence<ThreadPoolService<?>> services = pattern.getPrecipices(1L, nanoTime); if (services.isEmpty()) { return handleAllReject(nanoTime); } PrecipicePromise<TimeoutableResult, T> promise = Asynchronous.getPromise(guardRail, 1L, nanoTime); long adjustedTimeout = DelayQueueTimeoutService.adjustTimeout(millisTimeout); for (ThreadPoolService<?> service : services) { PrecipicePromise<TimeoutableResult, T> internal = Asynchronous.getPromise(service.guardRail(), 1L, nanoTime, promise); final C context = serviceToContext.get(service); ExecutorService executor = service.getExecutor(); DelayQueueTimeoutService timeoutService = service.getTimeoutService(); Callable<T> callable = new CallableWithContext<>(action, context); CancellableTask<TimeoutableResult, T> task = TaskFactory.createTask(callable, internal); executor.execute(task); timeoutService.scheduleTimeout(new ThreadPoolTimeout<>(task), adjustedTimeout, nanoTime); } return promise.future(); } ThreadPoolPattern(Map<ThreadPoolService<?>, C> serviceToContext, GuardRail<TimeoutableResult,
            PatternRejected> guardRail, PatternStrategy strategy);  ThreadPoolPattern(Map<ThreadPoolService<?>, C> serviceToContext,
                             GuardRail<TimeoutableResult, PatternRejected> guardRail,
                             Pattern<TimeoutableResult, ThreadPoolService<?>> pattern); @Override GuardRail<TimeoutableResult, PatternRejected> guardRail(); PrecipiceFuture<TimeoutableResult, T> submit(final PatternCallable<T, C> action, long millisTimeout); void shutdown(); }
ThreadPoolPattern implements Precipice<TimeoutableResult, PatternRejected> { public <T> PrecipiceFuture<TimeoutableResult, T> submit(final PatternCallable<T, C> action, long millisTimeout) { long nanoTime = acquirePermit(); Sequence<ThreadPoolService<?>> services = pattern.getPrecipices(1L, nanoTime); if (services.isEmpty()) { return handleAllReject(nanoTime); } PrecipicePromise<TimeoutableResult, T> promise = Asynchronous.getPromise(guardRail, 1L, nanoTime); long adjustedTimeout = DelayQueueTimeoutService.adjustTimeout(millisTimeout); for (ThreadPoolService<?> service : services) { PrecipicePromise<TimeoutableResult, T> internal = Asynchronous.getPromise(service.guardRail(), 1L, nanoTime, promise); final C context = serviceToContext.get(service); ExecutorService executor = service.getExecutor(); DelayQueueTimeoutService timeoutService = service.getTimeoutService(); Callable<T> callable = new CallableWithContext<>(action, context); CancellableTask<TimeoutableResult, T> task = TaskFactory.createTask(callable, internal); executor.execute(task); timeoutService.scheduleTimeout(new ThreadPoolTimeout<>(task), adjustedTimeout, nanoTime); } return promise.future(); } ThreadPoolPattern(Map<ThreadPoolService<?>, C> serviceToContext, GuardRail<TimeoutableResult,
            PatternRejected> guardRail, PatternStrategy strategy);  ThreadPoolPattern(Map<ThreadPoolService<?>, C> serviceToContext,
                             GuardRail<TimeoutableResult, PatternRejected> guardRail,
                             Pattern<TimeoutableResult, ThreadPoolService<?>> pattern); @Override GuardRail<TimeoutableResult, PatternRejected> guardRail(); PrecipiceFuture<TimeoutableResult, T> submit(final PatternCallable<T, C> action, long millisTimeout); void shutdown();  }