use of backtype.storm.topology.base.BaseWindowedBolt in project jstorm by alibaba.
the class SlidingTupleTsTopology method test.
public static void test() {
String[] className = Thread.currentThread().getStackTrace()[1].getClassName().split("\\.");
String topologyName = className[className.length - 1];
try {
TopologyBuilder builder = new TopologyBuilder();
BaseWindowedBolt bolt = new SlidingWindowSumBolt().withWindow(new Duration(5, TimeUnit.SECONDS), new Duration(3, TimeUnit.SECONDS)).withTimestampField("ts").withLag(new Duration(5, TimeUnit.SECONDS));
builder.setSpout("integer", new RandomIntegerSpout(), 1);
builder.setBolt("slidingsum", bolt, 1).shuffleGrouping("integer");
builder.setBolt("printer", new PrinterBolt(), 1).shuffleGrouping("slidingsum");
conf.setDebug(true);
JStormHelper.runTopology(builder.createTopology(), topologyName, conf, 60, new JStormHelper.CheckAckedFail(conf), isLocal);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Assert.fail("Failed");
}
}
use of backtype.storm.topology.base.BaseWindowedBolt in project jstorm by alibaba.
the class SlidingTupleTsTopologyTest method testSlidingTupleTsTopology.
@Test
public void testSlidingTupleTsTopology() {
TopologyBuilder topologyBuilder = new TopologyBuilder();
BaseWindowedBolt bolt = new SlidingTupleTestBolt().withWindow(new BaseWindowedBolt.Duration(WINDOW_LENGTH_SEC, TimeUnit.SECONDS), new BaseWindowedBolt.Duration(WINDOW_SLIDE_SEC, TimeUnit.SECONDS)).withTimestampField("ts").withLag(new BaseWindowedBolt.Duration(WINDOW_LAG_SEC, TimeUnit.SECONDS));
topologyBuilder.setSpout("spout", new SlidingTupleTestRandomSpout(SPOUT_LIMIT), 1);
topologyBuilder.setBolt("sum", bolt, 1).shuffleGrouping("spout");
Map config = new HashMap();
config.put(Config.TOPOLOGY_NAME, "SlidingTupleTsTopologyTest");
Set<String> userDefineMetrics = new HashSet<String>();
userDefineMetrics.add("SlidingTupleTsTopologyTest.SpoutSum");
userDefineMetrics.add("SlidingTupleTsTopologyTest.BoltSum");
JStormUnitTestValidator validator = new JStormUnitTestMetricValidator(userDefineMetrics) {
@Override
public boolean validateMetrics(Map<String, Double> metrics) {
int spoutSum = (int) metrics.get("SlidingTupleTsTopologyTest.SpoutSum").doubleValue();
int boltSum = (int) metrics.get("SlidingTupleTsTopologyTest.BoltSum").doubleValue();
assertEquals(spoutSum, boltSum);
return true;
}
};
JStormUnitTestRunner.submitTopology(topologyBuilder.createTopology(), config, 120, validator);
}
Aggregations