Search in sources :

Example 1 with ILocalTopology

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());
        }
    }
}
Also used : ILocalTopology(org.apache.storm.ILocalCluster.ILocalTopology) Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) AckFailMapTracker(org.apache.storm.testing.AckFailMapTracker) Values(org.apache.storm.tuple.Values) ConditionTimeoutException(org.awaitility.core.ConditionTimeoutException) FeederSpout(org.apache.storm.testing.FeederSpout) Test(org.junit.jupiter.api.Test)

Aggregations

ILocalTopology (org.apache.storm.ILocalCluster.ILocalTopology)1 AckFailMapTracker (org.apache.storm.testing.AckFailMapTracker)1 FeederSpout (org.apache.storm.testing.FeederSpout)1 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)1 Fields (org.apache.storm.tuple.Fields)1 Values (org.apache.storm.tuple.Values)1 ConditionTimeoutException (org.awaitility.core.ConditionTimeoutException)1 Test (org.junit.jupiter.api.Test)1