Search in sources :

Example 11 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 12 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 13 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)

Example 14 with MutableLong

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

the class GBPTreeTest method shouldReturnNoResultsOnEmptyIndex.

@Test
public void shouldReturnNoResultsOnEmptyIndex() throws Exception {
    // GIVEN
    index = createIndex(256);
    // WHEN
    RawCursor<Hit<MutableLong, MutableLong>, IOException> result = index.seek(new MutableLong(0), new MutableLong(10));
    // THEN
    assertFalse(result.next());
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) IOException(java.io.IOException) Test(org.junit.Test)

Example 15 with MutableLong

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

the class GBPTreeTest method shouldCheckpointOnCloseAfterChangesHappened.

@Test
public void shouldCheckpointOnCloseAfterChangesHappened() 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));
    }
    // THEN
    closeIndex();
    assertEquals(countBefore + 1, checkpointCounter.count);
}
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