Search in sources :

Example 11 with BoltStateMachine

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

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

the class BoltStateMachineV4Test method shouldResetWithOpenTransactionAndOpenResult.

@Test
void shouldResetWithOpenTransactionAndOpenResult() throws Throwable {
    // Given a ready machine with an open transaction...
    final BoltStateMachine machine = newMachineWithTransaction();
    // ...and an open result
    machine.process(BoltV4Messages.run(), nullResponseHandler());
    // Then
    assertThat(machine).satisfies(canReset());
    assertThat(machine).satisfies(hasNoTransaction());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) Test(org.junit.jupiter.api.Test)

Example 13 with BoltStateMachine

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

the class BoltStateMachineV4Test method shouldResetWithOpenResult.

@Test
void shouldResetWithOpenResult() throws Throwable {
    // Given a ready machine...
    final BoltStateMachine machine = init(newMachine());
    // ...and an open result
    machine.process(BoltV4Messages.run(), nullResponseHandler());
    // Then
    assertThat(machine).satisfies(canReset());
    assertThat(machine).satisfies(hasNoTransaction());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) Test(org.junit.jupiter.api.Test)

Example 14 with BoltStateMachine

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

the class BoltStateMachineV4Test method testRollbackError.

@Test
void testRollbackError() throws Throwable {
    // Given
    BoltStateMachine machine = init(newMachine());
    // Given there is a running transaction
    machine.process(BoltV4Messages.begin(), nullResponseHandler());
    // And given that transaction will fail to roll back
    TransactionStateMachine txMachine = txStateMachine(machine);
    doThrow(new TransactionFailureException("No Mr. Bond, I expect you to die.")).when(txMachine.ctx.currentTransaction).rollback();
    // When
    machine.process(BoltV4Messages.rollback(), nullResponseHandler());
    // Then
    assertThat(machine).satisfies(inState(FailedState.class));
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) FailedState(org.neo4j.bolt.v4.runtime.FailedState) Test(org.junit.jupiter.api.Test)

Example 15 with BoltStateMachine

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

the class BoltStateMachineV4Test method shouldFailWhenOutOfOrderRollback.

@Test
void shouldFailWhenOutOfOrderRollback() throws Throwable {
    // Given a failed machine
    final BoltStateMachine machine = newMachine();
    machine.markFailed(Neo4jError.from(new RuntimeException()));
    // When
    machine.process(BoltV4Messages.rollback(), nullResponseHandler());
    // Then
    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)

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