def test_create_multiple_topics_one_existing(kafka_service_config):
    topics_to_create = [
        add_prefix(topic, test_create_multiple_topics_one_existing.__name__)
        for topic in [TOPIC_NAME, OTHER_TOPIC_NAME]
    ]

    create_kafka_topics(
        new_topics=[topics_to_create[0]],
        bootstrap_servers=kafka_service_config.bootstrap_servers,
        service_name=SERVICE_NAME,
        replication_factor=1,
        num_partitions=1,
    )

    topics = list_topics(kafka_service_config.bootstrap_servers)
    assert topics_to_create[0] in topics

    create_kafka_topics(
        new_topics=topics_to_create,
        bootstrap_servers=kafka_service_config.bootstrap_servers,
        service_name=SERVICE_NAME,
        replication_factor=1,
        num_partitions=1,
    )

    topics = list_topics(kafka_service_config.bootstrap_servers)
    assert topics_to_create[1] in topics
Exemplo n.º 2
0
def test_kafka_client_create_topic(mocker):
    mock_kafka_admin_client = mocker.patch("bai_kafka_utils.kafka_client.KafkaAdminClient", create_autospec=True)

    num_partitions = 3
    replication_factor = 3

    create_kafka_topics([PRODUCER_TOPIC], BOOTSTRAP_SERVERS, SERVICE_NAME, num_partitions, replication_factor)

    _, kwargs = mock_kafka_admin_client.return_value.create_topics.call_args
    created_topic = kwargs["new_topics"][0]
    assert created_topic.name == PRODUCER_TOPIC
    assert created_topic.num_partitions == num_partitions
    assert created_topic.replication_factor == replication_factor
def test_create_new_topic(kafka_service_config):
    topic_name = add_prefix(TOPIC_NAME, test_create_new_topic.__name__)

    create_kafka_topics(
        new_topics=[topic_name],
        bootstrap_servers=kafka_service_config.bootstrap_servers,
        service_name=SERVICE_NAME,
        replication_factor=1,
        num_partitions=1,
    )
    topics = list_topics(kafka_service_config.bootstrap_servers)

    assert topic_name in topics