/** * 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 public void shouldBeAcceptedBecauseOfLeeway() throws InterruptedException, UnsupportedEncodingException { final SamlRequestIdManager manager = SamlRequestIdManager.ofJwt("me", "test", 1, 1); final Instant started = Instant.now(); final String id = manager.newId(); assertThat(manager.validateId(id)).isTrue(); await().pollDelay(Duration.TWO_HUNDRED_MILLISECONDS) .atMost(Duration.FIVE_SECONDS) .untilAsserted(() -> assertThat(manager.validateId(id)).isFalse()); assertThat(java.time.Duration.between(started, Instant.now()).toMillis()) .isGreaterThan(TimeUnit.SECONDS.toMillis(2)); }
@Test public void shouldBeExpired() throws InterruptedException, UnsupportedEncodingException { final SamlRequestIdManager manager = SamlRequestIdManager.ofJwt("me", "test", 1, 0); final Instant started = Instant.now(); final String id = manager.newId(); assertThat(manager.validateId(id)).isTrue(); await().pollDelay(Duration.TWO_HUNDRED_MILLISECONDS) .atMost(Duration.FIVE_SECONDS) .untilAsserted(() -> assertThat(manager.validateId(id)).isFalse()); assertThat(java.time.Duration.between(started, Instant.now()).toMillis()) .isGreaterThan(TimeUnit.SECONDS.toMillis(1)); }
@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()); }
given().pollDelay(0, MILLISECONDS).and().ignoreExceptions().await().until(new Callable<Boolean>() { @Override public Boolean call() {
@Test public void awaitilityThrowsIllegalStateExceptionWhenTimeoutIsLessThanPollDelay() { exception.expect(IllegalStateException.class); exception.expectMessage(is("Timeout (10 seconds) must be greater than the poll delay (10 minutes).")); with().pollDelay(10, MINUTES).await().atMost(10, SECONDS).until(fakeRepositoryValueEqualsOne()); }
@Test(timeout = 2000) public void awaitOperationSupportsSpecifyingPollDelay() { new Asynch(fakeRepository).perform(); with().pollDelay(Duration.ONE_HUNDRED_MILLISECONDS).await().until(fakeRepositoryValueEqualsOne()); assertEquals(1, fakeRepository.getValue()); }
@Test(timeout = 2000) public void awaitOperationSupportsSpecifyingZeroAsPollDelay() { new Asynch(fakeRepository).perform(); with().pollDelay(Duration.ZERO).pollInterval(Duration.ONE_HUNDRED_MILLISECONDS).then().await().until(fakeRepositoryValueEqualsOne()); assertEquals(1, fakeRepository.getValue()); }
@Test(timeout = 2000) public void awaitOperationSupportsSpecifyingZeroAsPollInterval() { new Asynch(fakeRepository).perform(); with().pollDelay(Duration.TWO_HUNDRED_MILLISECONDS).pollInterval(Duration.ZERO).then().await().until(fakeRepositoryValueEqualsOne()); assertEquals(1, fakeRepository.getValue()); }
@Test(timeout = 2000) public void awaitOperationDoesntSupportSpecifyingForeverAsPollInterval() { exception.expect(IllegalArgumentException.class); exception.expectMessage("Cannot use a fixed poll interval of length 'forever'"); new Asynch(fakeRepository).perform(); with().pollDelay(Duration.ONE_HUNDRED_MILLISECONDS).pollInterval(Duration.FOREVER).then().await().until(fakeRepositoryValueEqualsOne()); assertEquals(1, fakeRepository.getValue()); }
@Test(timeout = 2000) public void awaitOperationDoesntSupportSpecifyingForeverAsPollDelay() { exception.expect(IllegalArgumentException.class); exception.expectMessage("Cannot delay polling forever"); new Asynch(fakeRepository).perform(); with().pollDelay(Duration.FOREVER).pollInterval(Duration.ONE_HUNDRED_MILLISECONDS).then().await().until(fakeRepositoryValueEqualsOne()); assertEquals(1, fakeRepository.getValue()); }
@SuppressWarnings("unchecked") public static void testLibrary(KnowledgeBaseType type) { SpongeEngine engine = ScriptTestUtils.startWithConfig(type, "knowledge_base_library"); try { await().pollDelay(5, TimeUnit.SECONDS).atMost(60, TimeUnit.SECONDS) .until(() -> ((Map<String, String>) engine.getOperations().getVariable("hostStatus")).size() >= 2); Map<String, String> hostStatus = (Map<String, String>) engine.getOperations().getVariable("hostStatus"); assertEquals("ERROR", hostStatus.get("www.wikipedia.org.unknown")); assertTrue(Integer.decode(hostStatus.get("www.wikipedia.org").trim()).intValue() > 0); assertFalse(engine.isError()); } finally { engine.shutdown(); } }
void waitUntilReady() { System.out.println( ">> Riak HealthCheck BEGIN" ); Instant start = Instant.now(); Awaitility.await() .pollDelay( Duration.ZERO ) .pollInterval( Duration.ONE_SECOND ) .timeout( Duration.ONE_MINUTE ) .until( new HealthCheck() ); System.out.println( ">> Riak HealthCheck END, took " + java.time.Duration.between( start, Instant.now() ) ); }
private void waitForVideoCompleted(File video) { try { await().atMost(5, TimeUnit.SECONDS) .pollDelay(1, TimeUnit.SECONDS) .ignoreExceptions() .until(video::exists); } catch (ConditionTimeoutException ex) { throw new RecordingException(ex.getMessage()); } } }
public static void testCorrelatorsDuration(KnowledgeBaseType type) { SpongeEngine engine = ScriptTestUtils.startWithKnowledgeBase(type, "correlators_duration"); try { await().pollDelay(5, TimeUnit.SECONDS).atMost(30, TimeUnit.SECONDS) .until(() -> engine.getOperations().getVariable(Number.class, "hardwareFailureScriptCount").intValue() >= 3); assertFalse(engine.isError()); } finally { engine.shutdown(); } } }
private void waitForVideoCompleted(File video) { try { await().atMost(5, TimeUnit.SECONDS) .pollDelay(1, TimeUnit.SECONDS) .ignoreExceptions() .until(video::exists); } catch (ConditionTimeoutException ex) { throw new RecordingException(ex.getMessage()); } } }
@Test public void testOpen_error() throws IOException { doReturn(Single.error(new InterruptedException())).when(rxProcess).open(); RxShell rxShell = new RxShell(rxProcess); TestObserver<RxShell.Session> sessionObs = rxShell.open().test(); await().pollDelay(1, TimeUnit.SECONDS).until(sessionObs::isTerminated, is(true)); sessionObs.assertNoValues(); }
public static void testKbPlugin(KnowledgeBaseType type) { SpongeEngine engine = ScriptTestUtils.startWithConfig(type, "plugins_kb"); try { await().pollDelay(1, TimeUnit.SECONDS).atMost(30, TimeUnit.SECONDS) .until(() -> engine.getOperations().getVariable("valueAfter") != null); assertEquals("Value A", engine.getOperations().getVariable("valueBefore")); assertEquals("Value B", engine.getOperations().getVariable("valueAfter")); assertFalse(engine.isError()); } finally { engine.shutdown(); } } }
public static void testJavaPlugin(KnowledgeBaseType type) { SpongeEngine engine = ScriptTestUtils.startWithConfig(type, "plugins_java"); try { await().pollDelay(1, TimeUnit.SECONDS).atMost(30, TimeUnit.SECONDS) .until(() -> engine.getOperations().getVariable("connectionName") != null); assertEquals("Example connection", engine.getOperations().getVariable("connectionName")); assertEquals("Echo test! x 2", engine.getOperations().getVariable("echoConfig")); assertFalse(engine.isError()); } finally { engine.shutdown(); } }