use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class RemoteConceptsTest method whenSettingSub_ExecuteAConceptMethod.
@Test
public void whenSettingSub_ExecuteAConceptMethod() {
EntityType sup = RemoteConcepts.createEntityType(tx, A);
assertEquals(sup, sup.sub(entityType));
verifyConceptMethodCalled(ConceptMethods.setDirectSuperConcept(sup));
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class RemoteConceptsTest method whenCallingSups_GetTheExpectedResult.
@Test
public void whenCallingSups_GetTheExpectedResult() {
Type me = entityType;
Type mySuper = RemoteConcepts.createEntityType(tx, A);
Type mySupersSuper = RemoteConcepts.createEntityType(tx, B);
Type metaType = RemoteConcepts.createMetaType(tx, C);
mockConceptMethod(ConceptMethods.GET_SUPER_CONCEPTS, Stream.of(me, mySuper, mySupersSuper, metaType));
Set<Type> sups = entityType.sups().collect(toSet());
assertThat(sups, containsInAnyOrder(me, mySuper, mySupersSuper));
assertThat(sups, not(hasItem(metaType)));
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class GraknTxTest method checkThatMainCentralCacheIsNotAffectedByTransactionModifications.
@Test
public void checkThatMainCentralCacheIsNotAffectedByTransactionModifications() throws InvalidKBException, ExecutionException, InterruptedException {
// Check Central cache is empty
assertCacheOnlyContainsMetaTypes();
Role r1 = tx.putRole("r1");
Role r2 = tx.putRole("r2");
EntityType e1 = tx.putEntityType("e1").plays(r1).plays(r2);
RelationshipType rel1 = tx.putRelationshipType("rel1").relates(r1).relates(r2);
// Purge the above concepts into the main cache
tx.commit();
tx = EmbeddedGraknSession.create(tx.keyspace(), Grakn.IN_MEMORY).open(GraknTxType.WRITE);
// Check cache is in good order
Collection<SchemaConcept> cachedValues = tx.getGlobalCache().getCachedTypes().values();
assertTrue("Type [" + r1 + "] was not cached", cachedValues.contains(r1));
assertTrue("Type [" + r2 + "] was not cached", cachedValues.contains(r2));
assertTrue("Type [" + e1 + "] was not cached", cachedValues.contains(e1));
assertTrue("Type [" + rel1 + "] was not cached", cachedValues.contains(rel1));
assertThat(e1.plays().collect(toSet()), containsInAnyOrder(r1, r2));
ExecutorService pool = Executors.newSingleThreadExecutor();
// Mutate Schema in a separate thread
pool.submit(() -> {
GraknTx innerGraph = Grakn.session(Grakn.IN_MEMORY, tx.keyspace()).open(GraknTxType.WRITE);
EntityType entityType = innerGraph.getEntityType("e1");
Role role = innerGraph.getRole("r1");
entityType.deletePlays(role);
}).get();
// Check the above mutation did not affect central repo
SchemaConcept foundE1 = tx.getGlobalCache().getCachedTypes().get(e1.getLabel());
assertTrue("Main cache was affected by transaction", foundE1.asType().plays().anyMatch(role -> role.equals(r1)));
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class PostProcessingTest method buildSampleGraph.
@Before
public void buildSampleGraph() {
role1 = tx.putRole("role 1");
role2 = tx.putRole("role 2");
relationshipType = tx.putRelationshipType("rel type").relates(role1).relates(role2);
EntityType thing = tx.putEntityType("thingy").plays(role1).plays(role2);
instance1 = (ThingImpl) thing.addEntity();
instance2 = (ThingImpl) thing.addEntity();
thing.addEntity();
thing.addEntity();
relationshipType.addRelationship().addRolePlayer(role1, instance1).addRolePlayer(role2, instance2);
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class ValidateGlobalRulesTest method testValidatePlaysStructureUnique.
@Test
public void testValidatePlaysStructureUnique() {
Role role1 = tx.putRole("role1");
Role role2 = tx.putRole("role2");
RelationshipType relationshipType = tx.putRelationshipType("rt").relates(role1).relates(role2);
EntityType entityType = tx.putEntityType("et");
((EntityTypeImpl) entityType).plays(role1, true);
((EntityTypeImpl) entityType).plays(role2, false);
Entity other1 = entityType.addEntity();
Entity other2 = entityType.addEntity();
EntityImpl entity = (EntityImpl) entityType.addEntity();
RelationshipImpl relation1 = (RelationshipImpl) relationshipType.addRelationship().addRolePlayer(role2, other1).addRolePlayer(role1, entity);
// Valid with only a single relation
relation1.reified().get().castingsRelation().forEach(rolePlayer -> assertTrue(ValidateGlobalRules.validatePlaysAndRelatesStructure(rolePlayer).isEmpty()));
RelationshipImpl relation2 = (RelationshipImpl) relationshipType.addRelationship().addRolePlayer(role2, other2).addRolePlayer(role1, entity);
// Invalid with multiple relations
relation1.reified().get().castingsRelation().forEach(rolePlayer -> {
if (rolePlayer.getRole().equals(role1)) {
assertFalse(ValidateGlobalRules.validatePlaysAndRelatesStructure(rolePlayer).isEmpty());
}
});
relation2.reified().get().castingsRelation().forEach(rolePlayer -> {
if (rolePlayer.getRole().equals(role1)) {
assertFalse(ValidateGlobalRules.validatePlaysAndRelatesStructure(rolePlayer).isEmpty());
}
});
}
Aggregations