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(any(MessageRoute.class), any());
}
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());
}
use of org.apache.storm.windowing.TupleWindow in project storm by apache.
the class WindowedBoltExecutorTest method testExecuteWithTs.
@Test
public void testExecuteWithTs() throws Exception {
long[] timestamps = { 603, 605, 607, 618, 626, 636 };
for (long ts : timestamps) {
executor.execute(getTuple("s1", new Fields("ts"), new Values(ts), "s1Src"));
}
// 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) });
}
use of org.apache.storm.windowing.TupleWindow in project storm by apache.
the class TestJoinBolt method testNestedKeys.
@Test
public void testNestedKeys() throws Exception {
ArrayList<Tuple> userStream = makeNestedEventsStream("users", userFields, users, "usersSpout");
TupleWindow window = makeTupleWindow(userStream);
JoinBolt bolt = new JoinBolt(JoinBolt.Selector.STREAM, "users", "outer.userId").select("outer.name, outer.city");
MockCollector collector = new MockCollector();
bolt.prepare(null, null, collector);
bolt.execute(window);
printResults(collector);
Assert.assertEquals(userStream.size(), collector.actualResults.size());
}
use of org.apache.storm.windowing.TupleWindow in project storm by apache.
the class TestJoinBolt method testProjection_FieldsWithStreamName.
@Test
public void testProjection_FieldsWithStreamName() throws Exception {
ArrayList<Tuple> userStream = makeStream("users", userFields, users, "usersSpout");
ArrayList<Tuple> storeStream = makeStream("stores", storeFields, stores, "storesSpout");
TupleWindow window = makeTupleWindow(storeStream, userStream);
// join users and stores on city name
JoinBolt bolt = new JoinBolt(JoinBolt.Selector.STREAM, "users", userFields[2]).join("stores", "city", "users").select("userId,name,storeName,users:city,stores:city");
MockCollector collector = new MockCollector();
bolt.prepare(null, null, collector);
bolt.execute(window);
printResults(collector);
Assert.assertEquals(storeStream.size() + 1, collector.actualResults.size());
// ensure 5 fields per tuple and no null fields
for (List<Object> tuple : collector.actualResults) {
Assert.assertEquals(5, tuple.size());
for (Object o : tuple) {
Assert.assertNotNull(o);
}
}
}
Aggregations