Search in sources :

Example 26 with FakeClock

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

the class QueryLoggerTest method shouldLogUserName.

@Test
public void shouldLogUserName() throws Exception {
    // given
    final AssertableLogProvider logProvider = new AssertableLogProvider();
    FakeClock clock = Clocks.fakeClock();
    QueryLogger queryLogger = queryLoggerWithoutParams(logProvider, clock);
    // when
    ExecutingQuery query = query(0, SESSION_1, "TestUser", QUERY_1);
    queryLogger.startQueryExecution(query);
    clock.forward(10, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(query);
    ExecutingQuery anotherQuery = query(10, SESSION_1, "AnotherUser", QUERY_1);
    queryLogger.startQueryExecution(anotherQuery);
    clock.forward(10, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(anotherQuery);
    // then
    logProvider.assertExactly(inLog(getClass()).info(format("%d ms: %s - %s - {}", 10L, sessionConnectionDetails(SESSION_1, "TestUser"), QUERY_1)), inLog(getClass()).info(format("%d ms: %s - %s - {}", 10L, sessionConnectionDetails(SESSION_1, "AnotherUser"), 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)

Example 27 with FakeClock

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

the class QueryLoggerTest method shouldLogQuerySlowerThanThreshold.

@Test
public void shouldLogQuerySlowerThanThreshold() 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(11, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(query);
    // then
    String expectedSessionString = sessionConnectionDetails(SESSION_1, "TestUser");
    logProvider.assertExactly(inLog(getClass()).info(format("%d ms: %s - %s - {}", 11L, expectedSessionString, 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)

Example 28 with FakeClock

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

the class QueryLoggerTest method runAndCheck.

private void runAndCheck(String inputQuery, String outputQuery, Map<String, Object> params, String paramsString) {
    final AssertableLogProvider logProvider = new AssertableLogProvider();
    FakeClock clock = Clocks.fakeClock();
    QueryLogger queryLogger = queryLoggerWithParams(logProvider, clock);
    // when
    ExecutingQuery query = query(0, SESSION_1, "neo", inputQuery, params, emptyMap());
    queryLogger.startQueryExecution(query);
    clock.forward(10, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(query);
    // then
    logProvider.assertExactly(inLog(getClass()).info(format("%d ms: %s - %s - {%s} - {}", 10L, sessionConnectionDetails(SESSION_1, "neo"), outputQuery, paramsString)));
}
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)

Example 29 with FakeClock

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

the class RestfulGraphDatabasePagedTraversalTest method shouldRespondWith404WhenTraversalHasExpired.

@Test
public void shouldRespondWith404WhenTraversalHasExpired() {
    Response response = createAPagedTraverser();
    ((FakeClock) leaseManager.getClock()).forward(2, TimeUnit.MINUTES);
    String traverserId = parseTraverserIdFromLocationUri(response);
    response = service.pagedTraverse(traverserId, TraverserReturnType.node);
    assertEquals(404, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) FakeClock(org.neo4j.time.FakeClock) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 30 with FakeClock

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

the class RestfulGraphDatabasePagedTraversalTest method shouldRenewLeaseAtEachTraversal.

@Test
public void shouldRenewLeaseAtEachTraversal() {
    Response response = createAPagedTraverser();
    String traverserId = parseTraverserIdFromLocationUri(response);
    ((FakeClock) leaseManager.getClock()).forward(30, TimeUnit.SECONDS);
    response = service.pagedTraverse(traverserId, TraverserReturnType.node);
    assertEquals(200, response.getStatus());
    ((FakeClock) leaseManager.getClock()).forward(30, TimeUnit.SECONDS);
    response = service.pagedTraverse(traverserId, TraverserReturnType.node);
    assertEquals(200, response.getStatus());
    ((FakeClock) leaseManager.getClock()).forward(enoughMinutesToExpireTheLease(), TimeUnit.MINUTES);
    response = service.pagedTraverse(traverserId, TraverserReturnType.node);
    assertEquals(404, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) FakeClock(org.neo4j.time.FakeClock) Matchers.containsString(org.hamcrest.Matchers.containsString) 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