new Values("the man went to the store and bought some candy"),
new Values("four score and seven years ago"),
new Values("how many apples can you eat"));
spout.setCycle(false);
TridentTopology topology = new TridentTopology();
HashMap<String, Object> clientConfig = new HashMap<String, Object>();
clientConfig.put(StormCassandraConstants.CASSANDRA_HOST, "localhost:9160");
clientConfig.put(StormCassandraConstants.CASSANDRA_STATE_KEYSPACE, KEYSPACE);
Config config = new Config();
config.setMaxSpoutPending(25);
config.put("cassandra.config", clientConfig);
StateFactory cassandraStateFactory = null;
Options options = null;
switch(txType){
case TRANSACTIONAL:
options = new Options<TransactionalValue>();
options.columnFamily = "transactional";
cassandraStateFactory = CassandraMapState.transactional(options);
break;
case OPAQUE:
options = new Options<OpaqueValue>();
options.columnFamily = "opaque";
cassandraStateFactory = CassandraMapState.opaque(options);
break;
case NON_TRANSACTIONAL:
options = new Options<Object>();
options.columnFamily = "nontransactional";
cassandraStateFactory = CassandraMapState.nonTransactional(options);
break;
}
TridentState wordCounts = topology.newStream("spout1", spout)
.each(new Fields("sentence"), new Split(), new Fields("word")).groupBy(new Fields("word"))
.persistentAggregate(cassandraStateFactory, new Count(), new Fields("count")).parallelismHint(1);
LocalDRPC client = new LocalDRPC();
topology.newDRPCStream("words", client).each(new Fields("args"), new Split(), new Fields("word"))
.groupBy(new Fields("word"))
.stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("count"))
.each(new Fields("count"), new FilterNull())
.aggregate(new Fields("count"), new Sum(), new Fields("sum"));
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("test", config, topology.build());
Thread.sleep(10000);
assertEquals("[[5]]", client.execute("words", "cat dog the man")); // 5