Search in sources :

Example 61 with TopologyBuilder

use of org.apache.storm.topology.TopologyBuilder in project storm by apache.

the class TopologyIntegrationTest method testResetTimeout.

@Test
public void testResetTimeout() throws Exception {
    try (LocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().withDaemonConf(Collections.singletonMap(Config.TOPOLOGY_ENABLE_MESSAGE_TIMEOUTS, true)).build()) {
        FeederSpout feeder = new FeederSpout(new Fields("field1"));
        AckFailMapTracker tracker = new AckFailMapTracker();
        feeder.setAckFailDelegate(tracker);
        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("1", feeder);
        builder.setBolt("2", new ResetTimeoutBolt()).globalGrouping("1");
        StormTopology topology = builder.createTopology();
        cluster.submitTopology("reset-timeout-tester", Collections.singletonMap(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS, 10), topology);
        // The first tuple wil be used to check timeout reset
        feeder.feed(new Values("a"), 1);
        // The second tuple is used to wait for the spout to rotate its pending map
        feeder.feed(new Values("b"), 2);
        cluster.advanceClusterTime(9);
        // The other tuples are used to reset the first tuple's timeout,
        // and to wait for the message to get through to the spout (acks use the same path as timeout resets)
        feeder.feed(new Values("c"), 3);
        assertAcked(tracker, 3);
        cluster.advanceClusterTime(9);
        feeder.feed(new Values("d"), 4);
        assertAcked(tracker, 4);
        cluster.advanceClusterTime(2);
        // The time is now twice the message timeout, the second tuple should expire since it was not acked
        // Waiting for this also ensures that the first tuple gets failed if reset-timeout doesn't work
        assertFailed(tracker, 2);
        // Put in a tuple to cause the first tuple to be acked
        feeder.feed(new Values("e"), 5);
        assertAcked(tracker, 5);
        // The first tuple should be acked, and should not have failed
        assertThat(tracker.isFailed(1), is(false));
        assertAcked(tracker, 1);
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) AckFailMapTracker(org.apache.storm.testing.AckFailMapTracker) StormTopology(org.apache.storm.generated.StormTopology) Values(org.apache.storm.tuple.Values) FeederSpout(org.apache.storm.testing.FeederSpout) Test(org.junit.jupiter.api.Test) IntegrationTest(org.apache.storm.testing.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 62 with TopologyBuilder

use of org.apache.storm.topology.TopologyBuilder in project storm by apache.

the class TopologyIntegrationTest method mkInvalidateTopology3.

private StormTopology mkInvalidateTopology3() {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("1", new TestWordSpout(true), 3);
    builder.setBolt("2", new TestWordCounter(), 4).fieldsGrouping("1", "non-exists-stream", new Fields("word"));
    return builder.createTopology();
}
Also used : Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TestWordSpout(org.apache.storm.testing.TestWordSpout) TestWordCounter(org.apache.storm.testing.TestWordCounter)

Example 63 with TopologyBuilder

use of org.apache.storm.topology.TopologyBuilder in project storm by apache.

the class TopologyIntegrationTest method testSystemStream.

@Test
public void testSystemStream() throws Exception {
    // this test works because mocking a spout splits up the tuples evenly among the tasks
    try (LocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().build()) {
        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("1", new TestWordSpout(true), 3);
        builder.setBolt("2", new IdentityBolt(), 1).fieldsGrouping("1", new Fields("word")).globalGrouping("1", "__system");
        StormTopology topology = builder.createTopology();
        Map<String, Object> stormConf = new HashMap<>();
        stormConf.put(Config.TOPOLOGY_WORKERS, 2);
        List<FixedTuple> testTuples = Arrays.asList("a", "b", "c").stream().map(value -> new FixedTuple(new Values(value))).collect(Collectors.toList());
        MockedSources mockedSources = new MockedSources(Collections.singletonMap("1", testTuples));
        CompleteTopologyParam completeTopologyParams = new CompleteTopologyParam();
        completeTopologyParams.setMockedSources(mockedSources);
        completeTopologyParams.setStormConf(stormConf);
        Map<String, List<FixedTuple>> results = Testing.completeTopology(cluster, topology, completeTopologyParams);
        assertThat(Testing.readTuples(results, "2"), containsInAnyOrder(new Values("a"), new Values("b"), new Values("c")));
    }
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) OutputFieldsDeclarer(org.apache.storm.topology.OutputFieldsDeclarer) BaseRichSpout(org.apache.storm.topology.base.BaseRichSpout) Arrays(java.util.Arrays) TopologyContext(org.apache.storm.task.TopologyContext) SubmitOptions(org.apache.storm.generated.SubmitOptions) AssertLoop.assertFailed(org.apache.storm.AssertLoop.assertFailed) Assert.assertThat(org.junit.Assert.assertThat) Map(java.util.Map) TestAggregatesCounter(org.apache.storm.testing.TestAggregatesCounter) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TestWordSpout(org.apache.storm.testing.TestWordSpout) MockedSources(org.apache.storm.testing.MockedSources) BaseRichBolt(org.apache.storm.topology.base.BaseRichBolt) EmitInfo(org.apache.storm.hooks.info.EmitInfo) FixedTuple(org.apache.storm.testing.FixedTuple) BoltAckInfo(org.apache.storm.hooks.info.BoltAckInfo) Fields(org.apache.storm.tuple.Fields) Collectors(java.util.stream.Collectors) TestWordCounter(org.apache.storm.testing.TestWordCounter) Test(org.junit.jupiter.api.Test) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) TrackedTopology(org.apache.storm.testing.TrackedTopology) Config(org.apache.storm.Config) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) TestGlobalCount(org.apache.storm.testing.TestGlobalCount) IntStream(java.util.stream.IntStream) TestConfBolt(org.apache.storm.testing.TestConfBolt) Testing(org.apache.storm.Testing) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FeederSpout(org.apache.storm.testing.FeederSpout) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple) OutputCollector(org.apache.storm.task.OutputCollector) StormTopology(org.apache.storm.generated.StormTopology) BoltFailInfo(org.apache.storm.hooks.info.BoltFailInfo) CompleteTopologyParam(org.apache.storm.testing.CompleteTopologyParam) BoltExecuteInfo(org.apache.storm.hooks.info.BoltExecuteInfo) TestPlannerSpout(org.apache.storm.testing.TestPlannerSpout) ValueSource(org.junit.jupiter.params.provider.ValueSource) AssertLoop.assertAcked(org.apache.storm.AssertLoop.assertAcked) AckFailMapTracker(org.apache.storm.testing.AckFailMapTracker) TopologyInitialStatus(org.apache.storm.generated.TopologyInitialStatus) BaseTaskHook(org.apache.storm.hooks.BaseTaskHook) Consumer(java.util.function.Consumer) LocalCluster(org.apache.storm.LocalCluster) IntegrationTest(org.apache.storm.testing.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) Collections(java.util.Collections) LocalCluster(org.apache.storm.LocalCluster) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) HashMap(java.util.HashMap) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) StormTopology(org.apache.storm.generated.StormTopology) Values(org.apache.storm.tuple.Values) FixedTuple(org.apache.storm.testing.FixedTuple) MockedSources(org.apache.storm.testing.MockedSources) Fields(org.apache.storm.tuple.Fields) CompleteTopologyParam(org.apache.storm.testing.CompleteTopologyParam) TestWordSpout(org.apache.storm.testing.TestWordSpout) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) IntegrationTest(org.apache.storm.testing.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 64 with TopologyBuilder

use of org.apache.storm.topology.TopologyBuilder in project storm by apache.

the class TopologyIntegrationTest method testAckingSelfAnchor.

@Test
public void testAckingSelfAnchor() throws Exception {
    try (LocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().withTracked().build()) {
        AckTrackingFeeder feeder = new AckTrackingFeeder("num");
        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("1", feeder.getSpout());
        builder.setBolt("2", new DupAnchorBolt()).shuffleGrouping("1");
        builder.setBolt("3", new AckBolt()).shuffleGrouping("2");
        TrackedTopology tracked = new TrackedTopology(builder.createTopology(), cluster);
        cluster.submitTopology("test", Collections.emptyMap(), tracked);
        cluster.advanceClusterTime(11);
        feeder.feed(new Values(1));
        Testing.trackedWait(tracked, 1);
        feeder.assertNumAcks(1);
        feeder.feed(new Values(1));
        feeder.feed(new Values(1));
        feeder.feed(new Values(1));
        Testing.trackedWait(tracked, 3);
        feeder.assertNumAcks(3);
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) TrackedTopology(org.apache.storm.testing.TrackedTopology) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Values(org.apache.storm.tuple.Values) Test(org.junit.jupiter.api.Test) IntegrationTest(org.apache.storm.testing.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 65 with TopologyBuilder

use of org.apache.storm.topology.TopologyBuilder in project storm by apache.

the class TopologyIntegrationTest method testAckBranching.

@Test
public void testAckBranching() throws Exception {
    try (LocalCluster cluster = new LocalCluster.Builder().withSimulatedTime().withTracked().build()) {
        AckTrackingFeeder feeder = new AckTrackingFeeder("num");
        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("1", feeder.getSpout());
        builder.setBolt("2", new IdentityBolt()).shuffleGrouping("1");
        builder.setBolt("3", new IdentityBolt()).shuffleGrouping("1");
        builder.setBolt("4", new AggBolt(4)).shuffleGrouping("2").shuffleGrouping("3");
        TrackedTopology tracked = new TrackedTopology(builder.createTopology(), cluster);
        cluster.submitTopology("test-acking2", Collections.emptyMap(), tracked);
        cluster.advanceClusterTime(11);
        feeder.feed(new Values(1));
        Testing.trackedWait(tracked, 1);
        feeder.assertNumAcks(0);
        feeder.feed(new Values(1));
        Testing.trackedWait(tracked, 1);
        feeder.assertNumAcks(2);
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) TrackedTopology(org.apache.storm.testing.TrackedTopology) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Values(org.apache.storm.tuple.Values) Test(org.junit.jupiter.api.Test) IntegrationTest(org.apache.storm.testing.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TopologyBuilder (org.apache.storm.topology.TopologyBuilder)266 Config (org.apache.storm.Config)141 Fields (org.apache.storm.tuple.Fields)76 StormTopology (org.apache.storm.generated.StormTopology)47 HashMap (java.util.HashMap)41 LocalCluster (org.apache.storm.LocalCluster)39 TestWordSpout (org.apache.storm.testing.TestWordSpout)34 TopologyDetails (org.apache.storm.scheduler.TopologyDetails)26 Test (org.junit.Test)26 Test (org.junit.jupiter.api.Test)26 Cluster (org.apache.storm.scheduler.Cluster)25 SupervisorDetails (org.apache.storm.scheduler.SupervisorDetails)25 Topologies (org.apache.storm.scheduler.Topologies)25 Values (org.apache.storm.tuple.Values)25 TestUtilsForResourceAwareScheduler (org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 Map (java.util.Map)23 INimbus (org.apache.storm.scheduler.INimbus)23 StormMetricsRegistry (org.apache.storm.metric.StormMetricsRegistry)22 ResourceMetrics (org.apache.storm.scheduler.resource.normalization.ResourceMetrics)22