Search in sources :

Example 16 with RunMessage

use of org.neo4j.bolt.v4.messaging.RunMessage in project neo4j by neo4j.

the class BoltV4TransportIT method shouldReturnUpdatedBookmarkAfterAutoCommitTransaction.

@ParameterizedTest(name = "{0}")
@MethodSource("argumentsProvider")
public void shouldReturnUpdatedBookmarkAfterAutoCommitTransaction(Class<? extends TransportConnection> connectionClass) throws Exception {
    init(connectionClass);
    negotiateBoltV4();
    // bookmark is expected to advance once the auto-commit transaction is committed
    var lastClosedTransactionId = getLastClosedTransactionId();
    var expectedBookmark = new BookmarkWithDatabaseId(lastClosedTransactionId + 1, getDatabaseId()).toString();
    connection.send(util.chunk(new RunMessage("CREATE ()"), new PullMessage(asMapValue(map("n", -1L)))));
    assertThat(connection).satisfies(util.eventuallyReceives(msgSuccess(), msgSuccess(responseMessage -> assertThat(responseMessage).containsEntry("bookmark", expectedBookmark))));
}
Also used : BookmarkWithDatabaseId(org.neo4j.bolt.v4.runtime.bookmarking.BookmarkWithDatabaseId) PullMessage(org.neo4j.bolt.v4.messaging.PullMessage) RunMessage(org.neo4j.bolt.v4.messaging.RunMessage) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 17 with RunMessage

use of org.neo4j.bolt.v4.messaging.RunMessage in project neo4j by neo4j.

the class InTransactionStateIT method shouldStayInTxOnAnotherRun_succ.

@Test
void shouldStayInTxOnAnotherRun_succ() throws Throwable {
    // Given
    BoltStateMachineV4 machine = getBoltStateMachineInTxState();
    // When
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.process(new RunMessage("MATCH (n) RETURN n LIMIT 1"), recorder);
    // Then
    RecordedBoltResponse response = recorder.nextResponse();
    assertThat(response).satisfies(succeeded());
    assertFalse(response.hasMetadata("bookmark"));
    assertThat(machine.state()).isInstanceOf(InTransactionState.class);
}
Also used : BoltStateMachineV4(org.neo4j.bolt.v4.BoltStateMachineV4) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) RecordedBoltResponse(org.neo4j.bolt.testing.RecordedBoltResponse) RunMessage(org.neo4j.bolt.v4.messaging.RunMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with RunMessage

use of org.neo4j.bolt.v4.messaging.RunMessage in project neo4j by neo4j.

the class InTransactionStateIT method getBoltStateMachineInTxState.

private BoltStateMachineV4 getBoltStateMachineInTxState(String query) throws BoltConnectionFatality {
    BoltStateMachineV4 machine = newStateMachine();
    machine.process(newHelloMessage(), nullResponseHandler());
    machine.process(new BeginMessage(), nullResponseHandler());
    assertThat(machine.state()).isInstanceOf(InTransactionState.class);
    machine.process(new RunMessage(query, EMPTY_PARAMS), nullResponseHandler());
    // tx streaming state
    assertThat(machine.state()).isInstanceOf(InTransactionState.class);
    return machine;
}
Also used : BeginMessage(org.neo4j.bolt.v4.messaging.BeginMessage) BoltStateMachineV4(org.neo4j.bolt.v4.BoltStateMachineV4) RunMessage(org.neo4j.bolt.v4.messaging.RunMessage)

Example 19 with RunMessage

use of org.neo4j.bolt.v4.messaging.RunMessage in project neo4j by neo4j.

the class InTransactionStateIT method shouldMoveFromInTxToFailedOnAnotherRun_fail.

@Test
void shouldMoveFromInTxToFailedOnAnotherRun_fail() throws Throwable {
    // Given
    BoltStateMachineV4 machine = getBoltStateMachineInTxState();
    // When
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    machine.process(new RunMessage("any string"), recorder);
    // Then
    assertThat(machine.state()).isInstanceOf(FailedState.class);
}
Also used : BoltStateMachineV4(org.neo4j.bolt.v4.BoltStateMachineV4) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) RunMessage(org.neo4j.bolt.v4.messaging.RunMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 with RunMessage

use of org.neo4j.bolt.v4.messaging.RunMessage in project neo4j by neo4j.

the class InTransactionStateIT method shouldThrowExceptionOnIllegalMessagesInTxStreamingState.

private void shouldThrowExceptionOnIllegalMessagesInTxStreamingState(RequestMessage message) throws Throwable {
    // Given
    BoltStateMachineV4 machine = newStateMachine();
    machine.process(newHelloMessage(), nullResponseHandler());
    machine.process(new BeginMessage(), nullResponseHandler());
    machine.process(new RunMessage("CREATE (n {k:'k'}) RETURN n.k", EMPTY_PARAMS), nullResponseHandler());
    assertThat(machine.state()).isInstanceOf(InTransactionState.class);
    // when
    BoltResponseRecorder recorder = new BoltResponseRecorder();
    verifyKillsConnection(() -> machine.process(message, recorder));
    // then
    assertThat(recorder.nextResponse()).satisfies(failedWithStatus(Status.Request.Invalid));
    assertNull(machine.state());
}
Also used : BeginMessage(org.neo4j.bolt.v4.messaging.BeginMessage) BoltStateMachineV4(org.neo4j.bolt.v4.BoltStateMachineV4) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) RunMessage(org.neo4j.bolt.v4.messaging.RunMessage)

Aggregations

RunMessage (org.neo4j.bolt.v4.messaging.RunMessage)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 BoltStateMachineV4 (org.neo4j.bolt.v4.BoltStateMachineV4)9 PullMessage (org.neo4j.bolt.v4.messaging.PullMessage)9 BeginMessage (org.neo4j.bolt.v4.messaging.BeginMessage)8 BookmarkWithDatabaseId (org.neo4j.bolt.v4.runtime.bookmarking.BookmarkWithDatabaseId)8 BoltResponseRecorder (org.neo4j.bolt.testing.BoltResponseRecorder)7 Test (org.junit.jupiter.api.Test)6 RecordedBoltResponse (org.neo4j.bolt.testing.RecordedBoltResponse)2 ByteBuf (io.netty.buffer.ByteBuf)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 IOException (java.io.IOException)1 BoltChannel (org.neo4j.bolt.BoltChannel)1 BoltProtocol (org.neo4j.bolt.BoltProtocol)1 RequestMessage (org.neo4j.bolt.messaging.RequestMessage)1 BoltResponseHandler (org.neo4j.bolt.runtime.BoltResponseHandler)1 SynchronousBoltConnection (org.neo4j.bolt.runtime.SynchronousBoltConnection)1 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)1 BoltTestUtil.newTestBoltChannel (org.neo4j.bolt.testing.BoltTestUtil.newTestBoltChannel)1