3636from apache_beam .options .pipeline_options import DebugOptions
3737from apache_beam .options .pipeline_options import PortableOptions
3838from apache_beam .options .pipeline_options import StandardOptions
39+ from apache_beam .options .pipeline_options import TypeOptions
3940from apache_beam .runners .portability import portable_runner_test
4041from apache_beam .runners .portability import prism_runner
4142from apache_beam .testing .util import assert_that
@@ -68,6 +69,7 @@ def __init__(self, *args, **kwargs):
6869 self .environment_config = None
6970 self .enable_commit = False
7071 self .streaming = False
72+ self .allow_unsafe_triggers = False
7173
7274 def setUp (self ):
7375 self .enable_commit = False
@@ -180,6 +182,8 @@ def create_options(self):
180182 PortableOptions ).environment_options = self .environment_options
181183
182184 options .view_as (StandardOptions ).streaming = self .streaming
185+ options .view_as (
186+ TypeOptions ).allow_unsafe_triggers = self .allow_unsafe_triggers
183187 return options
184188
185189 # Can't read host files from within docker, read a "local" file there.
@@ -233,7 +237,11 @@ def test_metrics(self):
233237 def construct_timestamped (k , t ):
234238 return window .TimestampedValue ((k , t ), t )
235239
240+ def format_result (k , vs ):
241+ return ('%s-%s' % (k , len (list (vs ))), set (vs ))
242+
236243 def test_after_count_trigger_batch (self ):
244+ self .allow_unsafe_triggers = True
237245 with self .create_pipeline () as p :
238246 result = (
239247 p
@@ -246,17 +254,20 @@ def test_after_count_trigger_batch(self):
246254 trigger = trigger .AfterCount (3 ),
247255 accumulation_mode = trigger .AccumulationMode .DISCARDING ,
248256 )
249- | beam .GroupByKey ())
250- # yapf: disable
257+ | beam .GroupByKey ()
258+ | beam . MapTuple ( PrismRunnerTest . format_result ))
251259 assert_that (
252260 result ,
253- equal_to ([('A' , [1 , 2 , 3 , 4 , 5 ],
254- ('A' , [10 , 11 ]),
255- ('B' , [6 , 7 , 8 , 9 ]),
256- ('B' , [10 , 15 , 16 ]))]))
257- # yapf: enable
261+ equal_to (
262+ list ([
263+ ('A-5' , {1 , 2 , 3 , 4 , 5 }),
264+ ('A-2' , {10 , 11 }),
265+ ('B-4' , {6 , 7 , 8 , 9 }),
266+ ('B-3' , {10 , 15 , 16 }),
267+ ])))
258268
259269 def test_after_count_trigger_streaming (self ):
270+ self .allow_unsafe_triggers = True
260271 self .streaming = True
261272 with self .create_pipeline () as p :
262273 result = (
@@ -270,17 +281,19 @@ def test_after_count_trigger_streaming(self):
270281 trigger = trigger .AfterCount (3 ),
271282 accumulation_mode = trigger .AccumulationMode .DISCARDING ,
272283 )
273- | beam .GroupByKey ())
274- # yapf: disable
284+ | beam .GroupByKey ()
285+ | beam . MapTuple ( PrismRunnerTest . format_result ))
275286 assert_that (
276287 result ,
277- equal_to ([('A' , [1 , 2 , 3 ],
278- ('A' , [4 , 5 ]),
279- ('A' , [10 , 11 ]),
280- ('B' , [6 , 7 , 8 ]),
281- ('B' , [9 ,]),
282- ('B' , [10 , 15 , 16 ]))]))
283- # yapf: enable
288+ equal_to (
289+ list ([
290+ ('A-3' , {1 , 2 , 3 }),
291+ ('A-2' , {4 , 5 }),
292+ ('A-2' , {10 , 11 }),
293+ ('B-3' , {6 , 7 , 8 }),
294+ ('B-1' , {9 }),
295+ ('B-3' , {10 , 15 , 16 }),
296+ ])))
284297
285298
286299class PrismJobServerTest (unittest .TestCase ):
0 commit comments