Search in sources :

Example 6 with SynchronousBoltConnection

use of org.neo4j.bolt.runtime.SynchronousBoltConnection 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 7 with SynchronousBoltConnection

use of org.neo4j.bolt.runtime.SynchronousBoltConnection 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

SynchronousBoltConnection (org.neo4j.bolt.runtime.SynchronousBoltConnection)7 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)7 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)4 ChannelProtector (org.neo4j.bolt.transport.pipeline.ChannelProtector)4 Test (org.junit.jupiter.api.Test)3 BoltResponseHandler (org.neo4j.bolt.runtime.BoltResponseHandler)3 RequestMessage (org.neo4j.bolt.messaging.RequestMessage)2 Unpacker (org.neo4j.bolt.packstream.Neo4jPack.Unpacker)2 BoltConnection (org.neo4j.bolt.runtime.BoltConnection)2 RunMessage (org.neo4j.bolt.v3.messaging.request.RunMessage)2 NullLogService (org.neo4j.logging.internal.NullLogService)2 ByteBuf (io.netty.buffer.ByteBuf)1 IOException (java.io.IOException)1 System.lineSeparator (java.lang.System.lineSeparator)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1