Search in sources :

Example 81 with TopologyBuilder

use of backtype.storm.topology.TopologyBuilder in project jstorm by alibaba.

the class WordCountTopology method main.

/**
 * Main method
 */
public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException {
    if (args.length != 1) {
        throw new RuntimeException("Specify topology name");
    }
    int parallelism = 10;
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("word", new WordSpout(), parallelism);
    builder.setBolt("consumer", new ConsumerBolt(), parallelism).fieldsGrouping("word", new Fields("word"));
    Config conf = new Config();
    conf.setNumStmgrs(parallelism);
    /*
    Set config here
    */
    StormSubmitter.submitTopology(args[0], conf, builder.createTopology());
}
Also used : Fields(backtype.storm.tuple.Fields) TopologyBuilder(backtype.storm.topology.TopologyBuilder) Config(backtype.storm.Config)

Example 82 with TopologyBuilder

use of backtype.storm.topology.TopologyBuilder in project jstorm by alibaba.

the class TridentMapExample method test.

public static void test() {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("spout", new InOrderSpout(), 8);
    builder.setBolt("count", new Check(), 8).fieldsGrouping("spout", new Fields("c1"));
    Config conf = new Config();
    conf.setMaxSpoutPending(20);
    String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\.");
    String topologyName = className[className.length - 1];
    if (isLocal) {
        drpc = new LocalDRPC();
    }
    try {
        JStormHelper.runTopology(buildTopology(drpc), topologyName, conf, 60, new DrpcValidator(), isLocal);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Assert.fail("Failed");
    }
}
Also used : InOrderSpout(org.apache.storm.starter.InOrderDeliveryTest.InOrderSpout) Fields(backtype.storm.tuple.Fields) TopologyBuilder(backtype.storm.topology.TopologyBuilder) Config(backtype.storm.Config) Check(org.apache.storm.starter.InOrderDeliveryTest.Check) LocalDRPC(backtype.storm.LocalDRPC)

Example 83 with TopologyBuilder

use of backtype.storm.topology.TopologyBuilder in project jstorm by alibaba.

the class TridentMinMaxOfVehiclesTopology method test.

public static void test() {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("spout", new InOrderSpout(), 8);
    builder.setBolt("count", new Check(), 8).fieldsGrouping("spout", new Fields("c1"));
    conf.setMaxSpoutPending(20);
    String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\.");
    String topologyName = className[className.length - 1];
    if (isLocal) {
        drpc = new LocalDRPC();
    }
    try {
        JStormHelper.runTopology(buildVehiclesTopology(), topologyName, conf, 60, new JStormHelper.CheckAckedFail(conf), isLocal);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Assert.fail("Failed");
    }
}
Also used : InOrderSpout(org.apache.storm.starter.InOrderDeliveryTest.InOrderSpout) JStormHelper(com.alibaba.starter.utils.JStormHelper) Fields(backtype.storm.tuple.Fields) TopologyBuilder(backtype.storm.topology.TopologyBuilder) Check(org.apache.storm.starter.InOrderDeliveryTest.Check) LocalDRPC(backtype.storm.LocalDRPC)

Example 84 with TopologyBuilder

use of backtype.storm.topology.TopologyBuilder in project jstorm by alibaba.

the class ManualDRPCTest method testManualDRPC.

@Test
public void testManualDRPC() {
    TopologyBuilder topologyBuilder = new TopologyBuilder();
    LocalDRPC localDRPC = new LocalDRPC();
    DRPCSpout spout = new DRPCSpout("exclamation", localDRPC);
    topologyBuilder.setSpout("drpc", spout);
    topologyBuilder.setBolt("exclaim", new ManualDRPC.ExclamationBolt(), 3).shuffleGrouping("drpc");
    topologyBuilder.setBolt("return", new ReturnResults(), 3).shuffleGrouping("exclaim");
    Config config = new Config();
    config.put(Config.TOPOLOGY_NAME, "ManualDRPCTest");
    JStormUnitTestValidator validator = new JStormUnitTestDRPCValidator(localDRPC) {

        @Override
        public boolean validate(Map config) {
            assertEquals("hello!!!", executeLocalDRPC("exclamation", "hello"));
            assertEquals("good bye!!!", executeLocalDRPC("exclamation", "good bye"));
            return true;
        }
    };
    try {
        JStormUnitTestRunner.submitTopology(topologyBuilder.createTopology(), config, 60, validator);
    } finally {
        localDRPC.shutdown();
    }
}
Also used : JStormUnitTestValidator(com.jstorm.example.unittests.utils.JStormUnitTestValidator) TopologyBuilder(backtype.storm.topology.TopologyBuilder) Config(backtype.storm.Config) LocalDRPC(backtype.storm.LocalDRPC) ReturnResults(backtype.storm.drpc.ReturnResults) JStormUnitTestDRPCValidator(com.jstorm.example.unittests.utils.JStormUnitTestDRPCValidator) DRPCSpout(backtype.storm.drpc.DRPCSpout) Map(java.util.Map) Test(org.junit.Test)

Example 85 with TopologyBuilder

use of backtype.storm.topology.TopologyBuilder in project jstorm by alibaba.

the class FastWordCountTest method testFastWordCount.

@Test
public void testFastWordCount() {
    int spout_Parallelism_hint = 1;
    int split_Parallelism_hint = 1;
    int count_Parallelism_hint = 2;
    TopologyBuilder builder = new TopologyBuilder();
    boolean isLocalShuffle = false;
    builder.setSpout("spout", new FastWordCountTopology.FastRandomSentenceSpout(), spout_Parallelism_hint);
    if (isLocalShuffle)
        builder.setBolt("split", new FastWordCountTopology.SplitSentence(), split_Parallelism_hint).localFirstGrouping("spout");
    else
        builder.setBolt("split", new FastWordCountTopology.SplitSentence(), split_Parallelism_hint).shuffleGrouping("spout");
    builder.setBolt("count", new FastWordCountTopology.WordCount(), count_Parallelism_hint).fieldsGrouping("split", new Fields("word"));
    Map config = new HashMap();
    config.put(Config.TOPOLOGY_NAME, "FastWordCountTest");
    JStormUnitTestRunner.submitTopology(builder.createTopology(), config, 60, null);
}
Also used : Fields(backtype.storm.tuple.Fields) TopologyBuilder(backtype.storm.topology.TopologyBuilder) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) FastWordCountTopology(com.alipay.dw.jstorm.example.performance.test.FastWordCountTopology) Test(org.junit.Test)

Aggregations

TopologyBuilder (backtype.storm.topology.TopologyBuilder)92 Config (backtype.storm.Config)47 Fields (backtype.storm.tuple.Fields)41 LocalCluster (backtype.storm.LocalCluster)23 JStormHelper (com.alibaba.starter.utils.JStormHelper)16 Map (java.util.Map)15 Test (org.junit.Test)15 HashMap (java.util.HashMap)12 LocalDRPC (backtype.storm.LocalDRPC)7 BoltDeclarer (backtype.storm.topology.BoltDeclarer)6 JStormUnitTestMetricValidator (com.jstorm.example.unittests.utils.JStormUnitTestMetricValidator)5 ArrayList (java.util.ArrayList)5 CoordinatedBolt (backtype.storm.coordination.CoordinatedBolt)4 IdStreamSpec (backtype.storm.coordination.CoordinatedBolt.IdStreamSpec)4 SourceArgs (backtype.storm.coordination.CoordinatedBolt.SourceArgs)4 TestWordSpout (backtype.storm.testing.TestWordSpout)4 HashSet (java.util.HashSet)4 StormTopology (backtype.storm.generated.StormTopology)3 BaseWindowedBolt (backtype.storm.topology.base.BaseWindowedBolt)3 JStormUnitTestValidator (com.jstorm.example.unittests.utils.JStormUnitTestValidator)3