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();
}
}
Aggregations