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;
}
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 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) });
}
Aggregations