Search in sources :

Example 1 with TxResponse

use of ai.grakn.rpc.generated.GrpcGrakn.TxResponse in project grakn by graknlabs.

the class TxObserver method getConcept.

private void getConcept(GrpcConcept.ConceptId conceptId) {
    Optional<Concept> concept = Optional.ofNullable(tx().getConcept(GrpcUtil.convert(conceptId)));
    TxResponse response = TxResponse.newBuilder().setOptionalConcept(GrpcUtil.convertOptionalConcept(concept)).build();
    responseObserver.onNext(response);
}
Also used : Concept(ai.grakn.concept.Concept) GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse)

Example 2 with TxResponse

use of ai.grakn.rpc.generated.GrpcGrakn.TxResponse in project grakn by graknlabs.

the class TxObserver method getSchemaConcept.

private void getSchemaConcept(GrpcConcept.Label label) {
    Optional<Concept> concept = Optional.ofNullable(tx().getSchemaConcept(GrpcUtil.convert(label)));
    TxResponse response = TxResponse.newBuilder().setOptionalConcept(GrpcUtil.convertOptionalConcept(concept)).build();
    responseObserver.onNext(response);
}
Also used : Concept(ai.grakn.concept.Concept) GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse)

Example 3 with TxResponse

use of ai.grakn.rpc.generated.GrpcGrakn.TxResponse 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 4 with TxResponse

use of ai.grakn.rpc.generated.GrpcGrakn.TxResponse in project grakn by graknlabs.

the class RemoteGraknTxTest method whenExecutingAQueryWithASingleAnswer_GetAnAnswerBack.

@Test
public void whenExecutingAQueryWithASingleAnswer_GetAnAnswerBack() {
    Query<?> query = define(label("person").sub("entity"));
    String queryString = query.toString();
    GrpcConcept.Concept v123 = GrpcConcept.Concept.newBuilder().setId(V123).build();
    GrpcGrakn.Answer grpcAnswer = GrpcGrakn.Answer.newBuilder().putAnswer("x", v123).build();
    QueryResult queryResult = QueryResult.newBuilder().setAnswer(grpcAnswer).build();
    TxResponse response = TxResponse.newBuilder().setQueryResult(queryResult).build();
    server.setResponseSequence(GrpcUtil.execQueryRequest(query), response);
    Answer answer;
    try (GraknTx tx = RemoteGraknTx.create(session, GrpcUtil.openRequest(KEYSPACE, GraknTxType.WRITE))) {
        // The open request
        verify(server.requests()).onNext(any());
        answer = tx.graql().<DefineQuery>parse(queryString).execute();
    }
    assertEquals(answer.vars(), ImmutableSet.of(var("x")));
    assertEquals(ConceptId.of("V123"), answer.get(var("x")).getId());
}
Also used : Answer(ai.grakn.graql.admin.Answer) GraknTx(ai.grakn.GraknTx) QueryResult(ai.grakn.rpc.generated.GrpcGrakn.QueryResult) GrpcGrakn(ai.grakn.rpc.generated.GrpcGrakn) GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) DefineQuery(ai.grakn.graql.DefineQuery) TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse) Test(org.junit.Test)

Example 5 with TxResponse

use of ai.grakn.rpc.generated.GrpcGrakn.TxResponse in project grakn by graknlabs.

the class RemoteGraknTxTest method whenStreamingAQueryWithInfiniteAnswers_Terminate.

@Test(timeout = 5_000)
public void whenStreamingAQueryWithInfiniteAnswers_Terminate() {
    Query<?> query = match(var("x").sub("thing")).get();
    String queryString = query.toString();
    GrpcConcept.Concept v123 = GrpcConcept.Concept.newBuilder().setId(V123).build();
    GrpcGrakn.Answer grpcAnswer = GrpcGrakn.Answer.newBuilder().putAnswer("x", v123).build();
    QueryResult queryResult = QueryResult.newBuilder().setAnswer(grpcAnswer).build();
    TxResponse response = TxResponse.newBuilder().setQueryResult(queryResult).build();
    server.setResponse(GrpcUtil.execQueryRequest(query), GrpcUtil.iteratorResponse(ITERATOR));
    server.setResponse(GrpcUtil.nextRequest(ITERATOR), response);
    List<Answer> answers;
    int numAnswers = 10;
    try (GraknTx tx = RemoteGraknTx.create(session, GrpcUtil.openRequest(KEYSPACE, GraknTxType.WRITE))) {
        // The open request
        verify(server.requests()).onNext(any());
        answers = tx.graql().<GetQuery>parse(queryString).stream().limit(numAnswers).collect(toList());
    }
    assertEquals(10, answers.size());
    for (Answer answer : answers) {
        assertEquals(answer.vars(), ImmutableSet.of(var("x")));
        assertEquals(ConceptId.of("V123"), answer.get(var("x")).getId());
    }
}
Also used : GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) Answer(ai.grakn.graql.admin.Answer) GraknTx(ai.grakn.GraknTx) QueryResult(ai.grakn.rpc.generated.GrpcGrakn.QueryResult) GrpcGrakn(ai.grakn.rpc.generated.GrpcGrakn) GetQuery(ai.grakn.graql.GetQuery) TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse) Test(org.junit.Test)

Aggregations

TxResponse (ai.grakn.rpc.generated.GrpcGrakn.TxResponse)21 Test (org.junit.Test)10 IteratorId (ai.grakn.rpc.generated.GrpcIterator.IteratorId)9 GrpcConcept (ai.grakn.rpc.generated.GrpcConcept)8 Concept (ai.grakn.concept.Concept)6 QueryResult (ai.grakn.rpc.generated.GrpcGrakn.QueryResult)6 Answer (ai.grakn.graql.admin.Answer)5 GraknTx (ai.grakn.GraknTx)4 TxGrpcCommunicator (ai.grakn.grpc.TxGrpcCommunicator)4 GetQuery (ai.grakn.graql.GetQuery)3 GrpcGrakn (ai.grakn.rpc.generated.GrpcGrakn)3 Attribute (ai.grakn.concept.Attribute)2 Role (ai.grakn.concept.Role)2 DefineQuery (ai.grakn.graql.DefineQuery)2 QueryBuilder (ai.grakn.graql.QueryBuilder)2 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)2 TxRequest (ai.grakn.rpc.generated.GrpcGrakn.TxRequest)2 AttributeType (ai.grakn.concept.AttributeType)1 EntityType (ai.grakn.concept.EntityType)1 Label (ai.grakn.concept.Label)1