Search in sources :

Example 16 with BoltStateMachineV3

use of org.neo4j.bolt.v3.BoltStateMachineV3 in project neo4j by neo4j.

the class TransactionReadyStateIT method shouldMoveToStreamingOnRun_succ.

@Test
void shouldMoveToStreamingOnRun_succ() throws Throwable {
    // Given
    BoltStateMachineV3 machine = getBoltStateMachineInTxReadyState();
    // When
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.process(new RunMessage("CREATE (n {k:'k'}) RETURN n.k", EMPTY_PARAMS), recorder);
    // Then
    RecordedBoltResponse response = recorder.nextResponse();
    assertTrue(response.hasMetadata("fields"));
    assertTrue(response.hasMetadata("t_first"));
    assertThat(machine.state()).isInstanceOf(TransactionStreamingState.class);
}
Also used : BoltStateMachineV3(org.neo4j.bolt.v3.BoltStateMachineV3) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) RecordedBoltResponse(org.neo4j.bolt.testing.RecordedBoltResponse) RunMessage(org.neo4j.bolt.v3.messaging.request.RunMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with BoltStateMachineV3

use of org.neo4j.bolt.v3.BoltStateMachineV3 in project neo4j by neo4j.

the class TransactionReadyStateIT method shouldMoveToFailedOnRun_fail.

@Test
void shouldMoveToFailedOnRun_fail() throws Throwable {
    BoltStateMachineV3 machine = getBoltStateMachineInTxReadyState();
    // When
    BoltResponseHandler handler = mock(BoltResponseHandler.class);
    doThrow(new RuntimeException("Error!")).when(handler).onPullRecords(any(), anyLong());
    doThrow(new RuntimeException("Error!")).when(handler).onDiscardRecords(any(), anyLong());
    machine.process(new RunMessage("A cypher query"), handler);
    // Then
    assertThat(machine.state()).isInstanceOf(FailedState.class);
}
Also used : BoltStateMachineV3(org.neo4j.bolt.v3.BoltStateMachineV3) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) RunMessage(org.neo4j.bolt.v3.messaging.request.RunMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with BoltStateMachineV3

use of org.neo4j.bolt.v3.BoltStateMachineV3 in project neo4j by neo4j.

the class ConnectedStateIT method shouldHandleHelloMessage.

@Test
void shouldHandleHelloMessage() throws Throwable {
    // Given
    BoltStateMachineV3 machine = newStateMachine();
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    // When
    machine.process(newHelloMessage(), recorder);
    // Then
    RecordedBoltResponse response = recorder.nextResponse();
    assertThat(response).satisfies(succeededWithMetadata("server", BOLT_SERVER_VERSION_PREFIX + Version.getNeo4jVersion()));
    assertThat(response).satisfies(succeededWithMetadata("connection_id", "conn-v3-test-boltchannel-id"));
    assertThat(machine.state()).isInstanceOf(ReadyState.class);
}
Also used : BoltStateMachineV3(org.neo4j.bolt.v3.BoltStateMachineV3) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) RecordedBoltResponse(org.neo4j.bolt.testing.RecordedBoltResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 19 with BoltStateMachineV3

use of org.neo4j.bolt.v3.BoltStateMachineV3 in project neo4j by neo4j.

the class ReadyStateIT method shouldMoveToFailedStateOnBegin_fail.

@Test
void shouldMoveToFailedStateOnBegin_fail() throws Throwable {
    // Given
    BoltStateMachineV3 machine = newStateMachine();
    machine.process(newHelloMessage(), nullResponseHandler());
    // When
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    BeginMessage beginMessage = mock(BeginMessage.class);
    when(beginMessage.bookmarks()).thenThrow(new RuntimeException("Fail"));
    machine.process(beginMessage, recorder);
    // Then
    assertThat(recorder.nextResponse()).satisfies(failedWithStatus(Status.General.UnknownError));
    assertThat(machine.state()).isInstanceOf(FailedState.class);
}
Also used : BeginMessage(org.neo4j.bolt.v3.messaging.request.BeginMessage) BoltStateMachineV3(org.neo4j.bolt.v3.BoltStateMachineV3) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 with BoltStateMachineV3

use of org.neo4j.bolt.v3.BoltStateMachineV3 in project neo4j by neo4j.

the class ReadyStateIT method shouldMoveToStreamingOnRun_succ.

@Test
void shouldMoveToStreamingOnRun_succ() throws Throwable {
    // Given
    BoltStateMachineV3 machine = newStateMachine();
    machine.process(newHelloMessage(), nullResponseHandler());
    // When
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.process(new RunMessage("CREATE (n {k:'k'}) RETURN n.k", EMPTY_PARAMS), recorder);
    // Then
    RecordedBoltResponse response = recorder.nextResponse();
    assertThat(response).satisfies(succeeded());
    assertTrue(response.hasMetadata("fields"));
    assertTrue(response.hasMetadata("t_first"));
    assertThat(machine.state()).isInstanceOf(StreamingState.class);
}
Also used : BoltStateMachineV3(org.neo4j.bolt.v3.BoltStateMachineV3) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) RecordedBoltResponse(org.neo4j.bolt.testing.RecordedBoltResponse) RunMessage(org.neo4j.bolt.v3.messaging.request.RunMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

BoltStateMachineV3 (org.neo4j.bolt.v3.BoltStateMachineV3)36 BoltResponseRecorder (org.neo4j.bolt.testing.BoltResponseRecorder)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 Test (org.junit.jupiter.api.Test)21 RecordedBoltResponse (org.neo4j.bolt.testing.RecordedBoltResponse)9 RunMessage (org.neo4j.bolt.v3.messaging.request.RunMessage)9 BeginMessage (org.neo4j.bolt.v3.messaging.request.BeginMessage)5 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 BoltResponseHandler (org.neo4j.bolt.runtime.BoltResponseHandler)3