Search in sources :

Example 16 with EntityType

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

the class SchemaMutationTest method whenAddingPlaysUsingBatchGraph_Throw.

@Test
public void whenAddingPlaysUsingBatchGraph_Throw() {
    String roleTypeId = "role-thing";
    String entityTypeId = "entityType";
    tx.putRole(roleTypeId);
    tx.putEntityType(entityTypeId);
    EmbeddedGraknTx<?> graknGraphBatch = batchTx();
    Role role = graknGraphBatch.getRole(roleTypeId);
    EntityType entityType = graknGraphBatch.getEntityType(entityTypeId);
    expectedException.expect(GraknTxOperationException.class);
    expectedException.expectMessage(GraknTxOperationException.schemaMutation().getMessage());
    entityType.plays(role);
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) Test(org.junit.Test)

Example 17 with EntityType

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

the class TailRecursionKB method buildExtensionalDB.

private void buildExtensionalDB(GraknTx graph, int n, int m) {
    Role qfrom = graph.getRole("Q-from");
    Role qto = graph.getRole("Q-to");
    EntityType aEntity = graph.getEntityType("a-entity");
    EntityType bEntity = graph.getEntityType("b-entity");
    RelationshipType q = graph.getRelationshipType("Q");
    putEntityWithResource(graph, "a0", aEntity, key);
    for (int i = 1; i <= m + 1; i++) {
        for (int j = 1; j <= n; j++) {
            putEntityWithResource(graph, "b" + i + "," + j, bEntity, key);
        }
    }
    for (int j = 1; j <= n; j++) {
        q.addRelationship().addRolePlayer(qfrom, getInstance(graph, "a0")).addRolePlayer(qto, getInstance(graph, "b1" + "," + j));
        for (int i = 1; i <= m; i++) {
            q.addRelationship().addRolePlayer(qfrom, getInstance(graph, "b" + i + "," + j)).addRolePlayer(qto, getInstance(graph, "b" + (i + 1) + "," + j));
        }
    }
}
Also used : Role(ai.grakn.concept.Role) EntityType(ai.grakn.concept.EntityType) RelationshipType(ai.grakn.concept.RelationshipType)

Example 18 with EntityType

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

the class TxCacheTest method whenMutatingSuperTypeOfConceptCreatedInAnotherTransaction_EnsureTransactionBoundConceptIsMutated.

@Test
public void whenMutatingSuperTypeOfConceptCreatedInAnotherTransaction_EnsureTransactionBoundConceptIsMutated() {
    EntityType e1 = tx.putEntityType("e1");
    EntityType e2 = tx.putEntityType("e2").sup(e1);
    EntityType e3 = tx.putEntityType("e3");
    tx.commit();
    // Check everything is okay
    tx = session.open(GraknTxType.WRITE);
    assertTxBoundConceptMatches(e2, Type::sup, is(e1));
    // Mutate Super Type
    e2.sup(e3);
    assertTxBoundConceptMatches(e2, Type::sup, is(e3));
}
Also used : EntityType(ai.grakn.concept.EntityType) Type(ai.grakn.concept.Type) EntityType(ai.grakn.concept.EntityType) AttributeType(ai.grakn.concept.AttributeType) RelationshipType(ai.grakn.concept.RelationshipType) GraknTxType(ai.grakn.GraknTxType) Test(org.junit.Test)

Example 19 with EntityType

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

the class TxCacheTest method whenClosingTransaction_EnsureTransactionCacheIsEmpty.

@Test
public void whenClosingTransaction_EnsureTransactionCacheIsEmpty() {
    TxCache cache = tx.txCache();
    // Load some sample data
    AttributeType<String> attributeType = tx.putAttributeType("Attribute Type", AttributeType.DataType.STRING);
    Role role1 = tx.putRole("role 1");
    Role role2 = tx.putRole("role 2");
    EntityType entityType = tx.putEntityType("My Type").plays(role1).plays(role2).attribute(attributeType);
    RelationshipType relationshipType = tx.putRelationshipType("My Relationship Type").relates(role1).relates(role2);
    Entity e1 = entityType.addEntity();
    Entity e2 = entityType.addEntity();
    Attribute<String> r1 = attributeType.putAttribute("test");
    e1.attribute(r1);
    relationshipType.addRelationship().addRolePlayer(role1, e1).addRolePlayer(role2, e2);
    // Check the caches are not empty
    assertThat(cache.getConceptCache().keySet(), not(empty()));
    assertThat(cache.getSchemaConceptCache().keySet(), not(empty()));
    assertThat(cache.getLabelCache().keySet(), not(empty()));
    assertThat(cache.getShardingCount().keySet(), not(empty()));
    assertThat(cache.getModifiedCastings(), not(empty()));
    // Close the transaction
    tx.commit();
    // Check the caches are empty
    assertThat(cache.getConceptCache().keySet(), empty());
    assertThat(cache.getSchemaConceptCache().keySet(), empty());
    assertThat(cache.getLabelCache().keySet(), empty());
    assertThat(cache.getShardingCount().keySet(), empty());
    assertThat(cache.getModifiedThings(), empty());
    assertThat(cache.getModifiedRoles(), empty());
    assertThat(cache.getModifiedRelationshipTypes(), empty());
    assertThat(cache.getModifiedRules(), empty());
    assertThat(cache.getModifiedCastings(), empty());
}
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 20 with EntityType

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

the class TxCacheTest method whenDeletingAnInstanceWithNoRelations_EnsureLogIsEmpty.

@Test
public void whenDeletingAnInstanceWithNoRelations_EnsureLogIsEmpty() {
    EntityType t1 = tx.putEntityType("1");
    Entity i1 = t1.addEntity();
    tx.commit();
    tx = EmbeddedGraknSession.create(tx.keyspace(), Grakn.IN_MEMORY).open(GraknTxType.WRITE);
    assertThat(tx.txCache().getModifiedThings(), is(empty()));
    i1.delete();
    assertThat(tx.txCache().getModifiedThings(), is(empty()));
}
Also used : EntityType(ai.grakn.concept.EntityType) Entity(ai.grakn.concept.Entity) Test(org.junit.Test)

Aggregations

EntityType (ai.grakn.concept.EntityType)168 Test (org.junit.Test)141 Role (ai.grakn.concept.Role)83 RelationshipType (ai.grakn.concept.RelationshipType)82 Entity (ai.grakn.concept.Entity)74 GraknTx (ai.grakn.GraknTx)45 Relationship (ai.grakn.concept.Relationship)21 Attribute (ai.grakn.concept.Attribute)19 AttributeType (ai.grakn.concept.AttributeType)17 ConceptId (ai.grakn.concept.ConceptId)17 Label (ai.grakn.concept.Label)17 Set (java.util.Set)16 HashSet (java.util.HashSet)15 Thing (ai.grakn.concept.Thing)14 GraknTxType (ai.grakn.GraknTxType)8 ArrayList (java.util.ArrayList)8 GraknSession (ai.grakn.GraknSession)7 Concept (ai.grakn.concept.Concept)7 HashMap (java.util.HashMap)7 Before (org.junit.Before)7