This repository was archived by the owner on Jul 11, 2025. It is now read-only.
forked from dpkp/kafka-python
-
Notifications
You must be signed in to change notification settings - Fork 14
Fix ssl connection #178
Merged
wbarnha
merged 7 commits into
kafka-python-ng:master
from
dingxiong:xiong-fix-ssl-connection
Apr 10, 2024
Merged
Fix ssl connection #178
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bec32d9
Fix ssl connection after wrap_ssl
dingxiong 5c8ec94
test
dingxiong 04786cd
refactor
dingxiong 1d446c1
remove global level
dingxiong 0137137
test
dingxiong e686d6b
revert test
dingxiong f76365c
address comments
dingxiong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,67 @@ | ||
import logging | ||
import uuid | ||
|
||
import pytest | ||
|
||
from kafka.admin import NewTopic | ||
from kafka.protocol.metadata import MetadataRequest_v1 | ||
from test.testutil import assert_message_count, env_kafka_version, random_string, special_to_underscore | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def ssl_kafka(request, kafka_broker_factory): | ||
return kafka_broker_factory(transport="SSL")[0] | ||
|
||
|
||
@pytest.mark.skipif(env_kafka_version() < (0, 10), reason="Inter broker SSL was implemented at version 0.9") | ||
def test_admin(request, ssl_kafka): | ||
topic_name = special_to_underscore(request.node.name + random_string(4)) | ||
admin, = ssl_kafka.get_admin_clients(1) | ||
admin.create_topics([NewTopic(topic_name, 1, 1)]) | ||
assert topic_name in ssl_kafka.get_topic_names() | ||
|
||
|
||
@pytest.mark.skipif(env_kafka_version() < (0, 10), reason="Inter broker SSL was implemented at version 0.9") | ||
def test_produce_and_consume(request, ssl_kafka): | ||
topic_name = special_to_underscore(request.node.name + random_string(4)) | ||
ssl_kafka.create_topics([topic_name], num_partitions=2) | ||
producer, = ssl_kafka.get_producers(1) | ||
|
||
messages_and_futures = [] # [(message, produce_future),] | ||
for i in range(100): | ||
encoded_msg = "{}-{}-{}".format(i, request.node.name, uuid.uuid4()).encode("utf-8") | ||
future = producer.send(topic_name, value=encoded_msg, partition=i % 2) | ||
messages_and_futures.append((encoded_msg, future)) | ||
producer.flush() | ||
|
||
for (msg, f) in messages_and_futures: | ||
assert f.succeeded() | ||
|
||
consumer, = ssl_kafka.get_consumers(1, [topic_name]) | ||
messages = {0: [], 1: []} | ||
for i, message in enumerate(consumer, 1): | ||
logging.debug("Consumed message %s", repr(message)) | ||
messages[message.partition].append(message) | ||
if i >= 100: | ||
break | ||
|
||
assert_message_count(messages[0], 50) | ||
assert_message_count(messages[1], 50) | ||
|
||
|
||
@pytest.mark.skipif(env_kafka_version() < (0, 10), reason="Inter broker SSL was implemented at version 0.9") | ||
def test_client(request, ssl_kafka): | ||
topic_name = special_to_underscore(request.node.name + random_string(4)) | ||
ssl_kafka.create_topics([topic_name], num_partitions=1) | ||
|
||
client, = ssl_kafka.get_clients(1) | ||
request = MetadataRequest_v1(None) | ||
client.send(0, request) | ||
for _ in range(10): | ||
result = client.poll(timeout_ms=10000) | ||
if len(result) > 0: | ||
break | ||
else: | ||
raise RuntimeError("Couldn't fetch topic response from Broker.") | ||
result = result[0] | ||
assert topic_name in [t[1] for t in result.topics] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.