Search in sources :

Example 1 with GraknException

use of ai.grakn.exception.GraknException in project grakn by graknlabs.

the class GrpcServerTest method whenOpeningTxFails_Throw.

@Test
public void whenOpeningTxFails_Throw() throws Throwable {
    String message = "the backend went wrong";
    GraknException error = GraknBackendException.create(message);
    when(txFactory.tx(MYKS, GraknTxType.WRITE)).thenThrow(error);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.WRITE));
        exception.expect(hasStatus(Status.UNKNOWN.withDescription(message)));
        exception.expect(hasMetadata(ErrorType.KEY, ErrorType.GRAKN_BACKEND_EXCEPTION));
        throw tx.receive().error();
    }
}
Also used : GraknException(ai.grakn.exception.GraknException) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) Test(org.junit.Test)

Example 2 with GraknException

use of ai.grakn.exception.GraknException in project grakn by graknlabs.

the class GrpcServerTest method whenExecutingQueryFails_Throw.

@Test
public void whenExecutingQueryFails_Throw() throws Throwable {
    String message = "your query is dumb";
    GraknException error = GraqlQueryException.create(message);
    when(query.results(any())).thenThrow(error);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.WRITE));
        tx.receive();
        tx.send(execQueryRequest(QUERY, null));
        exception.expect(hasStatus(Status.UNKNOWN.withDescription(message)));
        exception.expect(hasMetadata(ErrorType.KEY, ErrorType.GRAQL_QUERY_EXCEPTION));
        throw tx.receive().error();
    }
}
Also used : GraknException(ai.grakn.exception.GraknException) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) Test(org.junit.Test)

Example 3 with GraknException

use of ai.grakn.exception.GraknException in project grakn by graknlabs.

the class GrpcServerTest method whenParsingQueryFails_Throw.

@Test
public void whenParsingQueryFails_Throw() throws Throwable {
    String message = "you forgot a semicolon";
    GraknException error = GraqlSyntaxException.create(message);
    when(tx.graql().parse(QUERY)).thenThrow(error);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.WRITE));
        tx.receive();
        tx.send(execQueryRequest(QUERY, null));
        exception.expect(hasStatus(Status.UNKNOWN.withDescription(message)));
        exception.expect(hasMetadata(ErrorType.KEY, ErrorType.GRAQL_SYNTAX_EXCEPTION));
        throw tx.receive().error();
    }
}
Also used : GraknException(ai.grakn.exception.GraknException) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) Test(org.junit.Test)

Aggregations

GraknException (ai.grakn.exception.GraknException)3 TxGrpcCommunicator (ai.grakn.grpc.TxGrpcCommunicator)3 Test (org.junit.Test)3