Debian Codegraph @

tests/integration/consumer/test_consumer_memberid.py

raw symbols SCIP
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright 2022 Confluent Inc.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 import pytest
19 from tests.common import TestUtils
20
21
22 def test_consumer_memberid(kafka_cluster):
23 """
24 Test consumer memberid.
25 """
26
27 consumer_conf = {'group.id': 'test'}
28
29 topic = "testmemberid"
30
31 kafka_cluster.create_topic_and_wait_propogation(topic)
32
33 consumer = kafka_cluster.consumer(consumer_conf)
34
35 assert consumer is not None
36 before_memberid = consumer.memberid()
37
38 # With implementation of KIP-1082, member id is generated on the client
39 # side for ConsumerGroupHeartbeat used in the `consumer` protocol
40 # introduced in KIP-848
41 if TestUtils.use_group_protocol_consumer():
42 assert before_memberid is not None
43 assert isinstance(before_memberid, str)
44 assert len(before_memberid) > 0
45 else:
46 assert before_memberid is None
47
48 kafka_cluster.seed_topic(topic, value_source=[b'memberid'])
49
50 consumer.subscribe([topic])
51 msg = consumer.poll(10)
52 assert msg is not None
53 assert msg.value() == b'memberid'
54 after_memberid = consumer.memberid()
55 assert isinstance(after_memberid, str)
56 assert len(after_memberid) > 0
57 if TestUtils.use_group_protocol_consumer():
58 assert before_memberid == after_memberid
59 consumer.close()
60
61 with pytest.raises(RuntimeError) as error_info:
62 consumer.memberid()
63 assert error_info.value.args[0] == "Consumer closed"