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