Refine search
@Test(timeout = 10000) public void conditionResultsCanBeLoggedToSystemOut() { with() .conditionEvaluationListener(new ConditionEvaluationListener<Integer>() { public void conditionEvaluated(EvaluatedCondition<Integer> condition) { if (condition.isSatisfied()) { System.out.printf("%s (in %ds)%n", condition.getDescription(), condition.getElapsedTimeInMS() / 1000); } else { System.out.printf("%s (elapsed time %ds, remaining time %ds)%n", condition.getDescription(), condition.getElapsedTimeInMS() / 1000, condition.getRemainingTimeInMS() / 1000); } } }) .pollInterval(Duration.ONE_SECOND) .atMost(Duration.TEN_SECONDS) .until(new CountDown(5), is(equalTo(0))); }
private void waitForTicks(int minTicks) { try { Awaitility.with() .pollInterval(1, TimeUnit.MILLISECONDS) .atMost(Testing.TEST_TIMEOUT_MS, TimeUnit.MILLISECONDS) .untilAsserted(() -> assertThat(tickTupleCount.get(), Matchers.greaterThanOrEqualTo(minTicks))); } catch (ConditionTimeoutException e) { throw new AssertionError(e.getMessage()); } }
@Test public void awaitilityThrowsIllegalStateExceptionWhenTimeoutIsEqualToPollDelay() { exception.expect(IllegalStateException.class); exception.expectMessage(is("Timeout (200 milliseconds) must be greater than the poll delay (200 milliseconds).")); with().with().pollDelay(20, MILLISECONDS).pollDelay(200, MILLISECONDS).await().atMost(200, MILLISECONDS).until(fakeRepositoryValueEqualsOne()); }
public static ConditionFactory await() { return Awaitility.await().pollInterval(POLL_INTERVAL, SECONDS).atMost(TIMEOUT, SECONDS); }
/** * Start building an await statement using Geode's default test timeout. * * @param alias a name for this await, if you test has multiple await statements * * @return a {@link ConditionFactory} that is a builder for the await * * @see org.awaitility.Awaitility#await(String) */ public static ConditionFactory await(String alias) { return org.awaitility.Awaitility.await(alias) .atMost(getTimeout()) .pollDelay(POLL_DELAY) .pollInterval(POLL_INTERVAL); }
/** Returns a configured {@link ConditionFactory} that polls at a short interval. */ public static ConditionFactory await() { return Awaitility.with() .pollDelay(1, TimeUnit.MILLISECONDS).and() .pollInterval(1, TimeUnit.MILLISECONDS); } }
@Test(expected = RuntimeException.class) public void listenerExceptionsAreNotCaught() { with() .catchUncaughtExceptions() .conditionEvaluationListener(new ConditionEvaluationListener<Integer>() { public void conditionEvaluated(EvaluatedCondition<Integer> condition) { throw new RuntimeException(); } }) .until(new CountDown(10), is(equalTo(0))); }
@Test(dataProvider = "caches") @CacheSpec(refreshAfterWrite = Expire.ONE_MINUTE, loader = Loader.NULL) public void get_null(AsyncLoadingCache<Integer, Integer> cache, CacheContext context) { Integer key = 1; cache.synchronous().put(key, key); context.ticker().advance(2, TimeUnit.MINUTES); await().until(() -> cache.synchronous().getIfPresent(key), is(nullValue())); }
@Test public void getMultipleInstances() throws Exception { // Arrange TestBean[] beans = new TestBean[2]; Thread thread1 = new Thread(() -> beans[0] = applicationContext.getBean("threadScopedObject", TestBean.class)); Thread thread2 = new Thread(() -> beans[1] = applicationContext.getBean("threadScopedObject", TestBean.class)); // Act thread1.start(); thread2.start(); // Assert Awaitility.await() .atMost(500, TimeUnit.MILLISECONDS) .pollInterval(10, TimeUnit.MILLISECONDS) .until(() -> (beans[0] != null) && (beans[1] != null)); assertNotSame(beans[0], beans[1]); }
@Test(timeout = 2000) public void exceptionsDuringEvaluationAreReportedByDefault() { exception.expect(RuntimeException.class); exception.expectMessage(is("Repository value is not 1")); new Asynch(fakeRepository).perform(); await().atMost(1000, MILLISECONDS).with().until(conditionsThatIsThrowingAnExceptionForATime(RuntimeException.class)); }
@Test(timeout = 2000) public void awaitDisplaysMethodDeclaringTheSupplierWhenSupplierIsAnonymousClassAndConditionTimeoutExceptionOccurs() { exception.expect(ConditionTimeoutException.class); exception .expectMessage(String .format("%s.valueAsAnonymous Callable expected %s but was <0> within 120 milliseconds.", AwaitilityTest.class.getName(), equalTo(2).toString())); with().pollInterval(10, MILLISECONDS).await().atMost(120, MILLISECONDS).until(valueAsAnonymous(), equalTo(2)); }
@Test(timeout = 2000) public void assertionErrorIgnoringWorksForHamcrestMatchers() { new Asynch(fakeRepository).perform(); await().atMost(1000, MILLISECONDS).with().ignoreExceptionsMatching(instanceOf(AssertionError.class)).until(conditionsThatIsThrowingAnExceptionForATime(AssertionError.class)); }
@Test(timeout = 2000, expected = IllegalStateException.class) public void uncaughtExceptionsArePropagatedToAwaitingThreadAndBreaksForeverBlockWhenSetToCatchAllUncaughtExceptions() { catchUncaughtExceptionsByDefault(); new ExceptionThrowingAsynch(new IllegalStateException("Illegal state!")).perform(); await().forever().until(value(), equalTo(1)); }
@Test(timeout = 2000) public void usingAtomicReferenceAndTimeout() throws Exception { exception.expect(ConditionTimeoutException.class); exception.expectMessage( "org.awaitility.core.ConditionFactory.untilAtomic Callable expected \"1\" but was \"0\" within 200 milliseconds."); AtomicReference<String> atomic = new AtomicReference<String>("0"); await().atMost(200, MILLISECONDS).untilAtomic(atomic, equalTo("1")); }
@Test(timeout = 2000) public void noIgnoredExceptionsHavePrecedenceOverStaticallyDefinedExceptionIgnorer() { exception.expect(IllegalArgumentException.class); exception.expectMessage("Repository value is not 1"); new Asynch(fakeRepository).perform(); Awaitility.ignoreExceptionsByDefaultMatching(instanceOf(RuntimeException.class)); await().atMost(1000, MILLISECONDS).with().ignoreNoExceptions().until(conditionsThatIsThrowingAnExceptionForATime(IllegalArgumentException.class)); }