Search in sources :

Example 16 with BoltStateMachine

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

the class BoltConditions method verifyOneResponse.

public static void verifyOneResponse(ThrowingBiConsumer<BoltStateMachine, BoltResponseRecorder, BoltConnectionFatality> transition) throws Exception {
    BoltStateMachine machine = newMachine();
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    try {
        transition.accept(machine, recorder);
    } catch (BoltConnectionFatality connectionFatality) {
    // acceptable for invalid transitions
    }
    assertEquals(1, recorder.responseCount());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) AbstractBoltStateMachine(org.neo4j.bolt.runtime.statemachine.impl.AbstractBoltStateMachine) BoltConnectionFatality(org.neo4j.bolt.runtime.BoltConnectionFatality)

Example 17 with BoltStateMachine

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

the class BoltStateMachineContextImplTest method shouldHandleFailure.

@Test
void shouldHandleFailure() throws BoltConnectionFatality {
    BoltStateMachine machine = mock(BoltStateMachine.class);
    BoltStateMachineContextImpl context = newContext(machine, mock(BoltStateMachineSPI.class));
    RuntimeException cause = new RuntimeException();
    context.handleFailure(cause, true);
    verify(machine).handleFailure(cause, true);
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltStateMachineSPI(org.neo4j.bolt.runtime.statemachine.BoltStateMachineSPI) Test(org.junit.jupiter.api.Test)

Example 18 with BoltStateMachine

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

the class BoltStateMachineV4Test method shouldRemainStoppedAfterInterrupted.

@Test
void shouldRemainStoppedAfterInterrupted() throws Throwable {
    // Given a ready machine
    final BoltStateMachine machine = init(newMachine());
    // ...which is subsequently closed
    machine.close();
    assertThat(machine).satisfies(isClosed());
    // When and interrupt and reset occurs
    reset(machine, nullResponseHandler());
    // Then the machine should remain closed
    assertThat(machine).satisfies(isClosed());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) Test(org.junit.jupiter.api.Test)

Example 19 with BoltStateMachine

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

the class BoltStateMachineV4Test method testCantDoAnythingIfInFailedState.

@Test
void testCantDoAnythingIfInFailedState() throws Throwable {
    // Given a FAILED machine
    BoltStateMachine machine = init(newMachine());
    machine.markFailed(Neo4jError.from(new RuntimeException()));
    // Then no RUN...
    machine.process(BoltV4Messages.run(), nullResponseHandler());
    assertThat(machine).satisfies(inState(FailedState.class));
    // ...DISCARD_ALL...
    machine.process(BoltV4Messages.discardAll(), nullResponseHandler());
    assertThat(machine).satisfies(inState(FailedState.class));
    // ...or PULL_ALL should be possible
    machine.process(BoltV4Messages.pullAll(), nullResponseHandler());
    assertThat(machine).satisfies(inState(FailedState.class));
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) FailedState(org.neo4j.bolt.v4.runtime.FailedState) Test(org.junit.jupiter.api.Test)

Example 20 with BoltStateMachine

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

the class BoltStateMachineV4Test method multipleInterruptsShouldBeMatchedWithMultipleResets.

@Test
void multipleInterruptsShouldBeMatchedWithMultipleResets() throws Throwable {
    // Given
    final BoltStateMachine machine = init(newMachine());
    // When
    machine.interrupt();
    machine.interrupt();
    // ...and
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.process(BoltV4Messages.run(), recorder);
    machine.process(BoltV4Messages.reset(), recorder);
    machine.process(BoltV4Messages.run(), recorder);
    // Then
    assertThat(recorder.nextResponse()).satisfies(wasIgnored());
    assertThat(recorder.nextResponse()).satisfies(wasIgnored());
    assertThat(recorder.nextResponse()).satisfies(wasIgnored());
    // But when
    recorder.reset();
    machine.process(BoltV4Messages.reset(), recorder);
    machine.process(BoltV4Messages.run(), recorder);
    // Then
    assertThat(recorder.nextResponse()).satisfies(succeeded());
    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)

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