Ejemplo n.º 1
0
async def fixture_registry_async(
    tmp_path: Path, kafka_server: Optional[KafkaConfig]
) -> AsyncIterator[KarapaceSchemaRegistry]:
    if not kafka_server:
        assert REGISTRY_URI in os.environ or REST_URI in os.environ
        instance, _ = mock_factory("registry")()
        yield instance
    else:
        config_path = tmp_path / "karapace_config.json"
        kafka_port = kafka_server.kafka_port

        config = set_config_defaults({
            "log_level":
            "WARNING",
            "bootstrap_uri":
            f"127.0.0.1:{kafka_port}",
            "topic_name":
            new_random_name(),
            "group_id":
            new_random_name("schema_registry")
        })
        write_config(config_path, config)
        registry = KarapaceSchemaRegistry(config_file_path=str(config_path),
                                          config=set_config_defaults(config))
        await registry.get_master()
        try:
            yield registry
        finally:
            registry.close()
Ejemplo n.º 2
0
async def fixture_registry_async(
    request,
    tmp_path: Path,
    kafka_servers: KafkaServers,
) -> AsyncIterator[Optional[KarapaceSchemaRegistry]]:
    # Do not start a registry when the user provided an external service. Doing
    # so would cause this node to join the existing group and participate in
    # the election process. Without proper configuration for the listeners that
    # won't work and will cause test failures.
    rest_url = request.config.getoption("registry_url")
    if rest_url:
        yield None
        return

    config_path = tmp_path / "karapace_config.json"

    config = set_config_defaults({
        "bootstrap_uri":
        kafka_servers.bootstrap_servers,

        # Using the default settings instead of random values, otherwise it
        # would not be possible to run the tests with external services.
        # Because of this every test must be written in such a way that it can
        # be executed twice with the same servers.
        # "topic_name": new_random_name("topic"),
        # "group_id": new_random_name("schema_registry")
    })
    write_config(config_path, config)
    registry = KarapaceSchemaRegistry(config_file_path=str(config_path),
                                      config=config)
    await registry.get_master()
    try:
        yield registry
    finally:
        registry.close()
Ejemplo n.º 3
0
async def fixture_registry_async(session_tmpdir, kafka_server):
    if REGISTRY_URI in os.environ or REST_URI in os.environ:
        instance, _ = mock_factory("registry")()
        yield instance
    else:
        config_path = os.path.join(session_tmpdir(), "karapace_config.json")
        kafka_port = kafka_server["kafka_port"]
        write_config(
            config_path, {
                "log_level": "WARNING",
                "bootstrap_uri": f"127.0.0.1:{kafka_port}",
                "topic_name": new_random_name(),
                "group_id": new_random_name("schema_registry")
            })
        registry = KarapaceSchemaRegistry(config_path)
        await registry.get_master()
        try:
            yield registry
        finally:
            registry.close()