use of ai.grakn.rpc.generated.GrpcGrakn.TxResponse in project grakn by graknlabs.
the class RemoteConceptsTest method whenCallingAllRolePlayers_GetTheExpectedResult.
@Test
public void whenCallingAllRolePlayers_GetTheExpectedResult() {
Role foo = RemoteConcepts.createRole(tx, ConceptId.of("foo"));
Role bar = RemoteConcepts.createRole(tx, ConceptId.of("bar"));
Thing a = RemoteConcepts.createEntity(tx, A);
Thing b = RemoteConcepts.createRelationship(tx, B);
Thing c = RemoteConcepts.createAttribute(tx, C);
Stream<RolePlayer> mockedResponse = Stream.of(RolePlayer.create(foo, a), RolePlayer.create(bar, b), RolePlayer.create(bar, c));
TxResponse response = GET_ROLE_PLAYERS.createTxResponse(server.grpcIterators(), mockedResponse);
server.setResponse(GrpcUtil.runConceptMethodRequest(ID, GET_ROLE_PLAYERS), response);
Map<Role, Set<Thing>> allRolePlayers = relationship.allRolePlayers();
Map<Role, Set<Thing>> expected = ImmutableMap.of(foo, ImmutableSet.of(a), bar, ImmutableSet.of(b, c));
assertEquals(expected, allRolePlayers);
}
use of ai.grakn.rpc.generated.GrpcGrakn.TxResponse in project grakn by graknlabs.
the class RemoteConceptsTest method whenCallingIsDeleted_GetTheExpectedResult.
@Test
public void whenCallingIsDeleted_GetTheExpectedResult() {
TxResponse response = TxResponse.newBuilder().setOptionalConcept(convertOptionalConcept(Optional.of(concept))).build();
server.setResponse(GrpcUtil.getConceptRequest(ID), response);
assertFalse(entity.isDeleted());
TxResponse nullResponse = TxResponse.newBuilder().setOptionalConcept(convertOptionalConcept(Optional.empty())).build();
server.setResponse(GrpcUtil.getConceptRequest(ID), nullResponse);
assertTrue(entity.isDeleted());
}
use of ai.grakn.rpc.generated.GrpcGrakn.TxResponse in project grakn by graknlabs.
the class GrpcServerMock method before.
@Override
protected void before() throws Throwable {
when(service.tx(any())).thenAnswer(args -> {
serverResponses = args.getArgument(0);
return serverRequests;
});
doAnswer(args -> {
StreamObserver<DeleteResponse> deleteResponses = args.getArgument(1);
deleteResponses.onNext(GrpcUtil.deleteResponse());
deleteResponses.onCompleted();
return null;
}).when(service).delete(any(), any());
// Return a default "done" response to every message from the client
doAnswer(args -> {
if (serverResponses == null) {
throw new IllegalArgumentException("Set-up of rule not called");
}
TxRequest request = args.getArgument(0);
Optional<TxResponse> next = grpcIterators.next(request.getNext().getIteratorId());
serverResponses.onNext(next.orElse(GrpcUtil.doneResponse()));
return null;
}).when(serverRequests).onNext(any());
// Return a default "complete" response to every "complete" message from the client
doAnswer(args -> {
if (serverResponses == null) {
throw new IllegalArgumentException("Set-up of rule not called");
}
serverResponses.onCompleted();
return null;
}).when(serverRequests).onCompleted();
serverRule.getServiceRegistry().addService(service);
}
use of ai.grakn.rpc.generated.GrpcGrakn.TxResponse in project grakn by graknlabs.
the class RemoteGraknTxTest method whenExecutingAQueryWithABooleanResult_GetABoolBack.
@Test
public void whenExecutingAQueryWithABooleanResult_GetABoolBack() {
Query<?> query = match(var("x").isa("person")).aggregate(ask());
String queryString = query.toString();
TxResponse response = TxResponse.newBuilder().setQueryResult(QueryResult.newBuilder().setOtherResult("true")).build();
server.setResponseSequence(GrpcUtil.execQueryRequest(query), response);
try (GraknTx tx = RemoteGraknTx.create(session, GrpcUtil.openRequest(KEYSPACE, GraknTxType.WRITE))) {
// The open request
verify(server.requests()).onNext(any());
assertTrue(tx.graql().<Query<Boolean>>parse(queryString).execute());
}
}
use of ai.grakn.rpc.generated.GrpcGrakn.TxResponse in project grakn by graknlabs.
the class RemoteGraknTxTest method whenExecutingAQuery_GetAResultBack.
@Test
public void whenExecutingAQuery_GetAResultBack() {
Query<?> query = match(var("x").isa("person")).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.setResponseSequence(GrpcUtil.execQueryRequest(query), response);
List<Answer> results;
try (GraknTx tx = RemoteGraknTx.create(session, GrpcUtil.openRequest(KEYSPACE, GraknTxType.WRITE))) {
// The open request
verify(server.requests()).onNext(any());
results = tx.graql().<GetQuery>parse(queryString).execute();
}
Answer answer = Iterables.getOnlyElement(results);
assertEquals(answer.vars(), ImmutableSet.of(var("x")));
assertEquals(ConceptId.of("V123"), answer.get(var("x")).getId());
}
Aggregations