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();
}
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();
}
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();
}
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();
}
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());
}
Aggregations