use of ai.grakn.kb.internal.structure.Shard in project grakn by graknlabs.
the class EntityTypeTest method whenAddingInstanceToType_EnsureIsaEdgeIsPlacedOnShard.
@Test
public void whenAddingInstanceToType_EnsureIsaEdgeIsPlacedOnShard() {
EntityTypeImpl entityType = (EntityTypeImpl) tx.putEntityType("EntityType");
Shard shard = entityType.currentShard();
Entity e1 = entityType.addEntity();
assertFalse("The isa edge was places on the type rather than the shard", entityType.neighbours(Direction.IN, Schema.EdgeLabel.ISA).iterator().hasNext());
assertEquals(e1, shard.links().findAny().get());
}
use of ai.grakn.kb.internal.structure.Shard in project grakn by graknlabs.
the class ConceptImpl method createShard.
// ----------------------------------- Sharding Functionality
public void createShard() {
VertexElement shardVertex = vertex().tx().addVertexElement(Schema.BaseType.SHARD);
Shard shard = vertex().tx().factory().buildShard(this, shardVertex);
vertex().property(Schema.VertexProperty.CURRENT_SHARD, shard.id());
currentShard.set(shard);
// Updated the cached shard count if needed
if (shardCount.isPresent()) {
shardCount.set(shardCount() + 1);
}
}
use of ai.grakn.kb.internal.structure.Shard in project grakn by graknlabs.
the class GraknTxTest method whenShardingSuperNode_EnsureNewInstancesGoToNewShard.
@Test
public void whenShardingSuperNode_EnsureNewInstancesGoToNewShard() {
EntityTypeImpl entityType = (EntityTypeImpl) tx.putEntityType("The Special Type");
Shard s1 = entityType.currentShard();
// Add 3 instances to first shard
Entity s1_e1 = entityType.addEntity();
Entity s1_e2 = entityType.addEntity();
Entity s1_e3 = entityType.addEntity();
tx.shard(entityType.getId());
Shard s2 = entityType.currentShard();
// Add 5 instances to second shard
Entity s2_e1 = entityType.addEntity();
Entity s2_e2 = entityType.addEntity();
Entity s2_e3 = entityType.addEntity();
Entity s2_e4 = entityType.addEntity();
Entity s2_e5 = entityType.addEntity();
tx.shard(entityType.getId());
Shard s3 = entityType.currentShard();
// Add 2 instances to 3rd shard
Entity s3_e1 = entityType.addEntity();
Entity s3_e2 = entityType.addEntity();
// Check Type was sharded correctly
assertThat(entityType.shards().collect(toSet()), containsInAnyOrder(s1, s2, s3));
// Check shards have correct instances
assertThat(s1.links().collect(toSet()), containsInAnyOrder(s1_e1, s1_e2, s1_e3));
assertThat(s2.links().collect(toSet()), containsInAnyOrder(s2_e1, s2_e2, s2_e3, s2_e4, s2_e5));
assertThat(s3.links().collect(toSet()), containsInAnyOrder(s3_e1, s3_e2));
}
Aggregations