use of backtype.storm.drpc.LinearDRPCTopologyBuilder in project jstorm by alibaba.
the class ReachTopology method main.
public static void main(String[] args) throws Exception {
LinearDRPCTopologyBuilder builder = construct();
Config conf = new Config();
conf.setNumWorkers(6);
if (args.length != 0) {
try {
Map yamlConf = LoadConf.LoadYaml(args[0]);
if (yamlConf != null) {
conf.putAll(yamlConf);
}
} catch (Exception e) {
System.out.println("Input " + args[0] + " isn't one yaml ");
}
StormSubmitter.submitTopology(TOPOLOGY_NAME, conf, builder.createRemoteTopology());
} else {
conf.setMaxTaskParallelism(3);
LocalDRPC drpc = new LocalDRPC();
LocalCluster cluster = new LocalCluster();
cluster.submitTopology(TOPOLOGY_NAME, conf, builder.createLocalTopology(drpc));
JStormUtils.sleepMs(10000);
String[] urlsToTry = new String[] { "foo.com/blog/1", "engineering.twitter.com/blog/5", "notaurl.com" };
for (String url : urlsToTry) {
System.out.println("Reach of " + url + ": " + drpc.execute(TOPOLOGY_NAME, url));
}
cluster.shutdown();
drpc.shutdown();
}
}
use of backtype.storm.drpc.LinearDRPCTopologyBuilder in project jstorm by alibaba.
the class ReachTopology method construct.
public static LinearDRPCTopologyBuilder construct() {
LinearDRPCTopologyBuilder builder = new LinearDRPCTopologyBuilder(TOPOLOGY_NAME);
builder.addBolt(new GetTweeters(), 1);
builder.addBolt(new GetFollowers(), 1).shuffleGrouping();
builder.addBolt(new PartialUniquer(), 1).fieldsGrouping(new Fields("id", "follower"));
builder.addBolt(new CountAggregator(), 1).fieldsGrouping(new Fields("id"));
return builder;
}
use of backtype.storm.drpc.LinearDRPCTopologyBuilder in project jstorm by alibaba.
the class BasicDRPCTopologyTest method testBasicDRPCTopology.
@Test
public void testBasicDRPCTopology() {
LinearDRPCTopologyBuilder topologyBuilder = new LinearDRPCTopologyBuilder("exclamation");
topologyBuilder.addBolt(new BasicDRPCTopology.ExclaimBolt(), 3);
Config config = new Config();
config.put(Config.TOPOLOGY_NAME, "BasicDRPCTopologyTest");
LocalDRPC localDRPC = new LocalDRPC();
JStormUnitTestDRPCValidator validator = new JStormUnitTestDRPCValidator(localDRPC) {
@Override
public boolean validate(Map config) {
String result = executeLocalDRPC("exclamation", "hello");
assertEquals("hello!", result);
result = executeLocalDRPC("exclamation", "goodbye");
assertEquals("goodbye!", result);
return true;
}
};
try {
JStormUnitTestRunner.submitTopology(topologyBuilder.createLocalTopology(localDRPC), config, 120, validator);
} finally {
localDRPC.shutdown();
}
}
use of backtype.storm.drpc.LinearDRPCTopologyBuilder in project jstorm by alibaba.
the class BasicDRPCTopology method testDrpc.
public static void testDrpc() {
LinearDRPCTopologyBuilder builder = new LinearDRPCTopologyBuilder("exclamation");
builder.addBolt(new ExclaimBolt(), 3);
Config conf = new Config();
LocalDRPC drpc = new LocalDRPC();
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("drpc-demo", conf, builder.createLocalTopology(drpc));
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
}
try {
for (String word : new String[] { "hello", "goodbye" }) {
System.out.println("Result for \"" + word + "\": " + drpc.execute("exclamation", word));
}
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Failed to run DRPC Test");
}
drpc.shutdown();
cluster.shutdown();
}
Aggregations