Search in sources :

Example 16 with TupleWindow

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;
}
Also used : TupleWindow(org.apache.storm.windowing.TupleWindow)

Example 17 with TupleWindow

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);
}
Also used : MessageDistributor(org.apache.metron.profiler.MessageDistributor) TupleWindow(org.apache.storm.windowing.TupleWindow) ProfileMeasurement(org.apache.metron.profiler.ProfileMeasurement) Tuple(org.apache.storm.tuple.Tuple) BaseBoltTest(org.apache.metron.test.bolt.BaseBoltTest) Test(org.junit.Test)

Example 18 with TupleWindow

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());
}
Also used : TupleWindow(org.apache.storm.windowing.TupleWindow) Tuple(org.apache.storm.tuple.Tuple) ProfilerConfigurations(org.apache.metron.common.configuration.profiler.ProfilerConfigurations) BaseBoltTest(org.apache.metron.test.bolt.BaseBoltTest) Test(org.junit.Test)

Aggregations

TupleWindow (org.apache.storm.windowing.TupleWindow)18 Test (org.junit.Test)16 Tuple (org.apache.storm.tuple.Tuple)15 BaseBoltTest (org.apache.metron.test.bolt.BaseBoltTest)6 MessageDistributor (org.apache.metron.profiler.MessageDistributor)5 ProfileMeasurement (org.apache.metron.profiler.ProfileMeasurement)2 ProfilerConfigurations (org.apache.metron.common.configuration.profiler.ProfilerConfigurations)1 MessageRoute (org.apache.metron.profiler.MessageRoute)1 Fields (org.apache.storm.tuple.Fields)1 Values (org.apache.storm.tuple.Values)1