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
assertEquals("[[0]]", client.execute("words", "cat")); // 0
assertEquals("[[0]]", client.execute("words", "dog")); // 0
assertEquals("[[4]]", client.execute("words", "the")); // 4
assertEquals("[[1]]", client.execute("words", "man")); // 1
cluster.shutdown();
client.shutdown();
}