Search in sources :

Example 1 with WindowedBoltExecutor

use of org.apache.storm.topology.WindowedBoltExecutor in project streamline by hortonworks.

the class WindowRulesBoltTest method doTest.

private boolean doTest(String rulesJson, int expectedExecuteCount, Function<Integer, Tuple> tupleGen) throws Exception {
    RulesProcessor rulesProcessor = Utils.createObjectFromJson(rulesJson, RulesProcessor.class);
    Window windowConfig = rulesProcessor.getRules().get(0).getWindow();
    final CountDownLatch latch = new CountDownLatch(expectedExecuteCount);
    WindowRulesBolt wb = new WindowRulesBolt(rulesJson, RuleProcessorRuntime.ScriptType.SQL) {

        @Override
        public void execute(TupleWindow inputWindow) {
            super.execute(inputWindow);
            latch.countDown();
        }
    };
    wb.withWindowConfig(windowConfig);
    WindowedBoltExecutor wbe = new WindowedBoltExecutor(wb);
    Map<String, Object> conf = wb.getComponentConfiguration();
    conf.put("topology.message.timeout.secs", 30);
    wbe.prepare(conf, mockContext, mockCollector);
    Thread.sleep(100);
    for (int i = 1; i <= 20; i++) {
        wbe.execute(tupleGen.apply(i));
    }
    // wait for up to 5 secs for the bolt's execute to finish
    return latch.await(5, TimeUnit.SECONDS);
}
Also used : TupleWindow(org.apache.storm.windowing.TupleWindow) Window(com.hortonworks.streamline.streams.layout.component.rule.expression.Window) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) TupleWindow(org.apache.storm.windowing.TupleWindow) WindowedBoltExecutor(org.apache.storm.topology.WindowedBoltExecutor) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 2 with WindowedBoltExecutor

use of org.apache.storm.topology.WindowedBoltExecutor in project streamline by hortonworks.

the class WindowRulesBoltTest method testCountBasedWindowWithGroupbyUnordered.

@Test
public void testCountBasedWindowWithGroupbyUnordered() throws Exception {
    String rulesJson = readFile("/window-rule-groupby-unordered.json");
    RulesProcessor rulesProcessor = Utils.createObjectFromJson(rulesJson, RulesProcessor.class);
    Window windowConfig = rulesProcessor.getRules().get(0).getWindow();
    WindowRulesBolt wb = new WindowRulesBolt(rulesJson, RuleProcessorRuntime.ScriptType.SQL);
    wb.withWindowConfig(windowConfig);
    WindowedBoltExecutor wbe = new WindowedBoltExecutor(wb);
    Map<String, Object> conf = wb.getComponentConfiguration();
    wbe.prepare(conf, mockContext, mockCollector);
    wbe.execute(getNextTuple(10));
    wbe.execute(getNextTuple(15));
    wbe.execute(getNextTuple(11));
    wbe.execute(getNextTuple(16));
    new Verifications() {

        {
            String streamId;
            Collection<Tuple> anchors;
            List<List<Object>> tuples = new ArrayList<>();
            mockCollector.emit(streamId = withCapture(), anchors = withCapture(), withCapture(tuples));
            Assert.assertEquals(2, tuples.size());
            Map<String, Object> fieldsAndValues = ((StreamlineEvent) tuples.get(0).get(0));
            Assert.assertEquals(2, fieldsAndValues.get("deptid"));
            Assert.assertEquals(110, fieldsAndValues.get("salary_MAX"));
            fieldsAndValues = ((StreamlineEvent) tuples.get(1).get(0));
            Assert.assertEquals(3, fieldsAndValues.get("deptid"));
            Assert.assertEquals(160, fieldsAndValues.get("salary_MAX"));
        }
    };
}
Also used : TupleWindow(org.apache.storm.windowing.TupleWindow) Window(com.hortonworks.streamline.streams.layout.component.rule.expression.Window) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ArrayList(java.util.ArrayList) Verifications(mockit.Verifications) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) WindowedBoltExecutor(org.apache.storm.topology.WindowedBoltExecutor) ArrayList(java.util.ArrayList) List(java.util.List) Tuple(org.apache.storm.tuple.Tuple) Test(org.junit.Test)

Aggregations

RulesProcessor (com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor)2 Window (com.hortonworks.streamline.streams.layout.component.rule.expression.Window)2 WindowedBoltExecutor (org.apache.storm.topology.WindowedBoltExecutor)2 TupleWindow (org.apache.storm.windowing.TupleWindow)2 StreamlineEvent (com.hortonworks.streamline.streams.StreamlineEvent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Verifications (mockit.Verifications)1 Tuple (org.apache.storm.tuple.Tuple)1 Test (org.junit.Test)1