use of org.neo4j.logging.AssertableLogProvider 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)));
}
use of org.neo4j.logging.AssertableLogProvider 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)));
}
use of org.neo4j.logging.AssertableLogProvider 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)));
}
use of org.neo4j.logging.AssertableLogProvider in project neo4j by neo4j.
the class AsyncLoggingTest method shouldLogWhenLoggingThreadStarts.
@Test
public void shouldLogWhenLoggingThreadStarts() throws Exception {
// given
AssertableLogProvider logs = new AssertableLogProvider();
AsyncLogging logging = new AsyncLogging(logs.getLog("meta"));
// when
new AsyncLogProvider(logging.eventSender(), logs).getLog("test").info("hello");
// then
logs.assertNoLoggingOccurred();
// when
logging.start();
logging.stop();
// then
logs.assertExactly(inLog("test").info(endsWith("hello")));
}
use of org.neo4j.logging.AssertableLogProvider in project neo4j by neo4j.
the class LearnerContextImplTest method shouldOnlyLogLearnMissOnce.
@Test
public void shouldOnlyLogLearnMissOnce() throws Exception {
// Given
final AssertableLogProvider logProvider = new AssertableLogProvider();
LearnerContextImpl ctx = new LearnerContextImpl(new InstanceId(1), mock(CommonContextState.class), logProvider, mock(Timeouts.class), mock(PaxosInstanceStore.class), mock(AcceptorInstanceStore.class), mock(ObjectInputStreamFactory.class), mock(ObjectOutputStreamFactory.class), mock(HeartbeatContextImpl.class));
// When
ctx.notifyLearnMiss(new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(1L));
ctx.notifyLearnMiss(new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(1L));
ctx.notifyLearnMiss(new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(2L));
ctx.notifyLearnMiss(new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(2L));
ctx.notifyLearnMiss(new org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.InstanceId(1L));
// Then
logProvider.assertExactly(inLog(LearnerState.class).warn(containsString("Did not have learned value for Paxos instance 1.")), inLog(LearnerState.class).warn(containsString("Did not have learned value for Paxos instance 2.")), inLog(LearnerState.class).warn(containsString("Did not have learned value for Paxos instance 1.")));
}
Aggregations