| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
from confluent_kafka import TopicPartition |
| 19 |
|
| 20 |
|
| 21 |
def commit_and_check(consumer, topic, metadata): |
| 22 |
if metadata is None: |
| 23 |
consumer.commit(offsets=[TopicPartition(topic, 0, 1)], asynchronous=False) |
| 24 |
else: |
| 25 |
consumer.commit(offsets=[TopicPartition(topic, 0, 1, metadata)], asynchronous=False) |
| 26 |
|
| 27 |
offsets = consumer.committed([TopicPartition(topic, 0)], timeout=100) |
| 28 |
assert len(offsets) == 1 |
| 29 |
assert offsets[0].metadata == metadata |
| 30 |
|
| 31 |
|
| 32 |
def test_consumer_topicpartition_metadata(kafka_cluster): |
| 33 |
topic = kafka_cluster.create_topic_and_wait_propogation("test_topicpartition") |
| 34 |
consumer_conf = {'group.id': 'test_topicpartition'} |
| 35 |
|
| 36 |
c = kafka_cluster.consumer(consumer_conf) |
| 37 |
|
| 38 |
|
| 39 |
metadata = None |
| 40 |
commit_and_check(c, topic, metadata) |
| 41 |
|
| 42 |
|
| 43 |
metadata = 'hello world' |
| 44 |
commit_and_check(c, topic, metadata) |
| 45 |
|
| 46 |
|
| 47 |
metadata = 'नमस्ते दुनिया' |
| 48 |
commit_and_check(c, topic, metadata) |
| 49 |
|
| 50 |
|
| 51 |
metadata = '' |
| 52 |
commit_and_check(c, topic, metadata) |
| 53 |
|
| 54 |
|
| 55 |
metadata = 'xyz\x00abc' |
| 56 |
try: |
| 57 |
commit_and_check(c, topic, metadata) |
| 58 |
|
| 59 |
assert False |
| 60 |
except ValueError as ve: |
| 61 |
assert 'embedded null character' in str(ve) |
| 62 |
|
| 63 |
c.close() |