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));
}
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);
}
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);
}
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!");
}
Aggregations