Search in sources :

Example 21 with StorageNodeCursor

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

the class RecordStorageReaderRelTypesAndDegreeTest method testDegreesForDenseNodeWithPartiallyDeletedRelGroupChain.

protected void testDegreesForDenseNodeWithPartiallyDeletedRelGroupChain(TestRelType... typesToDelete) throws Exception {
    int inRelCount = randomRelCount();
    int outRelCount = randomRelCount();
    int loopRelCount = randomRelCount();
    long nodeId = createNode(inRelCount, outRelCount, loopRelCount);
    StorageNodeCursor cursor = newCursor(nodeId);
    for (TestRelType type : typesToDelete) {
        markRelGroupNotInUse(nodeId, type);
        switch(type) {
            case IN:
                inRelCount = 0;
                break;
            case OUT:
                outRelCount = 0;
                break;
            case LOOP:
                loopRelCount = 0;
                break;
            default:
                throw new IllegalArgumentException("Unknown type: " + type);
        }
    }
    Set<TestDegreeItem> expectedDegrees = new HashSet<>();
    if (outRelCount != 0) {
        expectedDegrees.add(new TestDegreeItem(relTypeId(OUT), outRelCount, 0));
    }
    if (inRelCount != 0) {
        expectedDegrees.add(new TestDegreeItem(relTypeId(IN), 0, inRelCount));
    }
    if (loopRelCount != 0) {
        expectedDegrees.add(new TestDegreeItem(relTypeId(LOOP), loopRelCount, loopRelCount));
    }
    Set<TestDegreeItem> actualDegrees = degrees(cursor);
    assertEquals(expectedDegrees, actualDegrees);
}
Also used : StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) HashSet(java.util.HashSet)

Example 22 with StorageNodeCursor

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

the class RecordStorageReaderRelTypesAndDegreeTest method newCursor.

protected StorageNodeCursor newCursor(long nodeId) {
    StorageNodeCursor nodeCursor = storageReader.allocateNodeCursor(NULL);
    nodeCursor.single(nodeId);
    assertTrue(nodeCursor.next());
    return nodeCursor;
}
Also used : StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor)

Example 23 with StorageNodeCursor

use of org.neo4j.storageengine.api.StorageNodeCursor 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 24 with StorageNodeCursor

use of org.neo4j.storageengine.api.StorageNodeCursor 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 25 with StorageNodeCursor

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

StorageNodeCursor (org.neo4j.storageengine.api.StorageNodeCursor)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 StubStorageCursors (org.neo4j.storageengine.api.StubStorageCursors)12 Test (org.junit.jupiter.api.Test)8 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 StoragePropertyCursor (org.neo4j.storageengine.api.StoragePropertyCursor)5 HashSet (java.util.HashSet)4 Value (org.neo4j.values.storable.Value)3 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)2 EntityUpdates (org.neo4j.storageengine.api.EntityUpdates)2 Values.intValue (org.neo4j.values.storable.Values.intValue)2 Values.stringValue (org.neo4j.values.storable.Values.stringValue)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)1