Search in sources :

Example 1 with TestInputStatsListener

use of com.datatorrent.stram.engine.StatsTest.TestOperator.TestInputStatsListener in project apex-core by apache.

the class StatsTest method testPortStatsPropagation.

/**
   * Verify buffer server bytes and tuple count.
   *
   * @throws Exception
   */
@Test
@SuppressWarnings("SleepWhileInLoop")
public void testPortStatsPropagation() throws Exception {
    int tupleCount = 10;
    LogicalPlan dag = new LogicalPlan();
    String workingDir = new File("target").getAbsolutePath();
    dag.setAttribute(OperatorContext.STORAGE_AGENT, new AsyncFSStorageAgent(workingDir, null));
    TestOperator testOper = dag.addOperator("TestOperator", TestOperator.class);
    TestInputStatsListener testInputStatsListener = new TestInputStatsListener();
    dag.setOperatorAttribute(testOper, OperatorContext.STATS_LISTENERS, Arrays.asList(new StatsListener[] { testInputStatsListener }));
    testOper.setMaxTuples(tupleCount);
    testOper.setEmitInterval(0);
    TestCollector collector = dag.addOperator("Collector", new TestCollector());
    TestCollectorStatsListener testCollectorStatsListener = new TestCollectorStatsListener();
    dag.setOperatorAttribute(collector, OperatorContext.STATS_LISTENERS, Arrays.asList(new StatsListener[] { testCollectorStatsListener }));
    dag.addStream("TestTuples", testOper.outport, collector.inport1).setLocality(null);
    StramLocalCluster lc = new StramLocalCluster(dag);
    lc.run();
    Assert.assertFalse("input operator stats", testInputStatsListener.inputOperatorStats.isEmpty());
    Assert.assertFalse("collector operator stats", testCollectorStatsListener.collectorOperatorStats.isEmpty());
    try {
        int outputPortTupleCount = 0;
        long outputPortBufferServerBytes = 0L;
        for (Iterator<OperatorStats> it = testInputStatsListener.inputOperatorStats.iterator(); it.hasNext(); ) {
            OperatorStats operatorStats = it.next();
            for (PortStats outputPortStats : operatorStats.outputPorts) {
                outputPortTupleCount += outputPortStats.tupleCount;
                outputPortBufferServerBytes += outputPortStats.bufferServerBytes;
            }
        }
        int inputPortTupleCount = 0;
        long inputPortBufferServerBytes = 0L;
        for (Iterator<OperatorStats> it = testCollectorStatsListener.collectorOperatorStats.iterator(); it.hasNext(); ) {
            OperatorStats operatorStats = it.next();
            for (PortStats inputPortStats : operatorStats.inputPorts) {
                inputPortTupleCount += inputPortStats.tupleCount;
                inputPortBufferServerBytes += inputPortStats.bufferServerBytes;
            }
        }
        Assert.assertEquals("Tuple Count emitted", tupleCount, outputPortTupleCount);
        Assert.assertTrue("Buffer server bytes", inputPortBufferServerBytes > 0);
        Assert.assertEquals("Tuple Count processed", tupleCount, inputPortTupleCount);
        Assert.assertTrue("Buffer server bytes", outputPortBufferServerBytes > 0);
    } finally {
        lc.shutdown();
    }
}
Also used : AsyncFSStorageAgent(com.datatorrent.common.util.AsyncFSStorageAgent) OperatorStats(com.datatorrent.api.Stats.OperatorStats) StatsListener(com.datatorrent.api.StatsListener) TestInputStatsListener(com.datatorrent.stram.engine.StatsTest.TestOperator.TestInputStatsListener) TestCollectorStatsListener(com.datatorrent.stram.engine.StatsTest.TestCollector.TestCollectorStatsListener) StramLocalCluster(com.datatorrent.stram.StramLocalCluster) TestInputStatsListener(com.datatorrent.stram.engine.StatsTest.TestOperator.TestInputStatsListener) TestCollectorStatsListener(com.datatorrent.stram.engine.StatsTest.TestCollector.TestCollectorStatsListener) LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) PortStats(com.datatorrent.api.Stats.OperatorStats.PortStats) File(java.io.File) Test(org.junit.Test)

Aggregations

OperatorStats (com.datatorrent.api.Stats.OperatorStats)1 PortStats (com.datatorrent.api.Stats.OperatorStats.PortStats)1 StatsListener (com.datatorrent.api.StatsListener)1 AsyncFSStorageAgent (com.datatorrent.common.util.AsyncFSStorageAgent)1 StramLocalCluster (com.datatorrent.stram.StramLocalCluster)1 TestCollectorStatsListener (com.datatorrent.stram.engine.StatsTest.TestCollector.TestCollectorStatsListener)1 TestInputStatsListener (com.datatorrent.stram.engine.StatsTest.TestOperator.TestInputStatsListener)1 LogicalPlan (com.datatorrent.stram.plan.logical.LogicalPlan)1 File (java.io.File)1 Test (org.junit.Test)1