Search in sources :

Example 6 with AckFailMapTracker

use of org.apache.storm.testing.AckFailMapTracker in project storm by apache.

the class TestingTest method testAdvanceClusterTime.

@Test
public void testAdvanceClusterTime() throws Exception {
    Config daemonConf = new Config();
    daemonConf.put(Config.TOPOLOGY_ENABLE_MESSAGE_TIMEOUTS, true);
    try (LocalCluster cluster = new LocalCluster.Builder().withDaemonConf(daemonConf).withSimulatedTime().build()) {
        FeederSpout feeder = new FeederSpout(new Fields("field1"));
        AckFailMapTracker tracker = new AckFailMapTracker();
        feeder.setAckFailDelegate(tracker);
        Map<String, Thrift.SpoutDetails> spoutMap = new HashMap<>();
        spoutMap.put("1", Thrift.prepareSpoutDetails(feeder));
        Map<String, Thrift.BoltDetails> boltMap = new HashMap<>();
        boltMap.put("2", Thrift.prepareBoltDetails(Collections.singletonMap(Utils.getGlobalStreamId("1", null), Thrift.prepareShuffleGrouping()), new AckEveryOtherBolt()));
        StormTopology topology = Thrift.buildTopology(spoutMap, boltMap);
        Config stormConf = new Config();
        stormConf.put(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS, 10);
        cluster.submitTopology("timeout-tester", stormConf, topology);
        feeder.feed(new Values("a"), 1);
        feeder.feed(new Values("b"), 2);
        feeder.feed(new Values("c"), 3);
        cluster.advanceClusterTime(9);
        assertAcked(tracker, 1, 3);
        assertThat(tracker.isFailed(2), is(false));
        cluster.advanceClusterTime(12);
        assertFailed(tracker, 2);
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) HashMap(java.util.HashMap) Config(org.apache.storm.Config) AckFailMapTracker(org.apache.storm.testing.AckFailMapTracker) StormTopology(org.apache.storm.generated.StormTopology) Values(org.apache.storm.tuple.Values) Fields(org.apache.storm.tuple.Fields) FeederSpout(org.apache.storm.testing.FeederSpout) Test(org.junit.jupiter.api.Test)

Aggregations

AckFailMapTracker (org.apache.storm.testing.AckFailMapTracker)6 FeederSpout (org.apache.storm.testing.FeederSpout)6 Fields (org.apache.storm.tuple.Fields)6 Values (org.apache.storm.tuple.Values)6 Test (org.junit.jupiter.api.Test)6 LocalCluster (org.apache.storm.LocalCluster)5 StormTopology (org.apache.storm.generated.StormTopology)5 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)4 IntegrationTest (org.apache.storm.testing.IntegrationTest)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 HashMap (java.util.HashMap)2 Config (org.apache.storm.Config)2 ILocalTopology (org.apache.storm.ILocalCluster.ILocalTopology)1 SubmitOptions (org.apache.storm.generated.SubmitOptions)1 ConditionTimeoutException (org.awaitility.core.ConditionTimeoutException)1