use of ai.grakn.grpc.TxGrpcCommunicator 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();
}
}
use of ai.grakn.grpc.TxGrpcCommunicator in project grakn by graknlabs.
the class GrpcServerTest method whenGettingALabelForANonExistentConcept_Throw.
@Test
public void whenGettingALabelForANonExistentConcept_Throw() throws InterruptedException {
ConceptId id = ConceptId.of("V123456");
when(tx.getConcept(id)).thenReturn(null);
try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
tx.send(openRequest(MYKS, GraknTxType.READ));
tx.receive().ok();
tx.send(GrpcUtil.runConceptMethodRequest(id, ConceptMethods.GET_LABEL));
exception.expect(hasStatus(Status.FAILED_PRECONDITION));
throw tx.receive().error();
}
}
use of ai.grakn.grpc.TxGrpcCommunicator in project grakn by graknlabs.
the class GrpcServerTest method whenCommittingBeforeOpeningTx_Throw.
@Test
public void whenCommittingBeforeOpeningTx_Throw() throws Throwable {
try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
tx.send(commitRequest());
exception.expect(hasStatus(Status.FAILED_PRECONDITION));
throw tx.receive().error();
}
}
use of ai.grakn.grpc.TxGrpcCommunicator 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();
}
}
use of ai.grakn.grpc.TxGrpcCommunicator in project grakn by graknlabs.
the class GrpcServerTest method whenGettingALabelForANonSchemaConcept_Throw.
@Test
public void whenGettingALabelForANonSchemaConcept_Throw() throws InterruptedException {
ConceptId id = ConceptId.of("V123456");
Concept concept = mock(Concept.class);
when(tx.getConcept(id)).thenReturn(concept);
when(concept.isSchemaConcept()).thenReturn(false);
when(concept.asSchemaConcept()).thenThrow(EXCEPTION);
try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
tx.send(openRequest(MYKS, GraknTxType.READ));
tx.receive().ok();
tx.send(GrpcUtil.runConceptMethodRequest(id, ConceptMethods.GET_LABEL));
exception.expect(hasStatus(Status.UNKNOWN.withDescription(EXCEPTION_MESSAGE)));
throw tx.receive().error();
}
}
Aggregations