Search in sources :

Example 6 with Values.parameters

use of org.neo4j.driver.v1.Values.parameters 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)

Aggregations

Test (org.junit.Test)6 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)6 Driver (org.neo4j.driver.v1.Driver)6 RoutingNetworkSession (org.neo4j.driver.internal.RoutingNetworkSession)5 Session (org.neo4j.driver.v1.Session)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 Record (org.neo4j.driver.v1.Record)4 Transaction (org.neo4j.driver.v1.Transaction)4 ReadReplica (org.neo4j.causalclustering.discovery.ReadReplica)2 SessionExpiredException (org.neo4j.driver.v1.exceptions.SessionExpiredException)2 HashSet (java.util.HashSet)1 BoltServerAddress (org.neo4j.driver.internal.net.BoltServerAddress)1