Search in sources :

Example 41 with MutableLong

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

the class GBPTreeTest method shouldRemapFileIfMappedWithPageSizeLargerThanCreationSize.

@Test
public void shouldRemapFileIfMappedWithPageSizeLargerThanCreationSize() throws Exception {
    // WHEN
    int pageSize = 1024;
    pageCache = createPageCache(pageSize);
    List<Long> expectedData = new ArrayList<>();
    for (long i = 0; i < 100; i++) {
        expectedData.add(i);
    }
    try (GBPTree<MutableLong, MutableLong> index = new GBPTree<>(pageCache, indexFile, layout, pageSize / 2, NO_MONITOR, NO_HEADER)) {
        // Insert some data
        try (Writer<MutableLong, MutableLong> writer = index.writer()) {
            MutableLong key = new MutableLong();
            MutableLong value = new MutableLong();
            for (Long insert : expectedData) {
                key.setValue(insert);
                value.setValue(insert);
                writer.put(key, value);
            }
        }
        index.checkpoint(IOLimiter.unlimited());
    }
    // THEN
    try (GBPTree<MutableLong, MutableLong> index = new GBPTree<>(pageCache, indexFile, layout, 0, NO_MONITOR, NO_HEADER)) {
        MutableLong fromInclusive = new MutableLong(0L);
        MutableLong toExclusive = new MutableLong(200L);
        try (RawCursor<Hit<MutableLong, MutableLong>, IOException> seek = index.seek(fromInclusive, toExclusive)) {
            int i = 0;
            while (seek.next()) {
                Hit<MutableLong, MutableLong> hit = seek.get();
                assertEquals(hit.key().getValue(), expectedData.get(i));
                assertEquals(hit.value().getValue(), expectedData.get(i));
                i++;
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableLong(org.apache.commons.lang3.mutable.MutableLong) Test(org.junit.Test)

Example 42 with MutableLong

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

the class GBPTreeTest method shouldAllowClosingWriterMultipleTimes.

@Test
public void shouldAllowClosingWriterMultipleTimes() throws Exception {
    // GIVEN
    index = createIndex(256);
    Writer<MutableLong, MutableLong> writer = index.writer();
    writer.put(new MutableLong(0), new MutableLong(1));
    writer.close();
    // WHEN
    writer.close();
// THEN that should be OK
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) Test(org.junit.Test)

Example 43 with MutableLong

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

the class GBPTreeTest method checkPointShouldLockOutWriter.

/* Check-pointing tests */
@Test
public void checkPointShouldLockOutWriter() throws Exception {
    // GIVEN
    CheckpointControlledMonitor monitor = new CheckpointControlledMonitor();
    index = createIndex(1024, monitor);
    long key = 10;
    try (Writer<MutableLong, MutableLong> writer = index.writer()) {
        writer.put(new MutableLong(key), new MutableLong(key));
    }
    // WHEN
    monitor.enabled = true;
    Thread checkpointer = new Thread(throwing(() -> index.checkpoint(IOLimiter.unlimited())));
    checkpointer.start();
    monitor.barrier.awaitUninterruptibly();
    // now we're in the smack middle of a checkpoint
    Thread t2 = new Thread(throwing(() -> index.writer().close()));
    t2.start();
    t2.join(200);
    assertTrue(Arrays.toString(checkpointer.getStackTrace()), t2.isAlive());
    monitor.barrier.release();
    // THEN
    t2.join();
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) Test(org.junit.Test)

Example 44 with MutableLong

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

the class InternalTreeLogicTest method shouldMergeValueInLeafAtParentKey.

@Test
public void shouldMergeValueInLeafAtParentKey() throws Exception {
    // GIVEN
    initialize();
    for (int i = 0; numberOfRootSplits == 0; i++) {
        insert(i, i);
    }
    // WHEN
    generationManager.checkpoint();
    long key = structurePropagation.rightKey.longValue();
    int toAdd = 5;
    insert(key, toAdd, ADDER);
    // THEN
    goTo(readCursor, rootId);
    long rightChild = childAt(readCursor, 1, stableGeneration, unstableGeneration);
    goTo(readCursor, rightChild);
    int searchResult = KeySearch.search(readCursor, node, key(key), new MutableLong(), keyCount());
    assertTrue(KeySearch.isHit(searchResult));
    int pos = KeySearch.positionOf(searchResult);
    assertEquals(0, 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 45 with MutableLong

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

the class InternalTreeLogicTest method remove.

private MutableLong remove(long key, MutableLong into) throws IOException {
    insertKey.setValue(key);
    MutableLong result = treeLogic.remove(cursor, structurePropagation, insertKey, into, stableGeneration, unstableGeneration);
    handleAfterChange();
    return result;
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong)

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