Search in sources :

Example 1 with BoltResult

use of org.neo4j.bolt.runtime.BoltResult in project neo4j by neo4j.

the class BoltStateMachineV4Test method testPublishingError.

@Test
void testPublishingError() throws Throwable {
    // Given a new ready machine...
    BoltStateMachine machine = init(newMachine());
    // ...and a result ready to be retrieved...
    machine.process(BoltV4Messages.run(), nullResponseHandler());
    // ...and a handler guaranteed to break
    BoltResponseRecorder recorder = new BoltResponseRecorder() {

        @Override
        public boolean onPullRecords(BoltResult result, long size) {
            throw new RuntimeException("I've been expecting you, Mr Bond.");
        }
    };
    // When we pull using that handler
    machine.process(BoltV4Messages.pullAll(), recorder);
    // Then the breakage should surface as a FAILURE
    assertThat(recorder.nextResponse()).satisfies(failedWithStatus(Status.General.UnknownError));
    // ...and the machine should have entered a FAILED state
    assertThat(machine).satisfies(inState(FailedState.class));
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) FailedState(org.neo4j.bolt.v4.runtime.FailedState) BoltResult(org.neo4j.bolt.runtime.BoltResult) Test(org.junit.jupiter.api.Test)

Example 2 with BoltResult

use of org.neo4j.bolt.runtime.BoltResult in project neo4j by neo4j.

the class ResultHandlerTest method shouldPullTheResult.

@Test
void shouldPullTheResult() throws Throwable {
    BoltResponseMessageRecorder messageWriter = new BoltResponseMessageRecorder();
    ResultHandler handler = new ResultHandler(messageWriter, mock(BoltConnection.class), NullLog.getInstance());
    Value[] record1 = values("a", "b", "c");
    Value[] record2 = values("1", "2", "3");
    BoltResult result = new TestBoltResult(record1, record2);
    handler.onPullRecords(result, STREAM_LIMIT_UNLIMITED);
    handler.onFinish();
    List<ResponseMessage> messages = messageWriter.asList();
    assertThat(messages.size()).isEqualTo(3);
    assertThat(messages.get(0)).isEqualTo(new RecordMessage(record1));
    assertThat(messages.get(1)).isEqualTo(new RecordMessage(record2));
    assertThat(messages.get(2)).isInstanceOf(SuccessMessage.class);
}
Also used : BoltResponseMessageRecorder(org.neo4j.bolt.messaging.BoltResponseMessageRecorder) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) AnyValue(org.neo4j.values.AnyValue) Value(org.neo4j.values.storable.Value) ResponseMessage(org.neo4j.bolt.messaging.ResponseMessage) RecordMessage(org.neo4j.bolt.v3.messaging.response.RecordMessage) BoltResult(org.neo4j.bolt.runtime.BoltResult) Test(org.junit.jupiter.api.Test)

Example 3 with BoltResult

use of org.neo4j.bolt.runtime.BoltResult in project neo4j by neo4j.

the class ResultHandlerTest method shouldDiscardTheResult.

@Test
void shouldDiscardTheResult() throws Throwable {
    BoltResponseMessageRecorder messageWriter = new BoltResponseMessageRecorder();
    ResultHandler handler = new ResultHandler(messageWriter, mock(BoltConnection.class), NullLog.getInstance());
    Value[] record1 = values("a", "b", "c");
    Value[] record2 = values("1", "2", "3");
    BoltResult result = new TestBoltResult(record1, record2);
    handler.onDiscardRecords(result, STREAM_LIMIT_UNLIMITED);
    handler.onFinish();
    List<ResponseMessage> messages = messageWriter.asList();
    assertThat(messages.size()).isEqualTo(1);
    assertThat(messages.get(0)).isInstanceOf(SuccessMessage.class);
}
Also used : BoltResponseMessageRecorder(org.neo4j.bolt.messaging.BoltResponseMessageRecorder) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) AnyValue(org.neo4j.values.AnyValue) Value(org.neo4j.values.storable.Value) ResponseMessage(org.neo4j.bolt.messaging.ResponseMessage) BoltResult(org.neo4j.bolt.runtime.BoltResult) Test(org.junit.jupiter.api.Test)

Example 4 with BoltResult

use of org.neo4j.bolt.runtime.BoltResult in project neo4j by neo4j.

the class BoltConnectionIT method shouldHandleFailureDuringResultPublishing.

@Test
void shouldHandleFailureDuringResultPublishing() throws Throwable {
    // Given
    var machine = newStateMachineAfterAuth();
    var pullAllCallbackCalled = new CountDownLatch(1);
    var error = new AtomicReference<Neo4jError>();
    // When something fails while publishing the result stream
    machine.process(run(), nullResponseHandler());
    machine.process(pullAll(), new BoltResponseHandler() {

        @Override
        public boolean onPullRecords(BoltResult result, long size) throws Throwable {
            throw new RuntimeException("Ooopsies!");
        }

        @Override
        public boolean onDiscardRecords(BoltResult result, long size) throws Throwable {
            throw new RuntimeException("Not this one!");
        }

        @Override
        public void onMetadata(String key, AnyValue 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));
    var err = error.get();
    assertThat(err.status()).isEqualTo(Status.General.UnknownError);
    assertThat(err.message()).contains("Ooopsies!");
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) AnyValue(org.neo4j.values.AnyValue) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) BoltResult(org.neo4j.bolt.runtime.BoltResult) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)4 BoltResult (org.neo4j.bolt.runtime.BoltResult)4 AnyValue (org.neo4j.values.AnyValue)3 BoltResponseMessageRecorder (org.neo4j.bolt.messaging.BoltResponseMessageRecorder)2 ResponseMessage (org.neo4j.bolt.messaging.ResponseMessage)2 BoltConnection (org.neo4j.bolt.runtime.BoltConnection)2 Value (org.neo4j.values.storable.Value)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 BoltResponseHandler (org.neo4j.bolt.runtime.BoltResponseHandler)1 Neo4jError (org.neo4j.bolt.runtime.Neo4jError)1 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)1 BoltResponseRecorder (org.neo4j.bolt.testing.BoltResponseRecorder)1 RecordMessage (org.neo4j.bolt.v3.messaging.response.RecordMessage)1 FailedState (org.neo4j.bolt.v4.runtime.FailedState)1