Search in sources :

Example 11 with RunMessage

use of org.neo4j.bolt.v3.messaging.request.RunMessage 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 12 with RunMessage

use of org.neo4j.bolt.v3.messaging.request.RunMessage 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)

Example 13 with RunMessage

use of org.neo4j.bolt.v3.messaging.request.RunMessage in project neo4j by neo4j.

the class ReadyStateIT method shouldMoveToFailedStateOnRun_fail.

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

Example 14 with RunMessage

use of org.neo4j.bolt.v3.messaging.request.RunMessage in project neo4j by neo4j.

the class BoltV3TransportIT method shouldSetTxMetadata.

@ParameterizedTest(name = "{0}")
@MethodSource("argumentsProvider")
public void shouldSetTxMetadata(Class<? extends TransportConnection> connectionClass) throws Exception {
    init(connectionClass);
    // Given
    negotiateBoltV3();
    Map<String, Object> txMetadata = map("who-is-your-boss", "Molly-mostly-white");
    Map<String, Object> msgMetadata = map("tx_metadata", txMetadata);
    MapValue meta = asMapValue(msgMetadata);
    connection.send(util.chunk(new BeginMessage(meta, List.of(), null, AccessMode.WRITE, txMetadata), new RunMessage("RETURN 1"), PullAllMessage.INSTANCE));
    // When
    assertThat(connection).satisfies(util.eventuallyReceives(msgSuccess(), msgSuccess(), msgRecord(eqRecord(longEquals(1L))), msgSuccess()));
    // Then
    GraphDatabaseAPI gdb = (GraphDatabaseAPI) server.graphDatabaseService();
    Set<KernelTransactionHandle> txHandles = gdb.getDependencyResolver().resolveDependency(KernelTransactions.class).activeTransactions();
    assertThat(txHandles.size()).isEqualTo(1);
    for (KernelTransactionHandle txHandle : txHandles) {
        assertThat(txHandle.getMetaData()).isEqualTo(txMetadata);
    }
    connection.send(util.chunk(ROLLBACK_MESSAGE));
}
Also used : BeginMessage(org.neo4j.bolt.v3.messaging.request.BeginMessage) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) KernelTransactions(org.neo4j.kernel.impl.api.KernelTransactions) ValueUtils.asMapValue(org.neo4j.kernel.impl.util.ValueUtils.asMapValue) MapValue(org.neo4j.values.virtual.MapValue) RunMessage(org.neo4j.bolt.v3.messaging.request.RunMessage) KernelTransactionHandle(org.neo4j.kernel.api.KernelTransactionHandle) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 15 with RunMessage

use of org.neo4j.bolt.v3.messaging.request.RunMessage in project neo4j by neo4j.

the class FailedStateIT method getBoltStateMachineInFailedState.

private BoltStateMachineV3 getBoltStateMachineInFailedState() throws BoltConnectionFatality, InterruptedException {
    BoltStateMachineV3 machine = newStateMachine();
    machine.process(newHelloMessage(), nullResponseHandler());
    RunMessage runMessage = mock(RunMessage.class);
    when(runMessage.statement()).thenThrow(new RuntimeException("error here"));
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.process(runMessage, recorder);
    assertThat(recorder.nextResponse()).satisfies(failedWithStatus(Status.General.UnknownError));
    assertThat(machine.state()).isInstanceOf(FailedState.class);
    return machine;
}
Also used : BoltStateMachineV3(org.neo4j.bolt.v3.BoltStateMachineV3) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) RunMessage(org.neo4j.bolt.v3.messaging.request.RunMessage)

Aggregations

RunMessage (org.neo4j.bolt.v3.messaging.request.RunMessage)15 BoltStateMachineV3 (org.neo4j.bolt.v3.BoltStateMachineV3)9 Test (org.junit.jupiter.api.Test)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 BoltResponseRecorder (org.neo4j.bolt.testing.BoltResponseRecorder)6 BeginMessage (org.neo4j.bolt.v3.messaging.request.BeginMessage)4 MapValue (org.neo4j.values.virtual.MapValue)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 RecordedBoltResponse (org.neo4j.bolt.testing.RecordedBoltResponse)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 BoltResponseHandler (org.neo4j.bolt.runtime.BoltResponseHandler)1 SynchronousBoltConnection (org.neo4j.bolt.runtime.SynchronousBoltConnection)1 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)1 HelloMessage (org.neo4j.bolt.v3.messaging.request.HelloMessage)1 BookmarkWithPrefix (org.neo4j.bolt.v3.runtime.bookmarking.BookmarkWithPrefix)1 KernelTransactionHandle (org.neo4j.kernel.api.KernelTransactionHandle)1 KernelTransactions (org.neo4j.kernel.impl.api.KernelTransactions)1 ValueUtils.asMapValue (org.neo4j.kernel.impl.util.ValueUtils.asMapValue)1 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)1