本文整理了Java中org.testcontainers.containers.Network.newNetwork()
方法的一些代码示例,展示了Network.newNetwork()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Network.newNetwork()
方法的具体详情如下:
包路径:org.testcontainers.containers.Network
类名称:Network
方法名:newNetwork
暂无
代码示例来源:origin: testcontainers/testcontainers-java
@Test
public void testExposedHostWithNetwork() throws Exception {
try (Network network = Network.newNetwork()) {
assertResponse(new GenericContainer().withNetwork(network).withCommand("top"));
}
}
代码示例来源:origin: testcontainers/testcontainers-java
@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());
}
}
代码示例来源:origin: testcontainers/testcontainers-java
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");
}
代码示例来源:origin: testcontainers/testcontainers-java
@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);
}
}
代码示例来源:origin: testcontainers/testcontainers-java
@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()
);
}
}
}
代码示例来源:origin: Playtika/testcontainers-spring-boot
@Bean(destroyMethod = "close")
@ConditionalOnMissingBean(Network.class)
public Network kafkaNetwork() {
Network network = Network.newNetwork();
log.info("Created docker Network id={}", network.getId());
return network;
}
代码示例来源:origin: Playtika/testcontainers-spring-boot
@Bean(destroyMethod = "close")
@ConditionalOnMissingBean(Network.class)
public Network couchbaseNetwork() {
Network network = Network.newNetwork();
log.info("Created docker Network id={}", network.getId());
return network;
}
代码示例来源:origin: mysql-time-machine/replicator
@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);
}
};
}
}
代码示例来源:origin: mysql-time-machine/replicator
@Override
public ServicesControl startKafka(String topic, int partitions, int replicas) {
Network network = Network.newNetwork();
代码示例来源:origin: mysql-time-machine/replicator
public ServicesControl startKafka(String kafkaImageTag, String topic, int partitions, int replicas) {
Network network = Network.newNetwork();
内容来源于网络,如有侵权,请联系作者删除!