Search in sources :

Example 61 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 62 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 63 with TopologyBuilder

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

the class InOrderDeliveryTest method test.

public static void test() {
    TopologyBuilder builder = new TopologyBuilder();
    int spoutNum = JStormUtils.parseInt(conf.get("spout.num"), 8);
    int countNum = JStormUtils.parseInt(conf.get("count.num"), 8);
    builder.setSpout("spout", new InOrderSpout(), spoutNum);
    builder.setBolt("count", new Check(), countNum).fieldsGrouping("spout", new Fields("c1"));
    String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\.");
    String topologyName = className[className.length - 1];
    try {
        JStormHelper.runTopology(builder.createTopology(), topologyName, conf, 60, new JStormHelper.CheckAckedFail(conf), isLocal);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        Assert.fail("Failed");
    }
}
Also used : JStormHelper(com.alibaba.starter.utils.JStormHelper) Fields(backtype.storm.tuple.Fields) TopologyBuilder(backtype.storm.topology.TopologyBuilder) FailedException(backtype.storm.topology.FailedException)

Example 64 with TopologyBuilder

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

the class ManualDRPC method testDrpc.

public static void testDrpc() {
    TopologyBuilder builder = new TopologyBuilder();
    LocalDRPC drpc = new LocalDRPC();
    DRPCSpout spout = new DRPCSpout("exclamation", drpc);
    builder.setSpout("drpc", spout);
    builder.setBolt("exclaim", new ExclamationBolt(), 3).shuffleGrouping("drpc");
    builder.setBolt("return", new ReturnResults(), 3).shuffleGrouping("exclaim");
    LocalCluster cluster = new LocalCluster();
    Config conf = new Config();
    cluster.submitTopology("exclaim", conf, builder.createTopology());
    JStormUtils.sleepMs(30 * 1000);
    try {
        System.out.println(drpc.execute("exclamation", "aaa"));
        System.out.println(drpc.execute("exclamation", "bbb"));
    } catch (Exception e) {
        Assert.fail("Failed to test drpc");
    }
    drpc.shutdown();
    cluster.shutdown();
}
Also used : LocalCluster(backtype.storm.LocalCluster) TopologyBuilder(backtype.storm.topology.TopologyBuilder) Config(backtype.storm.Config) LocalDRPC(backtype.storm.LocalDRPC) ReturnResults(backtype.storm.drpc.ReturnResults) DRPCSpout(backtype.storm.drpc.DRPCSpout)

Example 65 with TopologyBuilder

use of backtype.storm.topology.TopologyBuilder in project storm-kestrel by nathanmarz.

the class TestTopology method main.

public static void main(String[] args) throws Exception {
    TopologyBuilder builder = new TopologyBuilder();
    KestrelThriftSpout spout = new KestrelThriftSpout("localhost", 2229, "test", new StringScheme());
    builder.setSpout("spout", spout).setDebug(true);
    builder.setBolt("bolt", new FailEveryOther()).shuffleGrouping("spout");
    LocalCluster cluster = new LocalCluster();
    Config conf = new Config();
    cluster.submitTopology("test", conf, builder.createTopology());
    Thread.sleep(600000);
}
Also used : LocalCluster(backtype.storm.LocalCluster) TopologyBuilder(backtype.storm.topology.TopologyBuilder) Config(backtype.storm.Config) StringScheme(backtype.storm.scheme.StringScheme)

Aggregations

TopologyBuilder (backtype.storm.topology.TopologyBuilder)75 Config (backtype.storm.Config)38 Fields (backtype.storm.tuple.Fields)29 LocalCluster (backtype.storm.LocalCluster)23 Test (org.junit.Test)15 Map (java.util.Map)14 HashMap (java.util.HashMap)12 JStormHelper (com.alibaba.starter.utils.JStormHelper)8 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 HashSet (java.util.HashSet)4 TestWordSpout (backtype.storm.testing.TestWordSpout)3 BaseWindowedBolt (backtype.storm.topology.base.BaseWindowedBolt)3 JStormUnitTestValidator (com.jstorm.example.unittests.utils.JStormUnitTestValidator)3 Check (org.apache.storm.starter.InOrderDeliveryTest.Check)3