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());
}
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());
}
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());
}
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);
}
}
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);
}
Aggregations