use of org.neo4j.bolt.v1.messaging.message.ResponseMessage in project neo4j by neo4j.
the class BoltInteraction method collectResults.
private static BoltResult collectResults(TransportConnection client) throws Exception {
ResponseMessage message = TransportTestUtil.receiveOneResponseMessage(client);
List<String> fieldNames = new ArrayList<>();
List<Map<String, Object>> result = new ArrayList<>();
if (message instanceof SuccessMessage) {
Map<String, Object> metadata = ((SuccessMessage) message).meta();
fieldNames = (List<String>) metadata.get("fields");
} else if (message instanceof FailureMessage) {
FailureMessage failMessage = (FailureMessage) message;
// drain ignoredMessage, ack failure, get successMessage
TransportTestUtil.receiveOneResponseMessage(client);
client.send(TransportTestUtil.chunk(reset()));
TransportTestUtil.receiveOneResponseMessage(client);
throw new AuthenticationException(failMessage.status(), failMessage.message());
}
do {
message = TransportTestUtil.receiveOneResponseMessage(client);
if (message instanceof RecordMessage) {
Object[] row = ((RecordMessage) message).record().fields();
Map<String, Object> rowMap = new HashMap<>();
for (int i = 0; i < row.length; i++) {
rowMap.put(fieldNames.get(i), row[i]);
}
result.add(rowMap);
}
} while (!(message instanceof SuccessMessage) && !(message instanceof FailureMessage));
if (message instanceof FailureMessage) {
FailureMessage failMessage = (FailureMessage) message;
// ack failure, get successMessage
client.send(TransportTestUtil.chunk(reset()));
TransportTestUtil.receiveOneResponseMessage(client);
throw new AuthenticationException(failMessage.status(), failMessage.message());
}
return new BoltResult(result);
}
use of org.neo4j.bolt.v1.messaging.message.ResponseMessage in project neo4j by neo4j.
the class TransportTestUtil method eventuallyReceives.
public static Matcher<TransportConnection> eventuallyReceives(final Matcher<ResponseMessage>... messages) {
return new TypeSafeMatcher<TransportConnection>() {
@Override
protected boolean matchesSafely(TransportConnection conn) {
try {
for (Matcher<ResponseMessage> matchesMessage : messages) {
final ResponseMessage message = receiveOneResponseMessage(conn);
assertThat(message, matchesMessage);
}
return true;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public void describeTo(Description description) {
description.appendValueList("Messages[", ",", "]", messages);
}
};
}
Aggregations