Search in sources :

Example 1 with DRPCSpout

use of backtype.storm.drpc.DRPCSpout in project jstorm by alibaba.

the class TridentTopology method genSpoutIds.

private static Map<Node, String> genSpoutIds(Collection<SpoutNode> spoutNodes) {
    Map<Node, String> ret = new HashMap<>();
    int ctr = 0;
    for (SpoutNode n : spoutNodes) {
        if (n.type == SpoutNode.SpoutType.BATCH) {
            // if Batch spout then id contains txId
            ret.put(n, "spout-" + n.txId);
        } else if (n.type == SpoutNode.SpoutType.DRPC) {
            //if DRPC spout then id contains function
            ret.put(n, "spout-" + ((DRPCSpout) n.spout).get_function() + ctr);
            ctr++;
        } else {
            ret.put(n, "spout" + ctr);
            ctr++;
        }
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SpoutNode(storm.trident.planner.SpoutNode) SpoutNode(storm.trident.planner.SpoutNode) ProcessorNode(storm.trident.planner.ProcessorNode) PartitionNode(storm.trident.planner.PartitionNode) Node(storm.trident.planner.Node) DRPCSpout(backtype.storm.drpc.DRPCSpout)

Example 2 with DRPCSpout

use of backtype.storm.drpc.DRPCSpout 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 3 with DRPCSpout

use of backtype.storm.drpc.DRPCSpout 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)

Aggregations

DRPCSpout (backtype.storm.drpc.DRPCSpout)3 Config (backtype.storm.Config)2 LocalDRPC (backtype.storm.LocalDRPC)2 ReturnResults (backtype.storm.drpc.ReturnResults)2 TopologyBuilder (backtype.storm.topology.TopologyBuilder)2 LocalCluster (backtype.storm.LocalCluster)1 JStormUnitTestDRPCValidator (com.jstorm.example.unittests.utils.JStormUnitTestDRPCValidator)1 JStormUnitTestValidator (com.jstorm.example.unittests.utils.JStormUnitTestValidator)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 Node (storm.trident.planner.Node)1 PartitionNode (storm.trident.planner.PartitionNode)1 ProcessorNode (storm.trident.planner.ProcessorNode)1 SpoutNode (storm.trident.planner.SpoutNode)1