Search in sources :

Example 1 with BoltStateMachine

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

the class BoltStateMachineFactoryImplTest method shouldCreateBoltStateMachinesV41.

@Test
void shouldCreateBoltStateMachinesV41() {
    BoltStateMachineFactoryImpl factory = newBoltFactory();
    var memoryTracker = mock(MemoryTracker.class, RETURNS_MOCKS);
    BoltStateMachine boltStateMachine = factory.newStateMachine(new BoltProtocolVersion(4, 1), CHANNEL, MapValue.EMPTY, memoryTracker);
    assertNotNull(boltStateMachine);
    assertThat(boltStateMachine).isInstanceOf(BoltStateMachineV41.class);
    verify(memoryTracker).getScopedMemoryTracker();
    verify(memoryTracker, times(3)).allocateHeap(anyLong());
    verifyNoMoreInteractions(memoryTracker);
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltProtocolVersion(org.neo4j.bolt.BoltProtocolVersion) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with BoltStateMachine

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

the class BoltStateMachineFactoryImplTest method shouldCreateBoltStateMachinesV4.

@Test
void shouldCreateBoltStateMachinesV4() {
    BoltStateMachineFactoryImpl factory = newBoltFactory();
    var memoryTracker = mock(MemoryTracker.class, RETURNS_MOCKS);
    BoltStateMachine boltStateMachine = factory.newStateMachine(new BoltProtocolVersion(4, 0), CHANNEL, MapValue.EMPTY, memoryTracker);
    assertNotNull(boltStateMachine);
    assertThat(boltStateMachine).isInstanceOf(BoltStateMachineV4.class);
    verify(memoryTracker).getScopedMemoryTracker();
    verify(memoryTracker, times(3)).allocateHeap(anyLong());
    verifyNoMoreInteractions(memoryTracker);
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltProtocolVersion(org.neo4j.bolt.BoltProtocolVersion) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with BoltStateMachine

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

the class BoltStateMachineFactoryImplTest method shouldCreateBoltStateMachinesV43.

@Test
void shouldCreateBoltStateMachinesV43() {
    BoltStateMachineFactoryImpl factory = newBoltFactory();
    var memoryTracker = mock(MemoryTracker.class, RETURNS_MOCKS);
    BoltStateMachine boltStateMachine = factory.newStateMachine(new BoltProtocolVersion(4, 3), CHANNEL, MapValue.EMPTY, memoryTracker);
    assertNotNull(boltStateMachine);
    assertThat(boltStateMachine).isInstanceOf(BoltStateMachineV43.class);
    verify(memoryTracker).getScopedMemoryTracker();
    verify(memoryTracker, times(3)).allocateHeap(anyLong());
    verifyNoMoreInteractions(memoryTracker);
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltProtocolVersion(org.neo4j.bolt.BoltProtocolVersion) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with BoltStateMachine

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

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

the class BoltStateMachineV4Test method testPublishingError.

@Test
void testPublishingError() throws Throwable {
    // Given a new ready machine...
    BoltStateMachine machine = init(newMachine());
    // ...and a result ready to be retrieved...
    machine.process(BoltV4Messages.run(), nullResponseHandler());
    // ...and a handler guaranteed to break
    BoltResponseRecorder recorder = new BoltResponseRecorder() {

        @Override
        public boolean onPullRecords(BoltResult result, long size) {
            throw new RuntimeException("I've been expecting you, Mr Bond.");
        }
    };
    // When we pull using that handler
    machine.process(BoltV4Messages.pullAll(), recorder);
    // Then the breakage should surface as a FAILURE
    assertThat(recorder.nextResponse()).satisfies(failedWithStatus(Status.General.UnknownError));
    // ...and the machine should have entered a FAILED state
    assertThat(machine).satisfies(inState(FailedState.class));
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) FailedState(org.neo4j.bolt.v4.runtime.FailedState) BoltResult(org.neo4j.bolt.runtime.BoltResult) 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