Search in sources :

Example 1 with Group

use of org.neo4j.unsafe.impl.batchimport.ReadGroupsFromCacheStepTest.Group in project neo4j by neo4j.

the class EncodeGroupsStepTest method shouldEncodeGroupChains.

@SuppressWarnings("unchecked")
@Test
public void shouldEncodeGroupChains() throws Throwable {
    // GIVEN
    StageControl control = mock(StageControl.class);
    final AtomicLong nextId = new AtomicLong();
    RecordStore<RelationshipGroupRecord> store = mock(RecordStore.class);
    when(store.nextId()).thenAnswer(invocation -> nextId.incrementAndGet());
    doAnswer(invocation -> {
        invocation.getArgumentAt(0, RelationshipGroupRecord.class).setFirstOut(1);
        return null;
    }).when(store).prepareForCommit(any(RelationshipGroupRecord.class));
    Configuration config = Configuration.withBatchSize(DEFAULT, 10);
    EncodeGroupsStep encoder = new EncodeGroupsStep(control, config, store);
    // WHEN
    encoder.start(Step.ORDER_SEND_DOWNSTREAM);
    Catcher catcher = new Catcher();
    encoder.process(batch(new Group(1, 3), new Group(2, 3), new Group(3, 4)), catcher);
    encoder.process(batch(new Group(4, 2), new Group(5, 10)), catcher);
    encoder.process(batch(new Group(6, 35)), catcher);
    encoder.process(batch(new Group(7, 2)), catcher);
    encoder.endOfUpstream();
    while (!encoder.isCompleted()) {
        Thread.sleep(10);
    }
    encoder.close();
    // THEN
    assertEquals(4, catcher.batches.size());
    long lastOwningNodeLastBatch = -1;
    for (RelationshipGroupRecord[] batch : catcher.batches) {
        assertBatch(batch, lastOwningNodeLastBatch);
        lastOwningNodeLastBatch = batch[batch.length - 1].getOwningNode();
    }
}
Also used : Group(org.neo4j.unsafe.impl.batchimport.ReadGroupsFromCacheStepTest.Group) AtomicLong(java.util.concurrent.atomic.AtomicLong) StageControl(org.neo4j.unsafe.impl.batchimport.staging.StageControl) RelationshipGroupRecord(org.neo4j.kernel.impl.store.record.RelationshipGroupRecord) Test(org.junit.Test)

Aggregations

AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Test (org.junit.Test)1 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)1 Group (org.neo4j.unsafe.impl.batchimport.ReadGroupsFromCacheStepTest.Group)1 StageControl (org.neo4j.unsafe.impl.batchimport.staging.StageControl)1