ibzib commented on a change in pull request #13338:
URL: https://github.com/apache/beam/pull/13338#discussion_r527941960
##########
File path:
sdks/python/apache_beam/runners/portability/fn_api_runner/fn_runner_test.py
##########
@@ -835,23 +834,37 @@ def process(
assert_that(res, equal_to(['1', '2']))
def test_register_finalizations(self):
- event_recorder = EventRecorder(tempfile.gettempdir())
- elements_list = ['2', '1']
+ class FinalizableSplittableDoFn(beam.DoFn):
+ was_finalized = False
+
+ def set_finalized(self):
+ self.was_finalized = True
- class FinalizableDoFn(beam.DoFn):
def process(
- self, element, bundle_finalizer=beam.DoFn.BundleFinalizerParam):
- bundle_finalizer.register(lambda: event_recorder.record(element))
- yield element
+ self,
+ element,
+ bundle_finalizer=beam.DoFn.BundleFinalizerParam,
+ restriction_tracker=beam.DoFn.RestrictionParam(
Review comment:
Can you add a comment explaining why we use a splittable DoFn?
##########
File path:
sdks/python/apache_beam/runners/portability/fn_api_runner/fn_runner_test.py
##########
@@ -835,23 +834,37 @@ def process(
assert_that(res, equal_to(['1', '2']))
def test_register_finalizations(self):
- event_recorder = EventRecorder(tempfile.gettempdir())
- elements_list = ['2', '1']
+ class FinalizableSplittableDoFn(beam.DoFn):
+ was_finalized = False
+
+ def set_finalized(self):
+ self.was_finalized = True
- class FinalizableDoFn(beam.DoFn):
def process(
- self, element, bundle_finalizer=beam.DoFn.BundleFinalizerParam):
- bundle_finalizer.register(lambda: event_recorder.record(element))
- yield element
+ self,
+ element,
+ bundle_finalizer=beam.DoFn.BundleFinalizerParam,
+ restriction_tracker=beam.DoFn.RestrictionParam(
+ OffsetRangeProvider(use_bounded_offset_range=True))):
+ if self.was_finalized:
+ restriction_tracker.try_claim(
+ restriction_tracker.current_restriction().start)
+ yield element
+ restriction_tracker.try_claim(element)
+ return
+ if restriction_tracker.try_claim(
+ restriction_tracker.current_restriction().start):
+ bundle_finalizer.register(lambda: self.set_finalized())
+ time.sleep(1)
Review comment:
Why is the sleep necessary? Can you add a comment?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]