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);
}
}
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);
}
}
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;
});
}
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());
}
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());
}
Aggregations