Search in sources :

Example 1 with BoltStateMachineV4

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

the class BoltV4MachineRoom method newMachineWithTransactionSPI.

public static BoltStateMachine newMachineWithTransactionSPI(TransactionStateMachineSPI transactionSPI) throws BoltConnectionFatality, BoltIOException {
    BoltStateMachineSPI spi = mock(BoltStateMachineSPI.class, RETURNS_MOCKS);
    TransactionStateMachineSPIProvider transactionSPIProvider = mock(TransactionStateMachineSPIProvider.class);
    var memoryTracker = mock(MemoryTracker.class);
    when(transactionSPIProvider.getTransactionStateMachineSPI(any(String.class), any(StatementProcessorReleaseManager.class))).thenReturn(transactionSPI);
    when(spi.transactionStateMachineSPIProvider()).thenReturn(transactionSPIProvider);
    BoltChannel boltChannel = BoltTestUtil.newTestBoltChannel();
    BoltStateMachine machine = new BoltStateMachineV4(spi, boltChannel, Clock.systemUTC(), mock(DefaultDatabaseResolver.class), MapValue.EMPTY, memoryTracker);
    init(machine);
    return machine;
}
Also used : StatementProcessorReleaseManager(org.neo4j.bolt.runtime.statemachine.StatementProcessorReleaseManager) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltChannel(org.neo4j.bolt.BoltChannel) BoltStateMachineV4(org.neo4j.bolt.v4.BoltStateMachineV4) DefaultDatabaseResolver(org.neo4j.kernel.database.DefaultDatabaseResolver) BoltStateMachineSPI(org.neo4j.bolt.runtime.statemachine.BoltStateMachineSPI) TransactionStateMachineSPIProvider(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPIProvider)

Example 2 with BoltStateMachineV4

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

the class BoltStateMachineV4Test method shouldCloseBoltChannelWhenClosed.

@Test
void shouldCloseBoltChannelWhenClosed() {
    BoltStateMachineSPIImpl spi = mock(BoltStateMachineSPIImpl.class);
    BoltChannel boltChannel = mock(BoltChannel.class);
    var memoryTracker = mock(MemoryTracker.class);
    BoltStateMachine machine = new BoltStateMachineV4(spi, boltChannel, Clock.systemUTC(), mock(DefaultDatabaseResolver.class), MapValue.EMPTY, memoryTracker);
    machine.close();
    verify(boltChannel).close();
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltChannel(org.neo4j.bolt.BoltChannel) BoltStateMachineV4(org.neo4j.bolt.v4.BoltStateMachineV4) DefaultDatabaseResolver(org.neo4j.kernel.database.DefaultDatabaseResolver) Test(org.junit.jupiter.api.Test)

Example 3 with BoltStateMachineV4

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

the class FailedStateIT method shouldCloseConnectionOnIllegalMessages.

private void shouldCloseConnectionOnIllegalMessages(RequestMessage message) throws InterruptedException, BoltConnectionFatality {
    // Given
    BoltStateMachineV4 machine = getBoltStateMachineInFailedState();
    // when
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    verifyKillsConnection(() -> machine.process(message, recorder));
    // then
    assertThat(recorder.nextResponse()).satisfies(failedWithStatus(Status.Request.Invalid));
    assertNull(machine.state());
}
Also used : BoltStateMachineV4(org.neo4j.bolt.v4.BoltStateMachineV4) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder)

Example 4 with BoltStateMachineV4

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

the class FailedStateIT method getBoltStateMachineInFailedState.

private BoltStateMachineV4 getBoltStateMachineInFailedState() throws BoltConnectionFatality, InterruptedException {
    BoltStateMachineV4 machine = newStateMachine();
    machine.process(newHelloMessage(), nullResponseHandler());
    RunMessage runMessage = mock(RunMessage.class);
    when(runMessage.databaseName()).thenReturn(ABSENT_DB_NAME);
    when(runMessage.statement()).thenThrow(new RuntimeException("error here"));
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.process(runMessage, recorder);
    assertThat(recorder.nextResponse()).satisfies(failedWithStatus(Status.General.UnknownError));
    assertThat(machine.state()).isInstanceOf(FailedState.class);
    return machine;
}
Also used : BoltStateMachineV4(org.neo4j.bolt.v4.BoltStateMachineV4) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) RunMessage(org.neo4j.bolt.v4.messaging.RunMessage)

Example 5 with BoltStateMachineV4

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

the class ReadyStateIT method shouldMoveToFailedStateOnRun_fail.

@Test
void shouldMoveToFailedStateOnRun_fail() throws Throwable {
    // Given
    BoltStateMachineV4 machine = newStateMachine();
    machine.process(newHelloMessage(), nullResponseHandler());
    // When
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    RunMessage runMessage = mock(RunMessage.class);
    when(runMessage.databaseName()).thenReturn(ABSENT_DB_NAME);
    when(runMessage.statement()).thenThrow(new RuntimeException("Fail"));
    machine.process(runMessage, recorder);
    // Then
    assertThat(recorder.nextResponse()).satisfies(failedWithStatus(Status.General.UnknownError));
    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)

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