Search in sources :

Example 6 with StoragePropertyCursor

use of org.neo4j.storageengine.api.StoragePropertyCursor 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)

Aggregations

StoragePropertyCursor (org.neo4j.storageengine.api.StoragePropertyCursor)6 StorageNodeCursor (org.neo4j.storageengine.api.StorageNodeCursor)5 Test (org.junit.jupiter.api.Test)2 Value (org.neo4j.values.storable.Value)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1 SimpleStageControl (org.neo4j.internal.batchimport.staging.SimpleStageControl)1 TokenRead (org.neo4j.internal.kernel.api.TokenRead)1 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)1 GeneratedIndexUpdates (org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates)1 Lock (org.neo4j.lock.Lock)1 EntityUpdates (org.neo4j.storageengine.api.EntityUpdates)1 StorageReader (org.neo4j.storageengine.api.StorageReader)1 StubStorageCursors (org.neo4j.storageengine.api.StubStorageCursors)1 Values.intValue (org.neo4j.values.storable.Values.intValue)1 Values.stringValue (org.neo4j.values.storable.Values.stringValue)1