use of org.neo4j.kernel.impl.transaction.state.storeview.TestTokenScanConsumer in project neo4j by neo4j.
the class NodeStoreScanTest method shouldScanOverRelevantNodes.
private void shouldScanOverRelevantNodes(int[] labelFilter, IntPredicate propertyKeyFilter) {
// given
long total = 100;
MutableLongSet expectedPropertyUpdatesNodes = new LongHashSet();
MutableLongSet expectedTokenUpdatesNodes = new LongHashSet();
for (long id = 0; id < total; id++) {
StubStorageCursors.NodeData node = cursors.withNode(id);
int[] labels = randomLabels();
node.labels(intsToLongs(labels));
Map<String, Value> properties = new HashMap<>();
boolean passesPropertyFilter = false;
if (random.nextBoolean()) {
properties.put(KEY_NAME, Values.of("Node_" + id));
passesPropertyFilter |= propertyKeyFilter.test(nameKeyId);
}
if (random.nextBoolean()) {
properties.put(KEY_AGE, Values.of(id));
passesPropertyFilter |= propertyKeyFilter.test(ageKeyId);
}
node.properties(properties);
if (passesPropertyFilter && intersect(intsToLongs(labels), intsToLongs(labelFilter)).length > 0) {
expectedPropertyUpdatesNodes.add(id);
}
if (labels.length > 0) {
expectedTokenUpdatesNodes.add(id);
}
}
// when
var tokenConsumer = new TestTokenScanConsumer();
var propertyConsumer = new TestPropertyScanConsumer();
NodeStoreScan scan = new NodeStoreScan(Config.defaults(), cursors, locks, tokenConsumer, propertyConsumer, labelFilter, propertyKeyFilter, false, jobScheduler, NULL, INSTANCE);
assertThat(scan.getProgress().getCompleted()).isZero();
scan.run(StoreScan.NO_EXTERNAL_UPDATES);
// then
assertThat(LongSets.mutable.of(tokenConsumer.batches.stream().flatMap(Collection::stream).mapToLong(record -> record.getEntityId()).toArray())).isEqualTo(expectedTokenUpdatesNodes);
assertThat(LongSets.mutable.of(propertyConsumer.batches.stream().flatMap(Collection::stream).mapToLong(record -> record.getEntityId()).toArray())).isEqualTo(expectedPropertyUpdatesNodes);
}
Aggregations