Search in sources :

Example 16 with MutableBoolean

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

Example 17 with MutableBoolean

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

Example 18 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 19 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 20 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)

Aggregations

MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)28 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)11 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)8 Test (org.junit.Test)7 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 ExprTree (org.apache.asterix.external.classad.ExprTree)2