Skip to content

Feature/add stop in aioproducer #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/async-fake-aiokafka-produce.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ The `FakeAIOKafkaProducer` class is a mock implementation of aiokafka's AIOKafka
#### `start(self)`
- **Description:** No-operation.

#### `stop(self)`
- **Description:** No-operation.

#### `send(self, *args, **kwargs)`
- **Description:** Calls `_produce()` with keyword arguments.
- **Parameters:**
Expand All @@ -48,4 +51,4 @@ fake_producer = FakeAIOKafkaProducer()

# Produce a message
await fake_producer.send(topic='sample_topic', value='Hello, Kafka!', partition=0)
```
```
4 changes: 4 additions & 0 deletions mockafka/aiokafka/aiokafka_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class FakeAIOKafkaProducer:
- _produce(): Create a Message and produce to KafkaStore.
Takes topic, value, and optional partition.
- start(): No-op.
- stop(): No-op.
- send(): Call _produce() with kwargs.
- send_and_wait(): Call send().
"""
Expand All @@ -33,6 +34,9 @@ async def _produce(self, topic, value=None, *args, **kwargs) -> None:
async def start(self) -> None:
pass

async def stop(self) -> None:
pass

async def send(
self,
topic,
Expand Down
8 changes: 7 additions & 1 deletion tests/test_aiokafka/test_aiokafka_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ async def test_produce_once(self):

async def test_send_and_wait(self):
await self._create_mock_topic()
await self.producer.send_and_wait("topic_test", "sdfjhasdfhjsa", key="datakey")

await self.producer.start()
try:
await self.producer.send_and_wait("topic_test", "sdfjhasdfhjsa", key="datakey")
finally:
await self.producer.stop()

message: Message = self.kafka.get_messages_in_partition(
topic="topic_test", partition=0
)[0]
Expand Down