public static ClickHouseNode getClickHouseNode(ClickHouseProtocol protocol,
                                                   boolean useSecurePort,
                                                   ClickHouseNode template) {
        String host = clickhouseServer;
        int port = useSecurePort ? protocol.getDefaultSecurePort() : protocol.getDefaultPort();
        String database = template != null ? template.getDatabase().orElse("default") : "default";
        GenericContainer<?> container = clickhouseContainer;
        if (isCloud()) {
            port = 8443;
            host = System.getenv("CLICKHOUSE_CLOUD_HOST");
            return ClickHouseNode.builder(template)
                    .address(ClickHouseProtocol.HTTP, new InetSocketAddress(host, port))
                    .credentials(new ClickHouseCredentials("default", getPassword()))
                    .options(Collections.singletonMap("ssl", "true"))
                    .database(database)
                    .build();
        } else if (container != null) {
            host = container.getHost();
            port = container.getMappedPort(port);
        } else {
            String config = properties
                    .getProperty(String.format("clickhouse%SPort", protocol.name()));
            if (config != null && !config.isEmpty()) {
                port = Integer.parseInt(config);
            }
        }

        return ClickHouseNode.builder(template).address(protocol, new InetSocketAddress(host, port))
                .credentials(new ClickHouseCredentials("default", getPassword()))
                .build();
    }
Adaptive ClickHouse server environment for integration test. Two modes are
supported: 1) existing server(when system property {@code clickhouseServer}
is defined); and 2) test container.

<p>
Below system properties can be used for customization:
<ul>
<li>clickhouseServer - host of clickhouse server</li>
<li>clickhouse&lt;Protocol&gt;Port - port of specific protocol, for example:
{@code clickhouseGRPCPort}</li>
<li>clickhouseImage - custom docker image, with or without tag and/or image
digest</li>
<li>clickhouseVersion - version of clickhouse, could be replaced by the one
used in {@code clickhouseImage}</li>
<li>clickhouseTimezone - server timezone</li>
<li>additionalPackages - additional system packages should be installed in
container mode</li>
</ul>
clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java