Search in sources :

Example 1 with ClickHouseContainer

use of org.testcontainers.containers.ClickHouseContainer in project beam by apache.

the class BaseClickHouseTest method setup.

@BeforeClass
public static void setup() throws IOException, InterruptedException {
    // network sharing doesn't work with ClassRule
    network = Network.newNetwork();
    zookeeper = new GenericContainer<>(DockerImageName.parse("zookeeper").withTag(ZOOKEEPER_VERSION)).withStartupAttempts(10).withExposedPorts(2181).withNetwork(network).withNetworkAliases("zookeeper");
    // so far zookeeper container always starts successfully, so no extra retries
    zookeeper.start();
    clickHouse = (ClickHouseContainer) new ClickHouseContainer(CLICKHOUSE_IMAGE).withStartupAttempts(10).withCreateContainerCmdModifier(// type inference for `(CreateContainerCmd) -> cmd.` doesn't work
    cmd -> ((CreateContainerCmd) cmd).withMemory(256 * 1024 * 1024L).withMemorySwap(4L * 1024 * 1024 * 1024L)).withNetwork(network).withClasspathResourceMapping("config.d/zookeeper_default.xml", "/etc/clickhouse-server/config.d/zookeeper_default.xml", BindMode.READ_ONLY);
    BackOff backOff = FluentBackoff.DEFAULT.withMaxRetries(3).withInitialBackoff(Duration.standardSeconds(15)).backoff();
    // try to start clickhouse-server a couple of times, see BEAM-6639
    while (true) {
        try {
            Unreliables.retryUntilSuccess(10, () -> {
                DockerClientFactory.instance().checkAndPullImage(DockerClientFactory.instance().client(), CLICKHOUSE_IMAGE);
                return null;
            });
            clickHouse.start();
            break;
        } catch (Exception e) {
            if (!BackOffUtils.next(Sleeper.DEFAULT, backOff)) {
                throw e;
            } else {
                List<Image> images = DockerClientFactory.instance().client().listImagesCmd().withShowAll(true).exec();
                String listImagesOutput = "listImagesCmd:\n" + Joiner.on('\n').join(images) + "\n";
                LOG.warn("failed to start clickhouse-server\n\n" + listImagesOutput, e);
            }
        }
    }
}
Also used : CreateContainerCmd(com.github.dockerjava.api.command.CreateContainerCmd) List(java.util.List) ClickHouseContainer(org.testcontainers.containers.ClickHouseContainer) BackOff(org.apache.beam.sdk.util.BackOff) SQLException(java.sql.SQLException) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Example 2 with ClickHouseContainer

use of org.testcontainers.containers.ClickHouseContainer in project drill by apache.

the class TestJdbcPluginWithClickhouse method initClickhouse.

@BeforeClass
public static void initClickhouse() throws Exception {
    startCluster(ClusterFixture.builder(dirTestWatcher));
    String osName = System.getProperty("os.name").toLowerCase();
    DockerImageName imageName;
    if (osName.startsWith("linux") && "aarch64".equals(System.getProperty("os.arch"))) {
        imageName = DockerImageName.parse(DOCKER_IMAGE_CLICKHOUSE_ARM).asCompatibleSubstituteFor("yandex/clickhouse-server");
    } else {
        imageName = DockerImageName.parse(DOCKER_IMAGE_CLICKHOUSE_X86);
    }
    jdbcContainer = new ClickHouseContainer(imageName).withInitScript("clickhouse-test-data.sql");
    jdbcContainer.start();
    JdbcStorageConfig jdbcStorageConfig = new JdbcStorageConfig("ru.yandex.clickhouse.ClickHouseDriver", jdbcContainer.getJdbcUrl(), jdbcContainer.getUsername(), null, true, false, null, null, 0);
    jdbcStorageConfig.setEnabled(true);
    cluster.defineStoragePlugin("clickhouse", jdbcStorageConfig);
}
Also used : DockerImageName(org.testcontainers.utility.DockerImageName) ClickHouseContainer(org.testcontainers.containers.ClickHouseContainer) BeforeClass(org.junit.BeforeClass)

Aggregations

BeforeClass (org.junit.BeforeClass)2 ClickHouseContainer (org.testcontainers.containers.ClickHouseContainer)2 CreateContainerCmd (com.github.dockerjava.api.command.CreateContainerCmd)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 BackOff (org.apache.beam.sdk.util.BackOff)1 DockerImageName (org.testcontainers.utility.DockerImageName)1