use of org.neo4j.internal.helpers.collection.Visitor in project neo4j by neo4j.
the class TransactionLogsRecoveryTest method writeSomeDataWithVersion.
private void writeSomeDataWithVersion(Path file, Visitor<Pair<LogEntryWriter, Consumer<LogPositionMarker>>, IOException> visitor, KernelVersion version) throws IOException {
try (LogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(fileSystem.write(file), logVersion, CURRENT_LOG_FORMAT_VERSION, file, EMPTY_ACCESSOR);
PositionAwarePhysicalFlushableChecksumChannel writableLogChannel = new PositionAwarePhysicalFlushableChecksumChannel(versionedStoreChannel, new HeapScopedBuffer(1, KibiByte, INSTANCE))) {
writeLogHeader(writableLogChannel, new LogHeader(logVersion, 2L, StoreId.UNKNOWN));
writableLogChannel.beginChecksum();
Consumer<LogPositionMarker> consumer = marker -> {
try {
writableLogChannel.getCurrentPosition(marker);
} catch (IOException e) {
throw new RuntimeException(e);
}
};
LogEntryWriter first = new LogEntryWriter(writableLogChannel, version);
visitor.visit(Pair.of(first, consumer));
}
}
use of org.neo4j.internal.helpers.collection.Visitor in project neo4j by neo4j.
the class NodeStoreTest method scanningRecordsShouldVisitEachInUseRecordOnce.
@Test
void scanningRecordsShouldVisitEachInUseRecordOnce() throws IOException {
// GIVEN we have a NodeStore with data that spans several pages...
nodeStore = newNodeStore(fs);
ThreadLocalRandom rng = ThreadLocalRandom.current();
final MutableLongSet nextRelSet = new LongHashSet();
for (int i = 0; i < 10_000; i++) {
// Enough records to span several pages
int nextRelCandidate = rng.nextInt(0, Integer.MAX_VALUE);
if (nextRelSet.add(nextRelCandidate)) {
long nodeId = nodeStore.nextId(NULL);
NodeRecord record = new NodeRecord(nodeId).initialize(true, 20, false, nextRelCandidate, 0);
nodeStore.updateRecord(record, NULL);
if (rng.nextInt(0, 10) < 3) {
nextRelSet.remove(nextRelCandidate);
record.setInUse(false);
nodeStore.updateRecord(record, NULL);
}
}
}
// ...WHEN we now have an interesting set of node records, and we
// visit each and remove that node from our nextRelSet...
Visitor<NodeRecord, IOException> scanner = record -> {
// ...THEN we should observe that no nextRel is ever removed twice...
assertTrue(nextRelSet.remove(record.getNextRel()));
return false;
};
nodeStore.scanAllRecords(scanner, NULL);
// ...NOR do we have anything left in the set afterwards.
assertTrue(nextRelSet.isEmpty());
}
Aggregations