Search in sources :

Example 1 with SuccessMessage

use of org.neo4j.bolt.v3.messaging.response.SuccessMessage in project neo4j by neo4j.

the class SuccessMessageEncoderTest method shouldEncodeSuccessMessage.

@Test
void shouldEncodeSuccessMessage() throws Throwable {
    // Given
    Neo4jPack.Packer packer = mock(Neo4jPack.Packer.class);
    SuccessMessageEncoder encoder = new SuccessMessageEncoder();
    // When
    MapValue meta = mock(MapValue.class);
    encoder.encode(packer, new SuccessMessage(meta));
    // Then
    verify(packer).packStructHeader(anyInt(), eq(SuccessMessage.SIGNATURE));
    verify(packer).pack(meta);
}
Also used : SuccessMessage(org.neo4j.bolt.v3.messaging.response.SuccessMessage) MapValue(org.neo4j.values.virtual.MapValue) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) Test(org.junit.jupiter.api.Test)

Example 2 with SuccessMessage

use of org.neo4j.bolt.v3.messaging.response.SuccessMessage in project neo4j by neo4j.

the class BoltResponseMessageReader method read.

public void read(BoltResponseMessageWriter messageWriter) throws IOException {
    try {
        unpacker.unpackStructHeader();
        final int signature = unpacker.unpackStructSignature();
        BoltResponseMessage message = BoltResponseMessage.withSignature(signature);
        try {
            switch(message) {
                case SUCCESS:
                    MapValue successMetadata = unpacker.unpackMap();
                    messageWriter.write(new SuccessMessage(successMetadata));
                    break;
                case RECORD:
                    long length = unpacker.unpackListHeader();
                    final AnyValue[] fields = new AnyValue[(int) length];
                    for (int i = 0; i < length; i++) {
                        fields[i] = unpacker.unpack();
                    }
                    messageWriter.write(new RecordMessage(fields));
                    break;
                case IGNORED:
                    messageWriter.write(IgnoredMessage.IGNORED_MESSAGE);
                    break;
                case FAILURE:
                    MapValue failureMetadata = unpacker.unpackMap();
                    String code = failureMetadata.containsKey("code") ? ((StringValue) failureMetadata.get("code")).stringValue() : Status.General.UnknownError.name();
                    AnyValue msgValue = failureMetadata.get("message");
                    String msg = msgValue != NO_VALUE ? ((StringValue) msgValue).stringValue() : "<No message supplied>";
                    messageWriter.write(new FailureMessage(Neo4jError.codeFromString(code), msg));
                    break;
                default:
                    throw new BoltIOException(Status.Request.InvalidFormat, String.format("Message 0x%s is not supported.", Integer.toHexString(signature)));
            }
        } catch (IllegalArgumentException e) {
            throw new BoltIOException(Status.Request.InvalidFormat, String.format("Message 0x%s is not a valid message signature.", Integer.toHexString(signature)));
        }
    } catch (PackStream.PackStreamException e) {
        throw new BoltIOException(Status.Request.InvalidFormat, String.format("Unable to read message type. Error was: %s.", e.getMessage()), e);
    }
}
Also used : MapValue(org.neo4j.values.virtual.MapValue) PackStream(org.neo4j.bolt.packstream.PackStream) SuccessMessage(org.neo4j.bolt.v3.messaging.response.SuccessMessage) AnyValue(org.neo4j.values.AnyValue) FailureMessage(org.neo4j.bolt.v3.messaging.response.FailureMessage) RecordMessage(org.neo4j.bolt.v3.messaging.response.RecordMessage)

Example 3 with SuccessMessage

use of org.neo4j.bolt.v3.messaging.response.SuccessMessage in project neo4j by neo4j.

the class BoltResponseMessageTest method shouldHandleCommonMessages.

@Test
void shouldHandleCommonMessages() throws Throwable {
    assertSerializes(new RecordMessage(new AnyValue[] { longValue(1L), stringValue("b"), longValue(2L) }));
    assertSerializes(new SuccessMessage(VirtualValues.EMPTY_MAP));
    assertSerializes(new FailureMessage(Status.General.UnknownError, "Err"));
    assertSerializes(IGNORED_MESSAGE);
}
Also used : SuccessMessage(org.neo4j.bolt.v3.messaging.response.SuccessMessage) AnyValue(org.neo4j.values.AnyValue) FailureMessage(org.neo4j.bolt.v3.messaging.response.FailureMessage) RecordMessage(org.neo4j.bolt.v3.messaging.response.RecordMessage) Test(org.junit.jupiter.api.Test)

Example 4 with SuccessMessage

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

Aggregations

SuccessMessage (org.neo4j.bolt.v3.messaging.response.SuccessMessage)4 Test (org.junit.jupiter.api.Test)3 MapValue (org.neo4j.values.virtual.MapValue)3 Neo4jPack (org.neo4j.bolt.packstream.Neo4jPack)2 FailureMessage (org.neo4j.bolt.v3.messaging.response.FailureMessage)2 RecordMessage (org.neo4j.bolt.v3.messaging.response.RecordMessage)2 AnyValue (org.neo4j.values.AnyValue)2 InOrder (org.mockito.InOrder)1 PackOutput (org.neo4j.bolt.packstream.PackOutput)1 PackStream (org.neo4j.bolt.packstream.PackStream)1