InigoSJ commented on code in PR #23100:
URL: https://github.com/apache/beam/pull/23100#discussion_r966219109
##########
sdks/python/apache_beam/transforms/trigger_test.py:
##########
@@ -540,6 +540,88 @@ def test_trigger_encoding(self):
class TriggerPipelineTest(unittest.TestCase):
+ def test_after_processing_time(self):
+ test_options = PipelineOptions(
+ flags=['--allow_unsafe_triggers', '--streaming'])
+ with TestPipeline(options=test_options) as p:
+
+ total_elements_in_trigger = 4
+ processing_time_delay = 2
+ window_size = 10
+
+ # yapf: disable
+ test_stream = TestStream()
+ for i in range(total_elements_in_trigger):
+ (test_stream
+ .advance_processing_time(processing_time_delay /
total_elements_in_trigger )
+ .add_elements([('key', i)])
+ )
+
+ test_stream.advance_processing_time(processing_time_delay)
+
+ # Add dropped elements
+ (test_stream
+ .advance_processing_time(0.1)
+ .add_elements([('key', "dropped-1")])
+ .advance_processing_time(0.1)
+ .add_elements([('key', "dropped-2")])
+ )
+
+ (test_stream
+ .advance_processing_time(processing_time_delay)
+ .advance_watermark_to_infinity()
+ )
+ # yapf: enable
+
+ results = (
+ p
+ | test_stream
+ | beam.WindowInto(
+ FixedWindows(window_size),
+ trigger=AfterProcessingTime(processing_time_delay),
+ accumulation_mode=AccumulationMode.DISCARDING)
+ | beam.GroupByKey()
+ | beam.Map(lambda x: x[1]))
+
+ assert_that(results, equal_to([list(range(total_elements_in_trigger))]))
+
+ def test_repeatedly_after_processing_time(self):
+ test_options = PipelineOptions(flags=['--streaming'])
+ with TestPipeline(options=test_options) as p:
+ total_elements = 8
+ processing_time_delay = 2
+ window_size = 10
+ # yapf: disable
+ test_stream = TestStream()
+ for i in range(total_elements):
+ (test_stream
+ .advance_processing_time(processing_time_delay - 0.01)
+ .add_elements([('key', i)])
+ )
+
+ (test_stream
+ .advance_processing_time(processing_time_delay)
+ .advance_watermark_to_infinity()
+ )
+ # yapf: enable
+
+ results = (
+ p
+ | test_stream
+ | beam.WindowInto(
+ FixedWindows(window_size),
+ trigger=Repeatedly(AfterProcessingTime(processing_time_delay)),
+ accumulation_mode=AccumulationMode.DISCARDING)
+ | beam.GroupByKey()
+ | beam.Map(lambda x: x[1]))
+
+ expected = [[i, i + 1]
Review Comment:
Maybe this is overly complicated? and we can just assume a fixed value
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]