示例#1
0
def test_integration_broker_connect(ensure_broker_service: Fixture,
                                    ensure_connect_service: Fixture) -> None:
    """Test kafkaconnect with a Kafka broker and Kafka Connect.

    pytest-docker uses the docker-compose.yaml in the test directory.
    """
    broker_url = Config.broker_url
    admin_client = AdminClient({"bootstrap.servers": broker_url})
    t1 = NewTopic(topic="test.t1", num_partitions=1)
    t2 = NewTopic(topic="test.t2", num_partitions=1)
    t3 = NewTopic(topic="test.t3", num_partitions=1)
    # Create test topics in Kafka
    try:
        admin_client.create_topics([t1, t2, t3])
        time.sleep(1)
    except KafkaException:
        return None
    # Test topic discovery
    topic = Topic(broker_url=broker_url,
                  topic_regex="test.*",
                  excluded_topics="test.t1")
    assert "test.t2" in topic.names
    assert "test.t3" in topic.names
    # Configure the connector
    connect = Connect(connect_url=Config.connect_url)
    connect_config = InfluxConfig()
    connect_config.update_topics(topic.names)
    # Create the connector using the Kafka Connect API
    connect.create_or_update(name="influxdb-sink",
                             connect_config=connect_config.asjson())
    # List connectors from the Kafka Connect API
    list = connect.list()
    assert "influxdb-sink" in list
def test_integration_broker_connect(ensure_broker_service: Fixture,
                                    ensure_connect_service: Fixture) -> None:
    """Test kafkaconnect with a Kafka broker and Kafka Connect.

    pytest-docker uses the docker-compose.yaml in the test directory.
    """
    admin_client = AdminClient({"bootstrap.servers": BROKER_URL})
    t1 = NewTopic(topic="test.t1", num_partitions=1)
    t2 = NewTopic(topic="test.t2", num_partitions=1)
    t3 = NewTopic(topic="test.t3", num_partitions=1)
    # Create test topics in Kafka
    try:
        admin_client.create_topics([t1, t2, t3])
        time.sleep(5)
    except KafkaException:
        return None
    # Test topic discovery
    topic = Topic(
        broker_url=BROKER_URL,
        topic_regex="test.*",
        excluded_topic_regex="test.t1",
    )
    assert "test.t1" not in topic.names
    assert "test.t2" in topic.names
    assert "test.t3" in topic.names
    # Configure the connector
    connect = Connect(connect_url=CONNECT_URL)
    connect_config = InfluxConfig(
        name="influxdb-sink",
        connect_influx_url="http://localhost:8086",
        connect_influx_db="mydb",
        tasks_max=1,
        connect_influx_username="******",
        connect_influx_password="******",
        connect_influx_error_policy="foo",
        connect_influx_max_retries="1",
        connect_influx_retry_interval="1",
        connect_progress_enabled=True,
    )
    connect_config.update_topics(topic.names)
    # Create the connector using the Kafka Connect API
    connect.create_or_update(name="influxdb-sink",
                             connect_config=connect_config.asjson())
    # List connectors from the Kafka Connect API
    list = connect.list()
    assert "influxdb-sink" in list
示例#3
0
def list(ctx: click.Context) -> None:
    """Get a list of active connectors."""
    config = ctx.obj["config"]
    connect = Connect(config.connect_url)
    click.echo(connect.list())
def test_list() -> None:
    connect = Connect(connect_url="http://localhost:8083")
    result = connect.list()
    assert "influxdb-sink" in result