Search in sources :

Example 41 with BoltStateMachine

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

the class BoltStateMachineV4Test method testMarkFailedShouldYieldIgnoredIfAlreadyFailed.

private static void testMarkFailedShouldYieldIgnoredIfAlreadyFailed(ThrowingBiConsumer<BoltStateMachine, BoltResponseHandler, BoltConnectionFatality> action) throws Exception {
    // Given
    BoltStateMachine machine = init(newMachine());
    machine.markFailed(Neo4jError.from(new RuntimeException()));
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    Neo4jError error = Neo4jError.from(Status.Request.NoThreadsAvailable, "no threads");
    machine.markFailed(error);
    // When
    action.accept(machine, responseHandler);
    // Expect
    assertNull(pendingError(machine));
    assertFalse(pendingIgnore(machine));
    assertThat(machine).satisfies(inState(FailedState.class));
    verify(responseHandler).markIgnored();
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) FailedState(org.neo4j.bolt.v4.runtime.FailedState)

Example 42 with BoltStateMachine

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

the class BoltStateMachineV4Test method testMarkFailedOnNextMessage.

private static void testMarkFailedOnNextMessage(ThrowingBiConsumer<BoltStateMachine, BoltResponseHandler, BoltConnectionFatality> action) throws Exception {
    // Given
    BoltStateMachine machine = init(newMachine());
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    Neo4jError error = Neo4jError.from(Status.Request.NoThreadsAvailable, "no threads");
    machine.markFailed(error);
    // When
    action.accept(machine, responseHandler);
    // Expect
    assertNull(pendingError(machine));
    assertFalse(pendingIgnore(machine));
    assertThat(machine).satisfies(inState(FailedState.class));
    verify(responseHandler).markFailed(error);
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) FailedState(org.neo4j.bolt.v4.runtime.FailedState)

Example 43 with BoltStateMachine

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

the class BoltStateMachineV4Test method shouldResetWithOpenTransaction.

@Test
void shouldResetWithOpenTransaction() throws Throwable {
    BoltStateMachine machine = newMachineWithTransaction();
    assertThat(machine).satisfies(canReset());
    assertThat(machine).satisfies(hasNoTransaction());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) Test(org.junit.jupiter.api.Test)

Example 44 with BoltStateMachine

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

the class BoltStateMachineV4Test method shouldInvokeResponseHandlerOnMarkFailedIfThereIsHandler.

@Test
void shouldInvokeResponseHandlerOnMarkFailedIfThereIsHandler() throws Exception {
    BoltStateMachine machine = init(newMachine());
    Neo4jError error = Neo4jError.from(Status.Request.NoThreadsAvailable, "no threads");
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    ((AbstractBoltStateMachine) machine).connectionState().setResponseHandler(responseHandler);
    machine.markFailed(error);
    assertNull(pendingError(machine));
    assertFalse(pendingIgnore(machine));
    assertThat(machine).satisfies(inState(FailedState.class));
    verify(responseHandler).markFailed(error);
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) FailedState(org.neo4j.bolt.v4.runtime.FailedState) Test(org.junit.jupiter.api.Test)

Example 45 with BoltStateMachine

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

the class BoltStateMachineV4Test method actionsDisallowedBeforeInitialized.

@Test
void actionsDisallowedBeforeInitialized() {
    // Given
    BoltStateMachine machine = newMachine();
    // When
    try {
        machine.process(BoltV4Messages.run(), nullResponseHandler());
        fail("Failed to fail fatally");
    }// Then
     catch (BoltConnectionFatality e) {
    // fatality correctly generated
    }
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltConnectionFatality(org.neo4j.bolt.runtime.BoltConnectionFatality) 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