use of org.neo4j.driver.async.ResultCursor in project neo4j-java-driver by neo4j.
the class AsyncTransactionIT method shouldFailSingleWithMultiRecordCursor.
@Test
void shouldFailSingleWithMultiRecordCursor() {
AsyncTransaction tx = await(session.beginTransactionAsync());
ResultCursor cursor = await(tx.runAsync("UNWIND ['a', 'b'] AS x RETURN x"));
NoSuchRecordException e = assertThrows(NoSuchRecordException.class, () -> await(cursor.singleAsync()));
assertThat(e.getMessage(), startsWith("Expected a result with a single record"));
}
use of org.neo4j.driver.async.ResultCursor in project neo4j-java-driver by neo4j.
the class AsyncTransactionIT method shouldFailWhenListTransformationFunctionFails.
@Test
void shouldFailWhenListTransformationFunctionFails() {
AsyncTransaction tx = await(session.beginTransactionAsync());
ResultCursor cursor = await(tx.runAsync("RETURN 'Hello'"));
IOException error = new IOException("World");
Exception e = assertThrows(Exception.class, () -> await(cursor.listAsync(record -> {
throw new CompletionException(error);
})));
assertEquals(error, e);
}
use of org.neo4j.driver.async.ResultCursor in project neo4j-java-driver by neo4j.
the class AsyncTransactionIT method shouldExposeResultSummaryForSimpleQuery.
@Test
void shouldExposeResultSummaryForSimpleQuery() {
String query = "CREATE (p1:Person {name: $name1})-[:KNOWS]->(p2:Person {name: $name2}) RETURN p1, p2";
Value params = parameters("name1", "Bob", "name2", "John");
AsyncTransaction tx = await(session.beginTransactionAsync());
ResultCursor cursor = await(tx.runAsync(query, params));
ResultSummary summary = await(cursor.consumeAsync());
assertEquals(new Query(query, params), summary.query());
assertEquals(2, summary.counters().nodesCreated());
assertEquals(2, summary.counters().labelsAdded());
assertEquals(2, summary.counters().propertiesSet());
assertEquals(1, summary.counters().relationshipsCreated());
assertEquals(QueryType.READ_WRITE, summary.queryType());
assertFalse(summary.hasPlan());
assertFalse(summary.hasProfile());
assertNull(summary.plan());
assertNull(summary.profile());
assertEquals(0, summary.notifications().size());
assertThat(summary, containsResultAvailableAfterAndResultConsumedAfter());
}
use of org.neo4j.driver.async.ResultCursor in project neo4j-java-driver by neo4j.
the class AsyncTransactionIT method shouldExposeResultSummaryForProfileQuery.
@Test
void shouldExposeResultSummaryForProfileQuery() {
String query = "PROFILE MERGE (n {name: $name}) " + "ON CREATE SET n.created = timestamp() " + "ON MATCH SET n.counter = coalesce(n.counter, 0) + 1";
Value params = parameters("name", "Bob");
AsyncTransaction tx = await(session.beginTransactionAsync());
ResultCursor cursor = await(tx.runAsync(query, params));
ResultSummary summary = await(cursor.consumeAsync());
assertEquals(new Query(query, params), summary.query());
assertEquals(1, summary.counters().nodesCreated());
assertEquals(2, summary.counters().propertiesSet());
assertEquals(0, summary.counters().relationshipsCreated());
assertEquals(QueryType.WRITE_ONLY, summary.queryType());
assertTrue(summary.hasPlan());
assertTrue(summary.hasProfile());
assertNotNull(summary.plan());
assertNotNull(summary.profile());
// asserting on profile is a bit fragile and can break when server side changes or with different
// server versions; that is why do fuzzy assertions in this test based on string content
String profileAsString = summary.profile().toString().toLowerCase();
assertThat(profileAsString, containsString("hits"));
assertEquals(0, summary.notifications().size());
assertThat(summary, containsResultAvailableAfterAndResultConsumedAfter());
}
use of org.neo4j.driver.async.ResultCursor in project neo4j-java-driver by neo4j.
the class AsyncTransactionIT method shouldConvertToTransformedListWithEmptyCursor.
@Test
void shouldConvertToTransformedListWithEmptyCursor() {
AsyncTransaction tx = await(session.beginTransactionAsync());
ResultCursor cursor = await(tx.runAsync("CREATE ()"));
List<Map<String, Object>> maps = await(cursor.listAsync(record -> record.get(0).asMap()));
assertEquals(0, maps.size());
}
Aggregations