Search in sources :

Example 1 with Neo4jError

use of org.neo4j.bolt.v1.runtime.Neo4jError in project neo4j by neo4j.

the class BoltConnectionIT method shouldHandleFailureDuringResultPublishing.

@Test
public void shouldHandleFailureDuringResultPublishing() throws Throwable {
    // Given
    BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
    machine.init(USER_AGENT, emptyMap(), null);
    final CountDownLatch pullAllCallbackCalled = new CountDownLatch(1);
    final AtomicReference<Neo4jError> error = new AtomicReference<>();
    // When something fails while publishing the result stream
    machine.run("RETURN 1", EMPTY_PARAMS, nullResponseHandler());
    machine.pullAll(new BoltResponseHandler() {

        @Override
        public void onStart() {
        }

        @Override
        public void onRecords(BoltResult result, boolean pull) throws Exception {
            throw new RuntimeException("Ooopsies!");
        }

        @Override
        public void onMetadata(String key, Object value) {
        }

        @Override
        public void markFailed(Neo4jError err) {
            error.set(err);
            pullAllCallbackCalled.countDown();
        }

        @Override
        public void markIgnored() {
        }

        @Override
        public void onFinish() {
        }
    });
    // Then
    assertTrue(pullAllCallbackCalled.await(30, TimeUnit.SECONDS));
    final Neo4jError err = error.get();
    assertThat(err.status(), equalTo((Status) Status.General.UnknownError));
    assertThat(err.message(), CoreMatchers.containsString("Ooopsies!"));
}
Also used : Status(org.neo4j.kernel.api.exceptions.Status) BoltMatchers.failedWithStatus(org.neo4j.bolt.testing.BoltMatchers.failedWithStatus) BoltResponseHandler(org.neo4j.bolt.v1.runtime.BoltResponseHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) BoltResult(org.neo4j.bolt.v1.runtime.spi.BoltResult) Neo4jError(org.neo4j.bolt.v1.runtime.Neo4jError) BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.junit.Test)1 BoltMatchers.failedWithStatus (org.neo4j.bolt.testing.BoltMatchers.failedWithStatus)1 BoltResponseHandler (org.neo4j.bolt.v1.runtime.BoltResponseHandler)1 BoltStateMachine (org.neo4j.bolt.v1.runtime.BoltStateMachine)1 Neo4jError (org.neo4j.bolt.v1.runtime.Neo4jError)1 BoltResult (org.neo4j.bolt.v1.runtime.spi.BoltResult)1 Status (org.neo4j.kernel.api.exceptions.Status)1