use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.
the class ConsistencyCheckerTest method shouldThrowDescriptiveExceptionOnBrokenGSPP.
@Test
public void shouldThrowDescriptiveExceptionOnBrokenGSPP() throws Exception {
// GIVEN
int pageSize = 256;
PageCursor cursor = new PageAwareByteArrayCursor(pageSize);
Layout<MutableLong, MutableLong> layout = new SimpleLongLayout();
TreeNode<MutableLong, MutableLong> treeNode = new TreeNode<>(pageSize, layout);
long stableGeneration = MIN_GENERATION;
long crashGeneration = stableGeneration + 1;
long unstableGeneration = stableGeneration + 2;
String pointerFieldName = "abc";
long pointer = 123;
cursor.next(0);
treeNode.initializeInternal(cursor, stableGeneration, crashGeneration);
treeNode.setSuccessor(cursor, pointer, stableGeneration, crashGeneration);
// WHEN
try {
assertNoCrashOrBrokenPointerInGSPP(cursor, stableGeneration, unstableGeneration, pointerFieldName, TreeNode.BYTE_POS_SUCCESSOR, treeNode);
cursor.checkAndClearCursorException();
fail("Should have failed");
} catch (CursorException e) {
// THEN
assertThat(e.getMessage(), containsString(pointerFieldName));
assertThat(e.getMessage(), containsString(pointerFieldName));
assertThat(e.getMessage(), containsString("state=CRASH"));
assertThat(e.getMessage(), containsString("state=EMPTY"));
assertThat(e.getMessage(), containsString(String.valueOf(pointer)));
}
}
use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.
the class ConsistencyCheckerTest method shouldDetectUnusedPages.
@Test
public void shouldDetectUnusedPages() throws Exception {
// GIVEN
int pageSize = 256;
Layout<MutableLong, MutableLong> layout = new SimpleLongLayout();
TreeNode<MutableLong, MutableLong> node = new TreeNode<>(pageSize, layout);
long stableGeneration = GenerationSafePointer.MIN_GENERATION;
long unstableGeneration = stableGeneration + 1;
SimpleIdProvider idProvider = new SimpleIdProvider();
InternalTreeLogic<MutableLong, MutableLong> logic = new InternalTreeLogic<>(idProvider, node, layout);
PageCursor cursor = new PageAwareByteArrayCursor(pageSize);
cursor.next(idProvider.acquireNewId(stableGeneration, unstableGeneration));
node.initializeLeaf(cursor, stableGeneration, unstableGeneration);
logic.initialize(cursor);
StructurePropagation<MutableLong> structure = new StructurePropagation<>(layout.newKey(), layout.newKey(), layout.newKey());
MutableLong key = layout.newKey();
for (int g = 0, k = 0; g < 3; g++) {
for (int i = 0; i < 100; i++, k++) {
key.setValue(k);
logic.insert(cursor, structure, key, key, ValueMergers.overwrite(), stableGeneration, unstableGeneration);
if (structure.hasRightKeyInsert) {
goTo(cursor, "new root", idProvider.acquireNewId(stableGeneration, unstableGeneration));
node.initializeInternal(cursor, stableGeneration, unstableGeneration);
node.insertKeyAt(cursor, structure.rightKey, 0, 0);
node.setKeyCount(cursor, 1);
node.setChildAt(cursor, structure.midChild, 0, stableGeneration, unstableGeneration);
node.setChildAt(cursor, structure.rightChild, 1, stableGeneration, unstableGeneration);
logic.initialize(cursor);
}
if (structure.hasMidChildUpdate) {
logic.initialize(cursor);
}
structure.clear();
}
stableGeneration = unstableGeneration;
unstableGeneration++;
}
// WHEN
ConsistencyChecker<MutableLong> cc = new ConsistencyChecker<>(node, layout, stableGeneration, unstableGeneration);
try {
cc.checkSpace(cursor, idProvider.lastId(), PrimitiveLongCollections.emptyIterator());
fail("Should have failed");
} catch (RuntimeException e) {
// THEN good
assertThat(e.getMessage(), containsString("unused pages"));
}
}
use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.
the class GBPTreeTest method shouldNotCheckpointOnCloseIfNoChangesHappened.
@Test
public void shouldNotCheckpointOnCloseIfNoChangesHappened() throws Exception {
// GIVEN
CheckpointCounter checkpointCounter = new CheckpointCounter();
// WHEN
GBPTree<MutableLong, MutableLong> index = createIndex(256, checkpointCounter);
int countBefore = checkpointCounter.count;
try (Writer<MutableLong, MutableLong> writer = index.writer()) {
writer.put(new MutableLong(0), new MutableLong(1));
}
index.checkpoint(IOLimiter.unlimited());
assertEquals(countBefore + 1, checkpointCounter.count);
// THEN
closeIndex();
assertEquals(countBefore + 1, checkpointCounter.count);
}
use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.
the class GBPTreeTest method shouldSplitCorrectly.
/* Randomized tests */
@Test
public void shouldSplitCorrectly() throws Exception {
// GIVEN
GBPTree<MutableLong, MutableLong> index = createIndex(256);
// WHEN
int count = 1_000;
PrimitiveLongSet seen = Primitive.longSet(count);
try (Writer<MutableLong, MutableLong> writer = index.writer()) {
for (int i = 0; i < count; i++) {
MutableLong key;
do {
key = new MutableLong(random.nextInt(100_000));
} while (!seen.add(key.longValue()));
MutableLong value = new MutableLong(i);
writer.put(key, value);
seen.add(key.longValue());
}
}
// THEN
try (RawCursor<Hit<MutableLong, MutableLong>, IOException> cursor = index.seek(new MutableLong(0), new MutableLong(Long.MAX_VALUE))) {
long prev = -1;
while (cursor.next()) {
MutableLong hit = cursor.get().key();
if (hit.longValue() < prev) {
fail(hit + " smaller than prev " + prev);
}
prev = hit.longValue();
assertTrue(seen.remove(hit.longValue()));
}
if (!seen.isEmpty()) {
fail("expected hits " + Arrays.toString(PrimitiveLongCollections.asArray(seen.iterator())));
}
}
}
use of org.apache.commons.lang3.mutable.MutableLong in project neo4j by neo4j.
the class GBPTreeTest method shouldSeeSimpleInsertions.
/* Insertion and read tests */
@Test
public void shouldSeeSimpleInsertions() throws Exception {
index = createIndex(256);
int count = 1000;
try (Writer<MutableLong, MutableLong> writer = index.writer()) {
for (int i = 0; i < count; i++) {
writer.put(new MutableLong(i), new MutableLong(i));
}
}
try (RawCursor<Hit<MutableLong, MutableLong>, IOException> cursor = index.seek(new MutableLong(0), new MutableLong(Long.MAX_VALUE))) {
for (int i = 0; i < count; i++) {
assertTrue(cursor.next());
assertEquals(i, cursor.get().key().longValue());
}
assertFalse(cursor.next());
}
}
Aggregations