/** * This is to provide a convince when advancing the scheduler forward an explicit amount of time. * Where tick accepts an absolute time, this accepts an amount of time to advance forward. That * way the user does not have to track the current time. * * @param timeInMillis amount in milliseconds to advance the scheduler forward * @return quantity of tasks run during this tick call */ public int advance(long timeInMillis) { return advance(timeInMillis, null); }
/** * This function blocks till the first run completes then will return the time until the first * run started it's call. * * @return The amount of time between construction and run being called */ public long getDelayTillFirstRun() { return getDelayTillRun(1); }
/** * Blocks until run has been called at least once. Will throw an exception if run is not called * within 10 seconds. */ public void blockTillStarted() { blockTillStarted(DEFAULT_TIMEOUT_PER_RUN); }
@Override public void handleRunStart() { if (fLastRun != null) { av.assertTrue(fLastRun.ranOnce()); } av.signalComplete(); } };
/** * Blocks until run has completed at least once. Will throw an exception if runnable does not * run within 10 seconds. */ public void blockTillFinished() { blockTillFinished(DEFAULT_TIMEOUT_PER_RUN, 1); }
/** * Marks a failure with no cause. This causes an exception to be thrown in the calling thread, * as well was any blocking thread waiting at {@link #waitForTest()}. */ public void fail() { fail(""); }
/** * 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); }
/** * 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 scheduleWithFixedDelay(Runnable task, long initialDelay, long recurringDelay, TaskPriority priority) { scheduler.scheduleWithFixedDelay(task, initialDelay, recurringDelay, priority); }
/** * Removes any tasks waiting to be run. Will not interrupt any tasks currently running if * {@link #tick(ExceptionHandler)} is being called. But will avoid additional tasks from being * run on the current {@link #tick(ExceptionHandler)} call. * <p> * If tasks are added concurrently during this invocation they may or may not be removed. * * @return List of runnables which were waiting in the task queue to be executed (and were now removed) */ public List<Runnable> clearTasks() { return scheduler.clearTasks(); }
@Override public void handleRunStart() { if (! ranOnce) { // used to prevent infinite recursion ranOnce = true; this.run(); } } };
@Override public void handleRunStart() { if (fLastRun != null) { av.assertTrue(fLastRun.ranOnce()); } av.signalComplete(); } };
/** * This is to provide a convince when advancing the scheduler forward an explicit amount of time. * Where tick accepts an absolute time, this accepts an amount of time to advance forward. That * way the user does not have to track the current time. * * @param timeInMillis amount in milliseconds to advance the scheduler forward * @return quantity of tasks run during this tick call */ public int advance(long timeInMillis) { return advance(timeInMillis, null); }
/** * This function blocks till the run provided, and then gets the time between creation and a * given run. * * @param runNumber the run count to get delay to * @return The amount of time between construction and run being called */ public long getDelayTillRun(int runNumber) { return getDelayTillRun(runNumber, DEFAULT_TIMEOUT_PER_RUN * runNumber); }
/** * Blocks until run has completed at least once. * * @param timeout time to wait for run to be called before throwing exception */ public void blockTillFinished(int timeout) { blockTillFinished(timeout, 1); }
/** * Marks a failure with no cause. This causes an exception to be thrown in the calling thread, * as well was any blocking thread waiting at {@link #waitForTest()}. */ public void fail() { fail(""); }
/** * 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); }
/** * 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 handleRunStart() { if (fLastRun != null) { av.assertTrue(fLastRun.ranOnce()); } av.signalComplete(); } };