Search in sources :

Example 1 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 2 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 3 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 4 with TupleWindow

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

the class TestWindowedQueryBolt method testNestedKeys_trivial.

@Test
public void testNestedKeys_trivial() throws Exception {
    ArrayList<Tuple> userStream = makeStreamLineEventStream("users", userFields, users);
    TupleWindow window = makeTupleWindow(userStream);
    WindowedQueryBolt bolt = new WindowedQueryBolt("users", SL_PREFIX + "userId").selectStreamLine("name,users:city, users:city as cityagain");
    MockTopologyContext context = new MockTopologyContext(new String[] { StreamlineEvent.STREAMLINE_EVENT });
    MockCollector collector = new MockCollector();
    bolt.prepare(null, context, collector);
    bolt.execute(window);
    printResults_StreamLine(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 5 with TupleWindow

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

the class WindowRulesBoltTest method doTest.

private boolean doTest(String rulesJson, int expectedExecuteCount, Function<Integer, Tuple> tupleGen) throws Exception {
    RulesProcessor rulesProcessor = Utils.createObjectFromJson(rulesJson, RulesProcessor.class);
    Window windowConfig = rulesProcessor.getRules().get(0).getWindow();
    final CountDownLatch latch = new CountDownLatch(expectedExecuteCount);
    WindowRulesBolt wb = new WindowRulesBolt(rulesJson, RuleProcessorRuntime.ScriptType.SQL) {

        @Override
        public void execute(TupleWindow inputWindow) {
            super.execute(inputWindow);
            latch.countDown();
        }
    };
    wb.withWindowConfig(windowConfig);
    WindowedBoltExecutor wbe = new WindowedBoltExecutor(wb);
    Map<String, Object> conf = wb.getComponentConfiguration();
    conf.put("topology.message.timeout.secs", 30);
    wbe.prepare(conf, mockContext, mockCollector);
    Thread.sleep(100);
    for (int i = 1; i <= 20; i++) {
        wbe.execute(tupleGen.apply(i));
    }
    // wait for up to 5 secs for the bolt's execute to finish
    return latch.await(5, TimeUnit.SECONDS);
}
Also used : TupleWindow(org.apache.storm.windowing.TupleWindow) Window(com.hortonworks.streamline.streams.layout.component.rule.expression.Window) RulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor) TupleWindow(org.apache.storm.windowing.TupleWindow) WindowedBoltExecutor(org.apache.storm.topology.WindowedBoltExecutor) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

TupleWindow (org.apache.storm.windowing.TupleWindow)21 Test (org.junit.Test)18 Tuple (org.apache.storm.tuple.Tuple)17 BaseBoltTest (org.apache.metron.test.bolt.BaseBoltTest)6 MessageDistributor (org.apache.metron.profiler.MessageDistributor)5 ProfileMeasurement (org.apache.metron.profiler.ProfileMeasurement)2 RulesProcessor (com.hortonworks.streamline.streams.layout.component.impl.RulesProcessor)1 Window (com.hortonworks.streamline.streams.layout.component.rule.expression.Window)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ProfilerConfigurations (org.apache.metron.common.configuration.profiler.ProfilerConfigurations)1 MessageRoute (org.apache.metron.profiler.MessageRoute)1 WindowedBoltExecutor (org.apache.storm.topology.WindowedBoltExecutor)1 Fields (org.apache.storm.tuple.Fields)1 Values (org.apache.storm.tuple.Values)1