Beispiel #1
0
def test_edit_topic_works(
    interactive_cli_runner: CliRunner,
    monkeypatch: MonkeyPatch,
    topic_controller: TopicController,
    confluent_admin_client: confluent_kafka.admin.AdminClient,
    topic: str,
):

    topics = confluent_admin_client.list_topics(timeout=5).topics.keys()
    assert topic in topics

    config_dict = {
        "config": {
            "cleanup.policy": "delete",
            "compression.type": "producer",
            "delete.retention.ms": "123456789",
            "file.delete.delay.ms": "60000",
            "flush.messages": "123456789",
            "flush.ms": "9223372036854775807",
            "follower.replication.throttled.replicas": "",
            "index.interval.bytes": "4096",
            "leader.replication.throttled.replicas": "",
            "max.message.bytes": "1000012",
            "message.downconversion.enable": "true",
            "message.format.version": "2.2-IV1",
            "message.timestamp.difference.max.ms": "123456789",
            "message.timestamp.type": "CreateTime",
            "min.cleanable.dirty.ratio": "0.5",
            "min.compaction.lag.ms": "0",
            "min.insync.replicas": "1",
            "preallocate": "false",
            "retention.bytes": "-1",
            "retention.ms": "123456789",
            "segment.bytes": "123456789",
            "segment.index.bytes": "123456789",
            "segment.jitter.ms": "0",
            "segment.ms": "123456789",
            "unclean.leader.election.enable": "true",
        }
    }

    def mock_edit_function(text=None,
                           editor=None,
                           env=None,
                           require_save=None,
                           extension=None,
                           filename=None):
        return yaml.dump(config_dict, default_flow_style=False)

    monkeypatch.setattr(click, "edit", mock_edit_function)
    result = interactive_cli_runner.invoke(edit_topic,
                                           topic,
                                           input="y\n",
                                           catch_exceptions=False)
    assert result.exit_code == 0

    topic_config_dict = topic_controller.get_cluster_topic(topic).as_dict(
        only_editable=True)
    for key, value in config_dict["config"].items():
        assert (key, topic_config_dict["config"][key]) == (key, value)
Beispiel #2
0
def test_correct_amount_of_messages(mocker,
                                    non_interactive_cli_runner: CliRunner,
                                    topic_controller: TopicController):
    delete_topic_mock = mocker.patch.object(TopicController, "delete_topic",
                                            mocker.Mock())

    result = non_interactive_cli_runner.invoke(ping, catch_exceptions=False)
    assert result.exit_code == 0
    assert delete_topic_mock.call_count == 1

    ping_topic = topic_controller.get_cluster_topic(config.PING_TOPIC)
    assert ping_topic.watermarks[0].high == 10
Beispiel #3
0
def test_alter_topic_config_works(topic_controller: TopicController,
                                  topic_id: str):
    initial_topic = Topic(topic_id, config={"cleanup.policy": "delete"})

    topic_controller.create_topics([initial_topic])
    topic_controller.update_from_cluster(initial_topic)
    config = initial_topic.config
    assert config.get("cleanup.policy") == "delete"
    change_topic = Topic(topic_id, config={"cleanup.policy": "compact"})
    topic_controller.alter_configs([change_topic])
    topic_controller.update_from_cluster(change_topic)
    after_changes_applied_topic = topic_controller.get_cluster_topic(topic_id)

    final_config = after_changes_applied_topic.config
    assert final_config.get("cleanup.policy") == "compact"
Beispiel #4
0
def topic_from_template(
    template_topic: str,
    partitions: Optional[int],
    replication_factor: Optional[int],
    topic_controller: TopicController,
    topic_name: str,
) -> Topic:
    template_config = topic_controller.get_cluster_topic(template_topic)

    if partitions is None:
        partitions = template_config.num_partitions

    if replication_factor is None:
        replication_factor = template_config.replication_factor

    config = template_config.config

    topic = Topic(topic_name, num_partitions=partitions, replication_factor=replication_factor, config=config)
    return topic
Beispiel #5
0
def test_alter_topic_config_only_changes_mentioned_attributes(
        topic_controller: TopicController, topic_id: str):
    initial_topic = Topic(topic_id,
                          config={
                              "cleanup.policy": "delete",
                              "min.compaction.lag.ms": "1000000"
                          })

    topic_controller.create_topics([initial_topic])
    topic_controller.update_from_cluster(initial_topic)
    config = initial_topic.config
    assert config.get("cleanup.policy") == "delete"
    assert config.get("min.compaction.lag.ms") == "1000000"
    change_topic = Topic(topic_id, config={"cleanup.policy": "compact"})
    topic_controller.alter_configs([change_topic])
    topic_controller.update_from_cluster(change_topic)
    after_changes_applied_topic = topic_controller.get_cluster_topic(topic_id)

    final_config = after_changes_applied_topic.config
    assert final_config.get("cleanup.policy") == "compact"
    assert final_config.get("min.compaction.lag.ms") == "1000000"
Beispiel #6
0
def test_topic_object_works(topic_controller: TopicController, topic: str):
    topic = topic_controller.get_cluster_topic(topic)
    assert isinstance(topic, Topic)
    assert len(topic.watermarks) != 0