Search in sources :

Example 6 with ResultCursor

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"));
}
Also used : ResultCursor(org.neo4j.driver.async.ResultCursor) AsyncTransaction(org.neo4j.driver.async.AsyncTransaction) NoSuchRecordException(org.neo4j.driver.exceptions.NoSuchRecordException) Test(org.junit.jupiter.api.Test)

Example 7 with ResultCursor

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);
}
Also used : ResultCursor(org.neo4j.driver.async.ResultCursor) CompletionException(java.util.concurrent.CompletionException) AsyncTransaction(org.neo4j.driver.async.AsyncTransaction) IOException(java.io.IOException) NoSuchRecordException(org.neo4j.driver.exceptions.NoSuchRecordException) CompletionException(java.util.concurrent.CompletionException) ResultConsumedException(org.neo4j.driver.exceptions.ResultConsumedException) ServiceUnavailableException(org.neo4j.driver.exceptions.ServiceUnavailableException) ClientException(org.neo4j.driver.exceptions.ClientException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 8 with ResultCursor

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());
}
Also used : ResultCursor(org.neo4j.driver.async.ResultCursor) Query(org.neo4j.driver.Query) Value(org.neo4j.driver.Value) Matchers.nullValue(org.hamcrest.Matchers.nullValue) ResultSummary(org.neo4j.driver.summary.ResultSummary) AsyncTransaction(org.neo4j.driver.async.AsyncTransaction) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 9 with ResultCursor

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());
}
Also used : ResultCursor(org.neo4j.driver.async.ResultCursor) Query(org.neo4j.driver.Query) Value(org.neo4j.driver.Value) Matchers.nullValue(org.hamcrest.Matchers.nullValue) ResultSummary(org.neo4j.driver.summary.ResultSummary) AsyncTransaction(org.neo4j.driver.async.AsyncTransaction) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 10 with ResultCursor

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());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Values.parameters(org.neo4j.driver.Values.parameters) Matchers.syntaxError(org.neo4j.driver.internal.util.Matchers.syntaxError) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Value(org.neo4j.driver.Value) AsyncTransaction(org.neo4j.driver.async.AsyncTransaction) AsyncSession(org.neo4j.driver.async.AsyncSession) DatabaseExtension(org.neo4j.driver.util.DatabaseExtension) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) ResultSummary(org.neo4j.driver.summary.ResultSummary) MatcherAssert.assertThat(org.hamcrest.junit.MatcherAssert.assertThat) NoSuchRecordException(org.neo4j.driver.exceptions.NoSuchRecordException) SessionConfig.builder(org.neo4j.driver.SessionConfig.builder) CompletionException(java.util.concurrent.CompletionException) TestUtil.assertNoCircularReferences(org.neo4j.driver.util.TestUtil.assertNoCircularReferences) Node(org.neo4j.driver.types.Node) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Test(org.junit.jupiter.api.Test) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) ParallelizableIT(org.neo4j.driver.util.ParallelizableIT) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ResultConsumedException(org.neo4j.driver.exceptions.ResultConsumedException) TestUtil.await(org.neo4j.driver.util.TestUtil.await) Bookmark(org.neo4j.driver.Bookmark) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Matchers.containsResultAvailableAfterAndResultConsumedAfter(org.neo4j.driver.internal.util.Matchers.containsResultAvailableAfterAndResultConsumedAfter) ArrayList(java.util.ArrayList) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) ServiceUnavailableException(org.neo4j.driver.exceptions.ServiceUnavailableException) ResultCursor(org.neo4j.driver.async.ResultCursor) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ClientException(org.neo4j.driver.exceptions.ClientException) Collections.emptyMap(java.util.Collections.emptyMap) Iterables.single(org.neo4j.driver.internal.util.Iterables.single) Query(org.neo4j.driver.Query) InternalBookmark.parse(org.neo4j.driver.internal.InternalBookmark.parse) IOException(java.io.IOException) AfterEach(org.junit.jupiter.api.AfterEach) QueryType(org.neo4j.driver.summary.QueryType) Collections(java.util.Collections) Record(org.neo4j.driver.Record) ResultCursor(org.neo4j.driver.async.ResultCursor) AsyncTransaction(org.neo4j.driver.async.AsyncTransaction) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap) Test(org.junit.jupiter.api.Test)

Aggregations

ResultCursor (org.neo4j.driver.async.ResultCursor)94 Test (org.junit.jupiter.api.Test)64 AsyncTransaction (org.neo4j.driver.async.AsyncTransaction)38 ClientException (org.neo4j.driver.exceptions.ClientException)36 Record (org.neo4j.driver.Record)33 NoSuchRecordException (org.neo4j.driver.exceptions.NoSuchRecordException)30 ResultSummary (org.neo4j.driver.summary.ResultSummary)29 AsyncSession (org.neo4j.driver.async.AsyncSession)26 ServiceUnavailableException (org.neo4j.driver.exceptions.ServiceUnavailableException)24 CompletionStage (java.util.concurrent.CompletionStage)21 TransientException (org.neo4j.driver.exceptions.TransientException)20 Matchers.containsString (org.hamcrest.Matchers.containsString)18 Query (org.neo4j.driver.Query)18 CompletionException (java.util.concurrent.CompletionException)17 DatabaseException (org.neo4j.driver.exceptions.DatabaseException)17 Node (org.neo4j.driver.types.Node)17 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)16 List (java.util.List)15 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)14