Java Code Examples for org.testcontainers.containers.Network#newNetwork()

The following examples show how to use org.testcontainers.containers.Network#newNetwork() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DockerElasticSearch.java    From james-project with Apache License 2.0 6 votes vote down vote up
WithAuth(String imageName) {
    this.network = Network.newNetwork();
    this.elasticSearch = new DockerElasticSearch.NoAuth(
        DockerElasticSearch.NoAuth
            .defaultContainer(imageName)
            .withLogConsumer(frame -> LOGGER.debug("[ElasticSearch] " + frame.getUtf8String()))
            .withNetwork(network)
            .withNetworkAliases("elasticsearch"));

    this.nginx = new DockerContainer(
            new GenericContainer<>(
                new ImageFromDockerfile()
                .withFileFromClasspath("conf/nginx-conf/", "auth-es/nginx-conf/")
                .withFileFromClasspath("conf/default.crt", "auth-es/default.crt")
                .withFileFromClasspath("conf/default.key", "auth-es/default.key")
                .withFileFromClasspath("Dockerfile", "auth-es/NginxDockerfile")))
        .withExposedPorts(ES_HTTP_PORT)
        .withLogConsumer(frame -> LOGGER.debug("[NGINX] " + frame.getUtf8String()))
        .withNetwork(network);
}
 
Example 2
Source File: NetworkTest.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Test
public void testNetworkSupport() throws Exception {
    // useCustomNetwork {
    try (
            Network network = Network.newNetwork();

            GenericContainer foo = new GenericContainer()
                    .withNetwork(network)
                    .withNetworkAliases("foo")
                    .withCommand("/bin/sh", "-c", "while true ; do printf 'HTTP/1.1 200 OK\\n\\nyay' | nc -l -p 8080; done");

            GenericContainer bar = new GenericContainer()
                    .withNetwork(network)
                    .withCommand("top")
    ) {
        foo.start();
        bar.start();

        String response = bar.execInContainer("wget", "-O", "-", "http://foo:8080").getStdout();
        assertEquals("received response", "yay", response);
    }
    // }
}
 
Example 3
Source File: PulsarStandaloneTestBase.java    From pulsar with Apache License 2.0 6 votes vote down vote up
protected void startCluster(final String pulsarImageName) throws Exception {
    network = Network.newNetwork();
    String clusterName = PulsarClusterTestBase.randomName(8);
    container = new StandaloneContainer(clusterName, pulsarImageName)
        .withNetwork(network)
        .withNetworkAliases(StandaloneContainer.NAME + "-" + clusterName)
        .withEnv("PF_stateStorageServiceUrl", "bk://localhost:4181");
    container.start();
    log.info("Pulsar cluster {} is up running:", clusterName);
    log.info("\tBinary Service Url : {}", container.getPlainTextServiceUrl());
    log.info("\tHttp Service Url : {}", container.getHttpServiceUrl());

    // add cluster to public tenant
    ContainerExecResult result = container.execCmd(
            "/pulsar/bin/pulsar-admin", "namespaces", "policies", "public/default");
    assertEquals(0, result.getExitCode());
    log.info("public/default namespace policies are {}", result.getStdout());
}
 
Example 4
Source File: ReplicatorKafkaJSONTest.java    From replicator with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void before() {
    ServicesProvider servicesProvider = ServicesProvider.build(ServicesProvider.Type.CONTAINERS);
    ReplicatorKafkaJSONTest.zookeeper = servicesProvider.startZookeeper();

    MySQLConfiguration mySQLActiveSchemaConfiguration = new MySQLConfiguration(
            ReplicatorKafkaJSONTest.MYSQL_ACTIVE_SCHEMA,
            ReplicatorKafkaJSONTest.MYSQL_USERNAME,
            ReplicatorKafkaJSONTest.MYSQL_PASSWORD,
            ReplicatorKafkaJSONTest.MYSQL_CONF_FILE,
            Collections.emptyList(),
            null,
            null
    );

    ReplicatorKafkaJSONTest.mysqlBinaryLog = servicesProvider.startMySQL(MYSQL_CONFIG);
    ReplicatorKafkaJSONTest.mysqlActiveSchema = servicesProvider.startMySQL(mySQLActiveSchemaConfiguration);
    Network network = Network.newNetwork();
    ReplicatorKafkaJSONTest.kafkaZk = servicesProvider.startZookeeper(network, "kafkaZk");
    ReplicatorKafkaJSONTest.kafka = servicesProvider.startKafka(network, ReplicatorKafkaJSONTest.KAFKA_REPLICATOR_TOPIC_NAME, ReplicatorKafkaJSONTest.KAFKA_TOPIC_PARTITIONS, ReplicatorKafkaJSONTest.KAFKA_TOPIC_REPLICAS, "kafka");
}
 
Example 5
Source File: ReplicatorKafkaAvroTest.java    From replicator with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void before() {
    ServicesProvider servicesProvider = ServicesProvider.build(ServicesProvider.Type.CONTAINERS);

    ReplicatorKafkaAvroTest.zookeeper = servicesProvider.startZookeeper();

    MySQLConfiguration mySQLActiveSchemaConfiguration = new MySQLConfiguration(
            ReplicatorKafkaAvroTest.MYSQL_ACTIVE_SCHEMA,
            ReplicatorKafkaAvroTest.MYSQL_USERNAME,
            ReplicatorKafkaAvroTest.MYSQL_PASSWORD,
            ReplicatorKafkaAvroTest.MYSQL_CONF_FILE,
            Collections.emptyList(),
            null,
            null
    );

    ReplicatorKafkaAvroTest.mysqlBinaryLog = servicesProvider.startMySQL(MYSQL_CONFIG);
    ReplicatorKafkaAvroTest.mysqlActiveSchema = servicesProvider.startMySQL(mySQLActiveSchemaConfiguration);
    Network network = Network.newNetwork();
    ReplicatorKafkaAvroTest.kafkaZk = servicesProvider.startZookeeper(network, "kafkaZk");
    ReplicatorKafkaAvroTest.kafka = servicesProvider.startKafka(network, ReplicatorKafkaAvroTest.KAFKA_REPLICATOR_TOPIC_NAME, ReplicatorKafkaAvroTest.KAFKA_TOPIC_PARTITIONS, ReplicatorKafkaAvroTest.KAFKA_TOPIC_REPLICAS, "kafka");
    ReplicatorKafkaAvroTest.schemaRegistry = servicesProvider.startSchemaRegistry(network);
}
 
Example 6
Source File: NetworkTest.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Test
public void testReusability() throws Exception {
    try (Network network = Network.newNetwork()) {
        String firstId = network.getId();
        assertNotNull(
                "Network exists",
                DockerClientFactory.instance().client().inspectNetworkCmd().withNetworkId(firstId).exec()
        );

        network.close();

        assertNotEquals(
                "New network created",
                firstId,
                DockerClientFactory.instance().client().inspectNetworkCmd().withNetworkId(network.getId()).exec().getId()
        );
    }
}
 
Example 7
Source File: TestingKuduServer.java    From presto with Apache License 2.0 6 votes vote down vote up
public TestingKuduServer()
{
    Network network = Network.newNetwork();
    ImmutableList.Builder<GenericContainer<?>> tServersBuilder = ImmutableList.builder();
    this.master = new GenericContainer<>("apache/kudu:1.10.0")
            .withExposedPorts(KUDU_MASTER_PORT)
            .withCommand("master")
            .withNetwork(network)
            .withNetworkAliases("kudu-master");

    for (int instance = 0; instance < NUMBER_OF_REPLICA; instance++) {
        String instanceName = "kudu-tserver-" + instance;
        GenericContainer<?> tableServer = new GenericContainer<>("apache/kudu:1.10.0")
                .withExposedPorts(KUDU_TSERVER_PORT)
                .withCommand("tserver")
                .withEnv("KUDU_MASTERS", "kudu-master:" + KUDU_MASTER_PORT)
                .withNetwork(network)
                .withNetworkAliases("kudu-tserver-" + instance)
                .dependsOn(master)
                .withEnv("TSERVER_ARGS", "--fs_wal_dir=/var/lib/kudu/tserver --use_hybrid_clock=false --rpc_advertised_addresses=" + instanceName);
        tServersBuilder.add(tableServer);
    }
    this.tServers = tServersBuilder.build();
    master.start();
    tServers.forEach(GenericContainer::start);
}
 
Example 8
Source File: JaegerElasticsearchEnvironment.java    From spark-dependencies with Apache License 2.0 5 votes vote down vote up
public void start(Map<String, String> jaegerEnvs, String jaegerVersion, String elasticsearchVersion) {
  network = Network.newNetwork();
  elasticsearch = new GenericContainer<>(String.format("docker.elastic.co/elasticsearch/elasticsearch:%s", elasticsearchVersion))
      .withNetwork(network)
      .withNetworkAliases("elasticsearch")
      .waitingFor(new BoundPortHttpWaitStrategy(9200).forStatusCode(200))
      .withExposedPorts(9200, 9300)
      .withEnv("xpack.security.enabled", "false")
      .withEnv("discovery.type", "single-node")
      .withEnv("network.bind_host", "elasticsearch")
      .withEnv("network.host", "_site_")
      .withEnv("network.publish_host", "_local_");
  elasticsearch.start();

  jaegerCollector = new GenericContainer<>("jaegertracing/jaeger-collector:" + jaegerVersion)
      .withNetwork(network)
      .withEnv("SPAN_STORAGE_TYPE", "elasticsearch")
      .withEnv("ES_SERVER_URLS", "http://elasticsearch:9200")
      .withEnv("COLLECTOR_ZIPKIN_HTTP_PORT", "9411")
      .withEnv("COLLECTOR_QUEUE_SIZE", "100000")
      .withEnv(jaegerEnvs)
      .waitingFor(new BoundPortHttpWaitStrategy(14269).forStatusCodeMatching(statusCode -> statusCode >= 200 && statusCode < 300))
      // the first one is health check
      .withExposedPorts(14269, 14268, 9411);
  jaegerCollector.start();

  jaegerQuery = new GenericContainer<>("jaegertracing/jaeger-query:" + jaegerVersion())
      .withEnv("SPAN_STORAGE_TYPE", "elasticsearch")
      .withEnv("ES_SERVER_URLS", "http://elasticsearch:9200")
      .withEnv("ES_TAGS_AS_FIELDS_ALL", "true")
      .withNetwork(network)
      .withEnv(jaegerEnvs)
      .waitingFor(new BoundPortHttpWaitStrategy(16687).forStatusCodeMatching(statusCode -> statusCode >= 200 && statusCode < 300))
      .withExposedPorts(16687, 16686);
  jaegerQuery.start();

  collectorUrl = String.format("http://%s:%d", jaegerCollector.getContainerIpAddress(), jaegerCollector.getMappedPort(14268));
  zipkinCollectorUrl = String.format("http://%s:%d", jaegerCollector.getContainerIpAddress(), jaegerCollector.getMappedPort(9411));
  queryUrl = String.format("http://%s:%d", jaegerQuery.getContainerIpAddress(), jaegerQuery.getMappedPort(16686));
}
 
Example 9
Source File: ContainersProvider.java    From replicator with Apache License 2.0 5 votes vote down vote up
@Override
public ServicesControl startHbase() {

    Network network = Network.newNetwork();

    GenericContainer<?> hbase = this.getContainerHBase(
            VersionedPipelines.defaultTags.hbase,
            network,
            "",
            0,
            true
    );

    hbase.start();

    return new ServicesControl() {
        @Override
        public GenericContainer<?> getContainer() { return hbase; }

        @Override
        public void close() {
            hbase.stop();
        }

        @Override
        public int getPort() {
            return hbase.getMappedPort(ContainersProvider.HBASE_ZK_PORT);
        }
    };
}
 
Example 10
Source File: BootstrapReplicatorTest.java    From replicator with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void before() {
    ServicesProvider servicesProvider = ServicesProvider.build(ServicesProvider.Type.CONTAINERS);

    MySQLConfiguration mySQLConfiguration = new MySQLConfiguration(
            BootstrapReplicatorTest.MYSQL_SCHEMA,
            BootstrapReplicatorTest.MYSQL_USERNAME,
            BootstrapReplicatorTest.MYSQL_PASSWORD,
            BootstrapReplicatorTest.MYSQL_CONF_FILE,
            Collections.singletonList(BootstrapReplicatorTest.MYSQL_INIT_SCRIPT),
            null,
            null
    );

    MySQLConfiguration mySQLActiveSchemaConfiguration = new MySQLConfiguration(
            BootstrapReplicatorTest.MYSQL_ACTIVE_SCHEMA,
            BootstrapReplicatorTest.MYSQL_USERNAME,
            BootstrapReplicatorTest.MYSQL_PASSWORD,
            BootstrapReplicatorTest.MYSQL_CONF_FILE,
            Collections.emptyList(),
            null,
            null
    );

    BootstrapReplicatorTest.mysqlBinaryLog = servicesProvider.startMySQL(mySQLConfiguration);
    BootstrapReplicatorTest.mysqlActiveSchema = servicesProvider.startMySQL(mySQLActiveSchemaConfiguration);
    Network network = Network.newNetwork();
    BootstrapReplicatorTest.kafkaZk = servicesProvider.startZookeeper(network, "kafkaZk");
    BootstrapReplicatorTest.kafka = servicesProvider.startKafka(network, BootstrapReplicatorTest.KAFKA_REPLICATOR_TOPIC_NAME, 3, 1, "kafka");
    BootstrapReplicatorTest.schemaRegistry = servicesProvider.startSchemaRegistry(network);

}
 
Example 11
Source File: Linshare.java    From james-project with Apache License 2.0 5 votes vote down vote up
public Linshare() {
    network = Network.newNetwork();
    linshareDatabase = createDockerDatabase();
    linshareMongodb = createDockerMongodb();
    linshareLdap = createDockerLdap();
    linshareSmtp = createDockerSmtp();
    linshareBackend = createDockerBackend();
    linshareDBInit = createLinshareBackendInit();
}
 
Example 12
Source File: VaultTestExtension.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void start() throws InterruptedException, IOException {

        log.info("start containers on " + System.getProperty("os.name"));

        new File(HOST_POSTGRES_TMP_CMD).mkdirs();

        Network network = Network.newNetwork();

        postgresContainer = new PostgreSQLContainer<>()
                .withDatabaseName(DB_NAME)
                .withUsername(DB_USERNAME)
                .withPassword(DB_PASSWORD)
                .withNetwork(network)
                .withFileSystemBind(HOST_POSTGRES_TMP_CMD, CONTAINER_TMP_CMD)
                .withNetworkAliases(POSTGRESQL_HOST)
                .withExposedPorts(POSTGRESQL_PORT)
                .withClasspathResourceMapping("postgres-init.sql", TMP_POSTGRES_INIT_SQL_FILE, READ_ONLY);

        postgresContainer.setPortBindings(Arrays.asList(MAPPED_POSTGRESQL_PORT + ":" + POSTGRESQL_PORT));

        String configFile = useTls() ? "vault-config-tls.json" : "vault-config.json";

        log.info("starting vault with url=" + VAULT_URL + " and config file=" + configFile);

        new File(HOST_VAULT_TMP_CMD).mkdirs();

        vaultContainer = new GenericContainer<>("vault:" + getVaultVersion())
                .withExposedPorts(VAULT_PORT)
                .withEnv("SKIP_SETCAP", "true")
                .withEnv("VAULT_SKIP_VERIFY", "true") // this is internal to the container
                .withEnv("VAULT_ADDR", VAULT_URL)
                .withNetwork(network)
                .withFileSystemBind(HOST_VAULT_TMP_CMD, CONTAINER_TMP_CMD)
                .withClasspathResourceMapping(configFile, TMP_VAULT_CONFIG_JSON_FILE, READ_ONLY)
                .withClasspathResourceMapping("vault-tls.key", "/tmp/vault-tls.key", READ_ONLY)
                .withClasspathResourceMapping("vault-tls.crt", "/tmp/vault-tls.crt", READ_ONLY)
                .withClasspathResourceMapping("vault.policy", TMP_VAULT_POLICY_FILE, READ_ONLY)
                .withClasspathResourceMapping("vault-postgres-creation.sql", TMP_VAULT_POSTGRES_CREATION_SQL_FILE, READ_ONLY)
                .withCommand("server", "-log-level=debug", "-config=" + TMP_VAULT_CONFIG_JSON_FILE);

        vaultContainer.setPortBindings(Arrays.asList(VAULT_PORT + ":" + VAULT_PORT));

        postgresContainer.start();
        execPostgres(format("psql -U %s -d %s -f %s", DB_USERNAME, DB_NAME, TMP_POSTGRES_INIT_SQL_FILE));

        Consumer<OutputFrame> consumer = outputFrame -> System.out.print("VAULT >> " + outputFrame.getUtf8String());
        vaultContainer.setLogConsumers(Arrays.asList(consumer));
        vaultContainer.start();

        initVault();
        log.info("vault has started with root token: " + rootToken);
    }
 
Example 13
Source File: CassandraDependenciesJobTest.java    From spark-dependencies with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeClass() {
  network = Network.newNetwork();
  cassandra = new CassandraContainer("cassandra:3.11")
      .withNetwork(network)
      .withNetworkAliases("cassandra")
      .withExposedPorts(9042);
  cassandra.start();
  cassandraPort = cassandra.getMappedPort(9042);

  jaegerCassandraSchema = new GenericContainer<>("jaegertracing/jaeger-cassandra-schema:" + jaegerVersion())
      .withNetwork(network);
  jaegerCassandraSchema.start();
  /**
   * Wait until schema is created
   */
  await().until(() -> !jaegerCassandraSchema.isRunning());

  jaegerCollector = new GenericContainer<>("jaegertracing/jaeger-collector:" + jaegerVersion())
      .withNetwork(network)
      .withEnv("CASSANDRA_SERVERS", "cassandra")
      .withEnv("CASSANDRA_KEYSPACE", "jaeger_v1_dc1")
      .withEnv("COLLECTOR_ZIPKIN_HTTP_PORT", "9411")
      .withEnv("COLLECTOR_QUEUE_SIZE", "100000")
      // older versions of jaeger were using 204 status code, now changed to 200
      .waitingFor(new BoundPortHttpWaitStrategy(14269).forStatusCodeMatching(statusCode -> statusCode >= 200 && statusCode < 300))
      // the first one is health check
      .withExposedPorts(14269, 14268, 9411);
  jaegerCollector.start();

  jaegerQuery = new GenericContainer<>("jaegertracing/jaeger-query:" + jaegerVersion())
      .withNetwork(network)
      .withEnv("CASSANDRA_SERVERS", "cassandra")
      .withEnv("CASSANDRA_KEYSPACE", "jaeger_v1_dc1")
      .waitingFor(new BoundPortHttpWaitStrategy(16687).forStatusCodeMatching(statusCode -> statusCode >= 200 && statusCode < 300))
      .withExposedPorts(16687, 16686);
  jaegerQuery.start();

  queryUrl = String.format("http://localhost:%d", jaegerQuery.getMappedPort(16686));
  collectorUrl = String.format("http://localhost:%d", jaegerCollector.getMappedPort(14268));
  zipkinCollectorUrl = String.format("http://localhost:%d", jaegerCollector.getMappedPort(9411));
}
 
Example 14
Source File: ContainersProvider.java    From replicator with Apache License 2.0 4 votes vote down vote up
@Override
public ServicesControl startKafka(String topic, int partitions, int replicas) {
    Network network = Network.newNetwork();

    GenericContainer<?> zookeeper = this.getZookeeper(network, VersionedPipelines.defaultTags.zookeeperTag);

    zookeeper.start();

    GenericContainer<?> kafka = this.getContainer(
            System.getProperty(
                    ContainersProvider.KAFKA_DOCKER_IMAGE_KEY,
                    VersionedPipelines.defaultTags.kafkaTag
            ),
            ContainersProvider.KAFKA_PORT,
            network,
            ContainersProvider.KAFKA_STARTUP_WAIT_REGEX,
            partitions,
            true
    ).withEnv(
            ContainersProvider.KAFKA_ZOOKEEPER_CONNECT_KEY,
            String.format("%s:%d", zookeeper.getContainerInfo().getConfig().getHostName(), ContainersProvider.ZOOKEEPER_PORT)
    ).withEnv(
            ContainersProvider.KAFKA_CREATE_TOPICS_KEY,
            String.format("%s:%d:%d", topic, partitions, replicas)
    ).withEnv(
            ContainersProvider.KAFKA_ADVERTISED_HOST_NAME_KEY,
            "localhost"
    );

    kafka.start();

    return new ServicesControl() {
        @Override
        public GenericContainer<?> getContainer() { return kafka; }

        @Override
        public void close() {
            kafka.stop();
            zookeeper.stop();
        }

        @Override
        public int getPort() {
            return kafka.getMappedPort(ContainersProvider.KAFKA_PORT);
        }
    };
}
 
Example 15
Source File: KafkaConnectConverterIT.java    From apicurio-registry with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void startContainers() {
    String apicurioVersion = System.getProperty("project.version");
    assertNotNull(apicurioVersion);

    Path converterDistro = Paths.get(System.getProperty("user.dir"), "..", "distro", "connect-converter",
            "target", "apicurio-kafka-connect-converter-" + apicurioVersion + "-converter.tar.gz");

    if (Files.notExists(converterDistro)) {
        LOGGER.info("Connecter distribution {}", converterDistro.toString());
        throw new IllegalStateException("Kafka connect converter distribution is not present");
    }

    ImageFromDockerfile apicurioDebeziumImage = new ImageFromDockerfile()
            .withFileFromPath("converter-distro.tar.gz", converterDistro)
            .withDockerfileFromBuilder(builder -> builder
                    .from("debezium/connect:1.1.1.Final")
                    .env("KAFKA_CONNECT_DEBEZIUM_DIR", "$KAFKA_CONNECT_PLUGINS_DIR/debezium-connector-postgres")
                    .copy("converter-distro.tar.gz", "$KAFKA_CONNECT_DEBEZIUM_DIR/apicurio-kafka-connect-converter.tar.gz")
                    .run("cd $KAFKA_CONNECT_DEBEZIUM_DIR && tar -xvf apicurio-kafka-connect-converter.tar.gz")
                    .build());

    if (!TestUtils.isExternalRegistry()) {
        Testcontainers.exposeHostPorts(8081);
    }

    Testcontainers.exposeHostPorts(9092);
    kafka = new KafkaContainer();
    kafka.addEnv("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR", "1");
    kafka.addEnv("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR", "1");
    kafka.addExposedPorts(9092);
    kafka.withCreateContainerCmdModifier(cmd -> {
        cmd
                .withHostName("localhost")
                .withPortBindings(new PortBinding(Ports.Binding.bindPort(9092), new ExposedPort(9092)));
    });
    kafka.start();

    Network network = Network.newNetwork();

    postgres = new PostgreSQLContainer<>("debezium/postgres:11")
          .withNetwork(network)
          .withNetworkAliases("postgres");
    postgres.start();

    debeziumContainer = new DebeziumContainer("dummy-version");
    debeziumContainer.setImage(apicurioDebeziumImage);
    debeziumContainer.withNetwork(network)
          .withEnv("BOOTSTRAP_SERVERS", "host.testcontainers.internal:9092")
          .withLogConsumer(new Slf4jLogConsumer(LOGGER));
    debeziumContainer.setWaitStrategy(
            Wait.forHttp("/connectors")
            .forPort(8083)
            .forStatusCode(200)
            .withReadTimeout(Duration.ofSeconds(3))
            .withStartupTimeout(Duration.ofSeconds(300)));
    debeziumContainer.start();

}
 
Example 16
Source File: SlaveFailoverTest.java    From replicator with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void before() throws InterruptedException {
    ServicesProvider servicesProvider = ServicesProvider.build(ServicesProvider.Type.CONTAINERS);

    Network network = Network.newNetwork();

    LOG.info("Iniitializing mysql replication chain with 1 master and 2 slaves");

    mySQLMasterConfiguration = new MySQLConfiguration(
            SlaveFailoverTest.MYSQL_SCHEMA,
            SlaveFailoverTest.MYSQL_USERNAME,
            SlaveFailoverTest.MYSQL_PASSWORD,
            SlaveFailoverTest.MYSQL_CONF_FILE,
            Collections.singletonList(SlaveFailoverTest.MYSQL_MASTER_INIT_SCRIPT),
            network,
            "mysql-chain"
    );

    mySQLSlave1Configuration = new MySQLConfiguration(
            SlaveFailoverTest.MYSQL_SCHEMA,
            null,
            SlaveFailoverTest.MYSQL_PASSWORD,
            SlaveFailoverTest.MYSQL_SLAVE_CONF_FILE,
            Collections.emptyList(),
            network,
            "mysql-chain"
    );

    mySQLSlave2Configuration = new MySQLConfiguration(
            SlaveFailoverTest.MYSQL_SCHEMA,
            null,
            SlaveFailoverTest.MYSQL_PASSWORD,
            SlaveFailoverTest.MYSQL_SLAVE_CONF_FILE,
            Collections.emptyList(),
            network,
            "mysql-chain"
    );

    mySQLActiveSchemaConfiguration = new MySQLConfiguration(
            SlaveFailoverTest.MYSQL_ACTIVE_SCHEMA,
            SlaveFailoverTest.MYSQL_USERNAME,
            SlaveFailoverTest.MYSQL_PASSWORD,
            SlaveFailoverTest.MYSQL_CONF_FILE,
            Collections.emptyList(),
            network,
            "mysql-chain"
    );

    mysqlMaster = servicesProvider.startMySQL(mySQLMasterConfiguration);

    // Initialize replication on slave 1
    mysqlSlave1 = servicesProvider.startMySQL(mySQLSlave1Configuration);

    // Initialize replication on slave 2
    mysqlSlave2 = servicesProvider.startMySQL(mySQLSlave2Configuration);


    mysqlActiveSchema = servicesProvider.startMySQL(mySQLActiveSchemaConfiguration);

    boolean s1Initialized = initializeSlave(mysqlMaster, mysqlSlave1, mySQLSlave1Configuration);
    boolean s2Initialized = initializeSlave(mysqlMaster, mysqlSlave2, mySQLSlave2Configuration);
    assumeTrue("Mysql slaves failed to initialize",s1Initialized && s2Initialized );

    assumeTrue("File checkpoint failed to initialize",
            initializeGtidCheckpoint(mysqlSlave1, mySQLSlave1Configuration));


    LOG.info("Mysql replication chain initialized.. "
            + "Sleeping for 30 seconds to propagate changes");
    // Sleep for 30 seconds for master-slave mysql chain to initialize
    // Alternatively can poll slaves to check their state
    TimeUnit.SECONDS.sleep(30);
}
 
Example 17
Source File: KuduTestResource.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, String> start() {
    LOG.info(TestcontainersConfiguration.getInstance().toString());

    try {
        Network kuduNetwork = Network.newNetwork();

        // Setup the Kudu master server container
        masterContainer = new GenericContainer(KUDU_IMAGE).withCommand("master")
                .withExposedPorts(KUDU_MASTER_RPC_PORT, KUDU_MASTER_HTTP_PORT).withNetwork(kuduNetwork)
                .withNetworkAliases(KUDU_MASTER_NETWORK_ALIAS);
        masterContainer = masterContainer.withLogConsumer(new Slf4jLogConsumer(LOG)).waitingFor(Wait.forListeningPort());
        masterContainer.start();

        // Force host name and port, so that the tablet container is accessible from KuduResource, KuduTest and KuduIT.
        Consumer<CreateContainerCmd> consumer = cmd -> {
            Ports portBindings = new Ports();
            portBindings.bind(ExposedPort.tcp(KUDU_TABLET_RPC_PORT), Ports.Binding.bindPort(KUDU_TABLET_RPC_PORT));
            portBindings.bind(ExposedPort.tcp(KUDU_TABLET_HTTP_PORT), Ports.Binding.bindPort(KUDU_TABLET_HTTP_PORT));
            HostConfig hostConfig = HostConfig.newHostConfig().withPortBindings(portBindings)
                    .withNetworkMode(kuduNetwork.getId());
            cmd.withHostName(KUDU_TABLET_NETWORK_ALIAS).withHostConfig(hostConfig);
        };

        // Setup the Kudu tablet server container
        tabletContainer = new GenericContainer(KUDU_IMAGE).withCommand("tserver")
                .withEnv("KUDU_MASTERS", KUDU_MASTER_NETWORK_ALIAS)
                .withExposedPorts(KUDU_TABLET_RPC_PORT, KUDU_TABLET_HTTP_PORT).withNetwork(kuduNetwork)
                .withNetworkAliases(KUDU_TABLET_NETWORK_ALIAS).withCreateContainerCmdModifier(consumer);
        tabletContainer = tabletContainer.withLogConsumer(new Slf4jLogConsumer(LOG)).waitingFor(Wait.forListeningPort());
        tabletContainer.start();

        // Print interesting Kudu servers connectivity information
        final String masterRpcAuthority = masterContainer.getContainerIpAddress() + ":"
                + masterContainer.getMappedPort(KUDU_MASTER_RPC_PORT);
        LOG.info("Kudu master RPC accessible at " + masterRpcAuthority);
        final String masterHttpAuthority = masterContainer.getContainerIpAddress() + ":"
                + masterContainer.getMappedPort(KUDU_MASTER_HTTP_PORT);
        LOG.info("Kudu master HTTP accessible at " + masterHttpAuthority);
        final String tServerRpcAuthority = tabletContainer.getContainerIpAddress() + ":"
                + tabletContainer.getMappedPort(KUDU_TABLET_RPC_PORT);
        LOG.info("Kudu tablet server RPC accessible at " + tServerRpcAuthority);
        final String tServerHttpAuthority = tabletContainer.getContainerIpAddress() + ":"
                + tabletContainer.getMappedPort(KUDU_TABLET_HTTP_PORT);
        LOG.info("Kudu tablet server HTTP accessible at " + tServerHttpAuthority);

        return CollectionHelper.mapOf(KUDU_AUTHORITY_CONFIG_KEY, masterRpcAuthority);
    } catch (Exception ex) {
        LOG.error("Issue starting KuduTestResource, please have a look at KuduInfrastructureTestHelper", ex);
        return CollectionHelper.mapOf(KUDU_AUTHORITY_CONFIG_KEY,
                "Please_have_a_look_at_KuduInfrastructureTestHelper");
    }
}
 
Example 18
Source File: BaseClickHouseTest.java    From beam with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setup() throws IOException, InterruptedException {
  // network sharing doesn't work with ClassRule
  network = Network.newNetwork();

  zookeeper =
      new GenericContainer<>("zookeeper:3.4.13")
          .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);
      }
    }
  }
}
 
Example 19
Source File: PulsarCluster.java    From pulsar with Apache License 2.0 4 votes vote down vote up
private PulsarCluster(PulsarClusterSpec spec) {

        this.spec = spec;
        this.clusterName = spec.clusterName();
        this.network = Network.newNetwork();
        this.enablePrestoWorker = spec.enablePrestoWorker();

        if (enablePrestoWorker) {
            prestoWorkerContainer = new PrestoWorkerContainer(clusterName, PrestoWorkerContainer.NAME)
                    .withNetwork(network)
                    .withNetworkAliases(PrestoWorkerContainer.NAME)
                    .withEnv("clusterName", clusterName)
                    .withEnv("zkServers", ZKContainer.NAME)
                    .withEnv("zookeeperServers", ZKContainer.NAME + ":" + ZKContainer.ZK_PORT)
                    .withEnv("pulsar.zookeeper-uri", ZKContainer.NAME + ":" + ZKContainer.ZK_PORT)
                    .withEnv("pulsar.broker-service-url", "http://pulsar-broker-0:8080");
        } else {
            prestoWorkerContainer = null;
        }


        this.zkContainer = new ZKContainer(clusterName);
        this.zkContainer
            .withNetwork(network)
            .withNetworkAliases(ZKContainer.NAME)
            .withEnv("clusterName", clusterName)
            .withEnv("zkServers", ZKContainer.NAME)
            .withEnv("configurationStore", CSContainer.NAME + ":" + CS_PORT)
            .withEnv("forceSync", "no")
            .withEnv("pulsarNode", "pulsar-broker-0");

        this.csContainer = new CSContainer(clusterName)
            .withNetwork(network)
            .withNetworkAliases(CSContainer.NAME);

        this.bookieContainers = Maps.newTreeMap();
        this.brokerContainers = Maps.newTreeMap();
        this.workerContainers = Maps.newTreeMap();

        this.proxyContainer = new ProxyContainer(clusterName, ProxyContainer.NAME)
            .withNetwork(network)
            .withNetworkAliases("pulsar-proxy")
            .withEnv("zkServers", ZKContainer.NAME)
            .withEnv("zookeeperServers", ZKContainer.NAME)
            .withEnv("configurationStoreServers", CSContainer.NAME + ":" + CS_PORT)
            .withEnv("clusterName", clusterName);

        // create bookies
        bookieContainers.putAll(
                runNumContainers("bookie", spec.numBookies(), (name) -> new BKContainer(clusterName, name)
                        .withNetwork(network)
                        .withNetworkAliases(name)
                        .withEnv("zkServers", ZKContainer.NAME)
                        .withEnv("useHostNameAsBookieID", "true")
                        // Disable fsyncs for tests since they're slow within the containers
                        .withEnv("journalSyncData", "false")
                        .withEnv("journalMaxGroupWaitMSec", "0")
                        .withEnv("clusterName", clusterName)
                        .withEnv("diskUsageThreshold", "0.99")
                )
        );

        // create brokers
        brokerContainers.putAll(
                runNumContainers("broker", spec.numBrokers(), (name) -> new BrokerContainer(clusterName, name)
                        .withNetwork(network)
                        .withNetworkAliases(name)
                        .withEnv("zkServers", ZKContainer.NAME)
                        .withEnv("zookeeperServers", ZKContainer.NAME)
                        .withEnv("configurationStoreServers", CSContainer.NAME + ":" + CS_PORT)
                        .withEnv("clusterName", clusterName)
                        .withEnv("brokerServiceCompactionMonitorIntervalInSeconds", "1")
                        // used in s3 tests
                        .withEnv("AWS_ACCESS_KEY_ID", "accesskey")
                        .withEnv("AWS_SECRET_KEY", "secretkey")
                )
        );

        spec.classPathVolumeMounts.forEach((key, value) -> {
            zkContainer.withClasspathResourceMapping(key, value, BindMode.READ_WRITE);
            proxyContainer.withClasspathResourceMapping(key, value, BindMode.READ_WRITE);

            bookieContainers.values().forEach(c -> c.withClasspathResourceMapping(key, value, BindMode.READ_WRITE));
            brokerContainers.values().forEach(c -> c.withClasspathResourceMapping(key, value, BindMode.READ_WRITE));
            workerContainers.values().forEach(c -> c.withClasspathResourceMapping(key, value, BindMode.READ_WRITE));
        });

    }
 
Example 20
Source File: StrimziService.java    From camel-kafka-connector with Apache License 2.0 4 votes vote down vote up
public StrimziService() {
    Network network = Network.newNetwork();

    zookeeperContainer = new ZookeeperContainer(network, "zookeeper");
    strimziContainer = new StrimziContainer(network, "strimzi");
}