use of java.time.OffsetDateTime in project neo4j by neo4j.
the class BuiltInProceduresInteractionTestBase method shouldListQueriesEvenIfUsingPeriodicCommit.
@SuppressWarnings("unchecked")
@Test
public void shouldListQueriesEvenIfUsingPeriodicCommit() throws Throwable {
for (int i = 8; i <= 11; i++) {
// Spawns a throttled HTTP server, runs a PERIODIC COMMIT that fetches data from this server,
// and checks that the query is visible when using listQueries()
// Given
final DoubleLatch latch = new DoubleLatch(3, true);
final Barrier.Control barrier = new Barrier.Control();
// Serve CSV via local web server, let Jetty find a random port for us
Server server = createHttpServer(latch, barrier, i, 50 - i);
server.start();
int localPort = getLocalPort(server);
OffsetDateTime startTime = OffsetDateTime.now();
// When
ThreadedTransaction<S> write = new ThreadedTransaction<>(neo, latch);
try {
String writeQuery = write.executeEarly(threading, writeSubject, KernelTransaction.Type.implicit, format("USING PERIODIC COMMIT 10 LOAD CSV FROM 'http://localhost:%d' AS line ", localPort) + "CREATE (n:A {id: line[0], square: line[1]}) " + "RETURN count(*)");
latch.startAndWaitForAllToStart();
// Then
String query = "CALL dbms.listQueries()";
assertSuccess(adminSubject, query, r -> {
Set<Map<String, Object>> maps = r.stream().collect(Collectors.toSet());
Matcher<Map<String, Object>> thisMatcher = listedQuery(startTime, "adminSubject", query);
Matcher<Map<String, Object>> writeMatcher = listedQuery(startTime, "writeSubject", writeQuery);
assertThat(maps, hasItem(thisMatcher));
assertThat(maps, hasItem(writeMatcher));
});
} finally {
// When
barrier.release();
latch.finishAndWaitForAllToFinish();
server.stop();
// Then
write.closeAndAssertSuccess();
}
}
}
use of java.time.OffsetDateTime in project neo4j by neo4j.
the class BuiltInProceduresInteractionTestBase method shouldListAllQueriesWithAuthDisabled.
@Test
public void shouldListAllQueriesWithAuthDisabled() throws Throwable {
neo.tearDown();
neo = setUpNeoServer(stringMap(GraphDatabaseSettings.auth_enabled.name(), "false"));
DoubleLatch latch = new DoubleLatch(2, true);
OffsetDateTime startTime = OffsetDateTime.now();
ThreadedTransaction<S> read = new ThreadedTransaction<>(neo, latch);
String q = read.execute(threading, neo.login("user1", ""), "UNWIND [1,2,3] AS x RETURN x");
latch.startAndWaitForAllToStart();
String query = "CALL dbms.listQueries()";
try {
assertSuccess(neo.login("admin", ""), query, r -> {
Set<Map<String, Object>> maps = r.stream().collect(Collectors.toSet());
Matcher<Map<String, Object>> thisQuery = listedQueryOfInteractionLevel(startTime, "", query);
Matcher<Map<String, Object>> matcher1 = listedQuery(startTime, "", q);
assertThat(maps, matchesOneToOneInAnyOrder(matcher1, thisQuery));
});
} finally {
latch.finishAndWaitForAllToFinish();
}
read.closeAndAssertSuccess();
}
use of java.time.OffsetDateTime in project neo4j by neo4j.
the class BuiltInProceduresInteractionTestBase method shouldListAllQueryIncludingMetaData.
/*
==================================================================================
*/
//---------- list running queries -----------
@Test
public void shouldListAllQueryIncludingMetaData() throws Throwable {
String setMetaDataQuery = "CALL dbms.setTXMetaData( { realUser: 'MyMan' } )";
String matchQuery = "MATCH (n) RETURN n";
String listQueriesQuery = "CALL dbms.listQueries()";
DoubleLatch latch = new DoubleLatch(2);
OffsetDateTime startTime = OffsetDateTime.now();
ThreadedTransaction<S> tx = new ThreadedTransaction<>(neo, latch);
tx.execute(threading, writeSubject, setMetaDataQuery, matchQuery);
latch.startAndWaitForAllToStart();
assertSuccess(adminSubject, listQueriesQuery, r -> {
Set<Map<String, Object>> maps = r.stream().collect(Collectors.toSet());
Matcher<Map<String, Object>> thisQuery = listedQueryOfInteractionLevel(startTime, "adminSubject", listQueriesQuery);
Matcher<Map<String, Object>> matchQueryMatcher = listedQueryWithMetaData(startTime, "writeSubject", matchQuery, map("realUser", "MyMan"));
assertThat(maps, matchesOneToOneInAnyOrder(thisQuery, matchQueryMatcher));
});
latch.finishAndWaitForAllToFinish();
tx.closeAndAssertSuccess();
}
use of java.time.OffsetDateTime in project neo4j by neo4j.
the class BuiltInProceduresInteractionTestBase method shouldOnlyListOwnQueriesWhenNotRunningAsAdmin.
@Test
public void shouldOnlyListOwnQueriesWhenNotRunningAsAdmin() throws Throwable {
DoubleLatch latch = new DoubleLatch(3, true);
OffsetDateTime startTime = OffsetDateTime.now();
ThreadedTransaction<S> read1 = new ThreadedTransaction<>(neo, latch);
ThreadedTransaction<S> read2 = new ThreadedTransaction<>(neo, latch);
String q1 = read1.execute(threading, readSubject, "UNWIND [1,2,3] AS x RETURN x");
String ignored = read2.execute(threading, writeSubject, "UNWIND [4,5,6] AS y RETURN y");
latch.startAndWaitForAllToStart();
String query = "CALL dbms.listQueries()";
assertSuccess(readSubject, query, r -> {
Set<Map<String, Object>> maps = r.stream().collect(Collectors.toSet());
Matcher<Map<String, Object>> thisQuery = listedQuery(startTime, "readSubject", query);
Matcher<Map<String, Object>> queryMatcher = listedQuery(startTime, "readSubject", q1);
assertThat(maps, matchesOneToOneInAnyOrder(queryMatcher, thisQuery));
});
latch.finishAndWaitForAllToFinish();
read1.closeAndAssertSuccess();
read2.closeAndAssertSuccess();
}
use of java.time.OffsetDateTime in project querydsl by querydsl.
the class JSR310OffsetDateTimeTypeTest method get.
@Test
public void get() throws SQLException {
ResultSet resultSet = EasyMock.createNiceMock(ResultSet.class);
EasyMock.expect(resultSet.getTimestamp(1, UTC)).andReturn(new Timestamp(UTC.getTimeInMillis()));
EasyMock.replay(resultSet);
OffsetDateTime result = type.getValue(resultSet, 1);
EasyMock.verify(resultSet);
assertNotNull(result);
assertTrue(result.toEpochSecond() == 0);
}
Aggregations