Search in sources :

Example 11 with Transaction

use of edu.princeton.cs.algs4.Transaction 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 12 with Transaction

use of edu.princeton.cs.algs4.Transaction 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 13 with Transaction

use of edu.princeton.cs.algs4.Transaction in project neo4j by neo4j.

the class BoltCausalClusteringIT method executeReadQuery.

private void executeReadQuery(String bookmark, Session session) {
    try (Transaction tx = session.beginTransaction(bookmark)) {
        Record record = tx.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
        assertEquals(1, record.get("count").asInt());
    }
}
Also used : Transaction(org.neo4j.driver.v1.Transaction) Record(org.neo4j.driver.v1.Record)

Example 14 with Transaction

use of edu.princeton.cs.algs4.Transaction in project google-cloud-java by GoogleCloudPlatform.

the class SessionImplTest method multiUseReadOnlyTransactionReturnsMissingTransactionId.

@Test
public void multiUseReadOnlyTransactionReturnsMissingTransactionId() throws ParseException {
    com.google.protobuf.Timestamp t = Timestamps.parse("2015-10-01T10:54:20.021Z");
    Transaction txnMetadata = Transaction.newBuilder().setReadTimestamp(t).build();
    PartialResultSet resultSet = PartialResultSet.newBuilder().setMetadata(newMetadata(Type.struct(Type.StructField.of("C", Type.string())))).build();
    Mockito.when(rpc.beginTransaction(Mockito.<BeginTransactionRequest>any(), Mockito.eq(options))).thenReturn(txnMetadata);
    mockRead(resultSet);
    ReadOnlyTransaction txn = session.readOnlyTransaction(TimestampBound.strong());
    expectedException.expect(SpannerMatchers.isSpannerException(ErrorCode.INTERNAL));
    txn.readRow("Dummy", Key.of(), Arrays.asList("C"));
}
Also used : Transaction(com.google.spanner.v1.Transaction) PartialResultSet(com.google.spanner.v1.PartialResultSet) Test(org.junit.Test)

Example 15 with Transaction

use of edu.princeton.cs.algs4.Transaction in project google-cloud-java by GoogleCloudPlatform.

the class SessionImplTest method multiUseReadOnlyTransactionReturnsMissingTimestamp.

@Test
public void multiUseReadOnlyTransactionReturnsMissingTimestamp() {
    Transaction txnMetadata = Transaction.newBuilder().setId(ByteString.copyFromUtf8("x")).build();
    PartialResultSet resultSet = PartialResultSet.newBuilder().setMetadata(newMetadata(Type.struct(Type.StructField.of("C", Type.string())))).build();
    Mockito.when(rpc.beginTransaction(Mockito.<BeginTransactionRequest>any(), Mockito.eq(options))).thenReturn(txnMetadata);
    mockRead(resultSet);
    ReadOnlyTransaction txn = session.readOnlyTransaction(TimestampBound.strong());
    expectedException.expect(SpannerMatchers.isSpannerException(ErrorCode.INTERNAL));
    txn.readRow("Dummy", Key.of(), Arrays.asList("C"));
}
Also used : Transaction(com.google.spanner.v1.Transaction) PartialResultSet(com.google.spanner.v1.PartialResultSet) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 Transaction (org.neo4j.driver.v1.Transaction)8 Session (org.neo4j.driver.v1.Session)7 Record (org.neo4j.driver.v1.Record)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)5 RoutingNetworkSession (org.neo4j.driver.internal.RoutingNetworkSession)5 Driver (org.neo4j.driver.v1.Driver)5 Date (edu.princeton.cs.algs4.Date)4 Transaction (edu.princeton.cs.algs4.Transaction)4 PartialResultSet (com.google.spanner.v1.PartialResultSet)3 Transaction (com.google.spanner.v1.Transaction)3 In (edu.princeton.cs.algs4.In)2 Queue (edu.princeton.cs.algs4.Queue)2 ReadReplica (org.neo4j.causalclustering.discovery.ReadReplica)2 Exercise21_ComparableTransactions (chapter2.section1.Exercise21_ComparableTransactions)1 Stack (com.jimmysun.algorithms.chapter1_3.Stack)1 Transaction (com.jimmysun.algorithms.chapter2_1.Transaction)1 MinPQ (edu.princeton.cs.algs4.MinPQ)1 HashSet (java.util.HashSet)1