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)));
}
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)));
}
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)));
}
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());
}
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());
}
Aggregations