use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class GraknTxTest method whenGettingSubTypesFromRootMeta_IncludeAllTypes.
@Test
public void whenGettingSubTypesFromRootMeta_IncludeAllTypes() {
EntityType sampleEntityType = tx.putEntityType("Sample Entity Type");
RelationshipType sampleRelationshipType = tx.putRelationshipType("Sample Relationship Type");
assertThat(tx.getMetaConcept().subs().collect(toSet()), containsInAnyOrder(tx.getMetaConcept(), tx.getMetaRelationType(), tx.getMetaEntityType(), tx.getMetaAttributeType(), sampleEntityType, sampleRelationshipType));
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class GraknTxTest method whenAttemptingToMutateReadOnlyGraph_Throw.
@Test
public void whenAttemptingToMutateReadOnlyGraph_Throw() {
Keyspace keyspace = Keyspace.of("myreadonlygraph");
String entityType = "My Entity Type";
String roleType1 = "My Role Type 1";
String roleType2 = "My Role Type 2";
String relationType1 = "My Relationship Type 1";
String relationType2 = "My Relationship Type 2";
String resourceType = "My Attribute Type";
// Fail Some Mutations
tx = EmbeddedGraknSession.create(keyspace, Grakn.IN_MEMORY).open(GraknTxType.READ);
failMutation(tx, () -> tx.putEntityType(entityType));
failMutation(tx, () -> tx.putRole(roleType1));
failMutation(tx, () -> tx.putRelationshipType(relationType1));
// Pass some mutations
tx.close();
tx = EmbeddedGraknSession.create(keyspace, Grakn.IN_MEMORY).open(GraknTxType.WRITE);
EntityType entityT = tx.putEntityType(entityType);
entityT.addEntity();
Role roleT1 = tx.putRole(roleType1);
Role roleT2 = tx.putRole(roleType2);
RelationshipType relationT1 = tx.putRelationshipType(relationType1).relates(roleT1);
RelationshipType relationT2 = tx.putRelationshipType(relationType2).relates(roleT2);
AttributeType<String> resourceT = tx.putAttributeType(resourceType, AttributeType.DataType.STRING);
tx.commit();
// Fail some mutations again
tx = EmbeddedGraknSession.create(keyspace, Grakn.IN_MEMORY).open(GraknTxType.READ);
failMutation(tx, entityT::addEntity);
failMutation(tx, () -> resourceT.putAttribute("A resource"));
failMutation(tx, () -> tx.putEntityType(entityType));
failMutation(tx, () -> entityT.plays(roleT1));
failMutation(tx, () -> relationT1.relates(roleT2));
failMutation(tx, () -> relationT2.relates(roleT1));
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class GraknTxTest method whenShardingConcepts_EnsureCountsAreUpdated.
@Test
public void whenShardingConcepts_EnsureCountsAreUpdated() {
EntityType entity = tx.putEntityType("my amazing entity type");
assertEquals(1L, tx.getShardCount(entity));
tx.shard(entity.getId());
assertEquals(2L, tx.getShardCount(entity));
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class GrpcServerIT method whenDefiningASchema_TheSchemaIsDefined.
@Test
public void whenDefiningASchema_TheSchemaIsDefined() {
try (GraknTx tx = remoteSession.open(GraknTxType.WRITE)) {
EntityType animal = tx.putEntityType("animal");
EntityType dog = tx.putEntityType("dog").sup(animal);
EntityType cat = tx.putEntityType("cat");
animal.sub(cat);
cat.setLabel(Label.of("feline"));
dog.setAbstract(true).setAbstract(false);
cat.setAbstract(true);
RelationshipType chases = tx.putRelationshipType("chases");
Role chased = tx.putRole("chased");
Role chaser = tx.putRole("chaser");
chases.relates(chased).relates(chaser);
Role pointlessRole = tx.putRole("pointless-role");
tx.putRelationshipType("pointless").relates(pointlessRole);
chases.relates(pointlessRole).deleteRelates(pointlessRole);
dog.plays(chaser);
cat.plays(chased);
AttributeType<String> name = tx.putAttributeType("name", DataType.STRING);
AttributeType<String> id = tx.putAttributeType("id", DataType.STRING).setRegex("(good|bad)-dog");
AttributeType<Long> age = tx.putAttributeType("age", DataType.LONG);
animal.attribute(name);
animal.key(id);
dog.attribute(age).deleteAttribute(age);
cat.key(age).deleteKey(age);
cat.plays(chaser).deletePlays(chaser);
Entity dunstan = dog.addEntity();
Attribute<String> dunstanId = id.putAttribute("good-dog");
assertNotNull(dunstan.attributeRelationship(dunstanId));
Attribute<String> dunstanName = name.putAttribute("Dunstan");
dunstan.attribute(dunstanName).deleteAttribute(dunstanName);
chases.addRelationship().addRolePlayer(chaser, dunstan);
tx.commit();
}
try (GraknTx tx = localSession.open(GraknTxType.READ)) {
EntityType animal = tx.getEntityType("animal");
EntityType dog = tx.getEntityType("dog");
EntityType cat = tx.getEntityType("feline");
RelationshipType chases = tx.getRelationshipType("chases");
Role chased = tx.getRole("chased");
Role chaser = tx.getRole("chaser");
AttributeType<String> name = tx.getAttributeType("name");
AttributeType<String> id = tx.getAttributeType("id");
Entity dunstan = Iterators.getOnlyElement(dog.instances().iterator());
Relationship aChase = Iterators.getOnlyElement(chases.instances().iterator());
assertEquals(animal, dog.sup());
assertEquals(animal, cat.sup());
assertEquals(ImmutableSet.of(chased, chaser), chases.relates().collect(toSet()));
assertEquals(ImmutableSet.of(chaser), dog.plays().filter(role -> !role.isImplicit()).collect(toSet()));
assertEquals(ImmutableSet.of(chased), cat.plays().filter(role -> !role.isImplicit()).collect(toSet()));
assertEquals(ImmutableSet.of(name, id), animal.attributes().collect(toSet()));
assertEquals(ImmutableSet.of(id), animal.keys().collect(toSet()));
assertEquals(ImmutableSet.of(name, id), dog.attributes().collect(toSet()));
assertEquals(ImmutableSet.of(id), dog.keys().collect(toSet()));
assertEquals(ImmutableSet.of(name, id), cat.attributes().collect(toSet()));
assertEquals(ImmutableSet.of(id), cat.keys().collect(toSet()));
assertEquals("good-dog", Iterables.getOnlyElement(dunstan.keys(id).collect(toSet())).getValue());
ImmutableMap<Role, ImmutableSet<?>> expectedRolePlayers = ImmutableMap.of(chaser, ImmutableSet.of(dunstan), chased, ImmutableSet.of());
assertEquals(expectedRolePlayers, aChase.allRolePlayers());
assertEquals("(good|bad)-dog", id.getRegex());
assertFalse(dog.isAbstract());
assertTrue(cat.isAbstract());
}
}
use of ai.grakn.concept.EntityType in project grakn by graknlabs.
the class BatchExecutorClientIT method loader.
private BatchExecutorClient loader(int maxDelay) {
// load schema
try (EmbeddedGraknTx<?> graph = session.open(GraknTxType.WRITE)) {
Role role = graph.putRole("some-role");
graph.putRelationshipType("some-relationship").relates(role);
EntityType nameTag = graph.putEntityType("name_tag");
AttributeType<String> nameTagString = graph.putAttributeType("name_tag_string", AttributeType.DataType.STRING);
AttributeType<String> nameTagId = graph.putAttributeType("name_tag_id", AttributeType.DataType.STRING);
nameTag.attribute(nameTagString);
nameTag.attribute(nameTagId);
graph.commitSubmitNoLogs();
GraknClient graknClient = GraknClient.of(engine.uri());
return spy(BatchExecutorClient.newBuilder().taskClient(graknClient).maxDelay(maxDelay).requestLogEnabled(true).build());
}
}
Aggregations