Search in sources :

Example 56 with BoltStateMachine

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

the class BoltRequestMessageReaderV43Test method testMessageDecoding.

private static void testMessageDecoding(RequestMessage message) throws Exception {
    Neo4jPack neo4jPack = newNeo4jPack();
    BoltStateMachine stateMachine = mock(BoltStateMachine.class);
    BoltRequestMessageReader reader = requestMessageReader(stateMachine);
    PackedInputArray input = new PackedInputArray(encode(neo4jPack, message));
    Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
    reader.read(unpacker);
    verify(stateMachine).process(eq(message), any());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltRequestMessageReader(org.neo4j.bolt.messaging.BoltRequestMessageReader) PackedInputArray(org.neo4j.bolt.packstream.PackedInputArray) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BoltProtocolV43ComponentFactory.newNeo4jPack(org.neo4j.bolt.v43.BoltProtocolV43ComponentFactory.newNeo4jPack)

Example 57 with BoltStateMachine

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

the class BoltStateMachineContextImplTest method shouldResetMachine.

@Test
void shouldResetMachine() throws BoltConnectionFatality {
    BoltStateMachine machine = mock(BoltStateMachine.class);
    BoltStateMachineContextImpl context = newContext(machine, mock(BoltStateMachineSPI.class));
    context.resetMachine();
    verify(machine).reset();
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltStateMachineSPI(org.neo4j.bolt.runtime.statemachine.BoltStateMachineSPI) Test(org.junit.jupiter.api.Test)

Example 58 with BoltStateMachine

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

the class BoltStateMachineV4Test method shouldRollbackOpenTransactionOnReset.

@Test
void shouldRollbackOpenTransactionOnReset() throws Throwable {
    // Given a FAILED machine with an open transaction
    final BoltStateMachine machine = newMachineWithTransaction();
    machine.markFailed(Neo4jError.from(new RuntimeException()));
    // When RESET occurs
    reset(machine, nullResponseHandler());
    // Then the transaction should have been rolled back...
    assertThat(machine).satisfies(hasNoTransaction());
    // ...and the machine should go back to READY
    assertThat(machine).satisfies(inState(ReadyState.class));
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) ReadyState(org.neo4j.bolt.v4.runtime.ReadyState) Test(org.junit.jupiter.api.Test)

Example 59 with BoltStateMachine

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

the class BoltStateMachineV4Test method shouldTerminateOnAuthExpiryDuringSTREAMINGDiscardAll.

@Test
void shouldTerminateOnAuthExpiryDuringSTREAMINGDiscardAll() throws Throwable {
    // Given
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    doThrow(new AuthorizationExpiredException("Auth expired!")).when(responseHandler).onDiscardRecords(any(), eq(STREAM_LIMIT_UNLIMITED));
    BoltStateMachine machine = init(newMachine());
    // move to streaming state
    machine.process(BoltV4Messages.run(), nullResponseHandler());
    // We assume the only implementation of statement processor is TransactionStateMachine
    txStateMachine(machine).ctx.statementOutcomes.put(StatementMetadata.ABSENT_QUERY_ID, new StatementOutcome(BoltResult.EMPTY));
    // When & Then
    try {
        machine.process(BoltV4Messages.discardAll(), responseHandler);
        fail("Exception expected");
    } catch (BoltConnectionAuthFatality e) {
        assertEquals("Auth expired!", e.getCause().getMessage());
    }
}
Also used : AuthorizationExpiredException(org.neo4j.graphdb.security.AuthorizationExpiredException) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) StatementOutcome(org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) BoltConnectionAuthFatality(org.neo4j.bolt.runtime.BoltConnectionAuthFatality) Test(org.junit.jupiter.api.Test)

Example 60 with BoltStateMachine

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

the class BoltStateMachineV4Test method shouldTerminateOnAuthExpiryDuringSTREAMINGPullAll.

@Test
void shouldTerminateOnAuthExpiryDuringSTREAMINGPullAll() throws Throwable {
    // Given
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    doThrow(new AuthorizationExpiredException("Auth expired!")).when(responseHandler).onPullRecords(any(), eq(STREAM_LIMIT_UNLIMITED));
    BoltStateMachine machine = init(newMachine());
    // move to streaming state
    machine.process(BoltV4Messages.run(), nullResponseHandler());
    // We assume the only implementation of statement processor is TransactionStateMachine
    txStateMachine(machine).ctx.statementOutcomes.put(StatementMetadata.ABSENT_QUERY_ID, new StatementOutcome(BoltResult.EMPTY));
    // When & Then
    try {
        machine.process(BoltV4Messages.pullAll(), responseHandler);
        fail("Exception expected");
    } catch (BoltConnectionAuthFatality e) {
        assertEquals("Auth expired!", e.getCause().getMessage());
    }
    verify(responseHandler).onPullRecords(any(), eq(STREAM_LIMIT_UNLIMITED));
}
Also used : AuthorizationExpiredException(org.neo4j.graphdb.security.AuthorizationExpiredException) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) StatementOutcome(org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) BoltConnectionAuthFatality(org.neo4j.bolt.runtime.BoltConnectionAuthFatality) 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