use of com.datatorrent.stram.engine.AutoMetricTest.TestOperator.TestStatsListener in project apex-core by apache.
the class AutoMetricTest method testMetricPropagation.
/**
* Verify custom stats generated by operator are propagated and trigger repartition.
*
* @throws Exception
*/
@Test
@SuppressWarnings("SleepWhileInLoop")
public void testMetricPropagation() throws Exception {
dag.getAttributes().put(LogicalPlan.STREAMING_WINDOW_SIZE_MILLIS, 300);
dag.getAttributes().put(LogicalPlan.CONTAINERS_MAX_COUNT, 1);
TestOperator testOper = dag.addOperator("TestOperator", TestOperator.class);
TestStatsListener sl = new TestStatsListener();
dag.setOperatorAttribute(testOper, OperatorContext.STATS_LISTENERS, Lists.newArrayList((StatsListener) sl));
GenericTestOperator collector = dag.addOperator("Collector", new GenericTestOperator());
dag.addStream("TestTuples", testOper.outport, collector.inport1).setLocality(Locality.CONTAINER_LOCAL);
StramLocalCluster lc = new StramLocalCluster(dag);
lc.runAsync();
long startTms = System.currentTimeMillis();
while (TestOperator.lastMetric == null && StramTestSupport.DEFAULT_TIMEOUT_MILLIS > System.currentTimeMillis() - startTms) {
Thread.sleep(300);
LOG.debug("Waiting for stats");
}
while (StramTestSupport.DEFAULT_TIMEOUT_MILLIS > System.currentTimeMillis() - startTms) {
if (sl.lastPropVal) {
break;
}
Thread.sleep(100);
LOG.debug("Waiting for property set");
}
lc.shutdown();
Assert.assertNotNull("metric received", TestOperator.lastMetric);
Assert.assertEquals("metric message", "interesting", TestOperator.lastMetric.message);
Assert.assertTrue("attribute defined stats listener called", TestOperator.lastMetric.attributeListenerCalled);
Assert.assertSame("single thread", TestOperator.definePartitionsThread, TestOperator.processStatsThread);
Assert.assertTrue("property set", sl.lastPropVal);
}
Aggregations