use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class IndexIteratorIT method tracePageCacheAccessOnIteration.
@Test
void tracePageCacheAccessOnIteration() throws Exception {
var descriptors = indexAccessors.onlineRules();
assertThat(descriptors).hasSize(1);
try (CursorContext cursorContext = new CursorContext(pageCacheTracer.createPageCursorTracer("tracePageCacheAccessOnIteration"))) {
for (IndexDescriptor descriptor : descriptors) {
try (BoundedIterable<Long> indexIterator = indexAccessors.accessorFor(descriptor).newAllEntriesValueReader(cursorContext)) {
assertEquals(1, count(indexIterator.iterator()));
}
}
}
assertThat(pageCacheTracer.pins()).isOne();
assertThat(pageCacheTracer.unpins()).isOne();
assertThat(pageCacheTracer.hits()).isOne();
}
use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class KernelStatementTest method emptyPageCacheStatisticOnClosedStatement.
@Test
void emptyPageCacheStatisticOnClosedStatement() {
var transaction = mock(KernelTransactionImplementation.class, RETURNS_DEEP_STUBS);
try (var statement = createStatement(transaction)) {
var cursorContext = new CursorContext(new DefaultPageCursorTracer(new DefaultPageCacheTracer(), "test"));
statement.initialize(Mockito.mock(Locks.Client.class), cursorContext, 100);
statement.acquire();
cursorContext.getCursorTracer().beginPin(false, 1, null).hit();
cursorContext.getCursorTracer().beginPin(false, 1, null).hit();
cursorContext.getCursorTracer().beginPin(false, 1, null).beginPageFault(1, 2).done();
assertEquals(2, statement.getHits());
assertEquals(1, statement.getFaults());
statement.close();
assertEquals(0, statement.getHits());
assertEquals(0, statement.getFaults());
}
}
use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class EncodingIdMapperTest method shouldHandleGreatAmountsOfStuff.
@Test
public void shouldHandleGreatAmountsOfStuff() {
// GIVEN
IdMapper idMapper = mapper(new StringEncoder(), Radix.STRING, EncodingIdMapper.NO_MONITOR);
PropertyValueLookup inputIdLookup = (id, cursorContext) -> String.valueOf(id);
int count = 300_000;
// WHEN
for (long nodeId = 0; nodeId < count; nodeId++) {
idMapper.put(inputIdLookup.lookupProperty(nodeId, NULL), nodeId, Group.GLOBAL);
}
idMapper.prepare(inputIdLookup, mock(Collector.class), NONE);
// THEN
for (long nodeId = 0; nodeId < count; nodeId++) {
// the UUIDs here will be generated in the same sequence as above because we reset the random
Object id = inputIdLookup.lookupProperty(nodeId, NULL);
if (idMapper.get(id, Group.GLOBAL) == IdMapper.ID_NOT_FOUND) {
fail("Couldn't find " + id + " even though I added it just previously");
}
}
}
use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class EncodingIdMapperTest method tracePageCacheAccessOnCollisions.
@Test
public void tracePageCacheAccessOnCollisions() {
EncodingIdMapper.Monitor monitor = mock(EncodingIdMapper.Monitor.class);
Encoder encoder = mock(Encoder.class);
when(encoder.encode(any())).thenReturn(12345L);
var pageCacheTracer = new DefaultPageCacheTracer();
IdMapper mapper = mapper(encoder, Radix.STRING, monitor, pageCacheTracer);
PropertyValueLookup ids = (nodeId, cursorContext) -> {
cursorContext.getCursorTracer().beginPin(false, 1, null).done();
return nodeId + "";
};
int expectedCollisions = 2;
for (int i = 0; i < expectedCollisions; i++) {
mapper.put(ids.lookupProperty(i, NULL), i, Group.GLOBAL);
}
ProgressListener progress = mock(ProgressListener.class);
Collector collector = mock(Collector.class);
mapper.prepare(ids, collector, progress);
verifyNoMoreInteractions(collector);
verify(monitor).numberOfCollisions(expectedCollisions);
assertEquals(expectedCollisions, pageCacheTracer.pins());
assertEquals(expectedCollisions, pageCacheTracer.unpins());
}
use of org.neo4j.io.pagecache.context.CursorContext in project neo4j by neo4j.
the class EncodingIdMapperTest method shouldPutFromMultipleThreads.
@Test
public void shouldPutFromMultipleThreads() throws Throwable {
// GIVEN
IdMapper idMapper = mapper(new StringEncoder(), Radix.STRING, EncodingIdMapper.NO_MONITOR);
AtomicLong highNodeId = new AtomicLong();
int batchSize = 1234;
Race race = new Race();
PropertyValueLookup inputIdLookup = (id, cursorContext) -> String.valueOf(id);
int countPerThread = 30_000;
race.addContestants(processors, () -> {
int cursor = batchSize;
long nextNodeId = 0;
for (int j = 0; j < countPerThread; j++) {
if (cursor == batchSize) {
nextNodeId = highNodeId.getAndAdd(batchSize);
cursor = 0;
}
long nodeId = nextNodeId++;
cursor++;
idMapper.put(inputIdLookup.lookupProperty(nodeId, NULL), nodeId, Group.GLOBAL);
}
});
// WHEN
race.go();
idMapper.prepare(inputIdLookup, mock(Collector.class), ProgressListener.NONE);
// THEN
int count = processors * countPerThread;
int countWithGapsWorstCase = count + batchSize * processors;
int correctHits = 0;
for (long nodeId = 0; nodeId < countWithGapsWorstCase; nodeId++) {
long result = idMapper.get(inputIdLookup.lookupProperty(nodeId, NULL), Group.GLOBAL);
if (result != -1) {
assertEquals(nodeId, result);
correctHits++;
}
}
assertEquals(count, correctHits);
}
Aggregations