use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.
the class BoltRequestMessageReader method doRead.
private void doRead(Neo4jPack.Unpacker unpacker) throws IOException {
try {
unpacker.unpackStructHeader();
int signature = unpacker.unpackStructSignature();
RequestMessageDecoder decoder = decoders.get(signature);
if (decoder == null) {
throw new BoltIOException(Status.Request.InvalidFormat, String.format("Message 0x%s is not a valid message signature.", Integer.toHexString(signature)));
}
RequestMessage message = decoder.decode(unpacker);
BoltResponseHandler responseHandler = decoder.responseHandler();
connection.enqueue(stateMachine -> stateMachine.process(message, responseHandler));
channelProtector.afterRequestReceived();
} catch (PackStream.PackStreamException e) {
throw new BoltIOException(Status.Request.InvalidFormat, String.format("Unable to read message type. Error was: %s.", e.getMessage()), e);
}
}
use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.
the class StreamingStateIT method shouldMoveFromStreamingStateToFailedStateOnPullAllOrDiscardAll_fail.
@ParameterizedTest
@MethodSource("pullAllDiscardAllMessages")
void shouldMoveFromStreamingStateToFailedStateOnPullAllOrDiscardAll_fail(RequestMessage message) throws Throwable {
// Given
BoltStateMachineV3 machine = getBoltStateMachineInStreamingState();
// When
BoltResponseHandler handler = mock(BoltResponseHandler.class);
doThrow(new RuntimeException("Fail")).when(handler).onPullRecords(any(), anyLong());
doThrow(new RuntimeException("Fail")).when(handler).onDiscardRecords(any(), anyLong());
machine.process(message, handler);
// Then
assertThat(machine.state()).isInstanceOf(FailedState.class);
}
use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.
the class BoltRequestMessageReaderV3 method buildDecoders.
private static List<RequestMessageDecoder> buildDecoders(BoltConnection connection, BoltResponseMessageWriter responseMessageWriter, LogService logService) {
BoltResponseHandler resultHandler = new ResultHandler(responseMessageWriter, connection, internalLog(logService));
BoltResponseHandler defaultHandler = newSimpleResponseHandler(responseMessageWriter, connection, logService);
return Arrays.asList(new HelloMessageDecoder(defaultHandler), new RunMessageDecoder(defaultHandler), new DiscardAllMessageDecoder(resultHandler), new PullAllMessageDecoder(resultHandler), new BeginMessageDecoder(defaultHandler), new CommitMessageDecoder(resultHandler), new RollbackMessageDecoder(resultHandler), new ResetMessageDecoder(connection, defaultHandler), new GoodbyeMessageDecoder(connection, defaultHandler));
}
use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.
the class BoltStateMachineV4Test method testMarkFailedShouldYieldSuccessIfAlreadyFailed.
private static void testMarkFailedShouldYieldSuccessIfAlreadyFailed(ThrowingBiConsumer<BoltStateMachine, BoltResponseHandler, BoltConnectionFatality> action) throws Exception {
// Given
BoltStateMachine machine = init(newMachine());
machine.markFailed(Neo4jError.from(new RuntimeException()));
BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
Neo4jError error = Neo4jError.from(Status.Request.NoThreadsAvailable, "no threads");
machine.markFailed(error);
// When
action.accept(machine, responseHandler);
// Expect
assertNull(pendingError(machine));
assertFalse(pendingIgnore(machine));
assertThat(machine).satisfies(inState(ReadyState.class));
verify(responseHandler, never()).markIgnored();
verify(responseHandler, never()).markFailed(any());
}
use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.
the class BoltStateMachineV4Test method shouldNotFailWhenMarkedForTerminationAndPullAll.
@Test
void shouldNotFailWhenMarkedForTerminationAndPullAll() throws Exception {
BoltStateMachineSPIImpl spi = mock(BoltStateMachineSPIImpl.class, RETURNS_MOCKS);
BoltStateMachine machine = init(newMachine(spi));
// move to streaming state
machine.process(BoltV4Messages.run(), nullResponseHandler());
txStateMachine(machine).ctx.statementOutcomes.put(StatementMetadata.ABSENT_QUERY_ID, new StatementOutcome(BoltResult.EMPTY));
BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
machine.markForTermination();
machine.process(BoltV4Messages.pullAll(), responseHandler);
verify(spi, never()).reportError(any());
assertThat(machine).isNotEqualTo(inState(FailedState.class));
}
Aggregations