use of org.neo4j.internal.batchimport.ReadGroupsFromCacheStepTest.Group in project neo4j by neo4j.
the class EncodeGroupsStepTest method shouldEncodeGroupChains.
@Test
void shouldEncodeGroupChains() throws Throwable {
final AtomicLong nextId = new AtomicLong();
when(store.nextId(NULL)).thenAnswer(invocation -> nextId.incrementAndGet());
doAnswer(invocation -> {
// our own way of marking that this has record been prepared (firstOut=1)
invocation.<RelationshipGroupRecord>getArgument(0).setFirstOut(1);
return null;
}).when(store).prepareForCommit(any(RelationshipGroupRecord.class), any(CursorContext.class));
Configuration config = Configuration.withBatchSize(Configuration.DEFAULT, 10);
EncodeGroupsStep encoder = new EncodeGroupsStep(control, config, store, PageCacheTracer.NULL);
// 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, NULL);
encoder.process(batch(new Group(4, 2), new Group(5, 10)), catcher, NULL);
encoder.process(batch(new Group(6, 35)), catcher, NULL);
encoder.process(batch(new Group(7, 2)), catcher, NULL);
encoder.endOfUpstream();
encoder.awaitCompleted();
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();
}
}
use of org.neo4j.internal.batchimport.ReadGroupsFromCacheStepTest.Group in project neo4j by neo4j.
the class EncodeGroupsStepTest method tracePageCacheAccessOnEncode.
@Test
void tracePageCacheAccessOnEncode() throws Exception {
when(store.nextId(any(CursorContext.class))).thenAnswer(invocation -> {
CursorContext cursorContext = invocation.getArgument(0);
var event = cursorContext.getCursorTracer().beginPin(false, 1, null);
event.hit();
event.done();
return 1L;
});
var cacheTracer = new DefaultPageCacheTracer();
var cursorContext = new CursorContext(cacheTracer.createPageCursorTracer("tracePageCacheAccessOnEncode"));
Configuration config = Configuration.withBatchSize(Configuration.DEFAULT, 10);
try (EncodeGroupsStep encoder = new EncodeGroupsStep(control, config, store, PageCacheTracer.NULL)) {
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, cursorContext);
encoder.endOfUpstream();
encoder.awaitCompleted();
}
assertThat(cursorContext.getCursorTracer().pins()).isEqualTo(10);
assertThat(cursorContext.getCursorTracer().hits()).isEqualTo(10);
assertThat(cursorContext.getCursorTracer().unpins()).isEqualTo(10);
}
Aggregations