|
| 1 | +from arroyo.backends.kafka import ConfluentProducer |
| 2 | +from confluent_kafka import Producer |
| 3 | + |
| 4 | +from sentry.testutils.helpers.options import override_options |
| 5 | +from sentry.utils.confluent_producer import get_confluent_producer |
| 6 | + |
| 7 | + |
| 8 | +@override_options({"arroyo.producer.confluent-producer-rollout": {"test_producer": True}}) |
| 9 | +def test_get_confluent_producer() -> None: |
| 10 | + configuration = { |
| 11 | + "bootstrap.servers": "localhost:9092", |
| 12 | + "client.id": "test_producer", |
| 13 | + } |
| 14 | + |
| 15 | + producer = get_confluent_producer(configuration) |
| 16 | + assert producer is not None |
| 17 | + |
| 18 | + assert isinstance(producer, Producer) |
| 19 | + assert isinstance(producer, ConfluentProducer) |
| 20 | + |
| 21 | + for attrs in Producer.__dict__.keys(): |
| 22 | + assert hasattr(producer, attrs) |
| 23 | + |
| 24 | + |
| 25 | +@override_options({"arroyo.producer.confluent-producer-rollout": {"test_producer": False}}) |
| 26 | +def test_get_confluent_producer_not_rolled_out() -> None: |
| 27 | + configuration = { |
| 28 | + "bootstrap.servers": "localhost:9092", |
| 29 | + "client.id": "test_producer", |
| 30 | + } |
| 31 | + |
| 32 | + producer = get_confluent_producer(configuration) |
| 33 | + assert isinstance(producer, Producer) |
| 34 | + assert not isinstance(producer, ConfluentProducer) |
| 35 | + |
| 36 | + |
| 37 | +@override_options({"arroyo.producer.confluent-producer-rollout": {}}) |
| 38 | +def test_get_confluent_producer_no_client_id() -> None: |
| 39 | + configuration = { |
| 40 | + "bootstrap.servers": "localhost:9092", |
| 41 | + } |
| 42 | + |
| 43 | + producer = get_confluent_producer(configuration) |
| 44 | + assert isinstance(producer, Producer) |
| 45 | + assert not isinstance(producer, ConfluentProducer) |
0 commit comments