use of org.neo4j.bolt.v3.messaging.response.RecordMessage 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.RecordMessage 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.RecordMessage in project neo4j by neo4j.
the class BoltResponseMessageWriterV3Test method shouldNotifyOutputAboutFailedRecordMessage.
@Test
void shouldNotifyOutputAboutFailedRecordMessage() throws Exception {
PackOutput output = mock(PackOutput.class);
Neo4jPack.Packer packer = mock(Neo4jPack.Packer.class);
IOException error = new IOException("Unable to pack 42");
doThrow(error).when(packer).pack(longValue(42));
var writer = newWriter(output, packer);
var e = assertThrows(IOException.class, () -> writer.write(new RecordMessage(new AnyValue[] { stringValue("42"), longValue(42) })));
assertEquals(error, e);
InOrder inOrder = inOrder(output, packer);
inOrder.verify(output).beginMessage();
inOrder.verify(packer).pack(stringValue("42"));
inOrder.verify(packer).pack(longValue(42));
inOrder.verify(output).messageFailed();
}
Aggregations