use of org.apache.storm.ILocalCluster.ILocalTopology in project storm by apache.
the class TickTupleTest method testTickTupleWorksWithSystemBolt.
@Test
public void testTickTupleWorksWithSystemBolt() throws Exception {
try (ILocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().build()) {
TopologyBuilder builder = new TopologyBuilder();
FeederSpout feeder = new FeederSpout(new Fields("field1"));
AckFailMapTracker tracker = new AckFailMapTracker();
feeder.setAckFailDelegate(tracker);
builder.setSpout("Spout", feeder);
builder.setBolt("Bolt", new NoopBolt()).shuffleGrouping("Spout");
Config topoConf = new Config();
topoConf.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, TICK_INTERVAL_SECS);
try (ILocalTopology topo = cluster.submitTopology("test", topoConf, builder.createTopology())) {
// Use a bootstrap tuple to wait for topology to be running
feeder.feed(new Values("val"), 1);
AssertLoop.assertAcked(tracker, 1);
/*
* Verify that some ticks are received. The interval between ticks is validated by the bolt.
* Too few and the checks will time out. Too many and the bolt may crash (not reliably, but the test should become flaky).
*/
try {
cluster.advanceClusterTime(TICK_INTERVAL_SECS);
waitForTicks(1);
cluster.advanceClusterTime(TICK_INTERVAL_SECS);
waitForTicks(2);
cluster.advanceClusterTime(TICK_INTERVAL_SECS);
waitForTicks(3);
} catch (ConditionTimeoutException e) {
throw new AssertionError(e.getMessage());
}
assertNull("The bolt got a tuple that is not a tick tuple " + nonTickTuple.get(), nonTickTuple.get());
}
}
}
Aggregations