Search in sources :

Example 21 with MutableInt

use of org.apache.commons.lang3.mutable.MutableInt in project asterixdb by apache.

the class TestExecutor method executeTest.

public void executeTest(String actualPath, TestCaseContext testCaseCtx, ProcessBuilder pb, boolean isDmlRecoveryTest, TestGroup failedGroup) throws Exception {
    MutableInt queryCount = new MutableInt(0);
    int numOfErrors = 0;
    int numOfFiles = 0;
    List<CompilationUnit> cUnits = testCaseCtx.getTestCase().getCompilationUnit();
    for (CompilationUnit cUnit : cUnits) {
        List<String> expectedErrors = cUnit.getExpectedError();
        LOGGER.info("Starting [TEST]: " + testCaseCtx.getTestCase().getFilePath() + "/" + cUnit.getName() + " ... ");
        Map<String, Object> variableCtx = new HashMap<>();
        List<TestFileContext> testFileCtxs = testCaseCtx.getTestFiles(cUnit);
        List<TestFileContext> expectedResultFileCtxs = testCaseCtx.getExpectedResultFiles(cUnit);
        for (TestFileContext ctx : testFileCtxs) {
            numOfFiles++;
            final File testFile = ctx.getFile();
            final String statement = readTestFile(testFile);
            try {
                executeTestFile(testCaseCtx, ctx, variableCtx, statement, isDmlRecoveryTest, pb, cUnit, queryCount, expectedResultFileCtxs, testFile, actualPath);
            } catch (Exception e) {
                System.err.println("testFile " + testFile.toString() + " raised an exception: " + e);
                numOfErrors++;
                if (isUnExpected(e, expectedErrors, numOfErrors, queryCount)) {
                    e.printStackTrace();
                    System.err.println("...Unexpected!");
                    if (failedGroup != null) {
                        failedGroup.getTestCase().add(testCaseCtx.getTestCase());
                    }
                    throw new Exception("Test \"" + testFile + "\" FAILED!", e);
                }
            } finally {
                if (numOfFiles == testFileCtxs.size()) {
                    if (numOfErrors < cUnit.getExpectedError().size()) {
                        System.err.println("...Unexpected!");
                        Exception e = new Exception("Test \"" + cUnit.getName() + "\" FAILED!\nExpected error was not thrown...");
                        System.err.println(e);
                        throw e;
                    }
                    LOGGER.info("[TEST]: " + testCaseCtx.getTestCase().getFilePath() + "/" + cUnit.getName() + " PASSED ");
                }
            }
        }
    }
}
Also used : CompilationUnit(org.apache.asterix.testframework.xml.TestCase.CompilationUnit) HashMap(java.util.HashMap) TestFileContext(org.apache.asterix.testframework.context.TestFileContext) URISyntaxException(java.net.URISyntaxException) InvocationTargetException(java.lang.reflect.InvocationTargetException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) MutableInt(org.apache.commons.lang3.mutable.MutableInt) File(java.io.File)

Example 22 with MutableInt

use of org.apache.commons.lang3.mutable.MutableInt in project asterixdb by apache.

the class ExtractCommonOperatorsRule method computeMaterilizationFlags.

private boolean[] computeMaterilizationFlags(List<Mutable<ILogicalOperator>> group) {
    for (Mutable<ILogicalOperator> root : roots) {
        computeClusters(null, root, new MutableInt(++lastUsedClusterId));
    }
    boolean[] materializationFlags = new boolean[group.size()];
    boolean worthMaterialization = worthMaterialization(group.get(0));
    boolean requiresMaterialization;
    // get clusterIds for each candidate in the group
    List<Integer> groupClusterIds = new ArrayList<Integer>(group.size());
    for (int i = 0; i < group.size(); i++) {
        groupClusterIds.add(clusterMap.get(group.get(i)).getValue());
    }
    for (int i = group.size() - 1; i >= 0; i--) {
        requiresMaterialization = requiresMaterialization(groupClusterIds, i);
        if (requiresMaterialization && !worthMaterialization) {
            group.remove(i);
            groupClusterIds.remove(i);
        }
        materializationFlags[i] = requiresMaterialization;
    }
    if (group.size() < 2) {
        group.clear();
    }
    // if does not worth materialization, the flags for the remaining candidates should be false
    return worthMaterialization ? materializationFlags : new boolean[group.size()];
}
Also used : ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) MutableInt(org.apache.commons.lang3.mutable.MutableInt) ArrayList(java.util.ArrayList)

Example 23 with MutableInt

use of org.apache.commons.lang3.mutable.MutableInt in project asterixdb by apache.

the class ExtractCommonOperatorsRule method computeClusters.

private void computeClusters(Mutable<ILogicalOperator> parentRef, Mutable<ILogicalOperator> opRef, MutableInt currentClusterId) {
    // only replicate or split operator has multiple outputs
    int outputIndex = 0;
    if (opRef.getValue().getOperatorTag() == LogicalOperatorTag.REPLICATE || opRef.getValue().getOperatorTag() == LogicalOperatorTag.SPLIT) {
        ReplicateOperator rop = (ReplicateOperator) opRef.getValue();
        List<Mutable<ILogicalOperator>> outputs = rop.getOutputs();
        for (outputIndex = 0; outputIndex < outputs.size(); outputIndex++) {
            if (outputs.get(outputIndex).equals(parentRef)) {
                break;
            }
        }
    }
    AbstractLogicalOperator aop = (AbstractLogicalOperator) opRef.getValue();
    Pair<int[], int[]> labels = aop.getPhysicalOperator().getInputOutputDependencyLabels(opRef.getValue());
    List<Mutable<ILogicalOperator>> inputs = opRef.getValue().getInputs();
    for (int i = 0; i < inputs.size(); i++) {
        Mutable<ILogicalOperator> inputRef = inputs.get(i);
        if (labels.second[outputIndex] == 1 && labels.first[i] == 0) {
            // 1 -> 0
            if (labels.second.length == 1) {
                clusterMap.put(opRef, currentClusterId);
                // start a new cluster
                MutableInt newClusterId = new MutableInt(++lastUsedClusterId);
                computeClusters(opRef, inputRef, newClusterId);
                BitSet waitForList = clusterWaitForMap.get(currentClusterId.getValue());
                if (waitForList == null) {
                    waitForList = new BitSet();
                    clusterWaitForMap.put(currentClusterId.getValue(), waitForList);
                }
                waitForList.set(newClusterId.getValue());
            }
        } else {
            // 0 -> 0 and 1 -> 1
            MutableInt prevClusterId = clusterMap.get(opRef);
            if (prevClusterId == null || prevClusterId.getValue().equals(currentClusterId.getValue())) {
                clusterMap.put(opRef, currentClusterId);
                computeClusters(opRef, inputRef, currentClusterId);
            } else {
                // merge prevClusterId and currentClusterId: update all the map entries that has currentClusterId to prevClusterId
                for (BitSet bs : clusterWaitForMap.values()) {
                    if (bs.get(currentClusterId.getValue())) {
                        bs.clear(currentClusterId.getValue());
                        bs.set(prevClusterId.getValue());
                    }
                }
                clusterWaitForMap.remove(currentClusterId.getValue());
                currentClusterId.setValue(prevClusterId.getValue());
            }
        }
    }
}
Also used : Mutable(org.apache.commons.lang3.mutable.Mutable) ReplicateOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.ReplicateOperator) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) MutableInt(org.apache.commons.lang3.mutable.MutableInt) BitSet(java.util.BitSet)

Example 24 with MutableInt

use of org.apache.commons.lang3.mutable.MutableInt in project sling by apache.

the class PollingTest method testCallTimeout.

@Test
public void testCallTimeout() throws Exception {
    final MutableInt callCount = new MutableInt(0);
    Polling p = new Polling() {

        @Override
        public Boolean call() throws Exception {
            callCount.increment();
            return false;
        }
    };
    try {
        p.poll(100, 10);
    } catch (TimeoutException e) {
        assertTrue("Expected to execute call() at least 4 times, got instead only " + callCount.intValue() + " calls", callCount.intValue() > 5);
        return;
    }
    fail("Did not reach timeout");
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 25 with MutableInt

use of org.apache.commons.lang3.mutable.MutableInt in project sling by apache.

the class PollingTest method testNegativeTimeout.

@Test
public void testNegativeTimeout() throws Exception {
    final MutableInt callCount = new MutableInt(0);
    Polling p = new Polling() {

        @Override
        public Boolean call() throws Exception {
            callCount.increment();
            return true;
        }
    };
    p.poll(-1, 10);
    assertEquals(1, callCount.intValue());
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt) Test(org.junit.Test)

Aggregations

MutableInt (org.apache.commons.lang3.mutable.MutableInt)28 Test (org.junit.Test)10 HashMap (java.util.HashMap)5 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)5 Map (java.util.Map)4 TimeoutException (java.util.concurrent.TimeoutException)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 List (java.util.List)2 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 AllelicCount (org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount)2 AllelicCountCollection (org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountCollection)2 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)2 Utils (org.broadinstitute.hellbender.utils.Utils)2 IOUtils (org.broadinstitute.hellbender.utils.io.IOUtils)2 ParamUtils (org.broadinstitute.hellbender.utils.param.ParamUtils)2 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)2 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)2