use of org.neo4j.io.pagecache.context.CursorContext.NULL in project neo4j by neo4j.
the class ParallelNodeLabelScanTestBase method shouldScanASubsetOfNodes.
@Test
void shouldScanASubsetOfNodes() {
try (NodeLabelIndexCursor nodes = cursors.allocateNodeLabelIndexCursor(NULL)) {
for (int label : ALL_LABELS) {
Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(label);
assertTrue(scan.reserveBatch(nodes, 11));
MutableLongList found = LongLists.mutable.empty();
while (nodes.next()) {
found.add(nodes.nodeReference());
}
assertThat(found.size()).isGreaterThan(0);
if (label == FOO_LABEL) {
assertTrue(FOO_NODES.containsAll(found));
assertTrue(found.noneSatisfy(f -> BAR_NODES.contains(f)));
} else if (label == BAR_LABEL) {
assertTrue(BAR_NODES.containsAll(found));
assertTrue(found.noneSatisfy(f -> FOO_NODES.contains(f)));
} else {
fail();
}
}
}
}
use of org.neo4j.io.pagecache.context.CursorContext.NULL in project neo4j by neo4j.
the class ParallelNodeLabelScanTestBase method shouldHandleSizeHintOverflow.
@Test
void shouldHandleSizeHintOverflow() {
try (NodeLabelIndexCursor nodes = cursors.allocateNodeLabelIndexCursor(NULL)) {
// when
Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(FOO_LABEL);
assertTrue(scan.reserveBatch(nodes, NUMBER_OF_NODES * 2));
MutableLongList ids = LongLists.mutable.empty();
while (nodes.next()) {
ids.add(nodes.nodeReference());
}
assertEquals(FOO_NODES.size(), ids.size());
assertTrue(FOO_NODES.containsAll(ids));
assertTrue(ids.noneSatisfy(f -> BAR_NODES.contains(f)));
}
}
use of org.neo4j.io.pagecache.context.CursorContext.NULL in project neo4j by neo4j.
the class GBPTreeTest method readHeaderMustWorkWithOpenIndex.
@Test
void readHeaderMustWorkWithOpenIndex() throws Exception {
// GIVEN
byte[] headerBytes = new byte[12];
random.nextBytes(headerBytes);
Consumer<PageCursor> headerWriter = pc -> pc.putBytes(headerBytes);
// WHEN
try (PageCache pageCache = createPageCache(defaultPageSize);
GBPTree<MutableLong, MutableLong> ignore = index(pageCache).with(headerWriter).build()) {
byte[] readHeader = new byte[headerBytes.length];
AtomicInteger length = new AtomicInteger();
Header.Reader headerReader = headerData -> {
length.set(headerData.limit());
headerData.get(readHeader);
};
GBPTree.readHeader(pageCache, indexFile, headerReader, DEFAULT_DATABASE_NAME, NULL);
// THEN
assertEquals(headerBytes.length, length.get());
assertArrayEquals(headerBytes, readHeader);
}
}
use of org.neo4j.io.pagecache.context.CursorContext.NULL in project neo4j by neo4j.
the class SeekCursorTestBase method shouldCatchupRootWhenNodeHasTooNewGenerationWhileTraversingDownTree.
@Test
void shouldCatchupRootWhenNodeHasTooNewGenerationWhileTraversingDownTree() throws Exception {
// given
long generation = TreeNode.generation(cursor);
MutableBoolean triggered = new MutableBoolean(false);
// We don't care
long rightChild = 999;
// a newer leaf
long leftChild = cursor.getCurrentPageId();
// A newer leaf
node.initializeLeaf(cursor, stableGeneration + 1, unstableGeneration + 1);
cursor.next();
// a root
long rootId = cursor.getCurrentPageId();
node.initializeInternal(cursor, stableGeneration, unstableGeneration);
long keyInRoot = 10L;
node.insertKeyAndRightChildAt(cursor, key(keyInRoot), rightChild, 0, 0, stableGeneration, unstableGeneration, NULL);
TreeNode.setKeyCount(cursor, 1);
// with old pointer to child (simulating reuse of child node)
node.setChildAt(cursor, leftChild, 0, stableGeneration, unstableGeneration);
// a root catchup that records usage
RootCatchup rootCatchup = fromId -> {
triggered.setTrue();
// and set child generation to match pointer
cursor.next(leftChild);
cursor.zapPage();
node.initializeLeaf(cursor, stableGeneration, unstableGeneration);
cursor.next(rootId);
return new Root(rootId, generation);
};
// when
KEY from = key(1L);
KEY to = key(2L);
// noinspection EmptyTryBlock
try (SeekCursor<KEY, VALUE> ignored = new SeekCursor<>(cursor, node, from, to, layout, stableGeneration, unstableGeneration, generationSupplier, rootCatchup, unstableGeneration, exceptionDecorator, 1, LEAF_LEVEL, SeekCursor.NO_MONITOR, NULL)) {
// do nothing
}
// then
assertTrue(triggered.getValue());
}
use of org.neo4j.io.pagecache.context.CursorContext.NULL in project neo4j by neo4j.
the class MetaDataStoreTest method mustSupportScanningAllRecordsWithRecordCursor.
@Test
void mustSupportScanningAllRecordsWithRecordCursor() {
MetaDataStore.Position[] positions = MetaDataStore.Position.values();
long storeVersion = versionStringToLong(Standard.LATEST_RECORD_FORMATS.storeVersion());
try (MetaDataStore store = newMetaDataStore()) {
writeCorrectMetaDataRecord(store, positions, storeVersion);
}
List<Long> actualValues = new ArrayList<>();
try (MetaDataStore store = newMetaDataStore()) {
MetaDataRecord record = store.newRecord();
try (PageCursor cursor = store.openPageCursorForReading(0, NULL)) {
long highId = store.getHighId();
for (long id = 0; id < highId; id++) {
store.getRecordByCursor(id, record, RecordLoad.NORMAL, cursor);
if (record.inUse()) {
actualValues.add(record.getValue());
}
}
}
}
List<Long> expectedValues = Arrays.stream(positions).map(p -> {
if (p == STORE_VERSION) {
return storeVersion;
} else {
return p.ordinal() + 1L;
}
}).collect(Collectors.toList());
assertThat(actualValues).isEqualTo(expectedValues);
}
Aggregations