Search in sources :

Example 6 with TestGlobalCount

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

the class LocalNimbusTest method createTestTopology.

public static StormTopology createTestTopology() {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("words", new TestWordSpout(), generateParallelismHint());
    builder.setBolt("count", new TestWordCounter(), generateParallelismHint()).shuffleGrouping("words");
    builder.setBolt("globalCount", new TestGlobalCount(), generateParallelismHint()).shuffleGrouping("count");
    return builder.createTopology();
}
Also used : TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TestGlobalCount(org.apache.storm.testing.TestGlobalCount) TestWordSpout(org.apache.storm.testing.TestWordSpout) TestWordCounter(org.apache.storm.testing.TestWordCounter)

Example 7 with TestGlobalCount

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

the class NettyIntegrationTest method testIntegration.

@Test
public void testIntegration() throws Exception {
    Map<String, Object> daemonConf = new HashMap<>();
    daemonConf.put(Config.STORM_LOCAL_MODE_ZMQ, true);
    daemonConf.put(Config.STORM_MESSAGING_TRANSPORT, "org.apache.storm.messaging.netty.Context");
    daemonConf.put(Config.STORM_MESSAGING_NETTY_AUTHENTICATION, false);
    daemonConf.put(Config.STORM_MESSAGING_NETTY_BUFFER_SIZE, 1024000);
    daemonConf.put(Config.STORM_MESSAGING_NETTY_MIN_SLEEP_MS, 1000);
    daemonConf.put(Config.STORM_MESSAGING_NETTY_MAX_SLEEP_MS, 5000);
    daemonConf.put(Config.STORM_MESSAGING_NETTY_CLIENT_WORKER_THREADS, 1);
    daemonConf.put(Config.STORM_MESSAGING_NETTY_SERVER_WORKER_THREADS, 1);
    Builder builder = new Builder().withSimulatedTime().withSupervisors(4).withSupervisorSlotPortMin(6710).withDaemonConf(daemonConf);
    try (LocalCluster cluster = builder.build()) {
        TopologyBuilder topologyBuilder = new TopologyBuilder();
        topologyBuilder.setSpout("1", new TestWordSpout(true), 4);
        topologyBuilder.setBolt("2", new TestGlobalCount(), 6).shuffleGrouping("1");
        StormTopology topology = topologyBuilder.createTopology();
        // important for test that tuples = multiple of 4 and 6
        List<FixedTuple> testTuples = Stream.of("a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b").map(value -> new FixedTuple(new Values(value))).collect(Collectors.toList());
        MockedSources mockedSources = new MockedSources(Collections.singletonMap("1", testTuples));
        CompleteTopologyParam completeTopologyParams = new CompleteTopologyParam();
        completeTopologyParams.setStormConf(Collections.singletonMap(Config.TOPOLOGY_WORKERS, 3));
        completeTopologyParams.setMockedSources(mockedSources);
        Map<String, List<FixedTuple>> results = Testing.completeTopology(cluster, topology, completeTopologyParams);
        assertEquals(6 * 4, Testing.readTuples(results, "2").size());
    }
}
Also used : MockedSources(org.apache.storm.testing.MockedSources) Testing(org.apache.storm.Testing) FixedTuple(org.apache.storm.testing.FixedTuple) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) LocalCluster(org.apache.storm.LocalCluster) IntegrationTest(org.apache.storm.testing.IntegrationTest) Test(org.junit.jupiter.api.Test) Values(org.apache.storm.tuple.Values) List(java.util.List) Stream(java.util.stream.Stream) StormTopology(org.apache.storm.generated.StormTopology) CompleteTopologyParam(org.apache.storm.testing.CompleteTopologyParam) Map(java.util.Map) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) TestWordSpout(org.apache.storm.testing.TestWordSpout) Builder(org.apache.storm.LocalCluster.Builder) TestGlobalCount(org.apache.storm.testing.TestGlobalCount) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) LocalCluster(org.apache.storm.LocalCluster) HashMap(java.util.HashMap) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Builder(org.apache.storm.LocalCluster.Builder) StormTopology(org.apache.storm.generated.StormTopology) Values(org.apache.storm.tuple.Values) FixedTuple(org.apache.storm.testing.FixedTuple) MockedSources(org.apache.storm.testing.MockedSources) TestGlobalCount(org.apache.storm.testing.TestGlobalCount) CompleteTopologyParam(org.apache.storm.testing.CompleteTopologyParam) TestWordSpout(org.apache.storm.testing.TestWordSpout) List(java.util.List) IntegrationTest(org.apache.storm.testing.IntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

TestGlobalCount (org.apache.storm.testing.TestGlobalCount)7 TestWordSpout (org.apache.storm.testing.TestWordSpout)7 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)7 HashMap (java.util.HashMap)4 List (java.util.List)4 StormTopology (org.apache.storm.generated.StormTopology)4 CompleteTopologyParam (org.apache.storm.testing.CompleteTopologyParam)4 FixedTuple (org.apache.storm.testing.FixedTuple)4 MockedSources (org.apache.storm.testing.MockedSources)4 TestWordCounter (org.apache.storm.testing.TestWordCounter)4 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Config (org.apache.storm.Config)2 LocalCluster (org.apache.storm.LocalCluster)2 Testing (org.apache.storm.Testing)2 IntegrationTest (org.apache.storm.testing.IntegrationTest)2 Arrays (java.util.Arrays)1 Consumer (java.util.function.Consumer)1