Search in sources :

Example 1 with TestTokenScanConsumer

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);
}
Also used : HashMap(java.util.HashMap) TestPropertyScanConsumer(org.neo4j.kernel.impl.transaction.state.storeview.TestPropertyScanConsumer) TestTokenScanConsumer(org.neo4j.kernel.impl.transaction.state.storeview.TestTokenScanConsumer) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) NodeStoreScan(org.neo4j.kernel.impl.transaction.state.storeview.NodeStoreScan) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) Value(org.neo4j.values.storable.Value) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors)

Aggregations

HashMap (java.util.HashMap)1 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)1 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)1 NodeStoreScan (org.neo4j.kernel.impl.transaction.state.storeview.NodeStoreScan)1 TestPropertyScanConsumer (org.neo4j.kernel.impl.transaction.state.storeview.TestPropertyScanConsumer)1 TestTokenScanConsumer (org.neo4j.kernel.impl.transaction.state.storeview.TestTokenScanConsumer)1 StubStorageCursors (org.neo4j.storageengine.api.StubStorageCursors)1 Value (org.neo4j.values.storable.Value)1