Search in sources :

Example 56 with MutableLong

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

the class InternalTreeLogicTest method shouldMergeValueInLeafBetweenTwoParentKeys.

@Test
public void shouldMergeValueInLeafBetweenTwoParentKeys() throws Exception {
    // GIVEN
    initialize();
    long firstSplitPrimKey = -1;
    for (int i = 0; numberOfRootSplits == 0 || keyCount(rootId) < 1; i++) {
        insert(i, i);
        if (firstSplitPrimKey == -1 && numberOfRootSplits == 1) {
            firstSplitPrimKey = structurePropagation.rightKey.longValue();
        }
    }
    // WHEN
    generationManager.checkpoint();
    long key = firstSplitPrimKey + 1;
    int toAdd = 5;
    insert(key, toAdd, ADDER);
    // THEN
    goTo(readCursor, rootId);
    long middle = childAt(readCursor, 1, stableGeneration, unstableGeneration);
    goTo(readCursor, middle);
    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());
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) Test(org.junit.Test)

Example 57 with MutableLong

use of org.apache.commons.lang3.mutable.MutableLong in project apex-malhar by apache.

the class WEQueryQueueManagerTest method testSimpleRemoveEmpty.

@Test
public void testSimpleRemoveEmpty() {
    WindowEndQueueManager<Query, Void> wqqm = new WindowEndQueueManager<>();
    wqqm.setup(null);
    wqqm.beginWindow(0);
    QueryBundle<Query, Void, MutableLong> qb = wqqm.dequeue();
    Query queryD = qb == null ? null : qb.getQuery();
    Assert.assertEquals("The queries must match.", null, queryD);
    qb = wqqm.dequeue();
    queryD = qb == null ? null : qb.getQuery();
    Assert.assertEquals("The queries must match.", null, queryD);
    wqqm.endWindow();
    wqqm.teardown();
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) Query(org.apache.apex.malhar.lib.appdata.schemas.Query) Test(org.junit.Test)

Example 58 with MutableLong

use of org.apache.commons.lang3.mutable.MutableLong in project apex-malhar by apache.

the class WEQueryQueueManagerTest method testSimpleAddAfterStarted.

@Test
public void testSimpleAddAfterStarted() {
    WindowEndQueueManager<Query, Void> wqqm = new WindowEndQueueManager<>();
    wqqm.setup(null);
    wqqm.beginWindow(0);
    Query query = new MockQuery("0");
    wqqm.enqueue(query, null, new MutableLong(1L));
    Query query1 = new MockQuery("1");
    wqqm.enqueue(query1, null, new MutableLong(1L));
    Query queryD = wqqm.dequeue().getQuery();
    Query query2 = new MockQuery("2");
    wqqm.enqueue(query2, null, new MutableLong(1L));
    Query query1D = wqqm.dequeue().getQuery();
    Query query2D = wqqm.dequeue().getQuery();
    QueryBundle<Query, Void, MutableLong> qb = wqqm.dequeue();
    Query query3D = qb == null ? null : qb.getQuery();
    wqqm.endWindow();
    wqqm.teardown();
    Assert.assertEquals("The queries must match.", query, queryD);
    Assert.assertEquals("The queries must match.", query1, query1D);
    Assert.assertEquals("The queries must match.", query2, query2D);
    Assert.assertEquals("The queries must match.", null, query3D);
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) Query(org.apache.apex.malhar.lib.appdata.schemas.Query) Test(org.junit.Test)

Example 59 with MutableLong

use of org.apache.commons.lang3.mutable.MutableLong in project apex-malhar by apache.

the class WEQueryQueueManagerTest method testSimpleAddOneRemove.

@Test
public void testSimpleAddOneRemove() {
    WindowEndQueueManager<Query, Void> wqqm = new WindowEndQueueManager<>();
    wqqm.setup(null);
    wqqm.beginWindow(0);
    Query query = new MockQuery("1");
    wqqm.enqueue(query, null, new MutableLong(1L));
    Query queryD = wqqm.dequeue().getQuery();
    QueryBundle<Query, Void, MutableLong> qb = wqqm.dequeue();
    Query queryD1 = qb == null ? null : qb.getQuery();
    wqqm.endWindow();
    wqqm.teardown();
    Assert.assertEquals("The queries must match.", query, queryD);
    Assert.assertEquals("The queries must match.", null, queryD1);
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) Query(org.apache.apex.malhar.lib.appdata.schemas.Query) Test(org.junit.Test)

Example 60 with MutableLong

use of org.apache.commons.lang3.mutable.MutableLong in project apex-malhar by apache.

the class StateTracker method run.

@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
@Override
public void run() {
    synchronized (managedStateImpl.commitLock) {
        // freeing of state needs to be stopped during commit as commit results in transferring data to a state which
        // can be freed up as well.
        long bytesSum = 0;
        for (Bucket bucket : managedStateImpl.buckets.values()) {
            if (bucket != null) {
                bytesSum += bucket.getSizeInBytes();
            }
        }
        if (bytesSum > managedStateImpl.getMaxMemorySize()) {
            Duration duration = managedStateImpl.getDurationPreventingFreeingSpace();
            long durationMillis = 0;
            if (duration != null) {
                durationMillis = duration.getMillis();
            }
            synchronized (bucketLastAccess) {
                long now = System.currentTimeMillis();
                for (Iterator<Map.Entry<Long, MutableLong>> iterator = bucketLastAccess.entrySet().iterator(); bytesSum > managedStateImpl.getMaxMemorySize() && iterator.hasNext(); ) {
                    Map.Entry<Long, MutableLong> entry = iterator.next();
                    if (now - entry.getValue().longValue() < durationMillis) {
                        break;
                    }
                    long bucketId = entry.getKey();
                    Bucket bucket = managedStateImpl.getBucket(bucketId);
                    if (bucket != null) {
                        synchronized (bucket) {
                            long sizeFreed;
                            try {
                                sizeFreed = bucket.freeMemory(managedStateImpl.getCheckpointManager().getLastTransferredWindow());
                            } catch (IOException e) {
                                managedStateImpl.throwable.set(e);
                                throw new RuntimeException("freeing " + bucketId, e);
                            }
                            bytesSum -= sizeFreed;
                        }
                        if (bucket.getSizeInBytes() == 0) {
                            iterator.remove();
                        }
                    }
                }
            }
        }
    }
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableLong(org.apache.commons.lang3.mutable.MutableLong) Duration(org.joda.time.Duration) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

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