Search in sources :

Example 11 with TopologyContext

use of org.apache.heron.api.topology.TopologyContext in project heron by twitter.

the class WindowedBoltExecutorTest method testExecuteWithLateTupleStream.

@Test
public void testExecuteWithLateTupleStream() throws Exception {
    testWindowedBolt = new TestWindowedBolt();
    testWindowedBolt.withTimestampField("ts");
    executor = new WindowedBoltExecutor(testWindowedBolt);
    TopologyContext context = getTopologyContext();
    Mockito.when(context.getThisStreams()).thenReturn(new HashSet<>(Arrays.asList("default", "$late")));
    OutputCollector outputCollector = Mockito.mock(OutputCollector.class);
    Map<String, Object> conf = new HashMap<>();
    conf.put(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS, 100000);
    conf.put(WindowingConfigs.TOPOLOGY_BOLTS_WINDOW_LENGTH_DURATION_MS, 20L);
    conf.put(WindowingConfigs.TOPOLOGY_BOLTS_SLIDING_INTERVAL_DURATION_MS, 10L);
    conf.put(WindowingConfigs.TOPOLOGY_BOLTS_LATE_TUPLE_STREAM, "$late");
    conf.put(WindowingConfigs.TOPOLOGY_BOLTS_TUPLE_TIMESTAMP_MAX_LAG_MS, 5L);
    // Trigger manually to avoid timing issues
    conf.put(WindowingConfigs.TOPOLOGY_BOLTS_WATERMARK_EVENT_INTERVAL_MS, 1_000_000L);
    executor.prepare(conf, context, outputCollector);
    long[] timestamps = { 603, 605, 607, 618, 626, 636, 600 };
    List<Tuple> tuples = new ArrayList<>(timestamps.length);
    for (long ts : timestamps) {
        Tuple tuple = getTuple("s1", new Fields("ts"), new Values(ts));
        tuples.add(tuple);
        executor.execute(tuple);
        // Update the watermark to this timestamp
        executor.waterMarkEventGenerator.run();
    }
    System.out.println(testWindowedBolt.tupleWindows);
    Tuple tuple = tuples.get(tuples.size() - 1);
    Mockito.verify(outputCollector).emit("$late", Arrays.asList(tuple), new Values(tuple));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Values(org.apache.heron.api.tuple.Values) Fields(org.apache.heron.api.tuple.Fields) TopologyContext(org.apache.heron.api.topology.TopologyContext) Tuple(org.apache.heron.api.tuple.Tuple) Test(org.junit.Test)

Example 12 with TopologyContext

use of org.apache.heron.api.topology.TopologyContext in project heron by twitter.

the class WindowedBoltExecutorTest method getTopologyContext.

private TopologyContext getTopologyContext() {
    TopologyContext context = Mockito.mock(TopologyContext.class);
    Map<TopologyAPI.StreamId, TopologyAPI.Grouping> sources = Collections.singletonMap(TopologyAPI.StreamId.newBuilder().setComponentName("s1").setId("default").build(), null);
    Mockito.when(context.getThisSources()).thenReturn(sources);
    return context;
}
Also used : TopologyContext(org.apache.heron.api.topology.TopologyContext)

Aggregations

TopologyContext (org.apache.heron.api.topology.TopologyContext)12 HashMap (java.util.HashMap)4 Tuple (org.apache.heron.api.tuple.Tuple)4 Test (org.junit.Test)4 BaseBasicBolt (org.apache.heron.api.bolt.BaseBasicBolt)3 BasicOutputCollector (org.apache.heron.api.bolt.BasicOutputCollector)3 BaseRichSpout (org.apache.heron.api.spout.BaseRichSpout)3 SpoutOutputCollector (org.apache.heron.api.spout.SpoutOutputCollector)3 OutputFieldsDeclarer (org.apache.heron.api.topology.OutputFieldsDeclarer)3 TopologyBuilder (org.apache.heron.api.topology.TopologyBuilder)3 Fields (org.apache.heron.api.tuple.Fields)3 Context (org.apache.heron.streamlet.Context)3 ContextImpl (org.apache.heron.streamlet.impl.ContextImpl)3 HeronTopology (org.apache.heron.api.HeronTopology)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Config (org.apache.heron.api.Config)1 BoltDeclarer (org.apache.heron.api.topology.BoltDeclarer)1 Values (org.apache.heron.api.tuple.Values)1 MetricsCollector (org.apache.heron.common.utils.metrics.MetricsCollector)1