Search in sources :

Example 21 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(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.jupiter.api.Test)

Example 22 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.jupiter.api.Test)

Example 23 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[] 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) });
}
Also used : Fields(org.apache.storm.tuple.Fields) Values(org.apache.storm.tuple.Values) TupleWindow(org.apache.storm.windowing.TupleWindow) Test(org.junit.Test)

Example 24 with TupleWindow

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

Example 25 with TupleWindow

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

Aggregations

TupleWindow (org.apache.storm.windowing.TupleWindow)27 Tuple (org.apache.storm.tuple.Tuple)22 Test (org.junit.Test)18 BaseBoltTest (org.apache.metron.test.bolt.BaseBoltTest)10 MessageDistributor (org.apache.metron.profiler.MessageDistributor)9 ProfileMeasurement (org.apache.metron.profiler.ProfileMeasurement)4 Test (org.junit.jupiter.api.Test)4 ProfilerConfigurations (org.apache.metron.common.configuration.profiler.ProfilerConfigurations)3 MessageRoute (org.apache.metron.profiler.MessageRoute)3 RulesProcessor (com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor)1 Window (com.hortonworks.streamline.streams.layout.component.rule.expression.Window)1 String.format (java.lang.String.format)1 MethodHandles (java.lang.invoke.MethodHandles)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 LongSummaryStatistics (java.util.LongSummaryStatistics)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Executors (java.util.concurrent.Executors)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1