Search in sources :

Example 86 with FakeClock

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 ###"));
}
Also used : FakeClock(org.neo4j.time.FakeClock) Test(org.junit.Test)

Example 87 with FakeClock

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
    }
}
Also used : FakeClock(org.neo4j.time.FakeClock) InputStream(java.io.InputStream) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 88 with FakeClock

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
    }
}
Also used : FakeClock(org.neo4j.time.FakeClock) InputStream(java.io.InputStream) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 89 with FakeClock

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);
}
Also used : FakeClock(org.neo4j.time.FakeClock) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 90 with FakeClock

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);
}
Also used : FakeClock(org.neo4j.time.FakeClock) Test(org.junit.Test)

Aggregations

FakeClock (org.neo4j.time.FakeClock)111 Test (org.junit.Test)82 Test (org.junit.jupiter.api.Test)21 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)20 ControlledRenewableTimeoutService (org.neo4j.causalclustering.core.consensus.schedule.ControlledRenewableTimeoutService)17 MembershipEntry (org.neo4j.causalclustering.core.consensus.membership.MembershipEntry)16 RaftCoreState (org.neo4j.causalclustering.core.state.snapshot.RaftCoreState)16 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)9 QueryLogger (org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger)9 User (org.neo4j.kernel.impl.security.User)9 FollowerState (org.neo4j.causalclustering.core.consensus.roles.follower.FollowerState)7 Channel (org.jboss.netty.channel.Channel)5 Path (java.nio.file.Path)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Response (javax.ws.rs.core.Response)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 InputStream (java.io.InputStream)3 ExecutionException (java.util.concurrent.ExecutionException)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 RaftMachine (org.neo4j.causalclustering.core.consensus.RaftMachine)3