Search in sources :

Example 51 with BoltStateMachine

use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.

the class BoltStateMachineV4Test method shouldSucceedOnConsecutiveResetsOnFailedState.

@Test
void shouldSucceedOnConsecutiveResetsOnFailedState() throws Exception {
    // Given
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    // Given a FAILED machine
    BoltStateMachine machine = init(newMachine());
    machine.markFailed(Neo4jError.from(Status.Request.NoThreadsAvailable, "No Threads Available"));
    machine.process(BoltV4Messages.pullAll(), recorder);
    // When I RESET...
    machine.interrupt();
    machine.interrupt();
    machine.markFailed(Neo4jError.from(Status.Request.NoThreadsAvailable, "No Threads Available"));
    machine.process(BoltV4Messages.reset(), recorder);
    machine.markFailed(Neo4jError.from(Status.Request.NoThreadsAvailable, "No Threads Available"));
    machine.process(BoltV4Messages.reset(), recorder);
    assertThat(recorder.nextResponse()).satisfies(failedWithStatus(Status.Request.NoThreadsAvailable));
    // ...successfully
    assertThat(recorder.nextResponse()).satisfies(wasIgnored());
    assertThat(recorder.nextResponse()).satisfies(succeeded());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.jupiter.api.Test)

Example 52 with BoltStateMachine

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

use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine 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)

Example 54 with BoltStateMachine

use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.

the class BoltRequestMessageReaderV4Test method verifyBoltV3MessageIsReadAsBoltV4Message.

private static void verifyBoltV3MessageIsReadAsBoltV4Message(TransactionInitiatingMessage messageV3, TransactionInitiatingMessage messageV4) throws Exception {
    Neo4jPack neo4jPack = newNeo4jPack();
    BoltStateMachine stateMachine = mock(BoltStateMachine.class);
    BoltRequestMessageReader reader = requestMessageReader(stateMachine);
    PackedInputArray input = new PackedInputArray(encode(neo4jPack, messageV3));
    Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
    reader.read(unpacker);
    verify(stateMachine).process(eq(messageV4), any());
    assertThat(messageV3.meta()).isEqualTo(messageV4.meta());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltRequestMessageReader(org.neo4j.bolt.messaging.BoltRequestMessageReader) PackedInputArray(org.neo4j.bolt.packstream.PackedInputArray) BoltProtocolV4ComponentFactory.newNeo4jPack(org.neo4j.bolt.v4.BoltProtocolV4ComponentFactory.newNeo4jPack) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack)

Example 55 with BoltStateMachine

use of org.neo4j.bolt.runtime.statemachine.BoltStateMachine in project neo4j by neo4j.

the class BoltRequestMessageReaderV41Test method testMessageDecoding.

private static void testMessageDecoding(RequestMessage message) throws Exception {
    Neo4jPack neo4jPack = newNeo4jPack();
    BoltStateMachine stateMachine = mock(BoltStateMachine.class);
    BoltRequestMessageReader reader = requestMessageReader(stateMachine);
    PackedInputArray input = new PackedInputArray(encode(neo4jPack, message));
    Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
    reader.read(unpacker);
    verify(stateMachine).process(eq(message), any());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltRequestMessageReader(org.neo4j.bolt.messaging.BoltRequestMessageReader) PackedInputArray(org.neo4j.bolt.packstream.PackedInputArray) BoltProtocolV41ComponentFactory.newNeo4jPack(org.neo4j.bolt.v41.BoltProtocolV41ComponentFactory.newNeo4jPack) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack)

Aggregations

BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)61 Test (org.junit.jupiter.api.Test)40 BoltResponseHandler (org.neo4j.bolt.runtime.BoltResponseHandler)11 BoltResponseRecorder (org.neo4j.bolt.testing.BoltResponseRecorder)10 FailedState (org.neo4j.bolt.v4.runtime.FailedState)10 BoltRequestMessageReader (org.neo4j.bolt.messaging.BoltRequestMessageReader)8 Neo4jPack (org.neo4j.bolt.packstream.Neo4jPack)8 PackedInputArray (org.neo4j.bolt.packstream.PackedInputArray)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Neo4jError (org.neo4j.bolt.runtime.Neo4jError)7 SynchronousBoltConnection (org.neo4j.bolt.runtime.SynchronousBoltConnection)7 BoltProtocolVersion (org.neo4j.bolt.BoltProtocolVersion)6 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)5 BoltChannel (org.neo4j.bolt.BoltChannel)5 ChannelProtector (org.neo4j.bolt.transport.pipeline.ChannelProtector)4 BoltConnection (org.neo4j.bolt.runtime.BoltConnection)3 BoltConnectionAuthFatality (org.neo4j.bolt.runtime.BoltConnectionAuthFatality)3 BoltStateMachineSPI (org.neo4j.bolt.runtime.statemachine.BoltStateMachineSPI)3 StatementOutcome (org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome)3 BoltStateMachineV4 (org.neo4j.bolt.v4.BoltStateMachineV4)3