Search in sources :

Example 21 with BoltStateMachineV4

use of org.neo4j.bolt.v4.BoltStateMachineV4 in project neo4j by neo4j.

the class InTransactionStateIT method shouldMoveFromInTxToReadyOnRollback_succ.

@Test
void shouldMoveFromInTxToReadyOnRollback_succ() throws Throwable {
    // Given
    BoltStateMachineV4 machine = getBoltStateMachineInTxState();
    // When
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.process(ROLLBACK_MESSAGE, recorder);
    // Then
    RecordedBoltResponse response = recorder.nextResponse();
    assertThat(response).satisfies(succeeded());
    assertFalse(response.hasMetadata("bookmark"));
    assertFalse(response.hasMetadata("db"));
    assertThat(machine.state()).isInstanceOf(ReadyState.class);
}
Also used : BoltStateMachineV4(org.neo4j.bolt.v4.BoltStateMachineV4) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) RecordedBoltResponse(org.neo4j.bolt.testing.RecordedBoltResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with BoltStateMachineV4

use of org.neo4j.bolt.v4.BoltStateMachineV4 in project neo4j by neo4j.

the class InTransactionStateIT method shouldStayInTxOnDiscard_succ_hasMore.

@Test
void shouldStayInTxOnDiscard_succ_hasMore() throws Throwable {
    // Given
    BoltStateMachineV4 machine = getBoltStateMachineInTxState("Unwind [1, 2, 3] as n return n");
    // When
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.process(newDiscardMessage(2), recorder);
    // Then
    RecordedBoltResponse response = recorder.nextResponse();
    assertThat(response).satisfies(containsNoRecord());
    assertThat(response).satisfies(succeededWithMetadata("has_more", BooleanValue.TRUE));
    assertFalse(response.hasMetadata("db"));
    machine.process(newDiscardMessage(2), recorder);
    response = recorder.nextResponse();
    assertThat(response).satisfies(containsNoRecord());
    assertTrue(response.hasMetadata("type"));
    assertTrue(response.hasMetadata("t_last"));
    assertFalse(response.hasMetadata("bookmark"));
    assertTrue(response.hasMetadata("db"));
    assertThat(response).satisfies(succeededWithoutMetadata("has_more"));
    assertThat(machine.state()).isInstanceOf(InTransactionState.class);
}
Also used : BoltStateMachineV4(org.neo4j.bolt.v4.BoltStateMachineV4) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) RecordedBoltResponse(org.neo4j.bolt.testing.RecordedBoltResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with BoltStateMachineV4

use of org.neo4j.bolt.v4.BoltStateMachineV4 in project neo4j by neo4j.

the class InTransactionStateIT method shouldMoveFromInTxToFailedOnAnotherRun_fail.

@Test
void shouldMoveFromInTxToFailedOnAnotherRun_fail() throws Throwable {
    // Given
    BoltStateMachineV4 machine = getBoltStateMachineInTxState();
    // When
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.process(new RunMessage("any string"), recorder);
    // Then
    assertThat(machine.state()).isInstanceOf(FailedState.class);
}
Also used : BoltStateMachineV4(org.neo4j.bolt.v4.BoltStateMachineV4) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) RunMessage(org.neo4j.bolt.v4.messaging.RunMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with BoltStateMachineV4

use of org.neo4j.bolt.v4.BoltStateMachineV4 in project neo4j by neo4j.

the class InTransactionStateIT method shouldThrowExceptionOnIllegalMessagesInTxStreamingState.

private void shouldThrowExceptionOnIllegalMessagesInTxStreamingState(RequestMessage message) throws Throwable {
    // Given
    BoltStateMachineV4 machine = newStateMachine();
    machine.process(newHelloMessage(), nullResponseHandler());
    machine.process(new BeginMessage(), nullResponseHandler());
    machine.process(new RunMessage("CREATE (n {k:'k'}) RETURN n.k", EMPTY_PARAMS), nullResponseHandler());
    assertThat(machine.state()).isInstanceOf(InTransactionState.class);
    // when
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    verifyKillsConnection(() -> machine.process(message, recorder));
    // then
    assertThat(recorder.nextResponse()).satisfies(failedWithStatus(Status.Request.Invalid));
    assertNull(machine.state());
}
Also used : BeginMessage(org.neo4j.bolt.v4.messaging.BeginMessage) BoltStateMachineV4(org.neo4j.bolt.v4.BoltStateMachineV4) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) RunMessage(org.neo4j.bolt.v4.messaging.RunMessage)

Example 25 with BoltStateMachineV4

use of org.neo4j.bolt.v4.BoltStateMachineV4 in project neo4j by neo4j.

the class AutoCommitStateIT method getBoltStateMachineInAutoCommitState.

private BoltStateMachineV4 getBoltStateMachineInAutoCommitState(String query) throws BoltConnectionFatality {
    BoltStateMachineV4 machine = newStateMachine();
    machine.process(newHelloMessage(), nullResponseHandler());
    machine.process(new RunMessage(query, EMPTY_PARAMS), nullResponseHandler());
    assertThat(machine.state()).isInstanceOf(AutoCommitState.class);
    return machine;
}
Also used : BoltStateMachineV4(org.neo4j.bolt.v4.BoltStateMachineV4) RunMessage(org.neo4j.bolt.v4.messaging.RunMessage)

Aggregations

BoltStateMachineV4 (org.neo4j.bolt.v4.BoltStateMachineV4)31 BoltResponseRecorder (org.neo4j.bolt.testing.BoltResponseRecorder)25 Test (org.junit.jupiter.api.Test)21 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)21 RecordedBoltResponse (org.neo4j.bolt.testing.RecordedBoltResponse)12 RunMessage (org.neo4j.bolt.v4.messaging.RunMessage)9 BeginMessage (org.neo4j.bolt.v4.messaging.BeginMessage)4 BoltChannel (org.neo4j.bolt.BoltChannel)3 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)3 DefaultDatabaseResolver (org.neo4j.kernel.database.DefaultDatabaseResolver)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 BoltResponseHandler (org.neo4j.bolt.runtime.BoltResponseHandler)1 Neo4jError (org.neo4j.bolt.runtime.Neo4jError)1 BoltStateMachineSPI (org.neo4j.bolt.runtime.statemachine.BoltStateMachineSPI)1 StatementProcessorReleaseManager (org.neo4j.bolt.runtime.statemachine.StatementProcessorReleaseManager)1 TransactionStateMachineSPIProvider (org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPIProvider)1 FailedState (org.neo4j.bolt.v4.runtime.FailedState)1