/** * Waits for a default of 10 seconds, or until signalComplete has been called once, or until a * failure occurs. If signalComplete has been called before this, this call will never block. * * @throws InterruptedException Thrown if thread is interrupted while waiting * @throws TimeoutException Thrown if timeout occurs without signalComplete being called */ public void waitForTest() throws InterruptedException, TimeoutException { waitForTest(DEFAULT_TIMEOUT, 1); }
/** * Waits a specified amount of time, or until signalComplete has been called once, or until a * failure occurs. If signalComplete has been called before this, this call will never block. * * @param timeoutInMs Timeout to wait for signalComplete action to occur * @throws InterruptedException Thrown if thread is interrupted while waiting * @throws TimeoutException Thrown if timeout occurs without signalComplete being called */ public void waitForTest(long timeoutInMs) throws InterruptedException, TimeoutException { waitForTest(timeoutInMs, 1); }
/** * Waits for a default of 10 seconds, or until signalComplete has been called once, or until a * failure occurs. If signalComplete has been called before this, this call will never block. * * @throws InterruptedException Thrown if thread is interrupted while waiting * @throws TimeoutException Thrown if timeout occurs without signalComplete being called */ public void waitForTest() throws InterruptedException, TimeoutException { waitForTest(DEFAULT_TIMEOUT, 1); }
/** * Waits a specified amount of time, or until signalComplete has been called once, or until a * failure occurs. If signalComplete has been called before this, this call will never block. * * @param timeoutInMs Timeout to wait for signalComplete action to occur * @throws InterruptedException Thrown if thread is interrupted while waiting * @throws TimeoutException Thrown if timeout occurs without signalComplete being called */ public void waitForTest(long timeoutInMs) throws InterruptedException, TimeoutException { waitForTest(timeoutInMs, 1); }
@Override public void handleRunFinish() { try { verifier.waitForTest(); } catch (Exception e) { throw ExceptionUtils.makeRuntime(e); } } };
@Test (expected = TimeoutException.class) public void waitForTestTimeout() throws InterruptedException, TimeoutException { verifier.waitForTest(1); }
@Test public void signalCompleteBeforeWaitTest() throws InterruptedException, TimeoutException { verifier.signalComplete(); verifier.waitForTest(1); // no exception should throw as no blocking is needed }
public static void getLongRunningTasksWrappedFutureTest(final StatisticPriorityScheduler scheduler) throws InterruptedException, TimeoutException { final AsyncVerifier av = new AsyncVerifier(); scheduler.submit(new ClockUpdateRunnable() { @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(); } }); av.waitForTest(); }
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 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 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 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(); }
@Test public void rangedThreadPoolAvailableExecuteTest() throws InterruptedException, TimeoutException { AsyncVerifier av = new AsyncVerifier(); CentralThreadlyPool.rangedThreadPool(0, 1).execute(av::signalComplete); av.waitForTest(); }
@Test public void lowPrioritySingleThreadExecuteTest() throws InterruptedException, TimeoutException { AsyncVerifier av = new AsyncVerifier(); CentralThreadlyPool.lowPrioritySingleThreadPool().execute(av::signalComplete); av.waitForTest(); }
@Test public void threadRenamedTest() throws InterruptedException, TimeoutException { SubmitterSchedulerFactory schedulerFactory = getSubmitterSchedulerFactory(); try { AsyncVerifier av = new AsyncVerifier(); schedulerFactory.makeSubmitterExecutor(1, false).execute(() -> { av.assertTrue(Thread.currentThread().getName().startsWith(THREAD_NAME)); av.signalComplete(); }); av.waitForTest(); } finally { schedulerFactory.shutdown(); } }
@Test public void threadRenamedTest() throws InterruptedException, TimeoutException { SubmitterSchedulerFactory schedulerFactory = getSubmitterSchedulerFactory(); try { AsyncVerifier av = new AsyncVerifier(); schedulerFactory.makeSubmitterExecutor(1, false).execute(() -> { av.assertTrue(Thread.currentThread().getName().startsWith(THREAD_NAME)); av.signalComplete(); }); av.waitForTest(); } finally { schedulerFactory.shutdown(); } }