Search in sources :

Example 1 with TxRequest

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());
    }
}
Also used : GraknTx(ai.grakn.GraknTx) TxRequest(ai.grakn.rpc.generated.GrpcGrakn.TxRequest) GraqlQueryException(ai.grakn.exception.GraqlQueryException) Test(org.junit.Test)

Example 2 with TxRequest

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);
}
Also used : DeleteResponse(ai.grakn.rpc.generated.GrpcGrakn.DeleteResponse) TxRequest(ai.grakn.rpc.generated.GrpcGrakn.TxRequest) TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse)

Example 3 with TxRequest

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();
    }
}
Also used : GraknTx(ai.grakn.GraknTx) TxRequest(ai.grakn.rpc.generated.GrpcGrakn.TxRequest) GraqlQueryException(ai.grakn.exception.GraqlQueryException) Test(org.junit.Test)

Example 4 with TxRequest

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();
}
Also used : GraknTx(ai.grakn.GraknTx) TxRequest(ai.grakn.rpc.generated.GrpcGrakn.TxRequest) Test(org.junit.Test)

Aggregations

TxRequest (ai.grakn.rpc.generated.GrpcGrakn.TxRequest)4 GraknTx (ai.grakn.GraknTx)3 Test (org.junit.Test)3 GraqlQueryException (ai.grakn.exception.GraqlQueryException)2 DeleteResponse (ai.grakn.rpc.generated.GrpcGrakn.DeleteResponse)1 TxResponse (ai.grakn.rpc.generated.GrpcGrakn.TxResponse)1