Search in sources :

Example 16 with ConceptId

use of ai.grakn.concept.ConceptId in project grakn by graknlabs.

the class RedisCountStorageTest method whenChangingCountsOnRedis_EnsureValueIsChanges.

@Test
public void whenChangingCountsOnRedis_EnsureValueIsChanges() {
    Keyspace keyspace1 = SampleKBLoader.randomKeyspace();
    Keyspace keyspace2 = SampleKBLoader.randomKeyspace();
    ConceptId roach = ConceptId.of("Roach");
    ConceptId ciri = ConceptId.of("Ciri");
    assertEquals(0, redis.getCount(RedisCountStorage.getKeyNumInstances(keyspace1, roach)));
    assertEquals(0, redis.getCount(RedisCountStorage.getKeyNumInstances(keyspace2, roach)));
    redis.incrementCount(RedisCountStorage.getKeyNumInstances(keyspace1, roach), 1);
    assertEquals(1, redis.getCount(RedisCountStorage.getKeyNumInstances(keyspace1, roach)));
    assertEquals(0, redis.getCount(RedisCountStorage.getKeyNumInstances(keyspace2, roach)));
    redis.incrementCount(RedisCountStorage.getKeyNumInstances(keyspace2, ciri), 1);
    assertEquals(0, redis.getCount(RedisCountStorage.getKeyNumInstances(keyspace1, ciri)));
    assertEquals(1, redis.getCount(RedisCountStorage.getKeyNumInstances(keyspace2, ciri)));
}
Also used : Keyspace(ai.grakn.Keyspace) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 17 with ConceptId

use of ai.grakn.concept.ConceptId in project grakn by graknlabs.

the class GrpcServerTest method whenGettingALabel_TheLabelIsReturned.

@Test
public void whenGettingALabel_TheLabelIsReturned() throws InterruptedException {
    ConceptId id = ConceptId.of("V123456");
    Label label = Label.of("Dunstan");
    Concept concept = mock(Concept.class, RETURNS_DEEP_STUBS);
    when(tx.getConcept(id)).thenReturn(concept);
    when(concept.isSchemaConcept()).thenReturn(true);
    when(concept.asSchemaConcept().getLabel()).thenReturn(label);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.READ));
        tx.receive().ok();
        tx.send(GrpcUtil.runConceptMethodRequest(id, ConceptMethods.GET_LABEL));
        assertEquals(label, ConceptMethods.GET_LABEL.get(conceptConverter, client, tx.receive().ok()));
    }
}
Also used : GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) Concept(ai.grakn.concept.Concept) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) Label(ai.grakn.concept.Label) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 18 with ConceptId

use of ai.grakn.concept.ConceptId in project grakn by graknlabs.

the class GrpcServerTest method whenGettingIsImplicitProperty_IsImplicitIsReturned.

@Test
public void whenGettingIsImplicitProperty_IsImplicitIsReturned() throws InterruptedException {
    ConceptId id = ConceptId.of("V123456");
    Concept concept = mock(Concept.class, RETURNS_DEEP_STUBS);
    when(tx.getConcept(id)).thenReturn(concept);
    when(concept.isSchemaConcept()).thenReturn(true);
    when(concept.asSchemaConcept().isImplicit()).thenReturn(true);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.READ));
        tx.receive().ok();
        tx.send(GrpcUtil.runConceptMethodRequest(id, ConceptMethods.IS_IMPLICIT));
        assertTrue(ConceptMethods.IS_IMPLICIT.get(conceptConverter, client, tx.receive().ok()));
    }
}
Also used : GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) Concept(ai.grakn.concept.Concept) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 19 with ConceptId

use of ai.grakn.concept.ConceptId in project grakn by graknlabs.

the class GrpcServerTest method whenRemovingRolePlayer_RolePlayerIsRemoved.

@Test
public void whenRemovingRolePlayer_RolePlayerIsRemoved() throws InterruptedException {
    ConceptId conceptId = ConceptId.of("V123456");
    ConceptId roleId = ConceptId.of("ROLE");
    ConceptId playerId = ConceptId.of("PLAYER");
    Concept concept = mock(Concept.class, RETURNS_DEEP_STUBS);
    when(tx.getConcept(conceptId)).thenReturn(concept);
    when(concept.isRelationship()).thenReturn(true);
    Role role = mock(Role.class, RETURNS_DEEP_STUBS);
    when(tx.getConcept(roleId)).thenReturn(role);
    when(role.isRole()).thenReturn(true);
    when(role.asRole()).thenReturn(role);
    when(role.getId()).thenReturn(roleId);
    Entity player = mock(Entity.class, RETURNS_DEEP_STUBS);
    when(tx.getConcept(playerId)).thenReturn(player);
    when(player.isEntity()).thenReturn(true);
    when(player.asEntity()).thenReturn(player);
    when(player.isThing()).thenReturn(true);
    when(player.asThing()).thenReturn(player);
    when(player.getId()).thenReturn(playerId);
    try (TxGrpcCommunicator tx = TxGrpcCommunicator.create(stub)) {
        tx.send(openRequest(MYKS, GraknTxType.READ));
        tx.receive().ok();
        ConceptMethod<Void> conceptMethod = ConceptMethods.removeRolePlayer(RolePlayer.create(role, player));
        tx.send(GrpcUtil.runConceptMethodRequest(conceptId, conceptMethod));
        tx.receive().ok();
        verify(concept.asRelationship()).removeRolePlayer(role, player);
    }
}
Also used : GrpcConcept(ai.grakn.rpc.generated.GrpcConcept) Concept(ai.grakn.concept.Concept) Role(ai.grakn.concept.Role) Entity(ai.grakn.concept.Entity) TxGrpcCommunicator(ai.grakn.grpc.TxGrpcCommunicator) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 20 with ConceptId

use of ai.grakn.concept.ConceptId 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)

Aggregations

ConceptId (ai.grakn.concept.ConceptId)80 Test (org.junit.Test)55 Concept (ai.grakn.concept.Concept)23 Role (ai.grakn.concept.Role)22 RelationshipType (ai.grakn.concept.RelationshipType)19 GraknTx (ai.grakn.GraknTx)18 EntityType (ai.grakn.concept.EntityType)18 Label (ai.grakn.concept.Label)16 GrpcConcept (ai.grakn.rpc.generated.GrpcConcept)14 Var (ai.grakn.graql.Var)12 List (java.util.List)12 Entity (ai.grakn.concept.Entity)10 AttributeType (ai.grakn.concept.AttributeType)9 HashSet (java.util.HashSet)9 Set (java.util.Set)9 Assert.assertEquals (org.junit.Assert.assertEquals)9 ClassRule (org.junit.ClassRule)9 GraknTxType (ai.grakn.GraknTxType)8 Keyspace (ai.grakn.Keyspace)8 IdPredicate (ai.grakn.graql.internal.reasoner.atom.predicate.IdPredicate)8