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());
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.
the class SeekCursorTest method shouldCatchupRootWhenRootNodeHasTooNewGeneration.
@Test
public void shouldCatchupRootWhenRootNodeHasTooNewGeneration() throws Exception {
// given
long id = cursor.getCurrentPageId();
long generation = node.generation(cursor);
MutableBoolean triggered = new MutableBoolean(false);
Supplier<Root> rootCatchup = () -> {
triggered.setTrue();
return new Root(id, generation);
};
// when
try (SeekCursor<MutableLong, MutableLong> seek = new SeekCursor<>(cursor, node, from, to, layout, stableGeneration, unstableGeneration, generationSupplier, rootCatchup, generation - 1)) {
// do nothing
}
// then
assertTrue(triggered.getValue());
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.
the class QueryTranslator method asyncCreateAndRunJob.
private void asyncCreateAndRunJob(IHyracksClientConnection hcc, IStatementCompiler compiler, IMetadataLocker locker, ResultDelivery resultDelivery, String clientContextId, IStatementExecutorContext ctx, ResultSetId resultSetId, MutableBoolean printed) {
Mutable<JobId> jobId = new MutableObject<>(JobId.INVALID);
try {
createAndRunJob(hcc, jobId, compiler, locker, resultDelivery, id -> {
final ResultHandle handle = new ResultHandle(id, resultSetId);
ResultUtil.printStatus(sessionOutput, AbstractQueryApiServlet.ResultStatus.RUNNING);
ResultUtil.printResultHandle(sessionOutput, handle);
synchronized (printed) {
printed.setTrue();
printed.notify();
}
}, clientContextId, ctx);
} catch (Exception e) {
if (JobId.INVALID.equals(jobId.getValue())) {
// compilation failed
ResultUtil.printStatus(sessionOutput, AbstractQueryApiServlet.ResultStatus.FAILED);
ResultUtil.printError(sessionOutput.out(), e);
} else {
GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, resultDelivery.name() + " job with id " + jobId.getValue() + " " + "failed", e);
}
} finally {
synchronized (printed) {
if (printed.isFalse()) {
printed.setTrue();
printed.notify();
}
}
}
}
Aggregations