use of ai.grakn.grpc.TxGrpcCommunicator in project grakn by graknlabs.
the class GrpcServerTest method whenSendingStopWithNonExistentIterator_IgnoreRequest.
@Test
public void whenSendingStopWithNonExistentIterator_IgnoreRequest() throws Throwable {
try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
tx.send(openRequest(MYKS, GraknTxType.WRITE));
tx.receive();
tx.send(stopRequest(IteratorId.getDefaultInstance()));
assertEquals(GrpcUtil.doneResponse(), tx.receive().ok());
}
}
use of ai.grakn.grpc.TxGrpcCommunicator in project grakn by graknlabs.
the class GrpcServerTest method whenOpeningTwoTransactions_TransactionsAreOpenedInDifferentThreads.
@Test
public void whenOpeningTwoTransactions_TransactionsAreOpenedInDifferentThreads() {
List<Thread> threads = new ArrayList<>();
when(txFactory.tx(MYKS, GraknTxType.WRITE)).thenAnswer(invocation -> {
threads.add(Thread.currentThread());
return tx;
});
try (TxGrpcCommunicator tx1 = TxGrpcCommunicator.create(stub);
TxGrpcCommunicator tx2 = TxGrpcCommunicator.create(stub)) {
tx1.send(openRequest(MYKS, GraknTxType.WRITE));
tx2.send(openRequest(MYKS, GraknTxType.WRITE));
}
assertNotEquals(threads.get(0), threads.get(1));
}
use of ai.grakn.grpc.TxGrpcCommunicator in project grakn by graknlabs.
the class GrpcServerTest method whenExecutingQueryWithInferenceOff_InferenceIsTurnedOff.
@Test
public void whenExecutingQueryWithInferenceOff_InferenceIsTurnedOff() throws InterruptedException {
try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
tx.send(openRequest(MYKS, GraknTxType.WRITE));
tx.send(execQueryRequest(QUERY, false));
IteratorId iterator = tx.receive().ok().getIteratorId();
tx.send(nextRequest(iterator));
tx.send(stopRequest(iterator));
}
verify(tx.graql()).infer(false);
}
use of ai.grakn.grpc.TxGrpcCommunicator in project grakn by graknlabs.
the class GrpcServerTest method whenExecutingAQueryRemotely_AResultIsReturned.
@Test
public void whenExecutingAQueryRemotely_AResultIsReturned() throws InterruptedException {
Concept conceptX = mock(Concept.class, RETURNS_DEEP_STUBS);
when(conceptX.getId()).thenReturn(ConceptId.of("V123"));
when(conceptX.isRelationship()).thenReturn(true);
when(conceptX.asRelationship().type().getLabel()).thenReturn(Label.of("L123"));
Concept conceptY = mock(Concept.class, RETURNS_DEEP_STUBS);
when(conceptY.getId()).thenReturn(ConceptId.of("V456"));
when(conceptY.isAttribute()).thenReturn(true);
when(conceptY.asAttribute().type().getLabel()).thenReturn(Label.of("L456"));
ImmutableList<Answer> answers = ImmutableList.of(new QueryAnswer(ImmutableMap.of(Graql.var("x"), conceptX)), new QueryAnswer(ImmutableMap.of(Graql.var("y"), conceptY)));
// TODO: reduce wtf
when(query.results(any())).thenAnswer(params -> query.stream().map(params.<GrpcConverter>getArgument(0)::convert));
when(query.stream()).thenAnswer(params -> answers.stream());
try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
tx.send(openRequest(MYKS, GraknTxType.WRITE));
tx.receive();
tx.send(execQueryRequest(QUERY, null));
IteratorId iterator = tx.receive().ok().getIteratorId();
tx.send(nextRequest(iterator));
TxResponse response1 = tx.receive().ok();
GrpcConcept.Concept rpcX = GrpcConcept.Concept.newBuilder().setId(V123).setBaseType(BaseType.Relationship).build();
GrpcGrakn.Answer.Builder answerX = GrpcGrakn.Answer.newBuilder().putAnswer("x", rpcX);
QueryResult.Builder resultX = QueryResult.newBuilder().setAnswer(answerX);
assertEquals(TxResponse.newBuilder().setQueryResult(resultX).build(), response1);
tx.send(nextRequest(iterator));
TxResponse response2 = tx.receive().ok();
GrpcConcept.Concept rpcY = GrpcConcept.Concept.newBuilder().setId(V456).setBaseType(BaseType.Attribute).build();
GrpcGrakn.Answer.Builder answerY = GrpcGrakn.Answer.newBuilder().putAnswer("y", rpcY);
QueryResult.Builder resultY = QueryResult.newBuilder().setAnswer(answerY);
assertEquals(TxResponse.newBuilder().setQueryResult(resultY).build(), response2);
tx.send(nextRequest(iterator));
TxResponse response3 = tx.receive().ok();
TxResponse expected = doneResponse();
assertEquals(expected, response3);
tx.send(stopRequest(iterator));
}
}
use of ai.grakn.grpc.TxGrpcCommunicator in project grakn by graknlabs.
the class GrpcServerTest method whenGettingIsImplicitProperty_IsImplicitIsReturned.
@Test
public void whenGettingIsImplicitProperty_IsImplicitIsReturned() throws InterruptedException {
ConceptId id = ConceptId.of("V123456");
Concept concept = mock(Concept.class, RETURNS_DEEP_STUBS);
when(tx.getConcept(id)).thenReturn(concept);
when(concept.isSchemaConcept()).thenReturn(true);
when(concept.asSchemaConcept().isImplicit()).thenReturn(true);
try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
tx.send(openRequest(MYKS, GraknTxType.READ));
tx.receive().ok();
tx.send(GrpcUtil.runConceptMethodRequest(id, ConceptMethods.IS_IMPLICIT));
assertTrue(ConceptMethods.IS_IMPLICIT.get(conceptConverter, client, tx.receive().ok()));
}
}
Aggregations