use of org.neo4j.driver.Session in project neo4j by neo4j.
the class ProcedureTest method callsSimplisticProcedure.
@Test
void callsSimplisticProcedure(Neo4j neo4j) {
try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), configuration());
Session session = driver.session()) {
Result result = session.run("CALL " + procedureNamespace + ".theAnswer()");
assertThat(result.single().get("value").asLong()).isEqualTo(42L);
}
}
use of org.neo4j.driver.Session in project neo4j by neo4j.
the class ProcedureTest method callsProceduresWithSimpleInputTypeReturningRecordWithPrimitiveFields.
@Test
void callsProceduresWithSimpleInputTypeReturningRecordWithPrimitiveFields(Neo4j neo4j) {
try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), configuration());
Session session = driver.session()) {
assertThat(session.run("CALL " + procedureNamespace + ".simpleInput11('string') YIELD field04 AS p RETURN p").single()).isNotNull();
assertThat(session.run("CALL " + procedureNamespace + ".simpleInput12(42)").single()).isNotNull();
assertThat(session.run("CALL " + procedureNamespace + ".simpleInput13(42)").single()).isNotNull();
assertThat(session.run("CALL " + procedureNamespace + ".simpleInput14(4.2)").single()).isNotNull();
assertThat(session.run("CALL " + procedureNamespace + ".simpleInput15(true)").single()).isNotNull();
assertThat(session.run("CALL " + procedureNamespace + ".simpleInput16(false)").single()).isNotNull();
assertThat(session.run("CALL " + procedureNamespace + ".simpleInput17({foo:'bar'})").single()).isNotNull();
assertThat(session.run("CALL " + procedureNamespace + ".simpleInput21()").single()).isNotNull();
}
}
use of org.neo4j.driver.Session in project neo4j by neo4j.
the class ProcedureTest method callsProceduresWithSimpleInputTypeReturningVoid.
@Test
void callsProceduresWithSimpleInputTypeReturningVoid(Neo4j neo4j) {
try (Driver driver = GraphDatabase.driver(neo4j.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");
}
}
use of org.neo4j.driver.Session in project neo4j by neo4j.
the class ProcedureTest method callsProceduresWithDifferentModesReturningVoid.
@Test
void callsProceduresWithDifferentModesReturningVoid(Neo4j neo4j) {
try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), configuration());
Session session = driver.session()) {
session.run("CALL " + procedureNamespace + ".defaultMode()");
session.run("CALL " + procedureNamespace + ".readMode()");
session.run("CALL " + procedureNamespace + ".writeMode()");
session.run("CALL " + procedureNamespace + ".schemaMode()");
session.run("CALL " + procedureNamespace + ".dbmsMode()");
}
}
use of org.neo4j.driver.Session in project beam by apache.
the class Neo4jIOIT method testLargeWriteUnwind.
@Test
public void testLargeWriteUnwind() throws Exception {
final int startId = 5000;
final int endId = 6000;
// Create 1000 IDs
List<Integer> idList = new ArrayList<>();
for (int id = startId; id < endId; id++) {
idList.add(id);
}
PCollection<Integer> idCollection = largeWriteUnwindPipeline.apply(Create.of(idList));
// Every row is represented by a Map<String, Object> in the parameters map.
// We accumulate the rows and 'unwind' those to Neo4j for performance reasons.
//
SerializableFunction<Integer, Map<String, Object>> parametersFunction = id -> ImmutableMap.of("id", id, "name", "Casters", "firstName", "Matt");
// 1000 rows with a batch size of 123 should trigger most scenarios we can think of
// We've put a unique constraint on Something.id
//
Neo4jIO.WriteUnwind<Integer> read = Neo4jIO.<Integer>writeUnwind().withDriverConfiguration(Neo4jTestUtil.getDriverConfiguration(containerHostname, containerPort)).withSessionConfig(SessionConfig.forDatabase(Neo4jTestUtil.NEO4J_DATABASE)).withBatchSize(123).withUnwindMapName("rows").withCypher("UNWIND $rows AS row CREATE(n:Something { id : row.id })").withParametersFunction(parametersFunction).withCypherLogging();
idCollection.apply(read);
// Now run this pipeline
//
PipelineResult pipelineResult = largeWriteUnwindPipeline.run();
Assert.assertEquals(PipelineResult.State.DONE, pipelineResult.getState());
//
try (Driver driver = Neo4jTestUtil.getDriver(containerHostname, containerPort)) {
try (Session session = Neo4jTestUtil.getSession(driver, true)) {
List<Integer> values = session.readTransaction(tx -> {
List<Integer> v = null;
int nrRows = 0;
Result result = tx.run("MATCH(n:Something) RETURN count(n), min(n.id), max(n.id)");
while (result.hasNext()) {
Record record = result.next();
v = Arrays.asList(record.get(0).asInt(), record.get(1).asInt(), record.get(2).asInt(), ++nrRows);
}
return v;
});
Assert.assertNotNull(values);
assertThat(values, contains(endId - startId, startId, endId - 1, 1));
}
}
}
Aggregations