Search in sources :

Example 6 with TupleWindow

use of org.apache.storm.windowing.TupleWindow in project storm by apache.

the class WindowedProcessorBoltTest method getMockTupleWindow.

private TupleWindow getMockTupleWindow(Tuple... tuples) {
    TupleWindow tupleWindow = Mockito.mock(TupleWindow.class);
    Mockito.when(tupleWindow.get()).thenReturn(Arrays.asList(tuples));
    return tupleWindow;
}
Also used : TupleWindow(org.apache.storm.windowing.TupleWindow)

Example 7 with TupleWindow

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();
}
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 8 with TupleWindow

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());
}
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 9 with TupleWindow

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));
}
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 10 with TupleWindow

use of org.apache.storm.windowing.TupleWindow in project storm by apache.

the class WindowedBoltExecutorTest method testExecuteWithTs.

@Test
public void testExecuteWithTs() throws Exception {
    long[] timstamps = { 603, 605, 607, 618, 626, 636 };
    for (long ts : timstamps) {
        executor.execute(getTuple("s1", new Fields("ts"), new Values(ts)));
    }
    //Thread.sleep(120);
    executor.waterMarkEventGenerator.run();
    //System.out.println(testWindowedBolt.tupleWindows);
    assertEquals(3, testWindowedBolt.tupleWindows.size());
    TupleWindow first = testWindowedBolt.tupleWindows.get(0);
    assertArrayEquals(new long[] { 603, 605, 607 }, new long[] { (long) first.get().get(0).getValue(0), (long) first.get().get(1).getValue(0), (long) first.get().get(2).getValue(0) });
    TupleWindow second = testWindowedBolt.tupleWindows.get(1);
    assertArrayEquals(new long[] { 603, 605, 607, 618 }, new long[] { (long) second.get().get(0).getValue(0), (long) second.get().get(1).getValue(0), (long) second.get().get(2).getValue(0), (long) second.get().get(3).getValue(0) });
    TupleWindow third = testWindowedBolt.tupleWindows.get(2);
    assertArrayEquals(new long[] { 618, 626 }, new long[] { (long) third.get().get(0).getValue(0), (long) third.get().get(1).getValue(0) });
}
Also used : Fields(org.apache.storm.tuple.Fields) Values(org.apache.storm.tuple.Values) TupleWindow(org.apache.storm.windowing.TupleWindow) 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