Search in sources :

Example 1 with Unpacker

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);
}
Also used : ChannelProtector(org.neo4j.bolt.transport.pipeline.ChannelProtector) Unpacker(org.neo4j.bolt.packstream.Neo4jPack.Unpacker) Test(org.junit.jupiter.api.Test)

Example 2 with Unpacker

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());
}
Also used : ChannelProtector(org.neo4j.bolt.transport.pipeline.ChannelProtector) Unpacker(org.neo4j.bolt.packstream.Neo4jPack.Unpacker) Test(org.junit.jupiter.api.Test)

Example 3 with Unpacker

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);
}
Also used : ChannelProtector(org.neo4j.bolt.transport.pipeline.ChannelProtector) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) SynchronousBoltConnection(org.neo4j.bolt.runtime.SynchronousBoltConnection) SynchronousBoltConnection(org.neo4j.bolt.runtime.SynchronousBoltConnection) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) Unpacker(org.neo4j.bolt.packstream.Neo4jPack.Unpacker) Test(org.junit.jupiter.api.Test)

Example 4 with Unpacker

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);
}
Also used : ChannelProtector(org.neo4j.bolt.transport.pipeline.ChannelProtector) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) SynchronousBoltConnection(org.neo4j.bolt.runtime.SynchronousBoltConnection) SynchronousBoltConnection(org.neo4j.bolt.runtime.SynchronousBoltConnection) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) Unpacker(org.neo4j.bolt.packstream.Neo4jPack.Unpacker) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)4 Unpacker (org.neo4j.bolt.packstream.Neo4jPack.Unpacker)4 ChannelProtector (org.neo4j.bolt.transport.pipeline.ChannelProtector)4 BoltConnection (org.neo4j.bolt.runtime.BoltConnection)2 BoltResponseHandler (org.neo4j.bolt.runtime.BoltResponseHandler)2 SynchronousBoltConnection (org.neo4j.bolt.runtime.SynchronousBoltConnection)2 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)2