Java Code Examples for org.testcontainers.containers.GenericContainer#getMappedPort()
The following examples show how to use
org.testcontainers.containers.GenericContainer#getMappedPort() .
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: ContainersProvider.java From replicator with Apache License 2.0 | 6 votes |
@Override public ServicesControl startZookeeper() { GenericContainer<?> zookeeper = this.getZookeeper( null, VersionedPipelines.defaultTags.zookeeperTag); zookeeper.start(); return new ServicesControl() { @Override public GenericContainer<?> getContainer() { return zookeeper; } @Override public void close() { zookeeper.stop(); } @Override public int getPort() { return zookeeper.getMappedPort(ContainersProvider.ZOOKEEPER_PORT); } }; }
Example 2
Source File: ContainersProvider.java From replicator with Apache License 2.0 | 6 votes |
@Override public ServicesControl startZookeeper(Network network, String networkAlias) { GenericContainer<?> zookeeper = this.getZookeeper(network, VersionedPipelines.defaultTags.zookeeperTag); zookeeper.withNetworkAliases(networkAlias); zookeeper.start(); return new ServicesControl() { @Override public GenericContainer<?> getContainer() { return zookeeper; } @Override public void close() { zookeeper.stop(); } @Override public int getPort() { return zookeeper.getMappedPort(ContainersProvider.ZOOKEEPER_PORT); } }; }
Example 3
Source File: ContainersProvider.java From replicator with Apache License 2.0 | 5 votes |
@Override public ServicesControl startSchemaRegistry(Network network) { GenericContainer<?> schemaRegistry = this.getContainer(System.getProperty( ContainersProvider.SCHEMA_REGISTRY_IMAGE_KEY, VersionedPipelines.defaultTags.schemaRegistryTag ), ContainersProvider.SCHEMA_REGISTRY_PORT, network, ContainersProvider.SCHEMA_REGISTRY_WAIT_REGEX, 1, true ).withEnv( ContainersProvider.SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL_KEY, String.format("%s:%d", "kafkaZk", ContainersProvider.ZOOKEEPER_PORT) ).withEnv( ContainersProvider.SCHEMA_REGISTRY_HOST_NAME_KEY, "localhost" ); schemaRegistry.start(); return new ServicesControl() { @Override public GenericContainer<?> getContainer() { return schemaRegistry; } @Override public void close() { schemaRegistry.stop(); } @Override public int getPort() { return schemaRegistry.getMappedPort(ContainersProvider.SCHEMA_REGISTRY_PORT); } }; }
Example 4
Source File: ContainersProvider.java From replicator with Apache License 2.0 | 5 votes |
@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 5
Source File: ZkCopyIT.java From zkcopy with Apache License 2.0 | 5 votes |
private static String connectionString(GenericContainer<?> container, String path) { String containerIpAddress = container.getContainerIpAddress(); Integer mappedPort = container.getMappedPort(ZOOKEEPER_PORT); String hostPort = String.format("%s:%s", containerIpAddress, mappedPort); if(path != null) { return String.format("%s/%s", hostPort, path); } else { return hostPort; } }
Example 6
Source File: LdapAuthenticationBaseIT.java From datacollector with Apache License 2.0 | 5 votes |
static LdapConnection setupLdapServer(GenericContainer server, String setupFile) { // setup Ldap server 1 LdapConnection connection = new LdapNetworkConnection(server.getContainerIpAddress(), server.getMappedPort(LDAP_PORT)); try { connection.bind(BIND_DN, BIND_PWD); LdifReader reader = new LdifReader(Resources.getResource(setupFile).getFile()); for (LdifEntry entry : reader) { connection.add(entry.getEntry()); } } catch (LdapException e) { LOG.error("Setup server 1 failed " + e); } return connection; }
Example 7
Source File: MongoDbPluginIT.java From glowroot with Apache License 2.0 | 5 votes |
@Override public void executeApp() throws Exception { GenericContainer<?> mongo = new GenericContainer<>("mongo:4.0.3"); mongo.setExposedPorts(Arrays.asList(27017)); mongo.start(); try { mongoClient = new Mongo(mongo.getContainerIpAddress(), mongo.getMappedPort(27017)); transactionMarker(); } finally { mongo.close(); } }
Example 8
Source File: ContainersProvider.java From replicator with Apache License 2.0 | 4 votes |
public ServicesControl startCustomTagMySQL( String mysqlImageTag, String schema, String username, String password, String... initScripts) { GenericContainer<?> mysql = this.getContainer( System.getProperty( ContainersProvider.MYSQL_DOCKER_IMAGE_KEY, mysqlImageTag ), ContainersProvider.MYSQL_PORT, null, ContainersProvider.MYSQL_STARTUP_WAIT_REGEX, ContainersProvider.MYSQL_STARTUP_WAIT_TIMES, false ).withEnv(ContainersProvider.MYSQL_ROOT_PASSWORD_KEY, password ).withEnv(ContainersProvider.MYSQL_DATABASE_KEY, schema ).withEnv(ContainersProvider.MYSQL_USER_KEY, username ).withEnv(ContainersProvider.MYSQL_PASSWORD_KEY, password ).withClasspathResourceMapping(ContainersProvider.MYSQL_CONFIGURATION_FILE, ContainersProvider.MYSQL_CONFIGURATION_PATH, BindMode.READ_ONLY ); for (String initScript : initScripts) { mysql.withClasspathResourceMapping(initScript, String.format(ContainersProvider.MYSQL_INIT_SCRIPT_PATH, initScript), BindMode.READ_ONLY); } mysql.start(); return new ServicesControl() { @Override public GenericContainer<?> getContainer() { return mysql; } @Override public void close() { mysql.stop(); } @Override public int getPort() { return mysql.getMappedPort(ContainersProvider.MYSQL_PORT); } }; }
Example 9
Source File: ContainersProvider.java From replicator with Apache License 2.0 | 4 votes |
@Override public ServicesControl startMySQL(MySQLConfiguration mySQLConfiguration) { Map<String, String> envConfigs = new HashMap<>(); // Root password is mandatory for starting mysql docker instance envConfigs.put(ContainersProvider.MYSQL_ROOT_PASSWORD_KEY, mySQLConfiguration.getPassword()); envConfigs.computeIfAbsent(ContainersProvider.MYSQL_DATABASE_KEY, val -> mySQLConfiguration.getSchema()); envConfigs.computeIfAbsent(ContainersProvider.MYSQL_USER_KEY, val -> mySQLConfiguration.getUsername()); envConfigs.computeIfAbsent(ContainersProvider.MYSQL_PASSWORD_KEY, val -> mySQLConfiguration.getPassword()); GenericContainer<?> mysql = this.getContainer( System.getProperty( ContainersProvider.MYSQL_DOCKER_IMAGE_KEY, VersionedPipelines.defaultTags.mysqlReplicantTag ), ContainersProvider.MYSQL_PORT, mySQLConfiguration.getNetwork(), ContainersProvider.MYSQL_STARTUP_WAIT_REGEX, ContainersProvider.MYSQL_STARTUP_WAIT_TIMES, // Cannot match exposed port in mysql as it can have conflicts false) .withEnv(envConfigs) .withClasspathResourceMapping(mySQLConfiguration.getConfPath(), ContainersProvider.MYSQL_CONFIGURATION_PATH, BindMode.READ_ONLY ); for (String initScript : mySQLConfiguration.getInitScripts()) { mysql.withClasspathResourceMapping(initScript, String.format(ContainersProvider.MYSQL_INIT_SCRIPT_PATH, initScript), BindMode.READ_ONLY); } mysql.withNetworkAliases(mySQLConfiguration.getNetworkAlias()); mysql.start(); return new ServicesControl() { @Override public GenericContainer<?> getContainer() { return mysql; } @Override public void close() { mysql.stop(); } @Override public int getPort() { return mysql.getMappedPort(ContainersProvider.MYSQL_PORT); } }; }
Example 10
Source File: ContainersProvider.java From replicator with Apache License 2.0 | 4 votes |
@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 11
Source File: ContainersProvider.java From replicator with Apache License 2.0 | 4 votes |
@Override public ServicesControl startKafka(Network network, String topic, int partitions, int replicas, String networkAlias) { 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", "kafkaZk", ContainersProvider.ZOOKEEPER_PORT) ).withEnv( ContainersProvider.KAFKA_CREATE_TOPICS_KEY, String.format("%s:%d:%d", topic, partitions, replicas) ).withEnv(KAFKA_LISTENERS_KEY, String.format("PLAINTEXT://%s:29092,OUTSIDE://0.0.0.0:%d", networkAlias, KAFKA_PORT) ).withEnv(KAFKA_LISTENER_SECURITY_PROTOCOL_MAP_KEY, "PLAINTEXT:PLAINTEXT,OUTSIDE:PLAINTEXT" ).withEnv(KAFKA_ADVERTISED_LISTENERS_KEY, String.format("PLAINTEXT://%s:29092,OUTSIDE://localhost:%d", networkAlias, KAFKA_PORT) ).withEnv(KAFKA_INTER_BROKER_LISTENER_NAME_KEY, "PLAINTEXT"); // https://rmoff.net/2018/08/02/kafka-listeners-explained/ kafka.withNetworkAliases(networkAlias); kafka.start(); return new ServicesControl() { @Override public GenericContainer<?> getContainer() { return kafka; } @Override public void close() { kafka.stop(); } @Override public int getPort() { return kafka.getMappedPort(ContainersProvider.KAFKA_PORT); } }; }
Example 12
Source File: ContainersProvider.java From replicator with Apache License 2.0 | 4 votes |
public ServicesControl startKafka(String kafkaImageTag, 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, kafkaImageTag ), 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 13
Source File: SpamAssassinExtension.java From james-project with Apache License 2.0 | 4 votes |
private SpamAssassin(GenericContainer<?> spamAssassinContainer) { this.spamAssassinContainer = spamAssassinContainer; this.ip = spamAssassinContainer.getContainerIpAddress(); this.bindingPort = spamAssassinContainer.getMappedPort(SPAMASSASSIN_PORT); }
Example 14
Source File: TestRedisUtil.java From apiman with Apache License 2.0 | 4 votes |
public static Config buildComponentConfig(GenericContainer redis) { final String address = "redis://" + redis.getContainerIpAddress() + ":" + redis.getMappedPort(6379); final Config config = new Config(); config.useSingleServer().setAddress(address); return config; }