Search in sources :

Example 26 with MutableBoolean

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();
}
Also used : MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) Test(org.junit.Test)

Example 27 with MutableBoolean

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();
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) TraversalMetadata(org.neo4j.graphdb.traversal.TraversalMetadata) HashSet(java.util.HashSet)

Example 28 with MutableBoolean

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());
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) IOException(java.io.IOException) Test(org.junit.Test)

Example 29 with MutableBoolean

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());
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) Test(org.junit.Test)

Example 30 with MutableBoolean

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();
            }
        }
    }
}
Also used : ResultHandle(org.apache.asterix.app.result.ResultHandle) JobId(org.apache.hyracks.api.job.JobId) ACIDException(org.apache.asterix.common.exceptions.ACIDException) MetadataException(org.apache.asterix.metadata.MetadataException) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) CompilationException(org.apache.asterix.common.exceptions.CompilationException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) AsterixException(org.apache.asterix.common.exceptions.AsterixException) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Aggregations

MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)40 Test (org.junit.Test)19 Query (org.apache.apex.malhar.lib.appdata.schemas.Query)11 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)11 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)8 AMutableDouble (org.apache.asterix.om.base.AMutableDouble)6 IOException (java.io.IOException)4 ClassAd (org.apache.asterix.external.classad.ClassAd)4 MutableInt (org.apache.commons.lang3.mutable.MutableInt)4 CompilationException (org.apache.asterix.common.exceptions.CompilationException)3 AMutableCharArrayString (org.apache.asterix.external.classad.AMutableCharArrayString)3 ExprList (org.apache.asterix.external.classad.ExprList)3 Value (org.apache.asterix.external.classad.Value)3 RemoteException (java.rmi.RemoteException)2 ArrayList (java.util.ArrayList)2 TimeoutException (java.util.concurrent.TimeoutException)2 ResultHandle (org.apache.asterix.app.result.ResultHandle)2 ACIDException (org.apache.asterix.common.exceptions.ACIDException)2 AsterixException (org.apache.asterix.common.exceptions.AsterixException)2 IDataset (org.apache.asterix.common.metadata.IDataset)2