use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class EntityTypeTest method whenAddingResourceTypeAsResourceAfterResource_Throw.
@Test
public void whenAddingResourceTypeAsResourceAfterResource_Throw() {
AttributeType<String> attributeType = tx.putAttributeType("Shared Attribute", AttributeType.DataType.STRING);
EntityType entityType = tx.putEntityType("EntityType");
entityType.key(attributeType);
expectedException.expect(GraknTxOperationException.class);
expectedException.expectMessage(CANNOT_BE_KEY_AND_RESOURCE.getMessage(entityType.getLabel(), attributeType.getLabel()));
entityType.attribute(attributeType);
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class EntityTypeTest method whenRemovingRoleFromEntityType_TheRoleCanNoLongerBePlayed.
@Test
public void whenRemovingRoleFromEntityType_TheRoleCanNoLongerBePlayed() {
Role role1 = tx.putRole("A Role 1");
Role role2 = tx.putRole("A Role 2");
EntityType type = tx.putEntityType("A Concept Type").plays(role1).plays(role2);
assertThat(type.plays().collect(toSet()), containsInAnyOrder(role1, role2));
type.deletePlays(role1);
assertThat(type.plays().collect(toSet()), containsInAnyOrder(role2));
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class EntityTypeTest method whenGettingTheInstancesOfType_ReturnAllInstances.
@Test
public void whenGettingTheInstancesOfType_ReturnAllInstances() {
EntityType e1 = tx.putEntityType("e1");
EntityType e2 = tx.putEntityType("e2").sup(e1);
EntityType e3 = tx.putEntityType("e3").sup(e1);
Entity e2_child1 = e2.addEntity();
Entity e2_child2 = e2.addEntity();
Entity e3_child1 = e3.addEntity();
Entity e3_child2 = e3.addEntity();
Entity e3_child3 = e3.addEntity();
assertThat(e1.instances().collect(toSet()), containsInAnyOrder(e2_child1, e2_child2, e3_child1, e3_child2, e3_child3));
assertThat(e2.instances().collect(toSet()), containsInAnyOrder(e2_child1, e2_child2));
assertThat(e3.instances().collect(toSet()), containsInAnyOrder(e3_child1, e3_child2, e3_child3));
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class RemoteConceptsTest method whenSettingSuper_ExecuteAConceptMethod.
@Test
public void whenSettingSuper_ExecuteAConceptMethod() {
EntityType sup = RemoteConcepts.createEntityType(tx, A);
assertEquals(entityType, entityType.sup(sup));
verifyConceptMethodCalled(ConceptMethods.setDirectSuperConcept(sup));
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class GraknTxJanusTest method whenCreatingIndependentMutatingTransactionsConcurrently_TheGraphIsUpdatedSafely.
@Test
public void whenCreatingIndependentMutatingTransactionsConcurrently_TheGraphIsUpdatedSafely() throws ExecutionException, InterruptedException {
Set<Future> futures = new HashSet<>();
ExecutorService pool = Executors.newFixedThreadPool(40);
EntityType type = graknTx.putEntityType("A Type");
graknTx.commit();
for (int i = 0; i < 100; i++) {
futures.add(pool.submit(() -> addEntity(type)));
}
for (Future future : futures) {
future.get();
}
graknTx = janusGraphFactory.open(GraknTxType.WRITE);
assertEquals(100L, graknTx.admin().getMetaEntityType().instances().count());
}
Aggregations