Search in sources :

Example 1 with BeginMessage

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

the class TransactionStreamingStateIT method getBoltStateMachineInTxStreamingState.

private BoltStateMachineV3 getBoltStateMachineInTxStreamingState() throws BoltConnectionFatality {
    BoltStateMachineV3 machine = newStateMachine();
    machine.process(newHelloMessage(), nullResponseHandler());
    machine.process(new BeginMessage(), nullResponseHandler());
    assertThat(machine.state()).isInstanceOf(TransactionReadyState.class);
    machine.process(new RunMessage("CREATE (n {k:'k'}) RETURN n.k"), nullResponseHandler());
    // tx streaming state
    assertThat(machine.state()).isInstanceOf(TransactionStreamingState.class);
    return machine;
}
Also used : BeginMessage(org.neo4j.bolt.v3.messaging.request.BeginMessage) BoltStateMachineV3(org.neo4j.bolt.v3.BoltStateMachineV3) RunMessage(org.neo4j.bolt.v3.messaging.request.RunMessage)

Example 2 with BeginMessage

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

the class TransactionStreamingStateIT method shouldThrowExceptionOnIllegalMessagesInTxStreamingState.

private void shouldThrowExceptionOnIllegalMessagesInTxStreamingState(RequestMessage message) throws Throwable {
    // Given
    BoltStateMachineV3 machine = newStateMachine();
    machine.process(newHelloMessage(), nullResponseHandler());
    machine.process(new BeginMessage(), nullResponseHandler());
    machine.process(new RunMessage("CREATE (n {k:'k'}) RETURN n.k"), nullResponseHandler());
    assertThat(machine.state()).isInstanceOf(TransactionStreamingState.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.v3.messaging.request.BeginMessage) BoltStateMachineV3(org.neo4j.bolt.v3.BoltStateMachineV3) BoltResponseRecorder(org.neo4j.bolt.testing.BoltResponseRecorder) RunMessage(org.neo4j.bolt.v3.messaging.request.RunMessage)

Example 3 with BeginMessage

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

the class TransactionReadyStateIT method getBoltStateMachineInTxReadyState.

private BoltStateMachineV3 getBoltStateMachineInTxReadyState() throws BoltConnectionFatality {
    BoltStateMachineV3 machine = newStateMachine();
    machine.process(newHelloMessage(), nullResponseHandler());
    machine.process(new BeginMessage(), nullResponseHandler());
    return machine;
}
Also used : BeginMessage(org.neo4j.bolt.v3.messaging.request.BeginMessage) BoltStateMachineV3(org.neo4j.bolt.v3.BoltStateMachineV3)

Example 4 with BeginMessage

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

the class BoltResponseMessageWriterV3Test method shouldNotNotifyOutputWhenOutputItselfFails.

@Test
void shouldNotNotifyOutputWhenOutputItselfFails() throws Exception {
    PackOutput output = mock(PackOutput.class);
    Neo4jPack.Packer packer = mock(Neo4jPack.Packer.class);
    IOException error = new IOException("Unable to flush");
    doThrow(error).when(output).messageSucceeded();
    var writer = newWriter(output, packer);
    var e = assertThrows(IOException.class, () -> writer.write(new RecordMessage(new AnyValue[] { longValue(1), longValue(2) })));
    assertEquals(error, e);
    InOrder inOrder = inOrder(output, packer);
    inOrder.verify(output).beginMessage();
    inOrder.verify(packer).pack(longValue(1));
    inOrder.verify(packer).pack(longValue(2));
    inOrder.verify(output).messageSucceeded();
    verify(output, never()).messageFailed();
}
Also used : InOrder(org.mockito.InOrder) IOException(java.io.IOException) PackOutput(org.neo4j.bolt.packstream.PackOutput) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) RecordMessage(org.neo4j.bolt.v3.messaging.response.RecordMessage) Test(org.junit.jupiter.api.Test)

Example 5 with BeginMessage

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

the class BoltResponseMessageWriterV3Test method shouldWriteRecordMessage.

@Test
void shouldWriteRecordMessage() throws Exception {
    PackOutput output = mock(PackOutput.class);
    Neo4jPack.Packer packer = mock(Neo4jPack.Packer.class);
    var writer = newWriter(output, packer);
    writer.write(new RecordMessage(new AnyValue[] { longValue(42), stringValue("42") }));
    InOrder inOrder = inOrder(output, packer);
    inOrder.verify(output).beginMessage();
    inOrder.verify(packer).pack(longValue(42));
    inOrder.verify(packer).pack(stringValue("42"));
    inOrder.verify(output).messageSucceeded();
}
Also used : InOrder(org.mockito.InOrder) AnyValue(org.neo4j.values.AnyValue) PackOutput(org.neo4j.bolt.packstream.PackOutput) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) RecordMessage(org.neo4j.bolt.v3.messaging.response.RecordMessage) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)8 BeginMessage (org.neo4j.bolt.v3.messaging.request.BeginMessage)7 InOrder (org.mockito.InOrder)5 Neo4jPack (org.neo4j.bolt.packstream.Neo4jPack)5 PackOutput (org.neo4j.bolt.packstream.PackOutput)5 BoltStateMachineV3 (org.neo4j.bolt.v3.BoltStateMachineV3)5 RunMessage (org.neo4j.bolt.v3.messaging.request.RunMessage)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 BoltResponseRecorder (org.neo4j.bolt.testing.BoltResponseRecorder)3 RecordMessage (org.neo4j.bolt.v3.messaging.response.RecordMessage)3 IOException (java.io.IOException)2 MapValue (org.neo4j.values.virtual.MapValue)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 RecordedBoltResponse (org.neo4j.bolt.testing.RecordedBoltResponse)1 HelloMessage (org.neo4j.bolt.v3.messaging.request.HelloMessage)1 FailureMessage (org.neo4j.bolt.v3.messaging.response.FailureMessage)1 SuccessMessage (org.neo4j.bolt.v3.messaging.response.SuccessMessage)1 KernelTransactionHandle (org.neo4j.kernel.api.KernelTransactionHandle)1 Status (org.neo4j.kernel.api.exceptions.Status)1 KernelTransactions (org.neo4j.kernel.impl.api.KernelTransactions)1