Search in sources :

Example 6 with MutableInt

use of org.apache.commons.lang3.mutable.MutableInt in project apex-core by apache.

the class PhysicalPlanTest method testDefaultPartitionerWithParallel.

@Test
public void testDefaultPartitionerWithParallel() throws InterruptedException {
    final MutableInt loadInd = new MutableInt();
    StatsListener listener = new StatsListener() {

        @Override
        public Response processStats(BatchedOperatorStats stats) {
            Response response = new Response();
            response.repartitionRequired = true;
            response.loadIndicator = loadInd.intValue();
            return response;
        }
    };
    LogicalPlan dag = new LogicalPlan();
    GenericTestOperator nodeX = dag.addOperator("X", GenericTestOperator.class);
    dag.setOperatorAttribute(nodeX, Context.OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(2));
    dag.setOperatorAttribute(nodeX, Context.OperatorContext.STATS_LISTENERS, Lists.newArrayList(listener));
    GenericTestOperator nodeY = dag.addOperator("Y", GenericTestOperator.class);
    dag.setOperatorAttribute(nodeY, Context.OperatorContext.PARTITIONER, new TestPartitioner<GenericTestOperator>());
    GenericTestOperator nodeZ = dag.addOperator("Z", GenericTestOperator.class);
    dag.addStream("Stream1", nodeX.outport1, nodeY.inport1, nodeZ.inport1);
    dag.addStream("Stream2", nodeX.outport2, nodeY.inport2, nodeZ.inport2);
    dag.setInputPortAttribute(nodeY.inport1, Context.PortContext.PARTITION_PARALLEL, true);
    dag.setInputPortAttribute(nodeY.inport2, Context.PortContext.PARTITION_PARALLEL, true);
    dag.setInputPortAttribute(nodeZ.inport1, Context.PortContext.PARTITION_PARALLEL, true);
    dag.setInputPortAttribute(nodeZ.inport2, Context.PortContext.PARTITION_PARALLEL, true);
    StramTestSupport.MemoryStorageAgent msa = new StramTestSupport.MemoryStorageAgent();
    dag.setAttribute(Context.OperatorContext.STORAGE_AGENT, msa);
    TestPlanContext ctx = new TestPlanContext();
    PhysicalPlan plan = new PhysicalPlan(dag, ctx);
    LogicalPlan.OperatorMeta metaOfX = dag.getMeta(nodeX);
    LogicalPlan.OperatorMeta metaOfY = dag.getMeta(nodeY);
    Assert.assertEquals("number operators " + metaOfX.getName(), 2, plan.getOperators(metaOfX).size());
    Assert.assertEquals("number operators " + metaOfY.getName(), 2, plan.getOperators(metaOfY).size());
    List<PTOperator> ptOfX = plan.getOperators(metaOfX);
    for (PTOperator physicalX : ptOfX) {
        Assert.assertEquals("2 streams " + physicalX.getOutputs(), 2, physicalX.getOutputs().size());
        for (PTOutput outputPort : physicalX.getOutputs()) {
            Set<PTOperator> dopers = Sets.newHashSet();
            Assert.assertEquals("sink of " + metaOfX.getName() + " id " + physicalX.id + " port " + outputPort.portName, 2, outputPort.sinks.size());
            for (PTInput inputPort : outputPort.sinks) {
                dopers.add(inputPort.target);
            }
            Assert.assertEquals(2, dopers.size());
        }
    }
    //Invoke redo-partition of PhysicalPlan, no partition change
    loadInd.setValue(0);
    for (PTOperator ptOperator : ptOfX) {
        plan.onStatusUpdate(ptOperator);
    }
    ctx.events.remove(0).run();
    for (PTOperator physicalX : ptOfX) {
        Assert.assertEquals("2 streams " + physicalX.getOutputs(), 2, physicalX.getOutputs().size());
        for (PTOutput outputPort : physicalX.getOutputs()) {
            Set<PTOperator> dopers = Sets.newHashSet();
            Assert.assertEquals("sink of " + metaOfX.getName() + " id " + physicalX.id + " port " + outputPort.portName, 2, outputPort.sinks.size());
            for (PTInput inputPort : outputPort.sinks) {
                dopers.add(inputPort.target);
            }
            Assert.assertEquals(2, dopers.size());
        }
    }
    //scale up by splitting first partition
    loadInd.setValue(1);
    plan.onStatusUpdate(ptOfX.get(0));
    ctx.events.get(0).run();
    List<PTOperator> ptOfXScaleUp = plan.getOperators(metaOfX);
    Assert.assertEquals("3 partitons " + ptOfXScaleUp, 3, ptOfXScaleUp.size());
    for (PTOperator physicalX : ptOfXScaleUp) {
        Assert.assertEquals("2 streams " + physicalX.getOutputs(), 2, physicalX.getOutputs().size());
        for (PTOutput outputPort : physicalX.getOutputs()) {
            Set<PTOperator> dopers = Sets.newHashSet();
            Assert.assertEquals("sink of " + metaOfX.getName() + " id " + physicalX.id + " port " + outputPort.portName, 2, outputPort.sinks.size());
            for (PTInput inputPort : outputPort.sinks) {
                dopers.add(inputPort.target);
            }
            Assert.assertEquals(2, dopers.size());
        }
    }
}
Also used : PTInput(com.datatorrent.stram.plan.physical.PTOperator.PTInput) StatsListener(com.datatorrent.api.StatsListener) GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) MutableInt(org.apache.commons.lang3.mutable.MutableInt) TestPlanContext(com.datatorrent.stram.plan.TestPlanContext) StramTestSupport(com.datatorrent.stram.support.StramTestSupport) LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) PTOutput(com.datatorrent.stram.plan.physical.PTOperator.PTOutput) OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) Test(org.junit.Test) PartitioningTest(com.datatorrent.stram.PartitioningTest)

Example 7 with MutableInt

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

the class TokenCounterTest method testCommonTokens.

@Test
public void testCommonTokens() throws Exception {
    TokenCounter tokenCounter = new TokenCounter(analyzerManager.getCommonTokensAnalyzer());
    String s = "the http://www.cnn.com and blahdeblah@apache.org are in valuable www.sites.org 普林斯顿大学";
    tokenCounter.add(FIELD, s);
    Map<String, MutableInt> tokens = tokenCounter.getTokens(FIELD);
    assertEquals(new MutableInt(2), tokens.get("___url___"));
    assertEquals(new MutableInt(1), tokens.get("___email___"));
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt) Test(org.junit.Test)

Example 8 with MutableInt

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

the class PollingTest method testCallableOnce.

//
// Tests with Callable
//
@Test
public void testCallableOnce() 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();
            return true;
        }
    });
    p.poll(500, 10);
    assertEquals(1, 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 9 with MutableInt

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

the class PollingTest method testCallOnce.

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

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

Example 10 with MutableInt

use of org.apache.commons.lang3.mutable.MutableInt 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)

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