@Test public void testFixedHostPortMapping() throws IOException { // first find a free port on the docker host that will work for testing GenericContainer portDiscoveryRedis = new GenericContainer("redis:3.0.2").withExposedPorts(REDIS_PORT); portDiscoveryRedis.start(); Integer freePort = portDiscoveryRedis.getMappedPort(REDIS_PORT); portDiscoveryRedis.stop(); // Set up a FixedHostPortGenericContainer as if this were a @Rule FixedHostPortGenericContainer redis = new FixedHostPortGenericContainer("redis:3.0.2").withFixedExposedPort(freePort, REDIS_PORT); redis.start(); // Config redisConfig = new Config(); // redisConfig.useSingleServer().setAddress(redis.getContainerIpAddress() + ":" + freePort); // Redisson redisson = Redisson.create(redisConfig); // // redisson.getBucket("test").set("foo"); // // assertEquals("The bucket content was successfully set", "foo", redisson.getBucket("test").get()); // assertEquals("The container returns the fixed port from getMappedPort(...)", freePort, redis.getMappedPort(REDIS_PORT)); } }
final List<String> command = new ArrayList<>(); this.container = new FixedHostPortGenericContainer<>(ETCD_DOCKER_IMAGE_NAME); this.container.withExposedPorts(ETCD_CLIENT_PORT, ETCD_PEER_PORT); this.container.withNetwork(network);
final List<String> command = new ArrayList<>(); this.container = new FixedHostPortGenericContainer<>(ETCD_DOCKER_IMAGE_NAME); this.container.withExposedPorts(ETCD_CLIENT_PORT, ETCD_PEER_PORT); this.container.withNetwork(network);
final List<String> command = new ArrayList<>(); this.container = new FixedHostPortGenericContainer<>(ETCD_DOCKER_IMAGE_NAME); this.container.withExposedPorts(ETCD_CLIENT_PORT, ETCD_PEER_PORT); this.container.withNetwork(network);
@Profile("test") @Bean(destroyMethod = "stop") public FixedHostPortGenericContainer getFixedHostPortGenericContainer(){ String url = String.join(":", props.getElastic().getImageUrl(), props.getElastic().getVersion()); FixedHostPortGenericContainer fixed = new FixedHostPortGenericContainer(url); fixed.withFixedExposedPort(props.getClients().getHttpPort(), props.getClients().getContainerPort()); fixed.waitingFor(Wait.forHttp("/")); fixed.start(); return fixed; }
@Bean(name = ZOOKEEPER_BEAN_NAME, destroyMethod = "stop") public GenericContainer zookeeper(ZookeeperStatusCheck zookeeperStatusCheck, ZookeeperConfigurationProperties zookeeperProperties, ConfigurableEnvironment environment, Network network) { String currentTimestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH-mm-ss-nnnnnnnnn")); String zkData = Paths.get(zookeeperProperties.getDataFileSystemBind(), currentTimestamp).toAbsolutePath().toString(); log.info("Writing zookeeper data to: {}", zkData); String zkTransactionLogs = Paths.get(zookeeperProperties.getTxnLogsFileSystemBind(), currentTimestamp).toAbsolutePath().toString(); log.info("Writing zookeeper transaction logs to: {}", zkTransactionLogs); log.info("Starting zookeeper server. Docker image: {}", zookeeperProperties.getDockerImage()); int mappingPort = zookeeperProperties.getZookeeperPort(); GenericContainer zookeeper = new FixedHostPortGenericContainer<>(zookeeperProperties.getDockerImage()) .withLogConsumer(containerLogsConsumer(log)) .withEnv("ZOOKEEPER_CLIENT_PORT", String.valueOf(mappingPort)) .withFileSystemBind(zkData, "/var/lib/zookeeper/data", BindMode.READ_WRITE) .withFileSystemBind(zkTransactionLogs, "/var/lib/zookeeper/log", BindMode.READ_WRITE) .withExposedPorts(mappingPort) .withFixedExposedPort(mappingPort, mappingPort) .withNetwork(network) .withNetworkAliases(ZOOKEEPER_HOST_NAME) .waitingFor(zookeeperStatusCheck) .withStartupTimeout(zookeeperProperties.getTimeoutDuration()); zookeeper.start(); registerZookeeperEnvironment(zookeeper, environment, zookeeperProperties); return zookeeper; }
final List<String> command = new ArrayList<>(); this.container = new FixedHostPortGenericContainer<>(ETCD_DOCKER_IMAGE_NAME); this.container.withExposedPorts(ETCD_CLIENT_PORT, ETCD_PEER_PORT); this.container.withNetwork(network);
GenericContainer kafka = new FixedHostPortGenericContainer<>(kafkaProperties.getDockerImage()) .withLogConsumer(containerLogsConsumer(log)) .withCreateContainerCmdModifier(cmd -> cmd.withHostName(KAFKA_HOST_NAME))
static GenericContainer create(ElasticSearchProperties properties, Logger containerLogger) { return new FixedHostPortGenericContainer(properties.dockerImage) .withExposedPorts(properties.httpPort, properties.transportPort) .withEnv("cluster.name", properties.getClusterName()) .withEnv("discovery.type", "single-node") .withEnv("ES_JAVA_OPTS", getJavaOpts(properties)) .withLogConsumer(containerLogsConsumer(containerLogger)) .waitingFor(getCompositeWaitStrategy(properties)) .withStartupTimeout(properties.getTimeoutDuration()); }
private GenericContainer<?> getContainerHBase(String image, Network network, String logWaitRegex, int logWaitTimes, boolean matchExposedPort) { FixedHostPortGenericContainer<?> container = new FixedHostPortGenericContainer<>(image); container.withNetwork(network); container.withNetworkAliases("hbase_alias"); container.withFixedExposedPort(HBASE_ZK_PORT, HBASE_ZK_PORT); container.withFixedExposedPort(16201, HBASE_REGION_SERVER_PORT); container.withFixedExposedPort(16000, HBASE_MASTER_PORT); container.withCreateContainerCmdModifier(cmd -> cmd.withName(HBASE_CONTAINER_NAME)); container.withCreateContainerCmdModifier(cmd -> cmd.withHostName(HBASE_HOST_NAME)); return container; }
protected static GenericContainer create(CouchbaseProperties properties, Logger containerLogger, Network network) { return new FixedHostPortGenericContainer<>(properties.dockerImage) .withFixedExposedPort(properties.carrierDirectPort, properties.carrierDirectPort) .withFixedExposedPort(properties.httpDirectPort, properties.httpDirectPort) .withFixedExposedPort(properties.queryServicePort, properties.queryServicePort) .withFixedExposedPort(properties.queryRestTrafficPort, properties.queryRestTrafficPort) .withFixedExposedPort(properties.searchServicePort, properties.searchServicePort) .withFixedExposedPort(properties.analyticsServicePort, properties.analyticsServicePort) .withFixedExposedPort(properties.memcachedSslPort, properties.memcachedSslPort) .withFixedExposedPort(properties.memcachedPort, properties.memcachedPort) .withFixedExposedPort(properties.queryRestTrafficSslPort, properties.queryRestTrafficSslPort) .withFixedExposedPort(properties.queryServiceSslPort, properties.queryServiceSslPort) .withLogConsumer(containerLogsConsumer(containerLogger)) .withNetwork(network) .withNetworkAliases(COUCHBASE_HOST_NAME) .waitingFor(getCompositeWaitStrategy(properties)) .withStartupTimeout(properties.getTimeoutDuration()); }