/** * Condition has to be evaluated not earlier than <code>timeout</code> before throwing a timeout exception. * * @param timeout the timeout * @param unit the unit * @return the condition factory */ public ConditionFactory atLeast(long timeout, TimeUnit unit) { return atLeast(new Duration(timeout, unit)); }
/** * Specifies the duration window which has to be satisfied during operation execution. In case operation is executed * before <code>atLeast</code> or after <code>atMost</code> timeout exception is thrown. * * @param atLeast lower part of execution window * @param atMost upper part of execution window * @return the condition factory */ public ConditionFactory between(Duration atLeast, Duration atMost) { return atLeast(atLeast).and().atMost(atMost); }
@Test(timeout = 3000) public void doesNotThrowTimeoutExceptionWhenDoneLaterThanAtLeastConstraint() { new Asynch(fakeRepository).perform(); await().atLeast(100, NANOSECONDS).until(value(), equalTo(1)); }
@Test(timeout = 3000, expected = ConditionTimeoutException.class) public void throwsTimeoutExceptionWhenDoneEarlierThanAtLeastConstraint() { new Asynch(fakeRepository).perform(); await().atLeast(1, SECONDS).and().atMost(2, SECONDS).until(value(), equalTo(1)); }
/** * Condition has to be evaluated not earlier than <code>timeout</code> before throwing a timeout exception. * * @param timeout the timeout * @param unit the unit * @return the condition factory */ public ConditionFactory atLeast(long timeout, TimeUnit unit) { return atLeast(new Duration(timeout, unit)); }
/** * Specifies the duration window which has to be satisfied during operation execution. In case operation is executed * before <code>atLeast</code> or after <code>atMost</code> timeout exception is thrown. * * @param atLeast lower part of execution window * @param atMost upper part of execution window * @return the condition factory */ public ConditionFactory between(Duration atLeast, Duration atMost) { return atLeast(atLeast).and().atMost(atMost); }
public void explicitWait(long milliSeconds) { try { await().atLeast(new Duration(milliSeconds, MILLISECONDS)); } catch (Exception e) { LOGGER.error(e); } }
@Test public void testDispatchInterval() throws Exception { List<Packet> dryRunData = Collections.synchronizedList(new ArrayList<Packet>()); mDispatcher.setDryRunTarget(dryRunData); mDispatcher.setDispatchInterval(500); assertThat(dryRunData.isEmpty(), is(true)); mDispatcher.submit(getTestEvent()); await().atLeast(500, TimeUnit.MILLISECONDS).until(() -> dryRunData.size() == 1); }
@Test public void testDispatchInterval() throws Exception { List<Packet> dryRunData = Collections.synchronizedList(new ArrayList<Packet>()); mDispatcher.setDryRunTarget(dryRunData); mDispatcher.setDispatchInterval(500); assertThat(dryRunData.isEmpty(), is(true)); mDispatcher.submit(getTestEvent()); await().atLeast(500, TimeUnit.MILLISECONDS).until(() -> dryRunData.size() == 1); }
@Test(invocationCount = 5) public void testLoadingStopWithLogParser() throws IOException { saveLines(Range.closed(0, julSimpleLogLines.size()), julSimpleLogLines, outputStream); underTest = createLoadingRunnable(getJulLogParser()); executorService.submit(underTest); await().until(() -> collector.getCount() == 1000); underTest.stop(); saveLines(Range.closed(0, julSimpleLogLines.size()), julSimpleLogLines, outputStream); await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> collector.getCount() == 1000); }
@Test public void testDispatchRetryWithBackoff() throws Exception { AtomicInteger cnt = new AtomicInteger(0); when(mPacketSender.send(any())).then(new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { return cnt.incrementAndGet() > 5; } }); mDispatcher.setDispatchInterval(100); mDispatcher.submit(getTestEvent()); await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> cnt.get() == 1); await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> cnt.get() == 2); await().atMost(1900, TimeUnit.MILLISECONDS).until(() -> cnt.get() == 5); mDispatcher.submit(getTestEvent()); await().atMost(150, TimeUnit.MILLISECONDS).until(() -> cnt.get() == 5); }
@Test public void testDispatchRetryWithBackoff() throws Exception { AtomicInteger cnt = new AtomicInteger(0); when(mPacketSender.send(any())).then(new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { return cnt.incrementAndGet() > 5; } }); mDispatcher.setDispatchInterval(100); mDispatcher.submit(getTestEvent()); await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> cnt.get() == 1); await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> cnt.get() == 2); await().atMost(1900, TimeUnit.MILLISECONDS).until(() -> cnt.get() == 5); mDispatcher.submit(getTestEvent()); await().atMost(150, TimeUnit.MILLISECONDS).until(() -> cnt.get() == 5); }
@Test(invocationCount = 5, dataProvider = "testLoadingAndPauseResumeDataProvider") public void testLoadingAndPauseResume( String name, LogImporter importer, String logSource, Range<Integer> range1, int countForFirstImport, Range<Integer> range2, int countForSecondImport) throws Exception { List<String> logLines = linesOfResources(logSource); LOGGER.debug("Testing " + name); saveLines(range1, logLines, outputStream); underTest = createLoadingRunnable(importer); executorService.submit(underTest); await().until(() -> collector.getCount() == countForFirstImport); underTest.pause(); saveLines(range2, logLines, outputStream); await().atLeast(100, TimeUnit.MILLISECONDS).until(() -> collector.getCount() == countForFirstImport); underTest.resume(); await().until(() -> collector.getCount() == countForSecondImport); }