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());
}
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();
}
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);
}
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);
}
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();
}
}
}
}
}
}
}
Aggregations