use of org.apache.storm.windowing.TupleWindow in project metron by apache.
the class ProfileBuilderBoltTest method createWindow.
/**
* Creates a mock TupleWindow containing multiple tuples.
* @param tuples The tuples to add to the window.
*/
private TupleWindow createWindow(Tuple... tuples) {
TupleWindow window = mock(TupleWindow.class);
when(window.get()).thenReturn(Arrays.asList(tuples));
return window;
}
use of org.apache.storm.windowing.TupleWindow in project metron by apache.
the class ProfileBuilderBoltTest method testDoNotEmitWhenNoFlush.
/**
* If the {@code FlushSignal} tells the bolt NOT to flush, nothing should be emitted.
*/
@Test
public void testDoNotEmitWhenNoFlush() 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);
// no flush signal
flushSignal.setFlushNow(false);
// execute the bolt
Tuple tuple1 = createTuple("entity1", message1, profile1, 1000L);
TupleWindow tupleWindow = createWindow(tuple1);
bolt.execute(tupleWindow);
// nothing should have been emitted
getProfileMeasurements(outputCollector, 0);
}
use of org.apache.storm.windowing.TupleWindow in project metron by apache.
the class ProfileBuilderBoltTest method testEmitters.
/**
* A {@link ProfileMeasurement} is built for each profile/entity pair. The measurement should be emitted to each
* destination defined by the profile. By default, a profile uses both Kafka and HBase as destinations.
*/
@Test
public void testEmitters() throws Exception {
// defines the zk configurations accessible from the bolt
ProfilerConfigurations configurations = new ProfilerConfigurations();
configurations.updateGlobalConfig(Collections.emptyMap());
// create the bolt with 3 destinations
ProfileBuilderBolt bolt = (ProfileBuilderBolt) new ProfileBuilderBolt().withProfileTimeToLive(30, TimeUnit.MINUTES).withPeriodDuration(10, TimeUnit.MINUTES).withMaxNumberOfRoutes(Long.MAX_VALUE).withZookeeperClient(client).withZookeeperCache(cache).withEmitter(new TestEmitter("destination1")).withEmitter(new TestEmitter("destination2")).withEmitter(new TestEmitter("destination3")).withProfilerConfigurations(configurations).withTumblingWindow(new BaseWindowedBolt.Duration(10, TimeUnit.MINUTES));
bolt.prepare(new HashMap<>(), topologyContext, outputCollector);
// signal the bolt to flush
bolt.withFlushSignal(flushSignal);
flushSignal.setFlushNow(true);
// execute the bolt
Tuple tuple1 = createTuple("entity", message1, profile1, System.currentTimeMillis());
TupleWindow window = createWindow(tuple1);
bolt.execute(window);
// validate measurements emitted to each
verify(outputCollector, times(1)).emit(eq("destination1"), any());
verify(outputCollector, times(1)).emit(eq("destination2"), any());
verify(outputCollector, times(1)).emit(eq("destination3"), any());
}
Aggregations