use of org.neo4j.driver.v1.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"));
}
use of org.neo4j.driver.v1.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();
}
}
}
use of org.neo4j.driver.v1.Transaction 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);
}
use of org.neo4j.driver.v1.Transaction 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);
}
use of org.neo4j.driver.v1.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());
}
}
}
Aggregations