Search in sources :

Example 1 with StubStorageCursors

use of org.neo4j.storageengine.api.StubStorageCursors in project neo4j by neo4j.

the class DynamicIndexStoreViewTest method shouldVisitNodesUsingTokenIndex.

@Test
void shouldVisitNodesUsingTokenIndex() throws Exception {
    long[] nodeIds = { 1, 2, 3, 4, 5, 6, 7, 8 };
    int[] indexedLabels = { 2, 6 };
    StubStorageCursors cursors = new StubStorageCursors().withTokenIndexes();
    IndexProxy indexProxy = mock(IndexProxy.class);
    IndexProxyProvider indexProxies = mock(IndexProxyProvider.class);
    StubTokenIndexReader tokenReader = new StubTokenIndexReader();
    IndexDescriptor descriptor = forSchema(forAnyEntityTokens(NODE), DESCRIPTOR).withName("index").materialise(0);
    when(indexProxy.getState()).thenReturn(InternalIndexState.ONLINE);
    when(indexProxy.newTokenReader()).thenReturn(tokenReader);
    when(indexProxy.getDescriptor()).thenReturn(descriptor);
    when(indexProxies.getIndexProxy(any())).thenReturn(indexProxy);
    // Nodes indexed by label
    for (long nodeId : nodeIds) {
        cursors.withNode(nodeId).propertyId(1).relationship(1).labels(2, 6);
        tokenReader.index(indexedLabels, nodeId);
    }
    // Nodes not indexed
    cursors.withNode(9).labels(5);
    cursors.withNode(10).labels(6);
    DynamicIndexStoreView storeView = dynamicIndexStoreView(cursors, indexProxies);
    TestTokenScanConsumer consumer = new TestTokenScanConsumer();
    StoreScan storeScan = storeView.visitNodes(indexedLabels, Predicates.ALWAYS_TRUE_INT, new TestPropertyScanConsumer(), consumer, false, true, NULL, INSTANCE);
    storeScan.run(StoreScan.NO_EXTERNAL_UPDATES);
    assertThat(consumer.batches.size()).isEqualTo(1);
    assertThat(consumer.batches.get(0).size()).isEqualTo(nodeIds.length);
}
Also used : StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) IndexProxyProvider(org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 2 with StubStorageCursors

use of org.neo4j.storageengine.api.StubStorageCursors in project neo4j by neo4j.

the class DynamicIndexStoreViewTest method shouldVisitAllNodesWithoutTokenIndexes.

@Test
void shouldVisitAllNodesWithoutTokenIndexes() {
    long[] nodeIds = { 1, 2, 3, 4, 5, 6, 7, 8 };
    int[] indexedLabels = { 2, 6 };
    StubStorageCursors cursors = new StubStorageCursors().withoutTokenIndexes();
    IndexProxyProvider indexProxies = mock(IndexProxyProvider.class);
    // Nodes indexed by label
    for (long nodeId : nodeIds) {
        cursors.withNode(nodeId).propertyId(1).relationship(1).labels(2, 6);
    }
    // Nodes not in index
    cursors.withNode(9).labels(5);
    cursors.withNode(10).labels(6);
    DynamicIndexStoreView storeView = dynamicIndexStoreView(cursors, indexProxies);
    TestTokenScanConsumer consumer = new TestTokenScanConsumer();
    StoreScan storeScan = storeView.visitNodes(indexedLabels, Predicates.ALWAYS_TRUE_INT, new TestPropertyScanConsumer(), consumer, false, true, NULL, INSTANCE);
    storeScan.run(StoreScan.NO_EXTERNAL_UPDATES);
    assertThat(consumer.batches.size()).isEqualTo(1);
    assertThat(consumer.batches.get(0).size()).isEqualTo(nodeIds.length + 2);
}
Also used : StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) IndexProxyProvider(org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) Test(org.junit.jupiter.api.Test)

Example 3 with StubStorageCursors

use of org.neo4j.storageengine.api.StubStorageCursors in project neo4j by neo4j.

the class GenerateIndexUpdatesStepTest method shouldGenerateEntityPropertyUpdatesForRelevantEntityTokens.

@Test
void shouldGenerateEntityPropertyUpdatesForRelevantEntityTokens() throws Exception {
    // given
    StubStorageCursors data = new StubStorageCursors();
    int numNodes = 10;
    MutableLongSet relevantNodeIds = LongSets.mutable.empty();
    for (int i = 0; i < numNodes; i++) {
        int labelId = i % 2 == 0 ? LABEL : OTHER_LABEL;
        data.withNode(i).labels(labelId).properties(KEY, stringValue("name_" + i));
        if (labelId == LABEL) {
            relevantNodeIds.add(i);
        }
    }
    TestPropertyScanConsumer scanConsumer = new TestPropertyScanConsumer();
    GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep<>(new SimpleStageControl(), DEFAULT, data, alwaysTrue(), new NodeCursorBehaviour(data), new int[] { LABEL }, scanConsumer, null, NO_LOCKING, 1, mebiBytes(1), false, PageCacheTracer.NULL, INSTANCE);
    // when
    CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
    step.process(allNodeIds(data), sender, NULL);
    // then
    GeneratedIndexUpdates updates = sender.batches.get(0);
    updates.completeBatch();
    for (TestPropertyScanConsumer.Record update : scanConsumer.batches.get(0)) {
        assertThat(relevantNodeIds.remove(update.getEntityId())).isTrue();
    }
    assertThat(relevantNodeIds.isEmpty()).isTrue();
}
Also used : SimpleStageControl(org.neo4j.internal.batchimport.staging.SimpleStageControl) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) GeneratedIndexUpdates(org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with StubStorageCursors

use of org.neo4j.storageengine.api.StubStorageCursors in project neo4j by neo4j.

the class GenerateIndexUpdatesStepTest method shouldSendSingleBatchIfBelowMaxSizeThreshold.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldSendSingleBatchIfBelowMaxSizeThreshold(boolean alsoWrite) throws Exception {
    // given
    StubStorageCursors data = someUniformData(10);
    TestPropertyScanConsumer scanConsumer = new TestPropertyScanConsumer();
    GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep(new SimpleStageControl(), DEFAULT, data, alwaysTrue(), new NodeCursorBehaviour(data), new int[] { LABEL }, scanConsumer, null, NO_LOCKING, 1, mebiBytes(1), alsoWrite, PageCacheTracer.NULL, INSTANCE);
    // when
    CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
    step.process(allNodeIds(data), sender, NULL);
    // then
    if (alsoWrite) {
        assertThat(sender.batches).isEmpty();
        assertThat(scanConsumer.batches.size()).isEqualTo(1);
        assertThat(scanConsumer.batches.get(0).size()).isEqualTo(10);
    } else {
        assertThat(sender.batches.size()).isEqualTo(1);
        assertThat(scanConsumer.batches).isEmpty();
    }
}
Also used : SimpleStageControl(org.neo4j.internal.batchimport.staging.SimpleStageControl) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) GeneratedIndexUpdates(org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with StubStorageCursors

use of org.neo4j.storageengine.api.StubStorageCursors in project neo4j by neo4j.

the class GenerateIndexUpdatesStepTest method shouldGenerateEntityTokenUpdates.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldGenerateEntityTokenUpdates(boolean alsoWrite) throws Exception {
    // given
    StubStorageCursors data = someUniformData(10);
    TestTokenScanConsumer scanConsumer = new TestTokenScanConsumer();
    GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep<>(new SimpleStageControl(), DEFAULT, data, alwaysTrue(), new NodeCursorBehaviour(data), new int[] { LABEL }, null, scanConsumer, NO_LOCKING, 1, mebiBytes(1), alsoWrite, PageCacheTracer.NULL, INSTANCE);
    Set<TestTokenScanConsumer.Record> expectedUpdates = new HashSet<>();
    try (StorageNodeCursor cursor = data.allocateNodeCursor(NULL)) {
        cursor.scan();
        while (cursor.next()) {
            expectedUpdates.add(new TestTokenScanConsumer.Record(cursor.entityReference(), cursor.labels()));
        }
    }
    // when
    CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
    step.process(allNodeIds(data), sender, NULL);
    // then
    if (alsoWrite) {
        for (TestTokenScanConsumer.Record tokenUpdate : scanConsumer.batches.get(0)) {
            assertThat(expectedUpdates.remove(tokenUpdate)).isTrue();
        }
    } else {
        GeneratedIndexUpdates updates = sender.batches.get(0);
        updates.completeBatch();
        for (TestTokenScanConsumer.Record tokenUpdate : scanConsumer.batches.get(0)) {
            assertThat(expectedUpdates.remove(tokenUpdate)).isTrue();
        }
    }
    assertThat(expectedUpdates).isEmpty();
}
Also used : SimpleStageControl(org.neo4j.internal.batchimport.staging.SimpleStageControl) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) HashSet(java.util.HashSet) GeneratedIndexUpdates(org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

StubStorageCursors (org.neo4j.storageengine.api.StubStorageCursors)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 StorageNodeCursor (org.neo4j.storageengine.api.StorageNodeCursor)12 Test (org.junit.jupiter.api.Test)9 ValueSource (org.junit.jupiter.params.provider.ValueSource)7 SimpleStageControl (org.neo4j.internal.batchimport.staging.SimpleStageControl)7 GeneratedIndexUpdates (org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 CursorEntityIdIterator (org.neo4j.kernel.impl.transaction.state.storeview.PropertyAwareEntityStoreScan.CursorEntityIdIterator)5 Value (org.neo4j.values.storable.Value)5 IndexProxyProvider (org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider)4 StoreScan (org.neo4j.kernel.impl.api.index.StoreScan)4 HashMap (java.util.HashMap)3 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)3 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)3 HashSet (java.util.HashSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)2 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)2 Values.intValue (org.neo4j.values.storable.Values.intValue)2