use of org.apache.storm.testing.TestWordSpout in project storm by apache.
the class SkewedRollingTopWords method run.
/**
* Submits (runs) the topology.
*
* <p>Usage: "SkewedRollingTopWords [topology-name] [-local]"
*
* <p>By default, the topology is run locally under the name
* "slidingWindowCounts".
*
* <p>Examples:
*
* <p>```
* # Runs in remote/cluster mode, with topology name "production-topology"
* $ storm jar storm-starter-jar-with-dependencies.jar org.apache.storm.starter.SkewedRollingTopWords production-topology ```
*
* @param args
* First positional argument (optional) is topology name, second
* positional argument (optional) defines whether to run the topology
* locally ("-local") or remotely, i.e. on a real cluster
*/
@Override
protected int run(String[] args) {
String topologyName = "slidingWindowCounts";
if (args.length >= 1) {
topologyName = args[0];
}
TopologyBuilder builder = new TopologyBuilder();
String spoutId = "wordGenerator";
String counterId = "counter";
String aggId = "aggregator";
builder.setSpout(spoutId, new TestWordSpout(), 5);
builder.setBolt(counterId, new RollingCountBolt(9, 3), 4).partialKeyGrouping(spoutId, new Fields("word"));
builder.setBolt(aggId, new RollingCountAggBolt(), 4).fieldsGrouping(counterId, new Fields("obj"));
String intermediateRankerId = "intermediateRanker";
builder.setBolt(intermediateRankerId, new IntermediateRankingsBolt(TOP_N), 4).fieldsGrouping(aggId, new Fields("obj"));
String totalRankerId = "finalRanker";
builder.setBolt(totalRankerId, new TotalRankingsBolt(TOP_N)).globalGrouping(intermediateRankerId);
LOG.info("Topology name: " + topologyName);
return submit(topologyName, conf, builder);
}
use of org.apache.storm.testing.TestWordSpout in project storm by apache.
the class StatefulWordCount method main.
public static void main(String[] args) throws Exception {
StreamBuilder builder = new StreamBuilder();
// a stream of words
builder.newStream(new TestWordSpout(), new ValueMapper<String>(0), 2).window(TumblingWindows.of(BaseWindowedBolt.Duration.seconds(2))).mapToPair(w -> Pair.of(w, 1)).countByKey().updateStateByKey(0L, (state, count) -> state + count).toPairStream().print();
Config config = new Config();
// use redis based state store for persistence
config.put(Config.TOPOLOGY_STATE_PROVIDER, "org.apache.storm.redis.state.RedisKeyValueStateProvider");
String topoName = "test";
if (args.length > 0) {
topoName = args[0];
}
config.setNumWorkers(1);
StormSubmitter.submitTopologyWithProgressBar(topoName, config, builder.build());
}
use of org.apache.storm.testing.TestWordSpout in project storm by apache.
the class StateQueryExample method main.
public static void main(String[] args) throws Exception {
StreamBuilder builder = new StreamBuilder();
StreamState<String, Long> ss = builder.newStream(new TestWordSpout(), new ValueMapper<String>(0), 2).mapToPair(w -> Pair.of(w, 1)).updateStateByKey(0L, (count, val) -> count + 1);
/*
* A stream of words emitted by the QuerySpout is used as
* the keys to query the state.
*/
builder.newStream(new QuerySpout(), new ValueMapper<String>(0)).stateQuery(ss).print();
Config config = new Config();
// use redis based state store for persistence
config.put(Config.TOPOLOGY_STATE_PROVIDER, "org.apache.storm.redis.state.RedisKeyValueStateProvider");
String topoName = "test";
if (args.length > 0) {
topoName = args[0];
}
config.setNumWorkers(1);
StormSubmitter.submitTopologyWithProgressBar(topoName, config, builder.build());
}
use of org.apache.storm.testing.TestWordSpout in project storm by apache.
the class WordCountToBolt method main.
public static void main(String[] args) throws Exception {
StreamBuilder builder = new StreamBuilder();
// Redis config parameters for the RedisStoreBolt
JedisPoolConfig poolConfig = new JedisPoolConfig.Builder().setHost("127.0.0.1").setPort(6379).build();
// Storm tuple to redis key-value mapper
RedisStoreMapper storeMapper = new WordCountStoreMapper();
// The redis bolt (sink)
IRichBolt redisStoreBolt = new RedisStoreBolt(poolConfig, storeMapper);
// A stream of words
builder.newStream(new TestWordSpout(), new ValueMapper<String>(0)).mapToPair(w -> Pair.of(w, 1)).countByKey().to(redisStoreBolt);
Config config = new Config();
String topoName = "test";
if (args.length > 0) {
topoName = args[0];
}
config.setNumWorkers(1);
StormSubmitter.submitTopologyWithProgressBar(topoName, config, builder.build());
}
use of org.apache.storm.testing.TestWordSpout in project storm by apache.
the class TopologyIntegrationTest method mkValidateTopology.
private StormTopology mkValidateTopology() {
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("1", new TestWordSpout(true), 3);
builder.setBolt("2", new TestWordCounter(), 4).fieldsGrouping("1", new Fields("word"));
return builder.createTopology();
}
Aggregations