use of ai.grakn.rpc.generated.GrpcGrakn.TxRequest in project grakn by graknlabs.
the class RemoteGraknTxTest method whenAnErrorOccurs_TheTxCloses.
@Test
public void whenAnErrorOccurs_TheTxCloses() {
Query<?> query = match(var("x")).get();
TxRequest execQueryRequest = GrpcUtil.execQueryRequest(query);
throwOn(execQueryRequest, ErrorType.GRAQL_QUERY_EXCEPTION, "well something went wrong");
try (GraknTx tx = RemoteGraknTx.create(session, GrpcUtil.openRequest(KEYSPACE, GraknTxType.WRITE))) {
try {
tx.graql().match(var("x")).get().execute();
} catch (GraqlQueryException e) {
// Ignore
}
assertTrue(tx.isClosed());
}
}
use of ai.grakn.rpc.generated.GrpcGrakn.TxRequest in project grakn by graknlabs.
the class GrpcServerMock method before.
@Override
protected void before() throws Throwable {
when(service.tx(any())).thenAnswer(args -> {
serverResponses = args.getArgument(0);
return serverRequests;
});
doAnswer(args -> {
StreamObserver<DeleteResponse> deleteResponses = args.getArgument(1);
deleteResponses.onNext(GrpcUtil.deleteResponse());
deleteResponses.onCompleted();
return null;
}).when(service).delete(any(), any());
// Return a default "done" response to every message from the client
doAnswer(args -> {
if (serverResponses == null) {
throw new IllegalArgumentException("Set-up of rule not called");
}
TxRequest request = args.getArgument(0);
Optional<TxResponse> next = grpcIterators.next(request.getNext().getIteratorId());
serverResponses.onNext(next.orElse(GrpcUtil.doneResponse()));
return null;
}).when(serverRequests).onNext(any());
// Return a default "complete" response to every "complete" message from the client
doAnswer(args -> {
if (serverResponses == null) {
throw new IllegalArgumentException("Set-up of rule not called");
}
serverResponses.onCompleted();
return null;
}).when(serverRequests).onCompleted();
serverRule.getServiceRegistry().addService(service);
}
use of ai.grakn.rpc.generated.GrpcGrakn.TxRequest in project grakn by graknlabs.
the class RemoteGraknTxTest method whenAnErrorOccurs_AllFutureActionsThrow.
@Test
public void whenAnErrorOccurs_AllFutureActionsThrow() {
Query<?> query = match(var("x")).get();
TxRequest execQueryRequest = GrpcUtil.execQueryRequest(query);
throwOn(execQueryRequest, ErrorType.GRAQL_QUERY_EXCEPTION, "well something went wrong");
try (GraknTx tx = RemoteGraknTx.create(session, GrpcUtil.openRequest(KEYSPACE, GraknTxType.WRITE))) {
try {
tx.graql().match(var("x")).get().execute();
} catch (GraqlQueryException e) {
// Ignore
}
exception.expect(GraknTxOperationException.class);
exception.expectMessage(GraknTxOperationException.transactionClosed(null, "The gRPC connection closed").getMessage());
tx.admin().getMetaConcept();
}
}
use of ai.grakn.rpc.generated.GrpcGrakn.TxRequest in project grakn by graknlabs.
the class RemoteGraknTxTest method whenOpeningATxFails_Throw.
@Test
public void whenOpeningATxFails_Throw() {
TxRequest openRequest = GrpcUtil.openRequest(KEYSPACE, GraknTxType.WRITE);
throwOn(openRequest, ErrorType.GRAKN_BACKEND_EXCEPTION, "well something went wrong");
exception.expect(GraknBackendException.class);
exception.expectMessage("well something went wrong");
GraknTx tx = RemoteGraknTx.create(session, openRequest);
tx.close();
}
Aggregations