/** * For testing: force this web socket to release its threads. */ void tearDown() throws InterruptedException { if (cancelFuture != null) { cancelFuture.cancel(false); } executor.shutdown(); executor.awaitTermination(10, TimeUnit.SECONDS); }
/** * Stops the pool of workers. * * @throws InterruptedException if interrupted while stopping pool of workers. */ @Override public void stop() throws InterruptedException { executorService.shutdown(); executorService.awaitTermination(4, TimeUnit.SECONDS); } }
/** * Creates a pooled dispatcher with tunable pool size. * * @param poolSize number of pooled threads */ public ThreadPoolDispatcher(int poolSize) { this.executorService = Executors.newFixedThreadPool(poolSize); }
@Override public Void answer(InvocationOnMock invocation) throws Throwable { observerReceivedTwo.countDown(); return null; }
public static List<BlockingQueue<Object>> blockingQueues() { return ImmutableList.<BlockingQueue<Object>>of( new LinkedBlockingQueue<Object>(), new LinkedBlockingQueue<Object>(10), new SynchronousQueue<Object>(), new ArrayBlockingQueue<Object>(10), new LinkedBlockingDeque<Object>(), new LinkedBlockingDeque<Object>(10), new PriorityBlockingQueue<Object>(10, Ordering.arbitrary())); }
@Override public void accept(Integer v) throws Exception { if (!cdl.await(5, TimeUnit.SECONDS)) { throw new TimeoutException(); } } })
public Thread getThread() throws InterruptedException { latch.await(); return thread; } }
static Future<Integer> emptyFuture() { final ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); return exec.schedule(new Callable<Integer>() { @Override public Integer call() throws Exception { exec.shutdown(); return null; } }, 200, TimeUnit.MILLISECONDS); }
@Override public Scheduler apply(Callable<Scheduler> schedulerCallable) throws Exception { return schedulerCallable.call(); } };
@Override public Integer call() throws Exception { exec.shutdown(); return null; } }, 200, TimeUnit.MILLISECONDS);
/** * Returns true if TestObserver/TestSubscriber received any onError or onComplete events. * @return true if TestObserver/TestSubscriber received any onError or onComplete events */ public final boolean isTerminated() { return done.getCount() == 0; }
@Override public void shutdownExecutor() { List<Runnable> remainingTasks = concurrentExecutor.shutdownNow(); for (Runnable task : remainingTasks) { if (task instanceof RunnableFuture) { ((RunnableFuture<?>) task).cancel(true); } } }
@Override public boolean cancel(boolean mayInterruptIfRunning) { interrupted[0] = mayInterruptIfRunning; return super.cancel(mayInterruptIfRunning); } };
@Override public void run() { timedRunnable.disposed = true; queue.remove(timedRunnable); } }
@Override public void accept(Long aLong) { // Ensure there is at least some onNext events before un-subscription happens onNextLatch.countDown(); } })
@Override public boolean cancel(boolean mayInterruptIfRunning) { interrupted[0] = mayInterruptIfRunning; return super.cancel(mayInterruptIfRunning); } };
@Override public void accept(Long aLong) { // Ensure there is at least some onNext events before un-subscription happens onNextLatch.countDown(); } })