@Override public void handleRunFinish() { running.decrementAndGet(); verifier.signalComplete(); } };
@Override public void handleRunFinish() { running.decrementAndGet(); verifier.signalComplete(); } };
@Override public void handleFailure(Throwable t) { av.assertEquals(msg, t.getMessage()); av.signalComplete(); } });
@Override public void run() { interruptClearedAV.assertFalse(Thread.currentThread().isInterrupted()); interruptClearedAV.signalComplete(); } });
@Override public void handleRunFinish() { long startTime = System.currentTimeMillis(); Thread currentThread = Thread.currentThread(); while (System.currentTimeMillis() - startTime < taskRunTime && ! currentThread.isInterrupted()) { // spin } interruptSentAV.assertTrue(currentThread.isInterrupted()); interruptSentAV.signalComplete(); } };
@Override public void run() { try { rfca.run(); av.fail("Exception did not throw"); } catch (RuntimeException expected) { av.signalComplete(); } } });
@Test public void signalCompleteBeforeWaitTest() throws InterruptedException, TimeoutException { verifier.signalComplete(); verifier.waitForTest(1); // no exception should throw as no blocking is needed }
@Override public void handleRunStart() { if (fLastRun != null) { av.assertTrue(fLastRun.ranOnce()); } av.signalComplete(); } };
@Override public void handleRunStart() { if (fLastRun != null) { av.assertTrue(fLastRun.ranOnce()); } av.signalComplete(); } };
@Override public void run() { av.assertTrue(f.isDone()); Iterator<? extends ListenableFuture<?>> it = futures.iterator(); while (it.hasNext()) { av.assertTrue(it.next().isDone()); } av.signalComplete(); } });
@Override public void handleRunStart() { // even submitted (and thus wrapped in a future), we should get our direct reference av.assertTrue(scheduler.getLongRunningTasks(-1).get(0).getLeft() == this); av.signalComplete(); } });
@Override public void handleRunStart() { try { int runCount = scheduler.blockingTick(null); // should block av.assertEquals(1, runCount); av.signalComplete(); } catch (InterruptedException e) { av.fail(e); } } };
public static void optimizeDoneListenerExecutorTest(ListenableFuture<?> lf) throws InterruptedException, TimeoutException { AsyncVerifier av = new AsyncVerifier(); Thread t = Thread.currentThread(); lf.addListener(() -> {av.assertTrue(Thread.currentThread() == t) ; av.signalComplete();}, CentralThreadlyPool.computationPool(), ListenerOptimizationStrategy.SingleThreadIfExecutorMatchOrDone); av.waitForTest(); }
@Test public void computationPoolThreadRenamedTest() throws InterruptedException, TimeoutException { final String threadName = StringUtils.makeRandomString(5); AsyncVerifier av = new AsyncVerifier(); CentralThreadlyPool.computationPool(threadName).execute(() -> { av.assertTrue(Thread.currentThread().getName().startsWith(threadName)); av.signalComplete(); }); av.waitForTest(); }
@Test public void threadPoolRenamedTest() throws InterruptedException, TimeoutException { final String threadName = StringUtils.makeRandomString(5); AsyncVerifier av = new AsyncVerifier(); CentralThreadlyPool.threadPool(2, threadName).execute(() -> { av.assertTrue(Thread.currentThread().getName().startsWith(threadName)); av.signalComplete(); }); av.waitForTest(); }
@Test public void rangedThreadPoolThreadRenamedTest() throws InterruptedException, TimeoutException { final String threadName = StringUtils.makeRandomString(5); AsyncVerifier av = new AsyncVerifier(); CentralThreadlyPool.rangedThreadPool(0, 1, threadName).execute(() -> { av.assertTrue(Thread.currentThread().getName().startsWith(threadName)); av.signalComplete(); }); av.waitForTest(); }
@Test public void lowPriorityRenamedTest() throws InterruptedException, TimeoutException { final String threadName = StringUtils.makeRandomString(5); AsyncVerifier av = new AsyncVerifier(); CentralThreadlyPool.lowPriorityPool(threadName).execute(() -> { av.assertTrue(Thread.currentThread().getName().startsWith(threadName)); av.signalComplete(); }); av.waitForTest(); }
@Test public void lowPrioritySingleThreadRenamedTest() throws InterruptedException, TimeoutException { final String threadName = StringUtils.makeRandomString(5); AsyncVerifier av = new AsyncVerifier(); CentralThreadlyPool.lowPrioritySingleThreadPool(threadName).execute(() -> { av.assertTrue(Thread.currentThread().getName().startsWith(threadName)); av.signalComplete(); }); av.waitForTest(); }
@Test public void singleThreadRenamedTest() throws InterruptedException, TimeoutException { final String threadName = StringUtils.makeRandomString(5); AsyncVerifier av = new AsyncVerifier(); CentralThreadlyPool.singleThreadPool(false, threadName).execute(() -> { av.assertTrue(Thread.currentThread().getName().startsWith(threadName)); av.signalComplete(); }); av.waitForTest(); }
@Test public void singleThreadPriorityTest() throws InterruptedException, TimeoutException { AsyncVerifier av = new AsyncVerifier(); CentralThreadlyPool.singleThreadPool(false, null, Thread.MIN_PRIORITY).execute(() -> { av.assertEquals(Thread.MIN_PRIORITY, Thread.currentThread().getPriority()); av.signalComplete(); }); av.waitForTest(); }