Search in sources :

Example 1 with Shard

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());
}
Also used : Entity(ai.grakn.concept.Entity) Shard(ai.grakn.kb.internal.structure.Shard) Test(org.junit.Test)

Example 2 with Shard

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);
    }
}
Also used : VertexElement(ai.grakn.kb.internal.structure.VertexElement) Shard(ai.grakn.kb.internal.structure.Shard)

Example 3 with Shard

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));
}
Also used : Entity(ai.grakn.concept.Entity) EntityTypeImpl(ai.grakn.kb.internal.concept.EntityTypeImpl) Shard(ai.grakn.kb.internal.structure.Shard) Test(org.junit.Test)

Aggregations

Shard (ai.grakn.kb.internal.structure.Shard)3 Entity (ai.grakn.concept.Entity)2 Test (org.junit.Test)2 EntityTypeImpl (ai.grakn.kb.internal.concept.EntityTypeImpl)1 VertexElement (ai.grakn.kb.internal.structure.VertexElement)1