Search in sources :

Example 21 with FakeClock

use of org.neo4j.time.FakeClock in project neo4j by neo4j.

the class CappedLoggerTest method mustLogAfterResetWithTimeLimit.

@Test
public void mustLogAfterResetWithTimeLimit() throws Exception {
    FakeClock clock = getDefaultFakeClock();
    logger.setTimeLimit(1, TimeUnit.MILLISECONDS, clock);
    logMethod.log(logger, "### AAA ###");
    logMethod.log(logger, "### BBB ###");
    logger.reset();
    logMethod.log(logger, "### CCC ###");
    logProvider.assertContainsMessageMatching(containsString("### AAA ###"));
    logProvider.assertNone(currentLog(inLog(CappedLogger.class), containsString("### BBB ###")));
    logProvider.assertContainsMessageMatching(containsString("### CCC ###"));
}
Also used : FakeClock(org.neo4j.time.FakeClock) Test(org.junit.Test)

Example 22 with FakeClock

use of org.neo4j.time.FakeClock in project neo4j by neo4j.

the class DelayedRenewableTimeoutServiceTest method shouldNotDeadLockWhenCancellingDuringExpiryHandling.

@Test
public void shouldNotDeadLockWhenCancellingDuringExpiryHandling() throws Throwable {
    // given: a timeout handler that blocks on a latch
    final CountDownLatch latch = new CountDownLatch(1);
    FakeClock clock = Clocks.fakeClock();
    DelayedRenewableTimeoutService timeoutService = new DelayedRenewableTimeoutService(clock, NullLogProvider.getInstance());
    RenewableTimeoutService.RenewableTimeout timeout = timeoutService.create(Timeouts.FOOBAR, TIMEOUT_MS, 0, handler -> {
        try {
            latch.await(LONG_TIME_MS, MILLISECONDS);
        } catch (InterruptedException ignored) {
        }
    });
    life.add(timeoutService);
    clock.forward(TIMEOUT_MS, MILLISECONDS);
    // to allow the scheduled timeout to fire and get stuck in the latch
    Thread.sleep(TIMEOUT_MS / 2);
    // given: another thread that wants to cancel the timeout while the handler is in progress
    Thread cancelThread = new Thread() {

        @Override
        public void run() {
            // this would previously deadlock, because the timeout service was stuck handling the handler callback
            timeout.cancel();
        }
    };
    // when: we cancel the timeout, then it should not deadlock, and the latch be immediately released
    cancelThread.start();
    // so the following join should finish quicker than the latch expiry, and the cancelThread should be dead
    cancelThread.join(LONG_TIME_MS / 2);
    assertFalse(cancelThread.isAlive());
    // cleanup
    latch.countDown();
    cancelThread.interrupt();
}
Also used : FakeClock(org.neo4j.time.FakeClock) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 23 with FakeClock

use of org.neo4j.time.FakeClock in project neo4j by neo4j.

the class QueryLoggerTest method shouldLogQueryParametersOnFailure.

@Test
public void shouldLogQueryParametersOnFailure() throws Exception {
    // given
    final AssertableLogProvider logProvider = new AssertableLogProvider();
    Map<String, Object> params = new HashMap<>();
    params.put("ages", Arrays.asList(41, 42, 43));
    ExecutingQuery query = query(0, SESSION_1, "TestUser", QUERY_4, params, emptyMap());
    FakeClock clock = Clocks.fakeClock();
    QueryLogger queryLogger = queryLoggerWithParams(logProvider, clock);
    RuntimeException failure = new RuntimeException();
    // when
    queryLogger.startQueryExecution(query);
    clock.forward(1, TimeUnit.MILLISECONDS);
    queryLogger.endFailure(query, failure);
    // then
    logProvider.assertExactly(inLog(getClass()).error(is("1 ms: " + sessionConnectionDetails(SESSION_1, "TestUser") + " - MATCH (n) WHERE n.age IN {ages} RETURN n - {ages: [41, 42, 43]} - {}"), sameInstance(failure)));
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) HashMap(java.util.HashMap) FakeClock(org.neo4j.time.FakeClock) QueryLogger(org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 24 with FakeClock

use of org.neo4j.time.FakeClock in project neo4j by neo4j.

the class QueryLoggerTest method shouldNotLogQueryFasterThanThreshold.

@Test
public void shouldNotLogQueryFasterThanThreshold() throws Exception {
    // given
    final AssertableLogProvider logProvider = new AssertableLogProvider();
    ExecutingQuery query = query(0, SESSION_1, "TestUser", QUERY_1);
    FakeClock clock = Clocks.fakeClock();
    QueryLogger queryLogger = queryLoggerWithoutParams(logProvider, clock);
    // when
    queryLogger.startQueryExecution(query);
    clock.forward(9, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(query);
    // then
    logProvider.assertNoLoggingOccurred();
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) FakeClock(org.neo4j.time.FakeClock) QueryLogger(org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 25 with FakeClock

use of org.neo4j.time.FakeClock in project neo4j by neo4j.

the class QueryLoggerTest method shouldKeepTrackOfDifferentSessions.

@Test
public void shouldKeepTrackOfDifferentSessions() throws Exception {
    // given
    final AssertableLogProvider logProvider = new AssertableLogProvider();
    ExecutingQuery query1 = query(0, SESSION_1, "TestUser1", QUERY_1);
    ExecutingQuery query2 = query(1, SESSION_2, "TestUser2", QUERY_2);
    ExecutingQuery query3 = query(2, SESSION_3, "TestUser3", QUERY_3);
    FakeClock clock = Clocks.fakeClock();
    QueryLogger queryLogger = queryLoggerWithoutParams(logProvider, clock);
    // when
    queryLogger.startQueryExecution(query1);
    clock.forward(1, TimeUnit.MILLISECONDS);
    queryLogger.startQueryExecution(query2);
    clock.forward(1, TimeUnit.MILLISECONDS);
    queryLogger.startQueryExecution(query3);
    clock.forward(7, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(query3);
    clock.forward(7, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(query2);
    clock.forward(7, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(query1);
    // then
    String expectedSession1String = sessionConnectionDetails(SESSION_1, "TestUser1");
    String expectedSession2String = sessionConnectionDetails(SESSION_2, "TestUser2");
    logProvider.assertExactly(inLog(getClass()).info(format("%d ms: %s - %s - {}", 15L, expectedSession2String, QUERY_2)), inLog(getClass()).info(format("%d ms: %s - %s - {}", 23L, expectedSession1String, QUERY_1)));
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) FakeClock(org.neo4j.time.FakeClock) QueryLogger(org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Aggregations

FakeClock (org.neo4j.time.FakeClock)87 Test (org.junit.Test)85 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 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)14 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)9 QueryLogger (org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger)9 FollowerState (org.neo4j.causalclustering.core.consensus.roles.follower.FollowerState)7 Channel (org.jboss.netty.channel.Channel)5 User (org.neo4j.kernel.impl.security.User)5 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 RaftMachine (org.neo4j.causalclustering.core.consensus.RaftMachine)3 RaftMachineBuilder (org.neo4j.causalclustering.core.consensus.RaftMachineBuilder)3 TestMessageBuilders.voteRequest (org.neo4j.causalclustering.core.consensus.TestMessageBuilders.voteRequest)3 File (java.io.File)2 Clock (java.time.Clock)2