static Network newNetwork() { return builder().build(); }
@Test public void testExposedHostWithNetwork() throws Exception { try (Network network = Network.newNetwork()) { assertResponse(new GenericContainer().withNetwork(network).withCommand("top")); } }
@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() ); } } }
@Bean(destroyMethod = "close") @ConditionalOnMissingBean(Network.class) public Network kafkaNetwork() { Network network = Network.newNetwork(); log.info("Created docker Network id={}", network.getId()); return network; }
createCommand.withNetworkMode(network.getId()); createCommand.withAliases(this.networkAliases); } else if (networkMode != null) {
public void afterAll() throws Exception { cluster.stop(); network.close(); }
@Test public void testModifiers() throws Exception { try ( Network network = Network.builder() .createNetworkCmdModifier(cmd -> cmd.withDriver("macvlan")) .build(); ) { String id = network.getId(); assertEquals( "Flag is set", "macvlan", DockerClientFactory.instance().client().inspectNetworkCmd().withNetworkId(id).exec().getDriver() ); } }
@Bean(destroyMethod = "close") @ConditionalOnMissingBean(Network.class) public Network couchbaseNetwork() { Network network = Network.newNetwork(); log.info("Created docker Network id={}", network.getId()); return network; }
@Test public void testExternalZookeeperWithExternalNetwork() throws Exception { try ( Network network = Network.newNetwork(); KafkaContainer kafka = new KafkaContainer() .withNetwork(network) .withExternalZookeeper("zookeeper:2181"); GenericContainer zookeeper = new GenericContainer("confluentinc/cp-zookeeper:4.0.0") .withNetwork(network) .withNetworkAliases("zookeeper") .withEnv("ZOOKEEPER_CLIENT_PORT", "2181"); ) { Stream.of(kafka, zookeeper).parallel().forEach(GenericContainer::start); testKafkaFunctionality(kafka.getBootstrapServers()); } }
static NetworkImpl.NetworkImplBuilder builder() { return NetworkImpl.builder(); }
public KafkaContainer(String confluentPlatformVersion) { super(TestcontainersConfiguration.getInstance().getKafkaImage() + ":" + confluentPlatformVersion); withNetwork(Network.newNetwork()); withNetworkAliases("kafka-" + Base58.randomString(6)); withExposedPorts(KAFKA_PORT); // Use two listeners with different names, it will force Kafka to communicate with itself via internal // listener when KAFKA_INTER_BROKER_LISTENER_NAME is set, otherwise Kafka will try to use the advertised listener withEnv("KAFKA_LISTENERS", "PLAINTEXT://0.0.0.0:" + KAFKA_PORT + ",BROKER://0.0.0.0:9092"); withEnv("KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", "BROKER:PLAINTEXT,PLAINTEXT:PLAINTEXT"); withEnv("KAFKA_INTER_BROKER_LISTENER_NAME", "BROKER"); withEnv("KAFKA_BROKER_ID", "1"); withEnv("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR", "1"); withEnv("KAFKA_OFFSETS_TOPIC_NUM_PARTITIONS", "1"); withEnv("KAFKA_LOG_FLUSH_INTERVAL_MESSAGES", Long.MAX_VALUE + ""); withEnv("KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS", "0"); }
static Network newNetwork() { return builder().build(); }
@Test public void testNetworkSupport() throws Exception { try ( 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); } }
public static EtcdCluster buildCluster(@NonNull String clusterName, int nodes, boolean ssl, boolean restartable) { final Network network = Network.builder().id(clusterName).build(); final CountDownLatch latch = new CountDownLatch(nodes); final EtcdContainer.LifecycleListener listener = new EtcdContainer.LifecycleListener() {
@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 void close() { hbase.stop(); } @Override public int getPort() { return hbase.getMappedPort(ContainersProvider.HBASE_ZK_PORT); } }; } }
public static EtcdCluster buildCluster(@NonNull String clusterName, int nodes, boolean ssl, boolean restartable) { final Network network = Network.builder().id(clusterName).build(); final CountDownLatch latch = new CountDownLatch(nodes); final EtcdContainer.LifecycleListener listener = new EtcdContainer.LifecycleListener() {
@Override public ServicesControl startKafka(String topic, int partitions, int replicas) { Network network = Network.newNetwork();
public static EtcdCluster buildCluster(@NonNull String clusterName, int nodes, boolean ssl, boolean restartable) { final Network network = Network.builder().id(clusterName).build(); final CountDownLatch latch = new CountDownLatch(nodes); final EtcdContainer.LifecycleListener listener = new EtcdContainer.LifecycleListener() {
public ServicesControl startKafka(String kafkaImageTag, String topic, int partitions, int replicas) { Network network = Network.newNetwork();