Search in sources :

Example 46 with MutableLong

use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.

the class InternalTreeLogicTest method shouldMergeValueInLeafLeftOfParentKey.

@Test
public void shouldMergeValueInLeafLeftOfParentKey() throws Exception {
    // GIVEN
    initialize();
    for (int i = 0; numberOfRootSplits == 0; i++) {
        insert(i, i);
    }
    // WHEN
    generationManager.checkpoint();
    long key = 1;
    int toAdd = 5;
    insert(key, toAdd, ADDER);
    // THEN
    goTo(readCursor, structurePropagation.midChild);
    int searchResult = KeySearch.search(readCursor, node, key(key), new MutableLong(), keyCount());
    assertTrue(KeySearch.isHit(searchResult));
    int pos = KeySearch.positionOf(searchResult);
    assertEquals(1, pos);
    assertEquals(key, keyAt(pos).longValue());
    assertEquals(key + toAdd, valueAt(pos).longValue());
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) Test(org.junit.Test)

Example 47 with MutableLong

use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.

the class SeekCursorTest method mustNotContinueToSecondLeafAfterFindingEndOfRangeInFirst.

@Test
public void mustNotContinueToSecondLeafAfterFindingEndOfRangeInFirst() throws Exception {
    AtomicBoolean nextCalled = new AtomicBoolean();
    PageCursor pageCursorSpy = new DelegatingPageCursor(cursor) {

        @Override
        public boolean next(long pageId) throws IOException {
            nextCalled.set(true);
            return super.next(pageId);
        }
    };
    // GIVEN
    int i = 0;
    while (i < maxKeyCount * 2) {
        if (i == maxKeyCount) {
            createRightSibling(pageCursorSpy);
        }
        append(i);
        i++;
    }
    int fromInclusive = maxKeyCount * 2 - 1;
    int toExclusive = maxKeyCount;
    // Reset
    nextCalled.set(false);
    // WHEN
    try (SeekCursor<MutableLong, MutableLong> cursor = seekCursor(fromInclusive, toExclusive, pageCursorSpy)) {
        // THEN
        assertRangeInSingleLeaf(fromInclusive, toExclusive, cursor);
    }
    assertFalse("Cursor continued to next leaf even though end of range is within first leaf", nextCalled.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MutableLong(org.apache.commons.lang3.mutable.MutableLong) DelegatingPageCursor(org.neo4j.io.pagecache.impl.DelegatingPageCursor) PageCursor(org.neo4j.io.pagecache.PageCursor) DelegatingPageCursor(org.neo4j.io.pagecache.impl.DelegatingPageCursor) Test(org.junit.Test)

Example 48 with MutableLong

use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.

the class SeekCursorTest method shouldCatchupRootWhenNodeHasTooNewGenerationWhileTraversingLeaves.

@Test
public void shouldCatchupRootWhenNodeHasTooNewGenerationWhileTraversingLeaves() throws Exception {
    // given
    MutableBoolean triggered = new MutableBoolean(false);
    // a newer right leaf
    long rightChild = cursor.getCurrentPageId();
    node.initializeLeaf(cursor, stableGeneration, unstableGeneration);
    cursor.next();
    Supplier<Root> rootCatchup = () -> {
        try {
            // Use right child as new start over root to terminate test
            cursor.next(rightChild);
            triggered.setTrue();
            return new Root(cursor.getCurrentPageId(), node.generation(cursor));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    };
    // a left leaf
    long leftChild = cursor.getCurrentPageId();
    node.initializeLeaf(cursor, stableGeneration - 1, unstableGeneration - 1);
    // with an old pointer to right sibling
    node.setRightSibling(cursor, rightChild, stableGeneration - 1, unstableGeneration - 1);
    cursor.next();
    // a root
    node.initializeInternal(cursor, stableGeneration - 1, unstableGeneration - 1);
    long keyInRoot = 10L;
    insertKey.setValue(keyInRoot);
    node.insertKeyAt(cursor, insertKey, 0, 0);
    node.setKeyCount(cursor, 1);
    // with old pointer to child (simulating reuse of internal node)
    node.setChildAt(cursor, leftChild, 0, stableGeneration, unstableGeneration);
    // when
    from.setValue(1L);
    to.setValue(20L);
    try (SeekCursor<MutableLong, MutableLong> seek = new SeekCursor<>(cursor, node, from, to, layout, stableGeneration - 1, unstableGeneration - 1, generationSupplier, rootCatchup, unstableGeneration)) {
        while (seek.next()) {
            seek.get();
        }
    }
    // then
    assertTrue(triggered.getValue());
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) IOException(java.io.IOException) Test(org.junit.Test)

Example 49 with MutableLong

use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.

the class SeekCursorTest method mustRereadHeadersOnRetry.

@Test
public void mustRereadHeadersOnRetry() throws Exception {
    // GIVEN
    int keyCount = maxKeyCount - 1;
    insertKeysAndValues(keyCount);
    MutableLong from = layout.newKey();
    MutableLong to = layout.newKey();
    from.setValue(2);
    // +1 because we're adding one more down below
    to.setValue(keyCount + 1);
    // WHEN
    try (SeekCursor<MutableLong, MutableLong> cursor = new SeekCursor<>(this.cursor, node, from, to, layout, stableGeneration, unstableGeneration, () -> 0L, failingRootCatchup, unstableGeneration)) {
        // reading a couple of keys
        assertTrue(cursor.next());
        assertEquals(2, cursor.get().key().longValue());
        assertTrue(cursor.next());
        assertEquals(3, cursor.get().key().longValue());
        // and WHEN a change happens
        append(keyCount);
        this.cursor.forceRetry();
        // THEN at least keyCount should be re-read on next()
        assertTrue(cursor.next());
        // and the new key should be found in the end as well
        assertEquals(4, cursor.get().key().longValue());
        long lastFoundKey = 4;
        while (cursor.next()) {
            assertEquals(lastFoundKey + 1, cursor.get().key().longValue());
            lastFoundKey = cursor.get().key().longValue();
        }
        assertEquals(keyCount, lastFoundKey);
    }
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) Test(org.junit.Test)

Example 50 with MutableLong

use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.

the class SeekCursorTest method mustStartReadingFromCorrectLeafWhenRangeStartWithKeyEqualToPrimKeyBackwards.

@Test
public void mustStartReadingFromCorrectLeafWhenRangeStartWithKeyEqualToPrimKeyBackwards() throws Exception {
    // given
    for (int i = 0; i < maxKeyCount + 1; i++) {
        insert(i);
    }
    MutableLong primKey = layout.newKey();
    node.keyAt(cursor, primKey, 0);
    long expectedNext = primKey.longValue();
    long rightChild = GenerationSafePointerPair.pointer(node.childAt(cursor, 1, stableGeneration, unstableGeneration));
    // when
    try (SeekCursor<MutableLong, MutableLong> seek = seekCursor(expectedNext, -1)) {
        assertEquals(rightChild, cursor.getCurrentPageId());
        while (seek.next()) {
            assertKeyAndValue(seek, expectedNext);
            expectedNext--;
        }
    }
    // then
    assertEquals(-1, expectedNext);
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) Test(org.junit.Test)

Aggregations

MutableLong (org.apache.commons.lang3.mutable.MutableLong)66 Test (org.junit.Test)45 IOException (java.io.IOException)11 Query (org.apache.apex.malhar.lib.appdata.schemas.Query)6 CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)5 PageCache (org.neo4j.io.pagecache.PageCache)4 File (java.io.File)3 Map (java.util.Map)3 KeyedWindowedOperatorImpl (org.apache.apex.malhar.lib.window.impl.KeyedWindowedOperatorImpl)3 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)3 ParseException (java.text.ParseException)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 ConsoleOutputOperator (org.apache.apex.malhar.lib.io.ConsoleOutputOperator)2 SpillableComplexComponentImpl (org.apache.apex.malhar.lib.state.spillable.SpillableComplexComponentImpl)2 Tuple (org.apache.apex.malhar.lib.window.Tuple)2 WindowOption (org.apache.apex.malhar.lib.window.WindowOption)2 WindowState (org.apache.apex.malhar.lib.window.WindowState)2 SumLong (org.apache.apex.malhar.lib.window.accumulation.SumLong)2 WindowedOperatorImpl (org.apache.apex.malhar.lib.window.impl.WindowedOperatorImpl)2