use of org.apache.commons.lang3.mutable.MutableBoolean in project sling by apache.
the class PollingTest method testCallTwice.
@Test
public void testCallTwice() throws Exception {
final MutableInt callCount = new MutableInt(0);
final MutableBoolean called = new MutableBoolean(false);
Polling p = new Polling() {
@Override
public Boolean call() throws Exception {
callCount.increment();
boolean b = called.booleanValue();
called.setTrue();
return b;
}
};
p.poll(500, 10);
assertEquals(2, callCount.intValue());
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project sling by apache.
the class PollingTest method testCallableTwice.
@Test
public void testCallableTwice() throws Exception {
final MutableInt callCount = new MutableInt(0);
final MutableBoolean called = new MutableBoolean(false);
Polling p = new Polling(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
callCount.increment();
boolean b = called.booleanValue();
called.setTrue();
return b;
}
});
p.poll(500, 10);
assertEquals(2, callCount.intValue());
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.
the class RunnableBoltWorkerTest method runDoesNothingAfterHalt.
@Test
public void runDoesNothingAfterHalt() {
RunnableBoltWorker worker = new RunnableBoltWorker(machine, logService);
MutableBoolean jobWasExecuted = new MutableBoolean();
worker.enqueue(machine1 -> {
jobWasExecuted.setTrue();
fail("Should not be executed");
});
worker.halt();
worker.run();
assertFalse(jobWasExecuted.booleanValue());
verify(machine).close();
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.
the class ShortestPath method internalPaths.
private Iterable<Path> internalPaths(Node start, Node end, boolean stopAsap) {
lastMetadata = new Metadata();
if (start.equals(end)) {
return filterPaths(Collections.singletonList(PathImpl.singular(start)));
}
Hits hits = new Hits();
Collection<Long> sharedVisitedRels = new HashSet<>();
// ShortestPathLengthSoFar
MutableInt sharedFrozenDepth = new MutableInt(NULL);
MutableBoolean sharedStop = new MutableBoolean();
MutableInt sharedCurrentDepth = new MutableInt(0);
final DirectionData startData = new DirectionData(start, sharedVisitedRels, sharedFrozenDepth, sharedStop, sharedCurrentDepth, expander);
final DirectionData endData = new DirectionData(end, sharedVisitedRels, sharedFrozenDepth, sharedStop, sharedCurrentDepth, expander.reverse());
while (startData.hasNext() || endData.hasNext()) {
goOneStep(startData, endData, hits, startData, stopAsap);
goOneStep(endData, startData, hits, startData, stopAsap);
}
Collection<Hit> least = hits.least();
return least != null ? filterPaths(hitsToPaths(least, start, end, stopAsap)) : Collections.<Path>emptyList();
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.
the class SeekCursorTest method shouldCatchupRootWhenNodeHasTooNewGenerationWhileTraversingLeaves.
@Test
public void shouldCatchupRootWhenNodeHasTooNewGenerationWhileTraversingLeaves() throws Exception {
// given
MutableBoolean triggered = new MutableBoolean(false);
// a newer right leaf
long rightChild = cursor.getCurrentPageId();
node.initializeLeaf(cursor, stableGeneration, unstableGeneration);
cursor.next();
Supplier<Root> rootCatchup = () -> {
try {
// Use right child as new start over root to terminate test
cursor.next(rightChild);
triggered.setTrue();
return new Root(cursor.getCurrentPageId(), node.generation(cursor));
} catch (IOException e) {
throw new RuntimeException(e);
}
};
// a left leaf
long leftChild = cursor.getCurrentPageId();
node.initializeLeaf(cursor, stableGeneration - 1, unstableGeneration - 1);
// with an old pointer to right sibling
node.setRightSibling(cursor, rightChild, stableGeneration - 1, unstableGeneration - 1);
cursor.next();
// a root
node.initializeInternal(cursor, stableGeneration - 1, unstableGeneration - 1);
long keyInRoot = 10L;
insertKey.setValue(keyInRoot);
node.insertKeyAt(cursor, insertKey, 0, 0);
node.setKeyCount(cursor, 1);
// with old pointer to child (simulating reuse of internal node)
node.setChildAt(cursor, leftChild, 0, stableGeneration, unstableGeneration);
// when
from.setValue(1L);
to.setValue(20L);
try (SeekCursor<MutableLong, MutableLong> seek = new SeekCursor<>(cursor, node, from, to, layout, stableGeneration - 1, unstableGeneration - 1, generationSupplier, rootCatchup, unstableGeneration)) {
while (seek.next()) {
seek.get();
}
}
// then
assertTrue(triggered.getValue());
}
Aggregations