use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class ValidatorTest method whenCommittingWithRoleTypeHierarchyAndInstancesCannotPlayRolesExplicitly_Throw3.
@Test
public void whenCommittingWithRoleTypeHierarchyAndInstancesCannotPlayRolesExplicitly_Throw3() throws InvalidKBException {
Role parent = tx.putRole("parent");
Role child = tx.putRole("child");
EntityType person = tx.putEntityType("person").plays(child);
tx.putEntityType("man").plays(child);
RelationshipType parenthood = tx.putRelationshipType("parenthood").relates(parent).relates(child);
Entity x = person.addEntity();
Entity y = person.addEntity();
parenthood.addRelationship().addRolePlayer(parent, x).addRolePlayer(child, y);
expectedException.expect(InvalidKBException.class);
expectedException.expectMessage(ErrorMessage.VALIDATION_CASTING.getMessage(person.getLabel(), x.getId(), parent.getLabel()));
tx.commit();
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class GraknTxTest method whenShardingSuperNode_EnsureNewInstancesGoToNewShard.
@Test
public void whenShardingSuperNode_EnsureNewInstancesGoToNewShard() {
EntityTypeImpl entityType = (EntityTypeImpl) tx.putEntityType("The Special Type");
Shard s1 = entityType.currentShard();
// Add 3 instances to first shard
Entity s1_e1 = entityType.addEntity();
Entity s1_e2 = entityType.addEntity();
Entity s1_e3 = entityType.addEntity();
tx.shard(entityType.getId());
Shard s2 = entityType.currentShard();
// Add 5 instances to second shard
Entity s2_e1 = entityType.addEntity();
Entity s2_e2 = entityType.addEntity();
Entity s2_e3 = entityType.addEntity();
Entity s2_e4 = entityType.addEntity();
Entity s2_e5 = entityType.addEntity();
tx.shard(entityType.getId());
Shard s3 = entityType.currentShard();
// Add 2 instances to 3rd shard
Entity s3_e1 = entityType.addEntity();
Entity s3_e2 = entityType.addEntity();
// Check Type was sharded correctly
assertThat(entityType.shards().collect(toSet()), containsInAnyOrder(s1, s2, s3));
// Check shards have correct instances
assertThat(s1.links().collect(toSet()), containsInAnyOrder(s1_e1, s1_e2, s1_e3));
assertThat(s2.links().collect(toSet()), containsInAnyOrder(s2_e1, s2_e2, s2_e3, s2_e4, s2_e5));
assertThat(s3.links().collect(toSet()), containsInAnyOrder(s3_e1, s3_e2));
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class InsertQueryTest method whenAddingProvenanceToAnExistingRelationship_TheProvenanceIsAdded.
@Test
public void whenAddingProvenanceToAnExistingRelationship_TheProvenanceIsAdded() {
InsertQuery query = qb.match(w.isa("movie").has(title, x.val("The Muppets"), y)).insert(x, w, y.has("provenance", z.val("Someone told me")));
Answer answer = Iterables.getOnlyElement(query.execute());
Entity movie = answer.get(w).asEntity();
Attribute<String> theTitle = answer.get(x).asAttribute();
Relationship hasTitle = answer.get(y).asRelationship();
Attribute<String> provenance = answer.get(z).asAttribute();
assertThat(hasTitle.rolePlayers().toArray(), arrayContainingInAnyOrder(movie, theTitle));
assertThat(hasTitle.attributes().toArray(), arrayContaining(provenance));
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class TxCacheTest method whenCreatingInstances_EnsureLogContainsInstance.
@Test
public void whenCreatingInstances_EnsureLogContainsInstance() {
EntityType t1 = tx.putEntityType("1");
tx.commit();
tx = EmbeddedGraknSession.create(tx.keyspace(), Grakn.IN_MEMORY).open(GraknTxType.WRITE);
Entity i1 = t1.addEntity();
assertThat(tx.txCache().getConceptCache().values(), hasItem(i1));
}
use of ai.grakn.concept.Entity in project grakn by graknlabs.
the class TxCacheTest method whenAddingAndRemovingInstancesFromTypes_EnsureLogTracksNumberOfChanges.
@Test
public void whenAddingAndRemovingInstancesFromTypes_EnsureLogTracksNumberOfChanges() {
EntityType entityType = tx.putEntityType("My Type");
RelationshipType relationshipType = tx.putRelationshipType("My Relationship Type");
TxCache txCache = tx.txCache();
assertThat(txCache.getShardingCount().keySet(), empty());
// Add some instances
Entity e1 = entityType.addEntity();
Entity e2 = entityType.addEntity();
relationshipType.addRelationship();
assertEquals(2, (long) txCache.getShardingCount().get(entityType.getId()));
assertEquals(1, (long) txCache.getShardingCount().get(relationshipType.getId()));
// Remove an entity
e1.delete();
assertEquals(1, (long) txCache.getShardingCount().get(entityType.getId()));
assertEquals(1, (long) txCache.getShardingCount().get(relationshipType.getId()));
// Remove another entity
e2.delete();
assertFalse(txCache.getShardingCount().containsKey(entityType.getId()));
assertEquals(1, (long) txCache.getShardingCount().get(relationshipType.getId()));
}
Aggregations