derrickaw commented on code in PR #40885:
URL: https://github.com/apache/beam/pull/40885#discussion_r4414148784


##########
sdks/python/apache_beam/yaml/integration_tests.py:
##########
@@ -1214,6 +1214,130 @@ def 
temp_pubsub_emulator(project_id="apache-beam-testing"):
     yield created_topic_object.name
 
 
[email protected]
+def temp_pubsub_subscriptions(project_id="apache-beam-testing"):
+  """Context manager providing a temporary Pub/Sub emulator with input and
+  deadletter topics and subscriptions, plus bounded ReadFromPubSub and
+  WriteToPubSub transforms compatible with FnApiRunner for E2E testing.
+  """
+  from google.api_core import exceptions as gcp_exceptions
+
+  with PubSubContainer(project=project_id) as pubsub_container:
+    emulator_host = pubsub_container.get_pubsub_emulator_host()
+    with mock.patch.dict(os.environ, {"PUBSUB_EMULATOR_HOST": emulator_host}):
+      publisher = pubsub_v1.PublisherClient()
+      subscriber = pubsub_v1.SubscriberClient()
+      suffix = uuid.uuid4().hex[:8]
+
+      input_topic = 
f"projects/{pubsub_container.project}/topics/input-{suffix}"
+      input_sub = (
+          f"projects/{pubsub_container.project}/subscriptions/"
+          f"input-sub-{suffix}")
+      dlq_topic = (
+          f"projects/{pubsub_container.project}/topics/deadletter-{suffix}")
+      dlq_sub = (
+          f"projects/{pubsub_container.project}/subscriptions/"
+          f"deadletter-sub-{suffix}")
+
+      publisher.create_topic(name=input_topic)
+      subscriber.create_subscription(name=input_sub, topic=input_topic)
+      publisher.create_topic(name=dlq_topic)
+      subscriber.create_subscription(name=dlq_sub, topic=dlq_topic)
+
+      class _BoundedReadFromPubSub(beam.PTransform):
+        def __init__(
+            self,
+            topic=None,
+            subscription=None,
+            id_label=None,
+            with_attributes=False,
+            timestamp_attribute=None):
+          super().__init__()
+          self._topic = topic
+          self._subscription = subscription
+          self._with_attributes = with_attributes
+
+        def expand(self, pbegin):
+          sub_name = self._subscription

Review Comment:
   this function is geared toward subscription so should be fine



-- 
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]

Reply via email to