/** * Define a new bolt in this topology. This defines a windowed bolt, intended for windowing operations. The {@link * IWindowedBolt#execute(TupleWindow)} method is triggered for each window interval with the list of current events in the window. * * @param id the id of this component. This id is referenced by other components that want to consume this bolt's * outputs. * @param bolt the windowed bolt * @param parallelism_hint the number of tasks that should be assigned to execute this bolt. Each task will run on a thread in a process * somwehere around the cluster. * @return use the returned object to declare the inputs to this component * * @throws IllegalArgumentException if {@code parallelism_hint} is not positive */ public BoltDeclarer setBolt(String id, IWindowedBolt bolt, Number parallelism_hint) throws IllegalArgumentException { return setBolt(id, new WindowedBoltExecutor(bolt), parallelism_hint); }
@Before public void setUp() { testWindowedBolt = new TestWindowedBolt(); testWindowedBolt.withTimestampField("ts"); executor = new WindowedBoltExecutor(testWindowedBolt); Map<String, Object> conf = new HashMap<>(); conf.put(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS, 100000); conf.put(Config.TOPOLOGY_BOLTS_WINDOW_LENGTH_DURATION_MS, 20); conf.put(Config.TOPOLOGY_BOLTS_SLIDING_INTERVAL_DURATION_MS, 10); conf.put(Config.TOPOLOGY_BOLTS_TUPLE_TIMESTAMP_MAX_LAG_MS, 5); // trigger manually to avoid timing issues conf.put(Config.TOPOLOGY_BOLTS_WATERMARK_EVENT_INTERVAL_MS, 100000); executor.prepare(conf, getTopologyContext(), getOutputCollector()); }
@Test public void testPrepareLateTupleStreamWithoutTs() throws Exception { Map<String, Object> conf = new HashMap<>(); conf.put(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS, 100000); conf.put(Config.TOPOLOGY_BOLTS_WINDOW_LENGTH_DURATION_MS, 20); conf.put(Config.TOPOLOGY_BOLTS_SLIDING_INTERVAL_DURATION_MS, 10); conf.put(Config.TOPOLOGY_BOLTS_LATE_TUPLE_STREAM, "$late"); conf.put(Config.TOPOLOGY_BOLTS_TUPLE_TIMESTAMP_MAX_LAG_MS, 5); conf.put(Config.TOPOLOGY_BOLTS_WATERMARK_EVENT_INTERVAL_MS, 10); testWindowedBolt = new TestWindowedBolt(); executor = new WindowedBoltExecutor(testWindowedBolt); TopologyContext context = getTopologyContext(); // emulate the call of withLateTupleStream method Mockito.when(context.getThisStreams()).thenReturn(new HashSet<>(Arrays.asList("default", "$late"))); try { executor.prepare(conf, context, getOutputCollector()); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("Late tuple stream can be defined only when specifying a timestamp field")); } }
@Test public void testPrepareLateTupleStreamWithoutBuilder() throws Exception { Map<String, Object> conf = new HashMap<>(); conf.put(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS, 100000); conf.put(Config.TOPOLOGY_BOLTS_WINDOW_LENGTH_DURATION_MS, 20); conf.put(Config.TOPOLOGY_BOLTS_SLIDING_INTERVAL_DURATION_MS, 10); conf.put(Config.TOPOLOGY_BOLTS_LATE_TUPLE_STREAM, "$late"); conf.put(Config.TOPOLOGY_BOLTS_TUPLE_TIMESTAMP_MAX_LAG_MS, 5); conf.put(Config.TOPOLOGY_BOLTS_WATERMARK_EVENT_INTERVAL_MS, 10); testWindowedBolt = new TestWindowedBolt(); testWindowedBolt.withTimestampField("ts"); executor = new WindowedBoltExecutor(testWindowedBolt); TopologyContext context = getTopologyContext(); try { executor.prepare(conf, context, getOutputCollector()); fail(); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), is("Stream for late tuples must be defined with the builder method withLateTupleStream")); } }
/** * Define a new bolt in this topology. This defines a windowed bolt, intended * for windowing operations. The {@link IWindowedBolt#execute(TupleWindow)} method * is triggered for each window interval with the list of current events in the window. * * @param id the id of this component. This id is referenced by other components that want to consume this bolt's outputs. * @param bolt the windowed bolt * @param parallelism_hint the number of tasks that should be assigned to execute this bolt. Each task will run on a thread in a process somwehere around the cluster. * @return use the returned object to declare the inputs to this component * @throws IllegalArgumentException if {@code parallelism_hint} is not positive */ public BoltDeclarer setBolt(String id, IWindowedBolt bolt, Number parallelism_hint) throws IllegalArgumentException { return setBolt(id, new WindowedBoltExecutor(bolt), parallelism_hint); }