Search in sources :

Example 6 with OffsetDateTime

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();
        }
    }
}
Also used : Server(org.eclipse.jetty.server.Server) TransactionIT.createHttpServer(org.neo4j.bolt.v1.runtime.integration.TransactionIT.createHttpServer) Barrier(org.neo4j.test.Barrier) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) OffsetDateTime(java.time.OffsetDateTime) DoubleLatch(org.neo4j.test.DoubleLatch) Map(java.util.Map) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) Collections.emptyMap(java.util.Collections.emptyMap) Test(org.junit.Test)

Example 7 with OffsetDateTime

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();
}
Also used : OffsetDateTime(java.time.OffsetDateTime) DoubleLatch(org.neo4j.test.DoubleLatch) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) Collections.emptyMap(java.util.Collections.emptyMap) Test(org.junit.Test)

Example 8 with OffsetDateTime

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();
}
Also used : OffsetDateTime(java.time.OffsetDateTime) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DoubleLatch(org.neo4j.test.DoubleLatch) Map(java.util.Map) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) Collections.emptyMap(java.util.Collections.emptyMap) Test(org.junit.Test)

Example 9 with OffsetDateTime

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();
}
Also used : OffsetDateTime(java.time.OffsetDateTime) DoubleLatch(org.neo4j.test.DoubleLatch) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) Collections.emptyMap(java.util.Collections.emptyMap) Test(org.junit.Test)

Example 10 with OffsetDateTime

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);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) ResultSet(java.sql.ResultSet) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Aggregations

OffsetDateTime (java.time.OffsetDateTime)191 Test (org.testng.annotations.Test)139 Instant (java.time.Instant)22 Test (org.junit.Test)20 ZonedDateTime (java.time.ZonedDateTime)17 LocalDateTime (java.time.LocalDateTime)12 LocalDate (java.time.LocalDate)11 LocalTime (java.time.LocalTime)10 Timestamp (java.sql.Timestamp)6 OffsetTime (java.time.OffsetTime)6 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)6 Map (java.util.Map)6 Date (java.sql.Date)4 Clock (java.time.Clock)4 ZoneOffset (java.time.ZoneOffset)4 DateTimeFormatter (java.time.format.DateTimeFormatter)4 Collections.emptyMap (java.util.Collections.emptyMap)4 UUID (java.util.UUID)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 MapUtil.stringMap (org.neo4j.helpers.collection.MapUtil.stringMap)4