from kafka import KafkaProducer, KafkaConsumer  # type: ignore
from pytest_kafka import make_zookeeper_process, make_kafka_server, make_kafka_consumer, terminate
if TYPE_CHECKING:
    # Don't break anything else than typechecking if pytest changes.
    from _pytest.fixtures import SubRequest  # type: ignore  # noqa

ROOT = Path(__file__).parent
KAFKA_SCRIPTS = ROOT / 'kafka/bin/'

KAFKA_BIN = str(KAFKA_SCRIPTS / 'kafka-server-start.sh')
ZOOKEEPER_BIN = str(KAFKA_SCRIPTS / 'zookeeper-server-start.sh')

TOPIC = 'abc'

# 2 independent basic fixture sets.
zookeeper_proc = make_zookeeper_process(ZOOKEEPER_BIN)
kafka_server = make_kafka_server(KAFKA_BIN, 'zookeeper_proc')
kafka_consumer = make_kafka_consumer('kafka_server',
                                     seek_to_beginning=True,
                                     kafka_topics=[TOPIC])

zookeeper_proc_2 = make_zookeeper_process(ZOOKEEPER_BIN)
kafka_server_2 = make_kafka_server(KAFKA_BIN, 'zookeeper_proc_2')
kafka_consumer_2 = make_kafka_consumer('kafka_server',
                                       seek_to_beginning=True,
                                       kafka_topics=[TOPIC])

# Zookeeper shared with `kafka_server`.
kafka_server_same_zk = make_kafka_server(KAFKA_BIN, 'zookeeper_proc')
kafka_consumer_same_zk = make_kafka_consumer('kafka_server_same_zk',
                                             seek_to_beginning=True,
Beispiel #2
0
    _, port = kafka_port
    return "localhost", port


@pytest.fixture
def statsd_server():
    port = port_for.select_random(None)
    server = StatsDStub(port=port)
    server.start()
    yield server
    server.stop()


postgres_server = pg_factories.postgresql_proc(password="******")
redis_server = redis_factories.redis_proc(
    executable=shutil.which("redis-server"), timeout=3600)

KAFKA_BIN = download_kafka()
zookeeper_server = make_zookeeper_process(
    str(KAFKA_BIN / "zookeeper-server-start.sh"),
    zk_config_template="""
dataDir={zk_data_dir}
clientPort={zk_port}
maxClientCnxns=0
admin.enableServer=false""",
)
kafka_port = make_kafka_server(
    kafka_bin=str(KAFKA_BIN / "kafka-server-start.sh"),
    zookeeper_fixture_name="zookeeper_server",
)