use of ai.grakn.rpc.generated.GrpcIterator.IteratorId in project grakn by graknlabs.
the class TxObserver method next.
private void next(Next next) {
IteratorId iteratorId = next.getIteratorId();
TxResponse response = grpcIterators.next(iteratorId).orElseThrow(() -> GrpcGraknService.error(Status.FAILED_PRECONDITION));
responseObserver.onNext(response);
}
use of ai.grakn.rpc.generated.GrpcIterator.IteratorId in project grakn by graknlabs.
the class GrpcServerTest method whenExecutingQueryWithInferenceOn_InferenceIsTurnedOn.
@Test
public void whenExecutingQueryWithInferenceOn_InferenceIsTurnedOn() throws InterruptedException {
try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
tx.send(openRequest(MYKS, GraknTxType.WRITE));
tx.send(execQueryRequest(QUERY, true));
IteratorId iterator = tx.receive().ok().getIteratorId();
tx.send(nextRequest(iterator));
tx.send(stopRequest(iterator));
}
verify(tx.graql()).infer(true);
}
use of ai.grakn.rpc.generated.GrpcIterator.IteratorId in project grakn by graknlabs.
the class GrpcServerTest method whenSendingAnotherQueryDuringQueryExecution_ReturnResultsForBothQueries.
@Test
public void whenSendingAnotherQueryDuringQueryExecution_ReturnResultsForBothQueries() throws Throwable {
try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
tx.send(openRequest(MYKS, GraknTxType.WRITE));
tx.receive();
tx.send(execQueryRequest(QUERY, null));
IteratorId iterator1 = tx.receive().ok().getIteratorId();
tx.send(execQueryRequest(QUERY, null));
IteratorId iterator2 = tx.receive().ok().getIteratorId();
tx.send(nextRequest(iterator1));
tx.receive().ok();
tx.send(nextRequest(iterator2));
tx.receive().ok();
tx.send(stopRequest(iterator1));
tx.receive().ok();
tx.send(stopRequest(iterator2));
tx.receive().ok();
}
}
use of ai.grakn.rpc.generated.GrpcIterator.IteratorId 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.rpc.generated.GrpcIterator.IteratorId 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));
}
}
Aggregations