Search in sources :

Example 6 with BeginMessage

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

the class BoltRequestMessageV3Test method shouldHandleCommonMessages.

@Test
void shouldHandleCommonMessages() throws Throwable {
    assertSerializes(new HelloMessage(map("user_agent", "MyClient/1.0", "scheme", "basic")));
    assertSerializes(new RunMessage("CREATE (n) RETURN åäö"));
    assertSerializes(DiscardAllMessage.INSTANCE);
    assertSerializes(PullAllMessage.INSTANCE);
    assertSerializes(new BeginMessage());
    assertSerializes(COMMIT_MESSAGE);
    assertSerializes(ROLLBACK_MESSAGE);
    assertSerializes(ResetMessage.INSTANCE);
    assertSerializes(GOODBYE_MESSAGE);
}
Also used : HelloMessage(org.neo4j.bolt.v3.messaging.request.HelloMessage) BeginMessage(org.neo4j.bolt.v3.messaging.request.BeginMessage) RunMessage(org.neo4j.bolt.v3.messaging.request.RunMessage) Test(org.junit.jupiter.api.Test)

Example 7 with BeginMessage

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

the class BoltResponseMessageWriterV3Test method shouldWriteFailureMessage.

@Test
void shouldWriteFailureMessage() throws Exception {
    PackOutput output = mock(PackOutput.class);
    Neo4jPack.Packer packer = mock(Neo4jPack.Packer.class);
    var writer = newWriter(output, packer);
    Status.Transaction errorStatus = Status.Transaction.DeadlockDetected;
    String errorMessage = "Hi Deadlock!";
    writer.write(new FailureMessage(errorStatus, errorMessage));
    InOrder inOrder = inOrder(output, packer);
    inOrder.verify(output).beginMessage();
    inOrder.verify(packer).pack(errorStatus.code().serialize());
    inOrder.verify(packer).pack(errorMessage);
    inOrder.verify(output).messageSucceeded();
}
Also used : Status(org.neo4j.kernel.api.exceptions.Status) InOrder(org.mockito.InOrder) FailureMessage(org.neo4j.bolt.v3.messaging.response.FailureMessage) PackOutput(org.neo4j.bolt.packstream.PackOutput) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) Test(org.junit.jupiter.api.Test)

Example 8 with BeginMessage

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

the class BoltResponseMessageWriterV3Test method shouldWriteSuccessMessage.

@Test
void shouldWriteSuccessMessage() throws Exception {
    PackOutput output = mock(PackOutput.class);
    Neo4jPack.Packer packer = mock(Neo4jPack.Packer.class);
    var writer = newWriter(output, packer);
    MapValue metadata = map(new String[] { "a", "b", "c" }, new AnyValue[] { intValue(1), stringValue("2"), date(2010, 02, 02) });
    writer.write(new SuccessMessage(metadata));
    InOrder inOrder = inOrder(output, packer);
    inOrder.verify(output).beginMessage();
    inOrder.verify(packer).pack(metadata);
    inOrder.verify(output).messageSucceeded();
}
Also used : InOrder(org.mockito.InOrder) SuccessMessage(org.neo4j.bolt.v3.messaging.response.SuccessMessage) MapValue(org.neo4j.values.virtual.MapValue) PackOutput(org.neo4j.bolt.packstream.PackOutput) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) Test(org.junit.jupiter.api.Test)

Example 9 with BeginMessage

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

the class BoltResponseMessageWriterV3Test method shouldNotifyOutputAboutFailedRecordMessage.

@Test
void shouldNotifyOutputAboutFailedRecordMessage() throws Exception {
    PackOutput output = mock(PackOutput.class);
    Neo4jPack.Packer packer = mock(Neo4jPack.Packer.class);
    IOException error = new IOException("Unable to pack 42");
    doThrow(error).when(packer).pack(longValue(42));
    var writer = newWriter(output, packer);
    var e = assertThrows(IOException.class, () -> writer.write(new RecordMessage(new AnyValue[] { stringValue("42"), longValue(42) })));
    assertEquals(error, e);
    InOrder inOrder = inOrder(output, packer);
    inOrder.verify(output).beginMessage();
    inOrder.verify(packer).pack(stringValue("42"));
    inOrder.verify(packer).pack(longValue(42));
    inOrder.verify(output).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 10 with BeginMessage

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

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