/** * 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(""); }
/** * 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(""); }
@Override public void handleResult(Object result) { av.fail(); }
@Override public void run() { try { Thread.sleep(ASYNC_WAIT_AMOUNT); } catch (InterruptedException e) { // let thread exit return; } verifier.fail("foo"); } }).start();
@Override public void run() { try { Thread.sleep(ASYNC_WAIT_AMOUNT); } catch (InterruptedException e) { // let thread exit return; } verifier.fail(); } }).start();
@Override public void handleRunStart() { int runningCount = running.incrementAndGet(); if (runningCount > 1) { verifier.fail(runningCount + " currently running"); } }
@Override public void handleRunStart() { int runningCount = running.incrementAndGet(); if (runningCount > PARALLEL_COUNT) { verifier.fail(runningCount + " currently running"); } }
@Override public void run() { try { Thread.sleep(ASYNC_WAIT_AMOUNT); } catch (InterruptedException e) { // let thread exit return; } verifier.fail(new Exception()); } }).start();
@Test (expected = RuntimeException.class) public void failTest() { verifier.fail(); }
@Test public void failThrowableTest() { Exception failure = new Exception(); try { verifier.fail(failure); fail("Exception should have thrown"); } catch (RuntimeException e) { assertTrue(failure == e.getCause()); } }
@Override public void run() { try { rfca.run(); av.fail("Exception did not throw"); } catch (RuntimeException expected) { av.signalComplete(); } } });
@Test public void failMsgTest() { String msg = StringUtils.makeRandomString(5); try { verifier.fail(msg); fail("Exception should have thrown"); } catch (RuntimeException e) { assertEquals(msg, e.getMessage()); } }
@Override public void handleRunStart() { try { int runCount = scheduler.blockingTick(null); // should block av.assertEquals(1, runCount); av.signalComplete(); } catch (InterruptedException e) { av.fail(e); } } };
@Override public void handleRunStart() { try { long startTime = Clock.accurateForwardProgressingMillis(); scheduler.schedule(testTask, DELAY_TIME); int runCount = scheduler.blockingTick(null); // should block long finishTime = Clock.accurateForwardProgressingMillis(); av.assertEquals(1, runCount); av.assertTrue(finishTime - startTime >= DELAY_TIME); av.assertTrue(testTask.ranOnce()); av.signalComplete(); } catch (InterruptedException e) { av.fail(e); } } };
@Test public void startWithSameThreadExecutorTest() throws InterruptedException, TimeoutException { AsyncVerifier av = new AsyncVerifier(); PrioritySchedulerStatisticTracker s = new PrioritySchedulerStatisticTracker(1); try { s.schedule(() -> { av.assertTrue(profiler.isRunning()); try { blockForProfilerSample(); profiler.stop(); // this should unblock the test thread } catch (Exception e) { av.fail(e); } av.signalComplete(); }, 200); profiler.start(SameThreadSubmitterExecutor.instance()); // will block while profile runs av.waitForTest(); // test already completed, just check result } finally { s.shutdownNow(); } }