Lee-W commented on code in PR #68625:
URL: https://github.com/apache/airflow/pull/68625#discussion_r3472976264


##########
providers/apache/kafka/tests/integration/apache/kafka/triggers/test_shared_stream.py:
##########
@@ -0,0 +1,257 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+import asyncio
+import json
+import time
+import uuid
+
+import pytest
+from confluent_kafka import Consumer, Producer, TopicPartition
+
+pytest.importorskip("airflow.triggers.shared_stream")
+
+from airflow.models import Connection
+from airflow.providers.apache.kafka.triggers.shared_stream import 
KafkaSharedStreamProducer
+from airflow.triggers.shared_stream import AdvanceItem, AdvanceOutcome
+
+BROKER = "broker:29092"
+
+
+def _produce(topic: str, values: list[bytes]) -> None:
+    """Produce ``values`` to partition 0 of ``topic`` so offsets are 
deterministic (0, 1, ...)."""
+    producer = Producer({"bootstrap.servers": BROKER})
+    for value in values:
+        producer.produce(topic, value=value, partition=0)
+    assert producer.flush(10) == 0
+
+
+def _poll_one(consumer: Consumer, timeout: float):
+    """Poll ``consumer`` until a non-error message arrives or ``timeout`` 
elapses."""
+    deadline = time.monotonic() + timeout
+    while time.monotonic() < deadline:
+        message = consumer.poll(1.0)
+        if message is not None and message.error() is None:
+            return message
+    return None
+
+
+async def _take(stream, n: int) -> list:
+    out = []
+    async for item in stream:
+        out.append(item)
+        if len(out) >= n:
+            break
+    return out
+
+
[email protected]("kafka")
+class TestKafkaSharedStreamProducerIntegration:
+    @pytest.fixture(autouse=True)
+    def setup_connections(self, create_connection_without_db):
+        self.group = f"shared-stream-it-{uuid.uuid4().hex[:8]}"
+        self.conn_id = "kafka_shared_stream_it"
+        self.bad_conn_id = "kafka_shared_stream_it_autocommit"
+        create_connection_without_db(
+            Connection(
+                conn_id=self.conn_id,
+                conn_type="kafka",
+                extra=json.dumps(
+                    {
+                        "bootstrap.servers": BROKER,
+                        "group.id": self.group,
+                        "enable.auto.commit": False,
+                        "auto.offset.reset": "beginning",
+                        "socket.timeout.ms": 10000,
+                    }
+                ),
+            )
+        )
+        create_connection_without_db(
+            Connection(
+                conn_id=self.bad_conn_id,
+                conn_type="kafka",
+                extra=json.dumps(
+                    {
+                        "bootstrap.servers": BROKER,
+                        "group.id": f"{self.group}-bad",
+                        "enable.auto.commit": True,
+                        "auto.offset.reset": "beginning",
+                    }
+                ),
+            )
+        )

Review Comment:
   ```suggestion
          for conn_id, extra in (
               (
                   self.conn_id,
                   {
                       "bootstrap.servers": BROKER,
                       "group.id": self.group,
                       "enable.auto.commit": False,
                       "auto.offset.reset": "beginning",
                       "socket.timeout.ms": 10000,
                   },
               ),
               (
                   self.bad_conn_id,
                   {
                       "bootstrap.servers": BROKER,
                       "group.id": f"{self.group}-bad",
                       "enable.auto.commit": True,
                       "auto.offset.reset": "beginning",
                   }
               )
           ):
               create_connection_without_db(
                   Connection(
                       conn_id=conn_id,
                       conn_type="kafka",
                       extra=json.dumps(extras),
                   )
               )
   
   ```



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