use of org.apache.storm.windowing.TupleWindow in project metron by apache.
the class ProfileBuilderBoltTest method testFlushExpiredWithTick.
@Test
public void testFlushExpiredWithTick() throws Exception {
ProfileBuilderBolt bolt = createBolt();
// create a mock
MessageDistributor distributor = mock(MessageDistributor.class);
bolt.withMessageDistributor(distributor);
// tell the bolt to flush on the first window
flushSignal.setFlushNow(true);
// execute the bolt; include a tick tuple in the window
Tuple tuple1 = createTuple("entity", message1, profile1, 100000000L);
TupleWindow tupleWindow = createWindow(tuple1, mockTickTuple());
bolt.execute(tupleWindow);
// ensure the expired profiles were flushed when the tick tuple was received
verify(distributor).flushExpired();
}
use of org.apache.storm.windowing.TupleWindow in project metron by apache.
the class ProfileBuilderBoltTest method testExtractMessage.
/**
* The bolt should extract a message and timestamp from a tuple and
* pass that to a {@code MessageDistributor}.
*/
@Test
public void testExtractMessage() throws Exception {
ProfileBuilderBolt bolt = createBolt();
// create a mock
MessageDistributor distributor = mock(MessageDistributor.class);
bolt.withMessageDistributor(distributor);
// create a tuple
final long timestamp1 = 100000000L;
Tuple tuple1 = createTuple("entity1", message1, profile1, timestamp1);
// execute the bolt
TupleWindow tupleWindow = createWindow(tuple1);
bolt.execute(tupleWindow);
// the message should have been extracted from the tuple and passed to the MessageDistributor
verify(distributor).distribute(eq(message1), eq(timestamp1), any(MessageRoute.class), any());
}
use of org.apache.storm.windowing.TupleWindow in project metron by apache.
the class ProfileBuilderBoltTest method testEmitWhenFlush.
/**
* If the {@code FlushSignal} tells the bolt to flush, it should flush the {@code MessageDistributor}
* and emit the {@code ProfileMeasurement} values.
*/
@Test
public void testEmitWhenFlush() throws Exception {
ProfileBuilderBolt bolt = createBolt();
// create a profile measurement
ProfileMeasurement m = new ProfileMeasurement().withEntity("entity1").withProfileName("profile1").withPeriod(1000, 500, TimeUnit.MILLISECONDS).withProfileValue(22);
// create a mock that returns the profile measurement above
MessageDistributor distributor = mock(MessageDistributor.class);
when(distributor.flush()).thenReturn(Collections.singletonList(m));
bolt.withMessageDistributor(distributor);
// signal the bolt to flush
flushSignal.setFlushNow(true);
// execute the bolt
Tuple tuple1 = createTuple("entity1", message1, profile1, 1000L);
TupleWindow tupleWindow = createWindow(tuple1);
bolt.execute(tupleWindow);
// a profile measurement should be emitted by the bolt
List<ProfileMeasurement> measurements = getProfileMeasurements(outputCollector, 1);
assertEquals(1, measurements.size());
assertEquals(m, measurements.get(0));
}
use of org.apache.storm.windowing.TupleWindow in project streamline by hortonworks.
the class TestWindowedQueryBolt method testNestedKeys_trivial.
@Test
public void testNestedKeys_trivial() throws Exception {
ArrayList<Tuple> userStream = makeStreamLineEventStream("users", userFields, users);
TupleWindow window = makeTupleWindow(userStream);
WindowedQueryBolt bolt = new WindowedQueryBolt("users", SL_PREFIX + "userId").selectStreamLine("name,users:city, users:city as cityagain");
MockTopologyContext context = new MockTopologyContext(new String[] { StreamlineEvent.STREAMLINE_EVENT });
MockCollector collector = new MockCollector();
bolt.prepare(null, context, collector);
bolt.execute(window);
printResults_StreamLine(collector);
Assert.assertEquals(userStream.size(), collector.actualResults.size());
}
use of org.apache.storm.windowing.TupleWindow 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);
}
Aggregations