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