Search in sources :

Example 36 with GetQuery

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());
        }
    }
}
Also used : Concept(ai.grakn.concept.Concept) SchemaConcept(ai.grakn.concept.SchemaConcept) GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 37 with GetQuery

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());
    }
}
Also used : GraknTx(ai.grakn.GraknTx) GetQuery(ai.grakn.graql.GetQuery) Relationship(ai.grakn.concept.Relationship) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Thing(ai.grakn.concept.Thing) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 38 with GetQuery

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);
    }
}
Also used : GraknTx(ai.grakn.GraknTx) GetQuery(ai.grakn.graql.GetQuery) Attribute(ai.grakn.concept.Attribute) Test(org.junit.Test)

Example 39 with GetQuery

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());
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Entity(ai.grakn.concept.Entity) GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Example 40 with GetQuery

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());
        }
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Answer(ai.grakn.graql.admin.Answer) GetQuery(ai.grakn.graql.GetQuery) Test(org.junit.Test)

Aggregations

GetQuery (ai.grakn.graql.GetQuery)163 Test (org.junit.Test)161 Answer (ai.grakn.graql.admin.Answer)65 QueryBuilder (ai.grakn.graql.QueryBuilder)61 GraknTx (ai.grakn.GraknTx)51 EmbeddedGraknTx (ai.grakn.kb.internal.EmbeddedGraknTx)23 QueryAnswer (ai.grakn.graql.internal.query.QueryAnswer)14 SampleKBContext (ai.grakn.test.rule.SampleKBContext)12 Concept (ai.grakn.concept.Concept)9 List (java.util.List)8 Assert.assertEquals (org.junit.Assert.assertEquals)7 Assert.assertTrue (org.junit.Assert.assertTrue)7 Set (java.util.Set)6 Label (ai.grakn.concept.Label)5 RelationshipType (ai.grakn.concept.RelationshipType)5 VarPatternAdmin (ai.grakn.graql.admin.VarPatternAdmin)5 ReasonerAtomicQuery (ai.grakn.graql.internal.reasoner.query.ReasonerAtomicQuery)5 Sets (com.google.common.collect.Sets)5 Collectors (java.util.stream.Collectors)5 Collectors.toSet (java.util.stream.Collectors.toSet)5