Search in sources :

Example 81 with FakeClock

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

the class IdleChannelReaperTest method shouldCloseAnyChannelsThatHaveBeenIdleForLongerThanThreshold.

@Test
public void shouldCloseAnyChannelsThatHaveBeenIdleForLongerThanThreshold() {
    // given
    FakeClock clock = Clocks.fakeClock();
    ChannelCloser channelCloser = mock(ChannelCloser.class);
    IdleChannelReaper idleChannelReaper = new IdleChannelReaper(channelCloser, NO_LOGGING, clock, THRESHOLD);
    Channel channel = mock(Channel.class);
    idleChannelReaper.add(channel, dummyRequestContext());
    // when
    clock.forward(THRESHOLD + 1, TimeUnit.MILLISECONDS);
    idleChannelReaper.run();
    // then
    verify(channelCloser).tryToCloseChannel(channel);
}
Also used : FakeClock(org.neo4j.time.FakeClock) Channel(org.jboss.netty.channel.Channel) Test(org.junit.Test)

Example 82 with FakeClock

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

the class IdleChannelReaperTest method shouldNotTryToCloseAChannelThatHasBeenRemoved.

@Test
public void shouldNotTryToCloseAChannelThatHasBeenRemoved() {
    // given
    FakeClock clock = Clocks.fakeClock();
    ChannelCloser channelCloser = mock(ChannelCloser.class);
    IdleChannelReaper idleChannelReaper = new IdleChannelReaper(channelCloser, NO_LOGGING, clock, THRESHOLD);
    Channel channel = mock(Channel.class);
    RequestContext request = dummyRequestContext();
    idleChannelReaper.add(channel, request);
    // when
    idleChannelReaper.remove(channel);
    clock.forward(THRESHOLD + 1, TimeUnit.MILLISECONDS);
    idleChannelReaper.run();
    // then
    verifyNoMoreInteractions(channelCloser);
}
Also used : FakeClock(org.neo4j.time.FakeClock) Channel(org.jboss.netty.channel.Channel) Test(org.junit.Test)

Example 83 with FakeClock

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

the class QueryLoggerTest method shouldLogQueryOnFailureEvenIfFasterThanThreshold.

@Test
public void shouldLogQueryOnFailureEvenIfFasterThanThreshold() 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);
    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) RETURN n - {}"), sameInstance(failure)));
}
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 84 with FakeClock

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

the class QueryLoggerTest method shouldLogMetaData.

@Test
public void shouldLogMetaData() 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, emptyMap(), map("User", "UltiMate"));
    queryLogger.startQueryExecution(query);
    clock.forward(10, TimeUnit.MILLISECONDS);
    queryLogger.endSuccess(query);
    ExecutingQuery anotherQuery = query(10, SESSION_1, "AnotherUser", QUERY_1, emptyMap(), map("Place", "Town"));
    queryLogger.startQueryExecution(anotherQuery);
    clock.forward(10, TimeUnit.MILLISECONDS);
    Throwable error = new Throwable();
    queryLogger.endFailure(anotherQuery, error);
    // then
    logProvider.assertExactly(inLog(getClass()).info(format("%d ms: %s - %s - {User: 'UltiMate'}", 10L, sessionConnectionDetails(SESSION_1, "TestUser"), QUERY_1)), inLog(getClass()).error(equalTo(format("%d ms: %s - %s - {Place: 'Town'}", 10L, sessionConnectionDetails(SESSION_1, "AnotherUser"), QUERY_1)), sameInstance(error)));
}
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 85 with FakeClock

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

the class QueryLoggerTest method shouldLogQueryParameters.

@Test
public void shouldLogQueryParameters() 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);
    // 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 - %s - {}", 11L, expectedSessionString, QUERY_4, "{ages: " + "[41, 42, 43]}")));
}
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)

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