| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
import pytest |
| 20 |
from confluent_kafka import TopicPartition, OFFSET_END, KafkaError, KafkaException |
| 21 |
|
| 22 |
from confluent_kafka.error import ConsumeError |
| 23 |
from confluent_kafka.serialization import StringSerializer |
| 24 |
from tests.common import TestUtils |
| 25 |
|
| 26 |
|
| 27 |
def test_consume_error(kafka_cluster): |
| 28 |
""" |
| 29 |
Tests to ensure librdkafka errors are propagated as |
| 30 |
an instance of ConsumeError. |
| 31 |
""" |
| 32 |
topic = kafka_cluster.create_topic_and_wait_propogation("test_commit_transaction") |
| 33 |
consumer_conf = {'group.id': 'pytest', 'enable.partition.eof': True} |
| 34 |
|
| 35 |
producer = kafka_cluster.producer() |
| 36 |
producer.produce(topic=topic, value="a") |
| 37 |
producer.flush() |
| 38 |
|
| 39 |
consumer = kafka_cluster.consumer(consumer_conf, |
| 40 |
value_deserializer=StringSerializer()) |
| 41 |
consumer.assign([TopicPartition(topic, 0, OFFSET_END)]) |
| 42 |
|
| 43 |
with pytest.raises(ConsumeError) as exc_info: |
| 44 |
|
| 45 |
consumer.poll() |
| 46 |
assert exc_info.value.args[0].code() == KafkaError._PARTITION_EOF, \ |
| 47 |
"Expected _PARTITION_EOF, not {}".format(exc_info) |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
@pytest.mark.skipif(TestUtils.use_group_protocol_consumer(), |
| 54 |
reason="session.timeout.ms is not supported on client side for " |
| 55 |
"consumer protocol. Update this test to use IncrementalAlterConfigs " |
| 56 |
"Admin operation to update group.session.timeout.ms and enable " |
| 57 |
"the test again.") |
| 58 |
def test_consume_error_commit(kafka_cluster): |
| 59 |
""" |
| 60 |
Tests to ensure that we handle messages with errors when commiting. |
| 61 |
""" |
| 62 |
topic = kafka_cluster.create_topic_and_wait_propogation("test_commit_transaction") |
| 63 |
consumer_conf = {'group.id': 'pytest', |
| 64 |
'session.timeout.ms': 100} |
| 65 |
|
| 66 |
producer = kafka_cluster.producer() |
| 67 |
producer.produce(topic=topic, value="a") |
| 68 |
producer.flush() |
| 69 |
|
| 70 |
consumer = kafka_cluster.cimpl_consumer(consumer_conf) |
| 71 |
consumer.subscribe([topic]) |
| 72 |
try: |
| 73 |
|
| 74 |
|
| 75 |
m = consumer.poll(2) |
| 76 |
consumer.commit(m) |
| 77 |
except KafkaException as e: |
| 78 |
assert e.args[0].code() == KafkaError._INVALID_ARG, \ |
| 79 |
"Expected INVALID_ARG, not {}".format(e) |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
@pytest.mark.skipif(TestUtils.use_group_protocol_consumer(), |
| 86 |
reason="session.timeout.ms is not supported on client side for " |
| 87 |
"consumer protocol. Update this test to use IncrementalAlterConfigs " |
| 88 |
"Admin operation to update group.session.timeout.ms and enable " |
| 89 |
"the test again.") |
| 90 |
def test_consume_error_store_offsets(kafka_cluster): |
| 91 |
""" |
| 92 |
Tests to ensure that we handle messages with errors when storing offsets. |
| 93 |
""" |
| 94 |
topic = kafka_cluster.create_topic_and_wait_propogation("test_commit_transaction") |
| 95 |
consumer_conf = {'group.id': 'pytest', |
| 96 |
'session.timeout.ms': 100, |
| 97 |
'enable.auto.offset.store': True, |
| 98 |
'enable.auto.commit': False} |
| 99 |
|
| 100 |
producer = kafka_cluster.producer() |
| 101 |
producer.produce(topic=topic, value="a") |
| 102 |
producer.flush() |
| 103 |
|
| 104 |
consumer = kafka_cluster.cimpl_consumer(consumer_conf) |
| 105 |
consumer.subscribe([topic]) |
| 106 |
try: |
| 107 |
|
| 108 |
|
| 109 |
m = consumer.poll(2) |
| 110 |
consumer.store_offsets(m) |
| 111 |
except KafkaException as e: |
| 112 |
assert e.args[0].code() == KafkaError._INVALID_ARG, \ |
| 113 |
"Expected INVALID_ARG, not {}".format(e) |