use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class CappedLoggerTest method mustOnlyLogMessagesThatPassBothLimits.
@Test
public void mustOnlyLogMessagesThatPassBothLimits() throws Exception {
FakeClock clock = getDefaultFakeClock();
logger.setCountLimit(2);
logger.setTimeLimit(1, TimeUnit.MILLISECONDS, clock);
logMethod.log(logger, "### AAA ###");
// Filtered by the time limit
logMethod.log(logger, "### BBB ###");
clock.forward(1, TimeUnit.MILLISECONDS);
// Filtered by the count limit
logMethod.log(logger, "### CCC ###");
logger.reset();
logMethod.log(logger, "### DDD ###");
logProvider.assertContainsMessageMatching(containsString("### AAA ###"));
logProvider.assertNone(currentLog(inLog(CappedLogger.class), containsString("### BBB ###")));
logProvider.assertNone(currentLog(inLog(CappedLogger.class), containsString("### CCC ###")));
logProvider.assertContainsMessageMatching(containsString("### DDD ###"));
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class InputStreamAwaiterTest method shouldTimeoutWhenNoContentProvided.
@Test
public void shouldTimeoutWhenNoContentProvided() throws Exception {
// given
FakeClock clock = getFakeClock();
InputStream inputStream = spy(new MockInputStream(new Ticker(clock, 1, TimeUnit.SECONDS)));
InputStreamAwaiter awaiter = new InputStreamAwaiter(clock, inputStream);
// when
try {
awaiter.awaitLine("important message", 5, TimeUnit.SECONDS);
fail("should have thrown exception");
}// then
catch (TimeoutException e) {
// ok
}
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class InputStreamAwaiterTest method shouldTimeoutWhenDifferentContentProvided.
@Test
public void shouldTimeoutWhenDifferentContentProvided() throws Exception {
// given
FakeClock clock = getFakeClock();
InputStream inputStream = spy(new MockInputStream(new Ticker(clock, 1, TimeUnit.SECONDS), lines("different content"), lines("different message")));
InputStreamAwaiter awaiter = new InputStreamAwaiter(clock, inputStream);
// when
try {
awaiter.awaitLine("important message", 5, TimeUnit.SECONDS);
fail("should have thrown exception");
}// then
catch (TimeoutException e) {
// ok
}
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class InputStreamAwaiterTest method shouldWaitForALineWithoutBlocking.
@Test
public void shouldWaitForALineWithoutBlocking() throws Exception {
// given
FakeClock clock = getFakeClock();
InputStream inputStream = spy(new MockInputStream(new Ticker(clock, 5, TimeUnit.MILLISECONDS), lines("important message")));
InputStreamAwaiter awaiter = new InputStreamAwaiter(clock, inputStream);
// when
awaiter.awaitLine("important message", 5, TimeUnit.SECONDS);
}
use of org.neo4j.time.FakeClock in project neo4j by neo4j.
the class MultiExecutionMonitorTest method shouldCheckMultipleMonitors.
@Test
public void shouldCheckMultipleMonitors() throws Exception {
// GIVEN
FakeClock clock = Clocks.fakeClock();
TestableMonitor first = new TestableMonitor(clock, 100, MILLISECONDS, "first");
TestableMonitor other = new TestableMonitor(clock, 250, MILLISECONDS, "other");
MultiExecutionMonitor multiMonitor = new MultiExecutionMonitor(clock, first, other);
// WHEN/THEN
clock.forward(110, MILLISECONDS);
expectCallsToCheck(multiMonitor, first, 1, other, 0);
clock.forward(100, MILLISECONDS);
expectCallsToCheck(multiMonitor, first, 2, other, 0);
clock.forward(45, MILLISECONDS);
expectCallsToCheck(multiMonitor, first, 2, other, 1);
}
Aggregations