Search in sources :

Example 1 with PackOutput

use of org.neo4j.bolt.packstream.PackOutput 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 2 with PackOutput

use of org.neo4j.bolt.packstream.PackOutput 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)

Example 3 with PackOutput

use of org.neo4j.bolt.packstream.PackOutput 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 4 with PackOutput

use of org.neo4j.bolt.packstream.PackOutput in project neo4j by neo4j.

the class BoltResponseMessageWriterV3Test method shouldWriteIgnoredMessage.

@Test
void shouldWriteIgnoredMessage() throws Exception {
    PackOutput output = mock(PackOutput.class);
    Neo4jPack.Packer packer = mock(Neo4jPack.Packer.class);
    var writer = newWriter(output, packer);
    writer.write(IgnoredMessage.IGNORED_MESSAGE);
    InOrder inOrder = inOrder(output, packer);
    inOrder.verify(output).beginMessage();
    inOrder.verify(packer).packStructHeader(0, IGNORED.signature());
    inOrder.verify(output).messageSucceeded();
}
Also used : InOrder(org.mockito.InOrder) PackOutput(org.neo4j.bolt.packstream.PackOutput) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) Test(org.junit.jupiter.api.Test)

Example 5 with PackOutput

use of org.neo4j.bolt.packstream.PackOutput in project neo4j by neo4j.

the class BoltResponseMessageWriterV3Test method shouldLimitLogOutputToSensibleSizes.

/**
 * Asserts that large values aren't passed directly to the log provider as this may lead to overflows when flushing the message.
 */
@Test
void shouldLimitLogOutputToSensibleSizes() throws IOException {
    PackOutput output = mock(PackOutput.class);
    Neo4jPack.Packer packer = mock(Neo4jPack.Packer.class);
    IOException error = new IOException("Unable to flush");
    doThrow(error).when(packer).pack(ArgumentMatchers.any(AnyValue.class));
    AssertableLogProvider logProvider = new AssertableLogProvider();
    var writer = new BoltResponseMessageWriterV3(out -> packer, output, new SimpleLogService(logProvider));
    var listValue = VirtualValues.list();
    for (var i = 0; i < 1000; i++) {
        listValue = VirtualValues.list(listValue);
    }
    var testValue = listValue;
    var cause = assertThrows(IOException.class, () -> writer.consumeField(testValue));
    assertSame(error, cause);
    assertThat(logProvider).forClass(BoltResponseMessageWriterV3.class).containsMessagesOnce("Failed to write value");
    assertThat(logProvider).forClass(BoltResponseMessageWriterV3.class).doesNotContainMessageWithArguments("Failed to write value %s because: %s", listValue, cause.getMessage());
}
Also used : SimpleLogService(org.neo4j.logging.internal.SimpleLogService) AnyValue(org.neo4j.values.AnyValue) IOException(java.io.IOException) PackOutput(org.neo4j.bolt.packstream.PackOutput) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)8 Neo4jPack (org.neo4j.bolt.packstream.Neo4jPack)8 PackOutput (org.neo4j.bolt.packstream.PackOutput)8 InOrder (org.mockito.InOrder)6 IOException (java.io.IOException)3 RecordMessage (org.neo4j.bolt.v3.messaging.response.RecordMessage)3 AnyValue (org.neo4j.values.AnyValue)2 FailureMessage (org.neo4j.bolt.v3.messaging.response.FailureMessage)1 SuccessMessage (org.neo4j.bolt.v3.messaging.response.SuccessMessage)1 Status (org.neo4j.kernel.api.exceptions.Status)1 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)1 SimpleLogService (org.neo4j.logging.internal.SimpleLogService)1 MapValue (org.neo4j.values.virtual.MapValue)1