Search in sources :

Example 36 with BoltStateMachine

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

the class BoltStateMachineFactoryImplTest method shouldCreateBoltStateMachinesV3.

@Test
void shouldCreateBoltStateMachinesV3() {
    BoltStateMachineFactoryImpl factory = newBoltFactory();
    var memoryTracker = mock(MemoryTracker.class, RETURNS_MOCKS);
    BoltStateMachine boltStateMachine = factory.newStateMachine(new BoltProtocolVersion(3, 0), CHANNEL, MapValue.EMPTY, memoryTracker);
    assertNotNull(boltStateMachine);
    assertThat(boltStateMachine).isInstanceOf(BoltStateMachineV3.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 37 with BoltStateMachine

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

the class BoltV4MachineRoom method newMachineWithTransaction.

public static BoltStateMachine newMachineWithTransaction() throws BoltConnectionFatality, BoltIOException {
    BoltStateMachine machine = newMachine();
    init(machine);
    runBegin(machine);
    return machine;
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine)

Example 38 with BoltStateMachine

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

the class BoltConnectionAuthIT method shouldGiveCredentialsExpiredStatusOnExpiredCredentials.

@Test
void shouldGiveCredentialsExpiredStatusOnExpiredCredentials() throws Throwable {
    // Given it is important for client applications to programmatically
    // identify expired credentials as the cause of not being authenticated
    BoltStateMachine machine = newStateMachine();
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    // When
    var hello = BoltV4Messages.hello(newBasicAuthToken("neo4j", "neo4j"));
    machine.process(hello, recorder);
    machine.process(BoltV4Messages.run("CREATE ()"), recorder);
    // Then
    assertThat(recorder.nextResponse()).satisfies(succeededWithMetadata("credentials_expired", TRUE));
    assertThat(recorder.nextResponse()).satisfies(failedWithStatus(Status.Security.CredentialsExpired));
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.jupiter.api.Test)

Example 39 with BoltStateMachine

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

the class BoltStateMachineV4Test method testMarkFailedShouldYieldSuccessIfAlreadyFailed.

private static void testMarkFailedShouldYieldSuccessIfAlreadyFailed(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(ReadyState.class));
    verify(responseHandler, never()).markIgnored();
    verify(responseHandler, never()).markFailed(any());
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) ReadyState(org.neo4j.bolt.v4.runtime.ReadyState) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler)

Example 40 with BoltStateMachine

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

the class BoltStateMachineV4Test method shouldNotFailWhenMarkedForTerminationAndPullAll.

@Test
void shouldNotFailWhenMarkedForTerminationAndPullAll() throws Exception {
    BoltStateMachineSPIImpl spi = mock(BoltStateMachineSPIImpl.class, RETURNS_MOCKS);
    BoltStateMachine machine = init(newMachine(spi));
    // move to streaming state
    machine.process(BoltV4Messages.run(), nullResponseHandler());
    txStateMachine(machine).ctx.statementOutcomes.put(StatementMetadata.ABSENT_QUERY_ID, new StatementOutcome(BoltResult.EMPTY));
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    machine.markForTermination();
    machine.process(BoltV4Messages.pullAll(), responseHandler);
    verify(spi, never()).reportError(any());
    assertThat(machine).isNotEqualTo(inState(FailedState.class));
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) StatementOutcome(org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) 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