use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class GrpcServerIT method whenGettingAConcept_TheInformationOnTheConceptIsCorrect.
@Test
public void whenGettingAConcept_TheInformationOnTheConceptIsCorrect() {
try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
GraknTx localTx = localSession.open(GraknTxType.READ)) {
GetQuery query = remoteTx.graql().match(var("x")).get();
for (Answer answer : query) {
Concept remoteConcept = answer.get("x");
Concept localConcept = localTx.getConcept(remoteConcept.getId());
assertEquals(localConcept.isAttribute(), remoteConcept.isAttribute());
assertEquals(localConcept.isAttributeType(), remoteConcept.isAttributeType());
assertEquals(localConcept.isEntity(), remoteConcept.isEntity());
assertEquals(localConcept.isEntityType(), remoteConcept.isEntityType());
assertEquals(localConcept.isRelationship(), remoteConcept.isRelationship());
assertEquals(localConcept.isRelationshipType(), remoteConcept.isRelationshipType());
assertEquals(localConcept.isRole(), remoteConcept.isRole());
assertEquals(localConcept.isRule(), remoteConcept.isRule());
assertEquals(localConcept.isSchemaConcept(), remoteConcept.isSchemaConcept());
assertEquals(localConcept.isThing(), remoteConcept.isThing());
assertEquals(localConcept.isType(), remoteConcept.isType());
assertEquals(localConcept.getId(), remoteConcept.getId());
assertEquals(localConcept.isDeleted(), remoteConcept.isDeleted());
assertEquals(localConcept.keyspace(), remoteConcept.keyspace());
}
}
}
use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class GrpcServerIT method whenGettingARelationship_TheInformationOnTheRelationshipIsCorrect.
@Test
public void whenGettingARelationship_TheInformationOnTheRelationshipIsCorrect() {
try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
GraknTx localTx = localSession.open(GraknTxType.READ)) {
GetQuery query = remoteTx.graql().match(var("x").isa("has-cast")).get();
Relationship remoteConcept = query.stream().findAny().get().get("x").asRelationship();
Relationship localConcept = localTx.getConcept(remoteConcept.getId()).asRelationship();
assertEqualConcepts(localConcept, remoteConcept, Relationship::rolePlayers);
ImmutableMultimap.Builder<ConceptId, ConceptId> localRolePlayers = ImmutableMultimap.builder();
localConcept.allRolePlayers().forEach((role, players) -> {
for (Thing player : players) {
localRolePlayers.put(role.getId(), player.getId());
}
});
ImmutableMultimap.Builder<ConceptId, ConceptId> remoteRolePlayers = ImmutableMultimap.builder();
remoteConcept.allRolePlayers().forEach((role, players) -> {
for (Thing player : players) {
remoteRolePlayers.put(role.getId(), player.getId());
}
});
assertEquals(localRolePlayers.build(), remoteRolePlayers.build());
}
}
use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class GrpcServerIT method whenGettingAnAttribute_TheInformationOnTheAttributeIsCorrect.
@Test
public void whenGettingAnAttribute_TheInformationOnTheAttributeIsCorrect() {
try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
GraknTx localTx = localSession.open(GraknTxType.READ)) {
GetQuery query = remoteTx.graql().match(var("x").isa("title")).get();
Attribute<?> remoteConcept = query.stream().findAny().get().get("x").asAttribute();
Attribute<?> localConcept = localTx.getConcept(remoteConcept.getId()).asAttribute();
assertEquals(localConcept.dataType(), remoteConcept.dataType());
assertEquals(localConcept.getValue(), remoteConcept.getValue());
assertEquals(localConcept.owner().getId(), remoteConcept.owner().getId());
assertEqualConcepts(localConcept, remoteConcept, Attribute::ownerInstances);
}
}
use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class GrpcServerIT method whenGettingAnEntity_TheInformationOnTheEntityIsCorrect.
@Test
public void whenGettingAnEntity_TheInformationOnTheEntityIsCorrect() {
try (GraknTx remoteTx = remoteSession.open(GraknTxType.READ);
GraknTx localTx = localSession.open(GraknTxType.READ)) {
GetQuery query = remoteTx.graql().match(var("x").isa("movie")).get();
Entity remoteConcept = query.stream().findAny().get().get("x").asEntity();
Entity localConcept = localTx.getConcept(remoteConcept.getId()).asEntity();
// There actually aren't any new methods on Entity, but we should still check we can get them
assertEquals(localConcept.getId(), remoteConcept.getId());
}
}
use of ai.grakn.graql.GetQuery in project grakn by graknlabs.
the class GrpcServerIT method whenExecutingTwoParallelQueries_GetBothResults.
@Test
public void whenExecutingTwoParallelQueries_GetBothResults() throws Throwable {
try (GraknTx tx = remoteSession.open(GraknTxType.READ)) {
GetQuery query = tx.graql().match(var("x").sub("thing")).get();
Iterator<Answer> iterator1 = query.iterator();
Iterator<Answer> iterator2 = query.iterator();
while (iterator1.hasNext() || iterator2.hasNext()) {
assertEquals(iterator1.next(), iterator2.next());
assertEquals(iterator1.hasNext(), iterator2.hasNext());
}
}
}
Aggregations