Search in sources :

Example 86 with Entity

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();
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 87 with Entity

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));
}
Also used : Entity(ai.grakn.concept.Entity) EntityTypeImpl(ai.grakn.kb.internal.concept.EntityTypeImpl) Shard(ai.grakn.kb.internal.structure.Shard) Test(org.junit.Test)

Example 88 with Entity

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));
}
Also used : InsertQuery(ai.grakn.graql.InsertQuery) Answer(ai.grakn.graql.admin.Answer) Entity(ai.grakn.concept.Entity) Relationship(ai.grakn.concept.Relationship) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 89 with Entity

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

Example 90 with Entity

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

Aggregations

Entity (ai.grakn.concept.Entity)99 Test (org.junit.Test)81 EntityType (ai.grakn.concept.EntityType)74 Role (ai.grakn.concept.Role)53 RelationshipType (ai.grakn.concept.RelationshipType)50 GraknTx (ai.grakn.GraknTx)44 Attribute (ai.grakn.concept.Attribute)18 Set (java.util.Set)16 Relationship (ai.grakn.concept.Relationship)14 Label (ai.grakn.concept.Label)11 ConceptId (ai.grakn.concept.ConceptId)10 HashSet (java.util.HashSet)10 ArrayList (java.util.ArrayList)8 AttributeType (ai.grakn.concept.AttributeType)7 List (java.util.List)7 GraknSession (ai.grakn.GraknSession)6 Before (org.junit.Before)6 GraknTxType (ai.grakn.GraknTxType)5 Concept (ai.grakn.concept.Concept)5 GraqlQueryException (ai.grakn.exception.GraqlQueryException)5