Search in sources :

Example 16 with Driver

use of org.h2.Driver in project neo4j by neo4j.

the class BoltCausalClusteringIT method bookmarksShouldWorkWithDriverPinnedToSingleServer.

// Ensure that Bookmarks work with single instances using a driver created using a bolt[not+routing] URI.
@Test
public void bookmarksShouldWorkWithDriverPinnedToSingleServer() throws Exception {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(1).startCluster();
    CoreClusterMember leader = cluster.awaitLeader();
    try (Driver driver = GraphDatabase.driver(leader.directURI(), AuthTokens.basic("neo4j", "neo4j"))) {
        String bookmark = inExpirableSession(driver, Driver::session, (session) -> {
            try (Transaction tx = session.beginTransaction()) {
                tx.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Alistair"));
                tx.success();
            }
            return session.lastBookmark();
        });
        assertNotNull(bookmark);
        try (Session session = driver.session();
            Transaction tx = session.beginTransaction(bookmark)) {
            Record record = tx.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
            assertEquals(1, record.get("count").asInt());
            tx.success();
        }
    }
}
Also used : Transaction(org.neo4j.driver.v1.Transaction) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Driver(org.neo4j.driver.v1.Driver) Record(org.neo4j.driver.v1.Record) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Session(org.neo4j.driver.v1.Session) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) Test(org.junit.Test)

Example 17 with Driver

use of org.h2.Driver in project neo4j by neo4j.

the class TransactionGuardIntegrationTest method terminateLongRunningDriverPeriodicCommitQuery.

@Test
public void terminateLongRunningDriverPeriodicCommitQuery() throws Exception {
    GraphDatabaseAPI database = startDatabaseWithTimeoutCustomGuard();
    CommunityNeoServer neoServer = startNeoServer((GraphDatabaseFacade) database);
    org.neo4j.driver.v1.Config driverConfig = getDriverConfig();
    try (Driver driver = GraphDatabase.driver("bolt://localhost:" + boltPortCustomGuard, driverConfig);
        Session session = driver.session()) {
        URL url = prepareTestImportFile(8);
        session.run("USING PERIODIC COMMIT 5 LOAD CSV FROM '" + url + "' AS line CREATE ();").consume();
        fail("Transaction should be already terminated by execution guard.");
    } catch (Exception expected) {
    //
    }
    assertDatabaseDoesNotHaveNodes(database);
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CommunityNeoServer(org.neo4j.server.CommunityNeoServer) Driver(org.neo4j.driver.v1.Driver) URL(java.net.URL) GuardTimeoutException(org.neo4j.kernel.guard.GuardTimeoutException) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException) IOException(java.io.IOException) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 18 with Driver

use of org.h2.Driver in project neo4j by neo4j.

the class TransactionGuardIntegrationTest method terminateLongRunningDriverQuery.

@Test
public void terminateLongRunningDriverQuery() throws Exception {
    GraphDatabaseAPI database = startDatabaseWithTimeout();
    CommunityNeoServer neoServer = startNeoServer((GraphDatabaseFacade) database);
    org.neo4j.driver.v1.Config driverConfig = getDriverConfig();
    try (Driver driver = GraphDatabase.driver("bolt://localhost:" + boltPortDatabaseWithTimeout, driverConfig);
        Session session = driver.session()) {
        org.neo4j.driver.v1.Transaction transaction = session.beginTransaction();
        transaction.run("create (n)").consume();
        transaction.success();
        fakeClock.forward(3, TimeUnit.SECONDS);
        try {
            transaction.run("create (n)").consume();
            fail("Transaction should be already terminated by execution guard.");
        } catch (Exception expected) {
        // ignored
        }
    }
    assertDatabaseDoesNotHaveNodes(database);
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CommunityNeoServer(org.neo4j.server.CommunityNeoServer) Driver(org.neo4j.driver.v1.Driver) GuardTimeoutException(org.neo4j.kernel.guard.GuardTimeoutException) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException) IOException(java.io.IOException) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 19 with Driver

use of org.h2.Driver in project neo4j by neo4j.

the class BoltCausalClusteringIT method shouldUseBookmarkFromAReadSessionInAWriteSession.

@Test
public void shouldUseBookmarkFromAReadSessionInAWriteSession() throws Exception {
    // given
    cluster = clusterRule.withNumberOfReadReplicas(1).startCluster();
    CoreClusterMember leader = cluster.awaitLeader();
    try (Driver driver = GraphDatabase.driver(leader.directURI(), AuthTokens.basic("neo4j", "neo4j"))) {
        inExpirableSession(driver, (d) -> d.session(AccessMode.WRITE), (session) -> {
            session.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Jim"));
            return null;
        });
        String bookmark;
        try (Session session = driver.session(AccessMode.READ)) {
            try (Transaction tx = session.beginTransaction()) {
                tx.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
                tx.success();
            }
            bookmark = session.lastBookmark();
        }
        assertNotNull(bookmark);
        inExpirableSession(driver, (d) -> d.session(AccessMode.WRITE), (session) -> {
            try (Transaction tx = session.beginTransaction(bookmark)) {
                tx.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Alistair"));
                tx.success();
            }
            return null;
        });
        try (Session session = driver.session()) {
            Record record = session.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
            assertEquals(2, record.get("count").asInt());
        }
    }
}
Also used : Transaction(org.neo4j.driver.v1.Transaction) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Driver(org.neo4j.driver.v1.Driver) Record(org.neo4j.driver.v1.Record) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Session(org.neo4j.driver.v1.Session) RoutingNetworkSession(org.neo4j.driver.internal.RoutingNetworkSession) Test(org.junit.Test)

Example 20 with Driver

use of org.h2.Driver in project neo4j by neo4j.

the class ProcedureTest method calls_procedures_with_simple_input_type_returning_void.

@Test
public void calls_procedures_with_simple_input_type_returning_void() {
    try (Driver driver = GraphDatabase.driver(graphDb.boltURI(), configuration());
        Session session = driver.session()) {
        session.run("CALL " + procedureNamespace + ".simpleInput00()");
        session.run("CALL " + procedureNamespace + ".simpleInput01('string')");
        session.run("CALL " + procedureNamespace + ".simpleInput02(42)");
        session.run("CALL " + procedureNamespace + ".simpleInput03(42)");
        session.run("CALL " + procedureNamespace + ".simpleInput04(4.2)");
        session.run("CALL " + procedureNamespace + ".simpleInput05(true)");
        session.run("CALL " + procedureNamespace + ".simpleInput06(false)");
        session.run("CALL " + procedureNamespace + ".simpleInput07({foo:'bar'})");
        session.run("MATCH (n)            CALL " + procedureNamespace + ".simpleInput08(n) RETURN n");
        session.run("MATCH p=(()-[r]->()) CALL " + procedureNamespace + ".simpleInput09(p) RETURN p");
        session.run("MATCH ()-[r]->()     CALL " + procedureNamespace + ".simpleInput10(r) RETURN r");
    }
}
Also used : Driver(org.neo4j.driver.v1.Driver) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)17 Driver (org.neo4j.driver.v1.Driver)16 Session (org.neo4j.driver.v1.Session)14 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)10 RoutingNetworkSession (org.neo4j.driver.internal.RoutingNetworkSession)9 Record (org.neo4j.driver.v1.Record)6 Driver (org.h2.Driver)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 Transaction (org.neo4j.driver.v1.Transaction)5 SessionExpiredException (org.neo4j.driver.v1.exceptions.SessionExpiredException)5 IOException (java.io.IOException)4 Connection (java.sql.Connection)4 RemoteException (java.rmi.RemoteException)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 HashSet (java.util.HashSet)2 ReadReplica (org.neo4j.causalclustering.discovery.ReadReplica)2 BoltServerAddress (org.neo4j.driver.internal.net.BoltServerAddress)2 GuardTimeoutException (org.neo4j.kernel.guard.GuardTimeoutException)2 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)2