-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(confluent-kafka): Add test for poll and consume
- Loading branch information
Showing
2 changed files
with
202 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
instrumentation/opentelemetry-instrumentation-confluent-kafka/tests/utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from confluent_kafka import Consumer | ||
|
||
|
||
class MockConsumer(Consumer): | ||
|
||
def __init__(self, queue, config): | ||
self._queue = queue | ||
super().__init__(config) | ||
|
||
def consume(self, num_messages=1, *args, **kwargs): | ||
messages = self._queue[:num_messages] | ||
self._queue = self._queue[num_messages:] | ||
return messages | ||
|
||
def poll(self, timeout=None): | ||
if len(self._queue) > 0: | ||
return self._queue.pop(0) | ||
else: | ||
return None | ||
|
||
|
||
class MockedMessage: | ||
def __init__(self, topic: str, partition: int, offset: int, headers): | ||
self._topic = topic | ||
self._partition = partition | ||
self._offset = offset | ||
self._headers = headers | ||
|
||
def topic(self): | ||
return self._topic | ||
|
||
def partition(self): | ||
return self._partition | ||
|
||
def offset(self): | ||
return self._offset | ||
|
||
def headers(self): | ||
return self._headers |