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);
}
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"));
}
};
}
Aggregations