use of org.neo4j.bolt.packstream.Neo4jPack.Unpacker in project neo4j by neo4j.
the class BoltRequestMessageReaderTest method shouldPropagateFatalError.
@Test
void shouldPropagateFatalError() throws Exception {
Unpacker unpacker = mock(Unpacker.class);
RuntimeException error = new RuntimeException();
when(unpacker.unpackStructHeader()).thenThrow(error);
BoltRequestMessageReader reader = new TestBoltRequestMessageReader(connectionMock(), responseHandlerMock(), emptyList(), mock(ChannelProtector.class));
RuntimeException e = assertThrows(RuntimeException.class, () -> reader.read(unpacker));
assertEquals(error, e);
}
use of org.neo4j.bolt.packstream.Neo4jPack.Unpacker in project neo4j by neo4j.
the class BoltRequestMessageReaderTest method shouldThrowForUnknownMessage.
@Test
void shouldThrowForUnknownMessage() throws Exception {
Unpacker unpacker = mock(Unpacker.class);
when(unpacker.unpackStructSignature()).thenReturn('a');
RequestMessageDecoder decoder = new TestRequestMessageDecoder('b', responseHandlerMock(), mock(RequestMessage.class));
BoltRequestMessageReader reader = new TestBoltRequestMessageReader(connectionMock(), responseHandlerMock(), singletonList(decoder), mock(ChannelProtector.class));
BoltIOException e = assertThrows(BoltIOException.class, () -> reader.read(unpacker));
assertEquals(Status.Request.InvalidFormat, e.status());
assertFalse(e.causesFailureMessage());
assertEquals("Message 0x61 is not a valid message signature.", e.getMessage());
}
use of org.neo4j.bolt.packstream.Neo4jPack.Unpacker in project neo4j by neo4j.
the class BoltRequestMessageReaderTest method shouldHandleErrorThatCausesFailureMessage.
@Test
void shouldHandleErrorThatCausesFailureMessage() throws Exception {
Unpacker unpacker = mock(Unpacker.class);
BoltIOException error = new BoltIOException(Status.General.UnknownError, "Hello");
when(unpacker.unpackStructHeader()).thenThrow(error);
BoltStateMachine stateMachine = mock(BoltStateMachine.class);
BoltConnection connection = new SynchronousBoltConnection(stateMachine);
BoltResponseHandler externalErrorResponseHandler = responseHandlerMock();
BoltRequestMessageReader reader = new TestBoltRequestMessageReader(connection, externalErrorResponseHandler, emptyList(), mock(ChannelProtector.class));
reader.read(unpacker);
verify(stateMachine).handleExternalFailure(Neo4jError.from(error), externalErrorResponseHandler);
}
use of org.neo4j.bolt.packstream.Neo4jPack.Unpacker in project neo4j by neo4j.
the class BoltRequestMessageReaderTest method shouldDecodeKnownMessage.
@Test
void shouldDecodeKnownMessage() throws Exception {
Unpacker unpacker = mock(Unpacker.class);
when(unpacker.unpackStructSignature()).thenReturn('a');
RequestMessage message = mock(RequestMessage.class);
BoltResponseHandler responseHandler = responseHandlerMock();
RequestMessageDecoder decoder = new TestRequestMessageDecoder('a', responseHandler, message);
BoltStateMachine stateMachine = mock(BoltStateMachine.class);
BoltConnection connection = new SynchronousBoltConnection(stateMachine);
BoltRequestMessageReader reader = new TestBoltRequestMessageReader(connection, responseHandlerMock(), singletonList(decoder), mock(ChannelProtector.class));
reader.read(unpacker);
verify(stateMachine).process(message, responseHandler);
}
Aggregations