/** * @throws Exception If failed. */ @Test public void testSingleThreadExecutor() throws Exception { ExecutorService exec = Executors.newSingleThreadExecutor(); exec.submit(new InterruptingRunnable()).get(); // Thread is interrupted but Thread.interrupted() is called in AbstractQueuedSynchronizer.acquireInterruptibly // when blockingQueue wants to get the new task (see ThreadPoolExecutor.getTask()). // This will reset the interrupted flag. Any subsequent calls to Thread.currentThread.isInterrupted() // will return false. Future<Boolean> fut = exec.submit(new IsInterruptedAssertionCallable()); assert !fut.get() : "Expecting the executorService to reset the interrupted flag when reinvoking the thread"; exec.shutdown(); assert exec.awaitTermination(30, SECONDS); }
/** * @throws Exception If failed. */ @Test public void testSingleGridThreadExecutor() throws Exception { ExecutorService exec = Executors.newSingleThreadExecutor(new IgniteThreadFactory("gridName", "testThread")); exec.submit(new InterruptingRunnable()).get(); Future<Boolean> fut = exec.submit(new IsInterruptedAssertionCallable()); assert !fut.get() : "Expecting the executorService to reset the interrupted flag when reinvoking the thread"; // Thread is interrupted but Thread.interrupted() is called in AbstractQueuedSynchronizer.acquireInterruptibly // when blockingQueue wants to get the new task (see ThreadPoolExecutor.getTask()). // This will reset the interrupted flag but not the one from GridThread. Any subsequent calls to // Thread.currentThread.isInterrupted() will return true; exec.shutdown(); assert exec.awaitTermination(30, SECONDS); }
/** * @throws ExecutionException If failed. */ @Test public void testGridThreadPoolExecutor() throws Exception { IgniteThreadPoolExecutor exec = new IgniteThreadPoolExecutor("", "", 1, 1, 0, new LinkedBlockingQueue<Runnable>()); exec.submit(new InterruptingRunnable()).get(); Future<Boolean> fut = exec.submit(new IsInterruptedAssertionCallable()); assert !fut.get() : "Expecting the executor to reset the interrupted flag when reinvoking the thread"; exec.shutdown(); assert exec.awaitTermination(30, SECONDS); }