Search in sources :

Example 1 with IteratorId

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

Example 2 with IteratorId

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);
}
Also used : IteratorId(ai.grakn.rpc.generated.GrpcIterator.IteratorId) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) Test(org.junit.Test)

Example 3 with IteratorId

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();
    }
}
Also used : IteratorId(ai.grakn.rpc.generated.GrpcIterator.IteratorId) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) Test(org.junit.Test)

Example 4 with IteratorId

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);
}
Also used : IteratorId(ai.grakn.rpc.generated.GrpcIterator.IteratorId) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) Test(org.junit.Test)

Example 5 with IteratorId

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));
    }
}
Also used : GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) Concept(ai.grakn.concept.Concept) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(ai.grakn.graql.admin.Answer) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) QueryAnswer(ai.grakn.graql.internal.query.QueryAnswer) QueryResult(ai.grakn.rpc.generated.GrpcGrakn.QueryResult) IteratorId(ai.grakn.rpc.generated.GrpcIterator.IteratorId) GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse) Test(org.junit.Test)

Aggregations

IteratorId (ai.grakn.rpc.generated.GrpcIterator.IteratorId)15 TxResponse (ai.grakn.rpc.generated.GrpcGrakn.TxResponse)8 TxGrpcCommunicator (ai.grakn.grpc.TxGrpcCommunicator)7 Test (org.junit.Test)7 Concept (ai.grakn.concept.Concept)3 Answer (ai.grakn.graql.admin.Answer)2 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)2 GrpcConcept (ai.grakn.rpc.generated.GrpcConcept)2 QueryResult (ai.grakn.rpc.generated.GrpcGrakn.QueryResult)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)2 Attribute (ai.grakn.concept.Attribute)1 QueryBuilder (ai.grakn.graql.QueryBuilder)1