Search in sources :

Example 1 with MutableLong

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)));
    }
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) CursorException(org.neo4j.io.pagecache.CursorException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) PageCursor(org.neo4j.io.pagecache.PageCursor) Test(org.junit.Test)

Example 2 with MutableLong

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"));
    }
}
Also used : PageCursor(org.neo4j.io.pagecache.PageCursor) MutableLong(org.apache.commons.lang3.mutable.MutableLong) Test(org.junit.Test)

Example 3 with MutableLong

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);
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) Test(org.junit.Test)

Example 4 with MutableLong

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())));
        }
    }
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with MutableLong

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());
    }
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

MutableLong (org.apache.commons.lang3.mutable.MutableLong)42 Test (org.junit.Test)33 IOException (java.io.IOException)10 PageCache (org.neo4j.io.pagecache.PageCache)4 File (java.io.File)3 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)3 PageCursor (org.neo4j.io.pagecache.PageCursor)3 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Random (java.util.Random)1 TreeMap (java.util.TreeMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ZipFile (java.util.zip.ZipFile)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)1 CursorException (org.neo4j.io.pagecache.CursorException)1 DelegatingPageCursor (org.neo4j.io.pagecache.impl.DelegatingPageCursor)1 Randoms (org.neo4j.test.Randoms)1 Group (org.neo4j.unsafe.impl.batchimport.input.Group)1