Search in sources :

Example 11 with StubStorageCursors

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

the class DynamicIndexStoreViewTest method shouldVisitRelationshipsUsingTokenIndex.

@Test
void shouldVisitRelationshipsUsingTokenIndex() throws Throwable {
    // Given
    StubTokenIndexReader tokenReader = new StubTokenIndexReader();
    StubStorageCursors cursors = new StubStorageCursors().withTokenIndexes();
    IndexProxy indexProxy = mock(IndexProxy.class);
    IndexProxyProvider indexProxies = mock(IndexProxyProvider.class);
    IndexDescriptor descriptor = forSchema(forAnyEntityTokens(RELATIONSHIP), DESCRIPTOR).withName("index").materialise(0);
    when(indexProxy.getState()).thenReturn(InternalIndexState.ONLINE);
    when(indexProxy.getDescriptor()).thenReturn(descriptor);
    when(indexProxy.newTokenReader()).thenReturn(tokenReader);
    when(indexProxies.getIndexProxy(any())).thenReturn(indexProxy);
    int targetType = 1;
    int notTargetType = 2;
    int[] indexedTypes = { targetType };
    String targetPropertyKey = "key";
    String notTargetPropertyKey = "not-key";
    Value propertyValue = Values.stringValue("value");
    MutableLongList relationshipsWithTargetType = LongLists.mutable.empty();
    long id = 0;
    int wantedPropertyUpdates = 5;
    for (int i = 0; i < wantedPropertyUpdates; i++) {
        // Relationships that are indexed
        cursors.withRelationship(id, 1, targetType, 3).properties(targetPropertyKey, propertyValue);
        tokenReader.index(indexedTypes, id);
        relationshipsWithTargetType.add(id++);
        // Relationship with wrong property
        cursors.withRelationship(id++, 1, targetType, 3).properties(notTargetPropertyKey, propertyValue);
        // Relationship with wrong type
        cursors.withRelationship(id++, 1, notTargetType, 3).properties(targetPropertyKey, propertyValue);
    }
    // When
    DynamicIndexStoreView storeView = dynamicIndexStoreView(cursors, indexProxies);
    TestTokenScanConsumer tokenConsumer = new TestTokenScanConsumer();
    TestPropertyScanConsumer propertyScanConsumer = new TestPropertyScanConsumer();
    StoreScan storeScan = storeView.visitRelationships(indexedTypes, relationType -> true, propertyScanConsumer, tokenConsumer, false, true, NULL, INSTANCE);
    storeScan.run(StoreScan.NO_EXTERNAL_UPDATES);
    // Then make sure all the fitting relationships where included
    assertThat(propertyScanConsumer.batches.size()).isEqualTo(1);
    assertThat(propertyScanConsumer.batches.get(0).size()).isEqualTo(wantedPropertyUpdates);
    // and that we didn't visit any more relationships than what we would get from scan store
    assertThat(tokenConsumer.batches.size()).isEqualTo(1);
    assertThat(tokenConsumer.batches.get(0).size()).isEqualTo(relationshipsWithTargetType.size());
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) Value(org.neo4j.values.storable.Value) IndexProxyProvider(org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) Test(org.junit.jupiter.api.Test)

Example 12 with StubStorageCursors

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

the class DynamicIndexStoreViewTest method shouldVisitAllRelationshipsWithoutTokenIndexes.

@Test
void shouldVisitAllRelationshipsWithoutTokenIndexes() {
    StubStorageCursors cursors = new StubStorageCursors().withoutTokenIndexes();
    IndexProxyProvider indexProxies = mock(IndexProxyProvider.class);
    int targetType = 1;
    int notTargetType = 2;
    int[] targetTypeArray = { targetType };
    String targetPropertyKey = "key";
    Value propertyValue = Values.stringValue("value");
    MutableLongList relationshipsWithTargetType = LongLists.mutable.empty();
    long id = 0;
    int wantedPropertyUpdates = 5;
    for (int i = 0; i < wantedPropertyUpdates; i++) {
        // Relationship fitting our target
        cursors.withRelationship(id, 1, targetType, 3).properties(targetPropertyKey, propertyValue);
        relationshipsWithTargetType.add(id++);
        // Relationship with different type
        cursors.withRelationship(id, 1, notTargetType, 3).properties(targetPropertyKey, propertyValue);
        relationshipsWithTargetType.add(id++);
    }
    int targetPropertyKeyId = cursors.propertyKeyTokenHolder().getIdByName(targetPropertyKey);
    IntPredicate propertyKeyIdFilter = value -> value == targetPropertyKeyId;
    DynamicIndexStoreView storeView = dynamicIndexStoreView(cursors, indexProxies);
    TestTokenScanConsumer tokenConsumer = new TestTokenScanConsumer();
    TestPropertyScanConsumer propertyScanConsumer = new TestPropertyScanConsumer();
    StoreScan storeScan = storeView.visitRelationships(targetTypeArray, propertyKeyIdFilter, propertyScanConsumer, tokenConsumer, false, true, NULL, INSTANCE);
    storeScan.run(StoreScan.NO_EXTERNAL_UPDATES);
    assertThat(tokenConsumer.batches.size()).isEqualTo(1);
    assertThat(tokenConsumer.batches.get(0).size()).isEqualTo(relationshipsWithTargetType.size());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexPrototype.forSchema(org.neo4j.internal.schema.IndexPrototype.forSchema) InternalIndexState(org.neo4j.internal.kernel.api.InternalIndexState) IndexProxyProvider(org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider) Predicates(org.neo4j.function.Predicates) LongLists(org.eclipse.collections.impl.factory.primitive.LongLists) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) Value(org.neo4j.values.storable.Value) NULL(org.neo4j.io.pagecache.tracing.PageCacheTracer.NULL) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) NullLogProvider(org.neo4j.logging.NullLogProvider) IntPredicate(java.util.function.IntPredicate) Supplier(java.util.function.Supplier) Values(org.neo4j.values.storable.Values) StorageReader(org.neo4j.storageengine.api.StorageReader) JobSchedulerFactory(org.neo4j.kernel.impl.scheduler.JobSchedulerFactory) JobScheduler(org.neo4j.scheduler.JobScheduler) Mockito.when(org.mockito.Mockito.when) RELATIONSHIP(org.neo4j.common.EntityType.RELATIONSHIP) NO_LOCKS(org.neo4j.kernel.impl.locking.Locks.NO_LOCKS) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) INSTANCE(org.neo4j.memory.EmptyMemoryTracker.INSTANCE) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) NO_LOCK_SERVICE(org.neo4j.lock.LockService.NO_LOCK_SERVICE) DESCRIPTOR(org.neo4j.kernel.impl.index.schema.TokenIndexProvider.DESCRIPTOR) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) NODE(org.neo4j.common.EntityType.NODE) SchemaDescriptor.forAnyEntityTokens(org.neo4j.internal.schema.SchemaDescriptor.forAnyEntityTokens) Mockito.mock(org.mockito.Mockito.mock) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) IntPredicate(java.util.function.IntPredicate) StoreScan(org.neo4j.kernel.impl.api.index.StoreScan) Value(org.neo4j.values.storable.Value) IndexProxyProvider(org.neo4j.kernel.impl.api.index.IndexingService.IndexProxyProvider) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) Test(org.junit.jupiter.api.Test)

Example 13 with StubStorageCursors

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

the class GenerateIndexUpdatesStepTest method shouldGenerateBothEntityTokenAndPropertyUpdates.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldGenerateBothEntityTokenAndPropertyUpdates(boolean alsoWrite) throws Exception {
    // given
    int numNodes = 10;
    StubStorageCursors data = someUniformData(numNodes);
    TestPropertyScanConsumer propertyScanConsumer = new TestPropertyScanConsumer();
    TestTokenScanConsumer tokenScanConsumer = new TestTokenScanConsumer();
    GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep<>(new SimpleStageControl(), DEFAULT, data, alwaysTrue(), new NodeCursorBehaviour(data), new int[] { LABEL }, propertyScanConsumer, tokenScanConsumer, 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(propertyScanConsumer.batches.size()).isEqualTo(1);
        assertThat(propertyScanConsumer.batches.get(0).size()).isEqualTo(numNodes);
        assertThat(tokenScanConsumer.batches.size()).isEqualTo(1);
        assertThat(tokenScanConsumer.batches.get(0).size()).isEqualTo(numNodes);
    } else {
        GeneratedIndexUpdates updates = sender.batches.get(0);
        updates.completeBatch();
        assertThat(propertyScanConsumer.batches.size()).isEqualTo(1);
        assertThat(propertyScanConsumer.batches.get(0).size()).isEqualTo(numNodes);
        assertThat(tokenScanConsumer.batches.size()).isEqualTo(1);
        assertThat(tokenScanConsumer.batches.get(0).size()).isEqualTo(numNodes);
    }
}
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 14 with StubStorageCursors

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

the class GenerateIndexUpdatesStepTest method shouldGenerateEntityPropertyUpdates.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldGenerateEntityPropertyUpdates(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);
    Set<TestPropertyScanConsumer.Record> expectedUpdates = new HashSet<>();
    try (StorageNodeCursor cursor = data.allocateNodeCursor(NULL);
        StoragePropertyCursor propertyCursor = data.allocatePropertyCursor(NULL, INSTANCE)) {
        cursor.scan();
        while (cursor.next()) {
            cursor.properties(propertyCursor);
            Map<Integer, Value> properties = new HashMap<>();
            while (propertyCursor.next()) {
                properties.put(propertyCursor.propertyKey(), propertyCursor.propertyValue());
            }
            expectedUpdates.add(new TestPropertyScanConsumer.Record(cursor.entityReference(), cursor.labels(), properties));
        }
    }
    // when
    CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
    step.process(allNodeIds(data), sender, NULL);
    // then
    if (alsoWrite) {
        for (TestPropertyScanConsumer.Record update : scanConsumer.batches.get(0)) {
            assertThat(expectedUpdates.remove(update)).isTrue();
        }
    } else {
        GeneratedIndexUpdates updates = sender.batches.get(0);
        updates.completeBatch();
        for (TestPropertyScanConsumer.Record update : scanConsumer.batches.get(0)) {
            assertThat(expectedUpdates.remove(update)).isTrue();
        }
    }
    assertThat(expectedUpdates).isEmpty();
}
Also used : SimpleStageControl(org.neo4j.internal.batchimport.staging.SimpleStageControl) StoragePropertyCursor(org.neo4j.storageengine.api.StoragePropertyCursor) HashMap(java.util.HashMap) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) Value(org.neo4j.values.storable.Value) Values.stringValue(org.neo4j.values.storable.Values.stringValue) Values.intValue(org.neo4j.values.storable.Values.intValue) 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)

Example 15 with StubStorageCursors

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

the class GenerateIndexUpdatesStepTest method shouldSendBatchesOverMaxByteSizeThreshold.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldSendBatchesOverMaxByteSizeThreshold(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, 100, alsoWrite, PageCacheTracer.NULL, INSTANCE);
    // when
    CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
    step.process(allNodeIds(data), sender, NULL);
    // then
    if (alsoWrite) {
        assertThat(scanConsumer.batches.size()).isGreaterThan(1);
        assertThat(sender.batches).isEmpty();
    } else {
        assertThat(scanConsumer.batches).isEmpty();
        assertThat(sender.batches.size()).isGreaterThan(1);
    }
}
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)

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