Refine search
@Test(timeout = 2000) public void awaitOperationSupportsSpecifyingPollIntervalUsingTimeunit() { new Asynch(fakeRepository).perform(); with().pollInterval(20, TimeUnit.MILLISECONDS).await().until(fakeRepositoryValueEqualsOne()); given().pollInterval(20, TimeUnit.MILLISECONDS).await().until(fakeRepositoryValueEqualsOne()); assertEquals(1, fakeRepository.getValue()); }
@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 exceptionIgnoringWorksForHamcrestMatchersStatically() { new Asynch(fakeRepository).perform(); Awaitility.ignoreExceptionsByDefaultMatching(instanceOf(RuntimeException.class)); await().atMost(1000, MILLISECONDS).until(conditionsThatIsThrowingAnExceptionForATime(IllegalArgumentException.class)); }
@Test(timeout = 2000L, expected = ConditionTimeoutException.class) public void awaitOperationSupportsDefaultTimeout() { Awaitility.setDefaultTimeout(120, TimeUnit.MILLISECONDS); await().until(value(), greaterThan(0)); assertEquals(1, fakeRepository.getValue()); }
@Test public void will_compose_multiple_futures() throws Exception { CompletableFuture<Integer> f1 = supplyAsync(() -> 666); CompletableFuture<Integer> f2 = supplyAsync(() -> 999); PromisedValues<Integer> promisedValues = PromisedValues.allOf(f1, f2); assertThat(promisedValues.size(), equalTo(2)); await().until(promisedValues::isDone, is(true)); assertThat(promisedValues.toList(), equalTo(asList(666, 999))); }
@Test public void should_Support_loading_multiple_keys_in_one_call() { AtomicBoolean success = new AtomicBoolean(); DataLoader<Integer, Integer> identityLoader = new DataLoader<>(keysAsValues()); CompletionStage<List<Integer>> futureAll = identityLoader.loadMany(asList(1, 2)); futureAll.thenAccept(promisedValues -> { assertThat(promisedValues.size(), is(2)); success.set(true); }); identityLoader.dispatch(); await().untilAtomic(success, is(true)); assertThat(futureAll.toCompletableFuture().join(), equalTo(asList(1, 2))); }
@Test(timeout = 2000, expected = IllegalStateException.class) public void exceptionsInConditionsArePropagatedToAwaitingThreadAndBreaksForeverBlock() { final ExceptionThrowingFakeRepository repository = new ExceptionThrowingFakeRepository(); new Asynch(repository).perform(); await().until(new FakeRepositoryValue(repository), 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 public void should_Resolve_to_empty_list_when_no_keys_supplied() { AtomicBoolean success = new AtomicBoolean(); DataLoader<Integer, Integer> identityLoader = new DataLoader<>(keysAsValues()); CompletableFuture<List<Integer>> futureEmpty = identityLoader.loadMany(emptyList()); futureEmpty.thenAccept(promisedValues -> { assertThat(promisedValues.size(), is(0)); success.set(true); }); identityLoader.dispatch(); await().untilAtomic(success, is(true)); assertThat(futureEmpty.join(), empty()); }
@Test(timeout = 2000) public void usingAtomicInteger() throws Exception { AtomicInteger atomic = new AtomicInteger(0); new Asynch(new FakeRepositoryWithAtomicInteger(atomic)).perform(); await().untilAtomic(atomic, equalTo(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 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 specifyingDefaultPollIntervalImpactsAllSubsequentUndefinedPollIntervalStatements() { Awaitility.setDefaultPollInterval(20, TimeUnit.MILLISECONDS); new Asynch(fakeRepository).perform(); await().until(value(), equalTo(1)); assertEquals(1, fakeRepository.getValue()); }
@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) 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)); }