/** * Blocks till condition is true, useful for asynchronism operations, waiting for them to * complete in other threads during unit tests. * <p> * This uses a default timeout of 10 seconds, and a poll interval of 10ms */ public void blockTillTrue() { blockTillTrue(DEFAULT_TIMEOUT, DEFAULT_POLL_INTERVAL); }
/** * Blocks till condition is true, useful for asynchronism operations, waiting for them to * complete in other threads during unit tests. * <p> * This uses a default timeout of 10 seconds, and a poll interval of 10ms */ public void blockTillTrue() { blockTillTrue(DEFAULT_TIMEOUT, DEFAULT_POLL_INTERVAL); }
/** * Blocks till condition is true, useful for asynchronism operations, waiting for them to * complete in other threads during unit tests. * <p> * This uses the default poll interval of 10ms * * @param timeoutInMillis time to wait for value to become true */ public void blockTillTrue(int timeoutInMillis) { blockTillTrue(timeoutInMillis, DEFAULT_POLL_INTERVAL); }
/** * Blocks till condition is true, useful for asynchronism operations, waiting for them to * complete in other threads during unit tests. * <p> * This uses the default poll interval of 10ms * * @param timeoutInMillis time to wait for value to become true */ public void blockTillTrue(int timeoutInMillis) { blockTillTrue(timeoutInMillis, DEFAULT_POLL_INTERVAL); }
/** * Blocks until run has been called at least once. * * @param timeout time to wait for run to be called before throwing exception */ public void blockTillStarted(int timeout) { new TestCondition(() -> ! runTime.isEmpty()) .blockTillTrue(timeout, RUN_CONDITION_POLL_INTERVAL); }
/** * Blocks until run has been called at least once. * * @param timeout time to wait for run to be called before throwing exception */ public void blockTillStarted(int timeout) { new TestCondition(() -> ! runTime.isEmpty()) .blockTillTrue(timeout, RUN_CONDITION_POLL_INTERVAL); }
@Override protected void profilingExecutor(Executor executor) { AtomicReference<Thread> tAR = new AtomicReference<>(); executor.execute(() -> tAR.set(Thread.currentThread())); new TestCondition(() -> tAR.get() != null).blockTillTrue(); ctProfiler.addProfiledThread(tAR.get()); }
@Test public void supplierPredicateTest() { Queue<String> values = new ArrayDeque<>(8); values.add("foo"); values.add("false"); values.add("true"); new TestCondition(() -> values.remove(), Boolean::parseBoolean).blockTillTrue(); }
/** * Blocks until the System clock advances at least 1 millisecond. This will also ensure that * the {@link Clock} class's representation of time has advanced. */ public static void blockTillClockAdvances() { long startTime = Clock.accurateTimeMillis(); long alwaysProgressingStartTime = Clock.accurateForwardProgressingMillis(); new TestCondition(() -> Clock.accurateTimeMillis() > startTime && Clock.accurateForwardProgressingMillis() > alwaysProgressingStartTime) .blockTillTrue(TestCondition.DEFAULT_TIMEOUT, 1); } }
/** * Blocks until the System clock advances at least 1 millisecond. This will also ensure that * the {@link Clock} class's representation of time has advanced. */ public static void blockTillClockAdvances() { long startTime = Clock.accurateTimeMillis(); long alwaysProgressingStartTime = Clock.accurateForwardProgressingMillis(); new TestCondition(() -> Clock.accurateTimeMillis() > startTime && Clock.accurateForwardProgressingMillis() > alwaysProgressingStartTime) .blockTillTrue(TestCondition.DEFAULT_TIMEOUT, 1); } }
public static void blockTillSchedulerIdle(final StatisticPriorityScheduler scheduler, final int expectedSampleSize) { new TestCondition(() -> scheduler.getActiveTaskCount() == 0 && scheduler.getExecutionDurationSamples().size() >= expectedSampleSize) // block till all are finished .blockTillTrue(); }
protected void blockForProfilerSample() { int startCount = profiler.getCollectedSampleQty(); new TestCondition(() -> profiler.getCollectedSampleQty() > startCount).blockTillTrue(1000 * 20); }
@Test public void accurateTimeMillisTest() { final long startTime = Clock.accurateTimeMillis(); new TestCondition(() -> Clock.accurateTimeMillis() > startTime).blockTillTrue(200); }
@Test public void resetTest() { profiler.start(); // verify there are some samples blockForProfilerSample(); final Thread runningThread = profiler.pStore.collectorThread.get(); profiler.stop(); // verify stopped new TestCondition(() -> ! runningThread.isAlive()).blockTillTrue(1000 * 20); profiler.reset(); assertEquals(0, profiler.pStore.threadTraces.size()); assertEquals(0, profiler.getCollectedSampleQty()); }
@Test public void idlePrioritySchedulerTest() { PriorityScheduler ps = new PriorityScheduler(2); profilingExecutor(ps); ps.prestartAllThreads(); profiler.start(); blockForProfilerSample(); new TestCondition(() -> profiler.dump(false), (s) -> s.contains("PriorityScheduler idle thread (stack 1)") && s.contains("PriorityScheduler idle thread (stack 2)")) .blockTillTrue(); }
@Test public void automaticUpdateTest() { final long before = Clock.lastKnownTimeMillis(); Clock.startClockUpdateThread(); new TestCondition(() -> Clock.lastKnownTimeMillis() > before).blockTillTrue(1000); } }
@Test public void shutdownRecurringTest() { final SingleThreadScheduler sts = new SingleThreadScheduler(); TestRunnable tr = new TestRunnable(); sts.scheduleWithFixedDelay(tr, 0, 0); tr.blockTillStarted(); sts.shutdown(); new TestCondition(() -> ! sts.sManager.execThread.isAlive()).blockTillTrue(); }
@Test public void automaticAlwaysProgressingUpdateTest() { Clock.startClockUpdateThread(); final long before = Clock.lastKnownForwardProgressingMillis(); new TestCondition(() -> Clock.lastKnownForwardProgressingMillis() > before).blockTillTrue(1000); }
@Test public void accurateForwardProgressingMillisTest() { final long timeSinceClockStartMillis = Clock.accurateForwardProgressingMillis(); assertTrue(timeSinceClockStartMillis >= 0); assertTrue(timeSinceClockStartMillis < 1000 * 60 * 15); // less than 15 min new TestCondition(() -> Clock.accurateForwardProgressingMillis() > timeSinceClockStartMillis) .blockTillTrue(200); }
@Test public void timeoutTest() { poller = new Poller(new SingleThreadScheduler(), POLL_INTERVAL, 10); ListenableFuture<?> f = poller.watch(() -> false); TestUtils.sleep(10); new TestCondition(() -> f.isDone() && f.isCancelled()) .blockTillTrue();// will throw if does not become true }