Skip to content

Commit f0af284

Browse files
authored
Fix default replication_factor for topics created by Quix apps (#317)
Set replication_factor to None by default to let the Quix Cloud figure out the default value for the broker
1 parent fe4c210 commit f0af284

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

quixstreams/platforms/quix/topic_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class QuixTopicManager(TopicManager):
2020
"""
2121

2222
_topic_partitions = 1
23-
_topic_replication = 2
23+
# Setting it to None to use defaults defined in Quix Cloud
24+
_topic_replication = None
2425
_max_topic_name_len = 249
2526

2627
_changelog_extra_config_defaults = {"cleanup.policy": "compact"}

tests/test_quixstreams/fixtures.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,6 @@ def factory(workspace_id: Optional[str] = None):
391391
),
392392
)
393393
quix_topic_manager._create_topics = topic_manager._create_topics
394-
patcher = patch.object(quix_topic_manager, "_topic_replication", 1)
395-
patcher.start()
396394
return quix_topic_manager
397395

398396
return factory
@@ -428,6 +426,13 @@ def factory(
428426
workspace_id: str = "my_ws",
429427
) -> Application:
430428
state_dir = state_dir or (tmp_path / "state").absolute()
429+
topic_manager = quix_topic_manager_factory(workspace_id=workspace_id)
430+
# Patch the topic manager to always set replication_factor to 1
431+
# (normally QuixTopicManager will set it to None which is invalid for
432+
# Kafka Admin API)
433+
patcher = patch.object(topic_manager, "_topic_replication", 1)
434+
patcher.start()
435+
431436
return Application.Quix(
432437
consumer_group=random_consumer_group,
433438
state_dir=state_dir,
@@ -443,7 +448,7 @@ def factory(
443448
on_message_processed=on_message_processed,
444449
auto_create_topics=auto_create_topics,
445450
use_changelog_topics=use_changelog_topics,
446-
topic_manager=quix_topic_manager_factory(workspace_id=workspace_id),
451+
topic_manager=topic_manager,
447452
)
448453

449454
return factory

tests/test_quixstreams/test_platforms/test_quix/test_topic_manager.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from quixstreams.models import TopicConfig
2+
3+
14
class TestQuixTopicManager:
25
def test_quix_topic_name(self, quix_topic_manager_factory):
36
topic_name = "my_topic"
@@ -8,6 +11,8 @@ def test_quix_topic_name(self, quix_topic_manager_factory):
811
# should be the same regardless of workspace_id being included
912
assert topic_manager.topic(topic_name).name == expected
1013
assert topic_manager.topic(expected).name == expected
14+
# Replication factor should be None by default
15+
assert topic_manager.topic(expected).config.replication_factor is None
1116

1217
def test_quix_changelog_topic(self, quix_topic_manager_factory):
1318
"""
@@ -43,3 +48,14 @@ def test_quix_changelog_topic(self, quix_topic_manager_factory):
4348
assert changelog.name == expected
4449

4550
assert topic_manager.changelog_topics[topic.name][store_name] == changelog
51+
52+
def test_quix_topic_custom_config(self, quix_topic_manager_factory):
53+
topic_name = "my_topic"
54+
workspace_id = "my_wid"
55+
topic_manager = quix_topic_manager_factory(workspace_id=workspace_id)
56+
57+
config = TopicConfig(num_partitions=2, replication_factor=2)
58+
59+
topic = topic_manager.topic(topic_name, config=config)
60+
assert topic.config.replication_factor == config.replication_factor
61+
assert topic.config.num_partitions == config.num_partitions

0 commit comments

Comments
 (0)