use of org.neo4j.bolt.v1.runtime.spi.BoltResult in project neo4j by neo4j.
the class BoltStateMachineTest method testPublishingError.
@Test
public void testPublishingError() throws Throwable {
// Given a new ready machine...
BoltStateMachine machine = newMachine(READY);
// ...and a result ready to be retrieved...
machine.run("RETURN 1", null, nullResponseHandler());
// ...and a handler guaranteed to break
BoltResponseRecorder recorder = new BoltResponseRecorder() {
@Override
public void onRecords(BoltResult result, boolean pull) throws Exception {
throw new RuntimeException("I've been expecting you, Mr Bond.");
}
};
// When we pull using that handler
machine.pullAll(recorder);
// Then the breakage should surface as a FAILURE
assertThat(recorder.nextResponse(), failedWithStatus(Status.General.UnknownError));
// ...and the machine should have entered a FAILED state
assertThat(machine, inState(FAILED));
}
use of org.neo4j.bolt.v1.runtime.spi.BoltResult in project neo4j by neo4j.
the class BoltConnectionIT method shouldHandleFailureDuringResultPublishing.
@Test
public void shouldHandleFailureDuringResultPublishing() throws Throwable {
// Given
BoltStateMachine machine = env.newMachine(CONNECTION_DESCRIPTOR);
machine.init(USER_AGENT, emptyMap(), null);
final CountDownLatch pullAllCallbackCalled = new CountDownLatch(1);
final AtomicReference<Neo4jError> error = new AtomicReference<>();
// When something fails while publishing the result stream
machine.run("RETURN 1", EMPTY_PARAMS, nullResponseHandler());
machine.pullAll(new BoltResponseHandler() {
@Override
public void onStart() {
}
@Override
public void onRecords(BoltResult result, boolean pull) throws Exception {
throw new RuntimeException("Ooopsies!");
}
@Override
public void onMetadata(String key, Object value) {
}
@Override
public void markFailed(Neo4jError err) {
error.set(err);
pullAllCallbackCalled.countDown();
}
@Override
public void markIgnored() {
}
@Override
public void onFinish() {
}
});
// Then
assertTrue(pullAllCallbackCalled.await(30, TimeUnit.SECONDS));
final Neo4jError err = error.get();
assertThat(err.status(), equalTo((Status) Status.General.UnknownError));
assertThat(err.message(), CoreMatchers.containsString("Ooopsies!"));
}
use of org.neo4j.bolt.v1.runtime.spi.BoltResult 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.runtime.spi.BoltResult in project neo4j by neo4j.
the class TransactionStateMachineSPI method executeQuery.
@Override
public BoltResultHandle executeQuery(BoltQuerySource querySource, SecurityContext securityContext, String statement, Map<String, Object> params, ThrowingAction<KernelException> onFail) throws QueryExecutionKernelException {
InternalTransaction internalTransaction = queryService.beginTransaction(implicit, securityContext);
ClientConnectionInfo sourceDetails = new BoltConnectionInfo(querySource.principalName, querySource.clientName, querySource.connectionDescriptor.clientAddress, querySource.connectionDescriptor.serverAddress);
TransactionalContext transactionalContext = contextFactory.newContext(sourceDetails, internalTransaction, statement, params);
return new BoltResultHandle() {
@Override
public BoltResult start() throws KernelException {
try {
Result run = queryExecutionEngine.executeQuery(statement, params, transactionalContext);
return new CypherAdapterStream(run, clock);
} catch (KernelException e) {
onFail.apply();
throw new QueryExecutionKernelException(e);
} catch (Throwable e) {
onFail.apply();
throw e;
}
}
@Override
public void terminate() {
transactionalContext.terminate();
}
};
}
Aggregations