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