Search in sources :

Example 6 with BoltStateMachine

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

the class BoltStateMachineV4Test method shouldTerminateOnAuthExpiryDuringREADYRun.

@SuppressWarnings("unchecked")
@Test
void shouldTerminateOnAuthExpiryDuringREADYRun() throws Throwable {
    // Given
    TransactionStateMachineSPI transactionSPI = mock(TransactionStateMachineSPI.class);
    doThrow(new AuthorizationExpiredException("Auth expired!")).when(transactionSPI).beginTransaction(any(), any(), any(), any(), any(), any());
    BoltStateMachine machine = newMachineWithTransactionSPI(transactionSPI);
    // When & Then
    try {
        machine.process(BoltV4Messages.run("THIS WILL BE IGNORED"), nullResponseHandler());
        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) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) BoltConnectionAuthFatality(org.neo4j.bolt.runtime.BoltConnectionAuthFatality) Test(org.junit.jupiter.api.Test)

Example 7 with BoltStateMachine

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

the class BoltStateMachineV4Test method shouldSucceedOnResetOnFailedState.

@Test
void shouldSucceedOnResetOnFailedState() throws Exception {
    // Given
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    // Given a FAILED machine
    BoltStateMachine machine = init(newMachine());
    machine.markFailed(Neo4jError.from(Status.Request.NoThreadsAvailable, "No Threads Available"));
    machine.process(BoltV4Messages.pullAll(), recorder);
    // When I RESET...
    machine.interrupt();
    machine.markFailed(Neo4jError.from(Status.Request.NoThreadsAvailable, "No Threads Available"));
    machine.process(BoltV4Messages.reset(), recorder);
    assertThat(recorder.nextResponse()).satisfies(failedWithStatus(Status.Request.NoThreadsAvailable));
    // ...successfully
    assertThat(recorder.nextResponse()).satisfies(succeeded());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.jupiter.api.Test)

Example 8 with BoltStateMachine

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

the class BoltStateMachineV4Test method shouldRollbackOpenTransactionOnClose.

@Test
void shouldRollbackOpenTransactionOnClose() throws Throwable {
    // Given a ready machine with an open transaction
    final BoltStateMachine machine = newMachineWithTransaction();
    // When the machine is shut down
    machine.close();
    // Then the transaction should have been rolled back
    assertThat(machine).satisfies(hasNoTransaction());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) Test(org.junit.jupiter.api.Test)

Example 9 with BoltStateMachine

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

the class BoltStateMachineV4Test method shouldBeAbleToKillMessagesAheadInLineWithAnInterrupt.

@Test
void shouldBeAbleToKillMessagesAheadInLineWithAnInterrupt() throws Throwable {
    // Given
    final BoltStateMachine machine = init(newMachine());
    // When
    machine.interrupt();
    // ...and
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.process(BoltV4Messages.run(), recorder);
    machine.process(BoltV4Messages.reset(), recorder);
    machine.process(BoltV4Messages.run(), recorder);
    // Then
    assertThat(recorder.nextResponse()).satisfies(wasIgnored());
    assertThat(recorder.nextResponse()).satisfies(succeeded());
    assertThat(recorder.nextResponse()).satisfies(succeeded());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.jupiter.api.Test)

Example 10 with BoltStateMachine

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

the class BoltStateMachineV4Test method testUsingResetToAcknowledgeError.

@Test
void testUsingResetToAcknowledgeError() throws Throwable {
    // Given
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    // Given a FAILED machine
    BoltStateMachine machine = init(newMachine());
    machine.markFailed(Neo4jError.from(new RuntimeException()));
    // When I RESET...
    reset(machine, recorder);
    // ...successfully
    assertThat(recorder.nextResponse()).satisfies(succeeded());
    // Then if I RUN a statement...
    machine.process(BoltV4Messages.run(), recorder);
    // ...everything should be fine again
    assertThat(recorder.nextResponse()).satisfies(succeeded());
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) 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