Search in sources :

Example 11 with RecordingByteChannel

use of org.neo4j.bolt.messaging.RecordingByteChannel in project neo4j by neo4j.

the class TransportErrorIT method shouldHandleMessagesWithIncorrectFields.

@ParameterizedTest(name = "{displayName} {2}")
@MethodSource("argumentsProvider")
public void shouldHandleMessagesWithIncorrectFields(Class<? extends TransportConnection> connectionClass, Neo4jPack neo4jPack, String name) throws Exception {
    initParameters(connectionClass, neo4jPack, name);
    // Given I send a message with the wrong types in its fields
    final RecordingByteChannel rawData = new RecordingByteChannel();
    final PackStream.Packer packer = new PackStream.Packer(new BufferedChannelOutput(rawData));
    packer.packStructHeader(2, RunMessage.SIGNATURE);
    packer.pack("RETURN 1");
    // Should've been a map
    packer.pack(1234);
    packer.flush();
    byte[] invalidMessage = rawData.getBytes();
    // When
    connection.connect(address).send(util.defaultAcceptedVersions()).send(util.chunk(32, invalidMessage));
    // Then
    assertThat(connection).satisfies(util.eventuallyReceivesSelectedProtocolVersion());
    assertThat(connection).satisfies(eventuallyDisconnects());
}
Also used : PackStream(org.neo4j.bolt.packstream.PackStream) RecordingByteChannel(org.neo4j.bolt.messaging.RecordingByteChannel) BufferedChannelOutput(org.neo4j.bolt.packstream.BufferedChannelOutput) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with RecordingByteChannel

use of org.neo4j.bolt.messaging.RecordingByteChannel in project neo4j by neo4j.

the class TransportErrorIT method shouldHandleUnknownMessages.

@ParameterizedTest(name = "{displayName} {2}")
@MethodSource("argumentsProvider")
public void shouldHandleUnknownMessages(Class<? extends TransportConnection> connectionClass, Neo4jPack neo4jPack, String name) throws Exception {
    initParameters(connectionClass, neo4jPack, name);
    // Given I send a message with an invalid type
    final RecordingByteChannel rawData = new RecordingByteChannel();
    final PackStream.Packer packer = new PackStream.Packer(new BufferedChannelOutput(rawData));
    // Invalid message type
    packer.packStructHeader(1, (byte) 0x66);
    packer.pack(1234);
    packer.flush();
    byte[] invalidMessage = rawData.getBytes();
    // When
    connection.connect(address).send(util.defaultAcceptedVersions()).send(util.chunk(32, invalidMessage));
    // Then
    assertThat(connection).satisfies(util.eventuallyReceivesSelectedProtocolVersion());
    assertThat(connection).satisfies(eventuallyDisconnects());
}
Also used : PackStream(org.neo4j.bolt.packstream.PackStream) RecordingByteChannel(org.neo4j.bolt.messaging.RecordingByteChannel) BufferedChannelOutput(org.neo4j.bolt.packstream.BufferedChannelOutput) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

RecordingByteChannel (org.neo4j.bolt.messaging.RecordingByteChannel)12 BufferedChannelOutput (org.neo4j.bolt.packstream.BufferedChannelOutput)11 BoltRequestMessageWriter (org.neo4j.bolt.messaging.BoltRequestMessageWriter)8 Neo4jPack (org.neo4j.bolt.packstream.Neo4jPack)7 RequestMessage (org.neo4j.bolt.messaging.RequestMessage)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 PackStream (org.neo4j.bolt.packstream.PackStream)3 BoltResponseMessageWriter (org.neo4j.bolt.messaging.BoltResponseMessageWriter)2 BoltProtocolV3ComponentFactory.newNeo4jPack (org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack)2 BoltRequestMessageWriterV4 (org.neo4j.bolt.v4.BoltRequestMessageWriterV4)2 IOException (java.io.IOException)1 System.lineSeparator (java.lang.System.lineSeparator)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 Mockito.mock (org.mockito.Mockito.mock)1