-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable the customization of the kafka properties
- Loading branch information
Showing
4 changed files
with
101 additions
and
1 deletion.
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
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,81 @@ | ||
""" | ||
Copyright (c) 2024 Aiven Ltd | ||
See LICENSE for details | ||
""" | ||
from confluent_kafka.admin import NewTopic | ||
from karapace.backup.api import BackupVersion, create_backup | ||
from karapace.config import Config, set_config_defaults | ||
from karapace.kafka.admin import KafkaAdminClient | ||
from karapace.kafka_utils import kafka_producer_from_config | ||
from pathlib import Path | ||
from tests.integration.conftest import create_kafka_server | ||
from tests.integration.utils.config import KafkaDescription | ||
from tests.integration.utils.kafka_server import KafkaServers | ||
from tests.integration.utils.network import PortRangeInclusive | ||
|
||
import pytest | ||
|
||
|
||
SESSION_TIMEOUT_MS = 65000 | ||
GROUP_MIN_SESSION_TIMEOUT_MS = 60000 | ||
GROUP_MAX_SESSION_TIMEOUT_MS = 70000 | ||
|
||
|
||
# use a dedicated kafka server with specific values for | ||
# group.min.session.timeout.ms and group.max.session.timeout.ms | ||
@pytest.fixture(scope="function", name="kafka_server_session_timeout") | ||
def fixture_kafka_server( | ||
kafka_description: KafkaDescription, | ||
port_range: PortRangeInclusive, | ||
tmp_path_factory: pytest.TempPathFactory, | ||
): | ||
# use custom data and log dir to avoid conflict with other kafka servers | ||
session_datadir = tmp_path_factory.mktemp("kafka_server_min_data") | ||
session_logdir = tmp_path_factory.mktemp("kafka_server_min_log") | ||
kafka_config_extra = { | ||
"group.min.session.timeout.ms": GROUP_MIN_SESSION_TIMEOUT_MS, | ||
"group.max.session.timeout.ms": GROUP_MAX_SESSION_TIMEOUT_MS, | ||
} | ||
yield from create_kafka_server( | ||
session_datadir, | ||
session_logdir, | ||
kafka_description, | ||
port_range, | ||
kafka_config_extra, | ||
) | ||
|
||
|
||
def test_generic( | ||
kafka_server_session_timeout: KafkaServers, | ||
new_topic: NewTopic, | ||
tmp_path: Path, | ||
) -> None: | ||
config = set_config_defaults(Config( | ||
bootstrap_uri=kafka_server_session_timeout.bootstrap_servers, | ||
session_timeout_ms=SESSION_TIMEOUT_MS, | ||
)) | ||
# create topic | ||
admin_client = KafkaAdminClient(bootstrap_servers=kafka_server_session_timeout.bootstrap_servers) | ||
admin_client.new_topic(new_topic.topic, num_partitions=1, replication_factor=1) | ||
# write data into topic | ||
with kafka_producer_from_config(config) as producer: | ||
producer.send( | ||
new_topic.topic, | ||
key=b"foo", | ||
value=b"bar", | ||
partition=0, | ||
headers=[ | ||
("some-header", b"some header value"), | ||
("other-header", b"some other header value"), | ||
], | ||
timestamp=1683474657, | ||
) | ||
producer.flush() | ||
# backup the topic | ||
create_backup( | ||
config=config, | ||
backup_location=tmp_path / "backup", | ||
topic_name=new_topic.topic, | ||
version=BackupVersion.V3, | ||
replication_factor=1, | ||
) |
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
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