use of backtype.storm.drpc.ReturnResults 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();
}
}
use of backtype.storm.drpc.ReturnResults 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();
}
Aggregations