Search in sources :

Example 1 with INTERNAL

use of org.neo4j.index.internal.gbptree.TreeNode.Type.INTERNAL in project neo4j by neo4j.

the class SeekCursorTestBase method shouldCatchupRootWhenNodeHasTooNewGenerationWhileTraversingLeaves.

@Test
void shouldCatchupRootWhenNodeHasTooNewGenerationWhileTraversingLeaves() throws Exception {
    // given
    MutableBoolean triggered = new MutableBoolean(false);
    // We don't care
    long oldRightChild = 666;
    // a newer right leaf
    long rightChild = cursor.getCurrentPageId();
    node.initializeLeaf(cursor, stableGeneration, unstableGeneration);
    cursor.next();
    RootCatchup rootCatchup = fromId -> {
        // Use right child as new start over root to terminate test
        cursor.next(rightChild);
        triggered.setTrue();
        return new Root(cursor.getCurrentPageId(), TreeNode.generation(cursor));
    };
    // a left leaf
    long leftChild = cursor.getCurrentPageId();
    node.initializeLeaf(cursor, stableGeneration - 1, unstableGeneration - 1);
    // with an old pointer to right sibling
    TreeNode.setRightSibling(cursor, rightChild, stableGeneration - 1, unstableGeneration - 1);
    cursor.next();
    // a root
    node.initializeInternal(cursor, stableGeneration - 1, unstableGeneration - 1);
    long keyInRoot = 10L;
    node.insertKeyAndRightChildAt(cursor, key(keyInRoot), oldRightChild, 0, 0, stableGeneration, unstableGeneration, NULL);
    TreeNode.setKeyCount(cursor, 1);
    // with old pointer to child (simulating reuse of internal node)
    node.setChildAt(cursor, leftChild, 0, stableGeneration, unstableGeneration);
    // when
    KEY from = key(1L);
    KEY to = key(20L);
    try (SeekCursor<KEY, VALUE> seek = new SeekCursor<>(cursor, node, from, to, layout, stableGeneration - 1, unstableGeneration - 1, generationSupplier, rootCatchup, unstableGeneration, exceptionDecorator, 1, LEAF_LEVEL, SeekCursor.NO_MONITOR, NULL)) {
        while (seek.next()) {
            seek.key();
        }
    }
    // then
    assertTrue(triggered.getValue());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) PageCursor(org.neo4j.io.pagecache.PageCursor) LongSupplier(java.util.function.LongSupplier) RandomExtension(org.neo4j.test.extension.RandomExtension) SHARED_RESOURCE(org.neo4j.test.extension.ExecutionSharedContext.SHARED_RESOURCE) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GenerationSafePointerPair.pointer(org.neo4j.index.internal.gbptree.GenerationSafePointerPair.pointer) ArrayList(java.util.ArrayList) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Inject(org.neo4j.test.extension.Inject) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) RandomRule(org.neo4j.test.rule.RandomRule) LEAF(org.neo4j.index.internal.gbptree.TreeNode.Type.LEAF) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DEFAULT_MAX_READ_AHEAD(org.neo4j.index.internal.gbptree.SeekCursor.DEFAULT_MAX_READ_AHEAD) IOException(java.io.IOException) LEAF_LEVEL(org.neo4j.index.internal.gbptree.SeekCursor.LEAF_LEVEL) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock) String.format(java.lang.String.format) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) List(java.util.List) INTERNAL(org.neo4j.index.internal.gbptree.TreeNode.Type.INTERNAL) ValueMergers.overwrite(org.neo4j.index.internal.gbptree.ValueMergers.overwrite) DelegatingPageCursor(org.neo4j.io.pagecache.impl.DelegatingPageCursor) NO_MONITOR(org.neo4j.index.internal.gbptree.GBPTree.NO_MONITOR) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) Collections(java.util.Collections) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) Test(org.junit.jupiter.api.Test)

Aggregations

IOException (java.io.IOException)1 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Consumer (java.util.function.Consumer)1 LongSupplier (java.util.function.LongSupplier)1 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 ResourceLock (org.junit.jupiter.api.parallel.ResourceLock)1 NO_MONITOR (org.neo4j.index.internal.gbptree.GBPTree.NO_MONITOR)1