Search in sources :

Example 1 with MessageDistributor

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

Example 2 with MessageDistributor

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

Example 3 with MessageDistributor

use of org.apache.metron.profiler.MessageDistributor 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));
}
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 4 with MessageDistributor

use of org.apache.metron.profiler.MessageDistributor in project metron by apache.

the class ProfileBuilderBoltTest method testFlushExpiredWithNoTick.

@Test
public void testFlushExpiredWithNoTick() 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; NO tick tuple
    Tuple tuple1 = createTuple("entity", message1, profile1, 100000000L);
    TupleWindow tupleWindow = createWindow(tuple1);
    bolt.execute(tupleWindow);
    // there was no tick tuple; the expired profiles should NOT have been flushed
    verify(distributor, times(0)).flushExpired();
}
Also used : MessageDistributor(org.apache.metron.profiler.MessageDistributor) TupleWindow(org.apache.storm.windowing.TupleWindow) Tuple(org.apache.storm.tuple.Tuple) BaseBoltTest(org.apache.metron.test.bolt.BaseBoltTest) Test(org.junit.Test)

Example 5 with MessageDistributor

use of org.apache.metron.profiler.MessageDistributor 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)

Aggregations

MessageDistributor (org.apache.metron.profiler.MessageDistributor)5 BaseBoltTest (org.apache.metron.test.bolt.BaseBoltTest)5 Tuple (org.apache.storm.tuple.Tuple)5 TupleWindow (org.apache.storm.windowing.TupleWindow)5 Test (org.junit.Test)5 ProfileMeasurement (org.apache.metron.profiler.ProfileMeasurement)2 MessageRoute (org.apache.metron.profiler.MessageRoute)1