Search in sources :

Example 1 with BaseWindowedBolt

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");
    }
}
Also used : JStormHelper(com.alibaba.starter.utils.JStormHelper) TopologyBuilder(backtype.storm.topology.TopologyBuilder) RandomIntegerSpout(org.apache.storm.starter.spout.RandomIntegerSpout) Duration(backtype.storm.topology.base.BaseWindowedBolt.Duration) SlidingWindowSumBolt(org.apache.storm.starter.bolt.SlidingWindowSumBolt) PrinterBolt(org.apache.storm.starter.bolt.PrinterBolt) BaseWindowedBolt(backtype.storm.topology.base.BaseWindowedBolt)

Example 2 with BaseWindowedBolt

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);
}
Also used : JStormUnitTestValidator(com.jstorm.example.unittests.utils.JStormUnitTestValidator) TopologyBuilder(backtype.storm.topology.TopologyBuilder) JStormUnitTestMetricValidator(com.jstorm.example.unittests.utils.JStormUnitTestMetricValidator) BaseWindowedBolt(backtype.storm.topology.base.BaseWindowedBolt) Test(org.junit.Test)

Aggregations

TopologyBuilder (backtype.storm.topology.TopologyBuilder)2 BaseWindowedBolt (backtype.storm.topology.base.BaseWindowedBolt)2 Duration (backtype.storm.topology.base.BaseWindowedBolt.Duration)1 JStormHelper (com.alibaba.starter.utils.JStormHelper)1 JStormUnitTestMetricValidator (com.jstorm.example.unittests.utils.JStormUnitTestMetricValidator)1 JStormUnitTestValidator (com.jstorm.example.unittests.utils.JStormUnitTestValidator)1 PrinterBolt (org.apache.storm.starter.bolt.PrinterBolt)1 SlidingWindowSumBolt (org.apache.storm.starter.bolt.SlidingWindowSumBolt)1 RandomIntegerSpout (org.apache.storm.starter.spout.RandomIntegerSpout)1 Test (org.junit.Test)1