Search in sources :

Example 16 with TxResponse

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

the class GrpcServerTest method whenOpeningATransactionRemotely_ReceiveADoneMessage.

@Test
public void whenOpeningATransactionRemotely_ReceiveADoneMessage() throws InterruptedException {
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.READ));
        TxResponse response = tx.receive().ok();
        assertEquals(doneResponse(), response);
    }
}
Also used : TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse) Test(org.junit.Test)

Example 17 with TxResponse

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

the class GrpcServerTest method whenCommittingATransactionRemotely_ReceiveADoneMessage.

@Test
public void whenCommittingATransactionRemotely_ReceiveADoneMessage() throws InterruptedException {
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.WRITE));
        tx.receive();
        tx.send(commitRequest());
        TxResponse response = tx.receive().ok();
        assertEquals(doneResponse(), response);
    }
}
Also used : TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse) Test(org.junit.Test)

Example 18 with TxResponse

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

the class GrpcIterators method next.

/**
 * Return the next response from an iterator. Will return a {@link Done} response if the iterator is exhausted.
 */
public Optional<TxResponse> next(IteratorId iteratorId) {
    return Optional.ofNullable(iterators.get(iteratorId)).map(iterator -> {
        TxResponse response;
        if (iterator.hasNext()) {
            response = iterator.next();
        } else {
            response = GrpcUtil.doneResponse();
            stop(iteratorId);
        }
        return response;
    });
}
Also used : TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse)

Example 19 with TxResponse

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

the class TxObserver method getAttributesByValue.

private void getAttributesByValue(AttributeValue attributeValue) {
    Collection<Attribute<Object>> attributes = tx().getAttributesByValue(GrpcUtil.convert(attributeValue));
    Iterator<TxResponse> iterator = attributes.stream().map(GrpcUtil::conceptResponse).iterator();
    IteratorId iteratorId = grpcIterators.add(iterator);
    responseObserver.onNext(TxResponse.newBuilder().setIteratorId(iteratorId).build());
}
Also used : IteratorId(ai.grakn.rpc.generated.GrpcIterator.IteratorId) Attribute(ai.grakn.concept.Attribute) TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse)

Example 20 with TxResponse

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

the class TxObserver method execQuery.

private void execQuery(ExecQuery request) {
    String queryString = request.getQuery().getValue();
    QueryBuilder graql = tx().graql();
    if (request.hasInfer()) {
        graql = graql.infer(request.getInfer().getValue());
    }
    Stream<QueryResult> queryResultStream = graql.parse(queryString).results(GrpcConverter.get());
    Stream<TxResponse> txResponseStream = queryResultStream.map(queryResult -> TxResponse.newBuilder().setQueryResult(queryResult).build());
    Iterator<TxResponse> iterator = txResponseStream.iterator();
    IteratorId iteratorId = grpcIterators.add(iterator);
    responseObserver.onNext(TxResponse.newBuilder().setIteratorId(iteratorId).build());
}
Also used : QueryResult(ai.grakn.rpc.generated.GrpcGrakn.QueryResult) IteratorId(ai.grakn.rpc.generated.GrpcIterator.IteratorId) QueryBuilder(ai.grakn.graql.QueryBuilder) TxResponse(ai.grakn.rpc.generated.GrpcGrakn.TxResponse)

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