Skip to content

Commit 502ff51

Browse files
authored
Add Network Aliases (PlaytikaOSS#1355)
1 parent 90d0fe0 commit 502ff51

File tree

86 files changed

+345
-49
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+345
-49
lines changed

embedded-aerospike/README.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ ToxiProxy is a great tool for simulating network conditions, meaning that you ca
3434
* `embedded.aerospike.namespace`
3535
* `embedded.aerospike.toxiproxy.host`
3636
* `embedded.aerospike.toxiproxy.port`
37+
* `embedded.aerospike.networkAlias`
38+
* `embedded.aerospike.internalPort`
3739
* Bean `AerospikeTestOperations aerospikeTestOperations`
3840
* Bean `ToxiproxyContainer.ContainerProxy aerospikeContainerProxy`
3941

embedded-aerospike/src/main/java/com/playtika/testcontainer/aerospike/EmbeddedAerospikeBootstrapConfiguration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
@EnableConfigurationProperties(AerospikeProperties.class)
4040
public class EmbeddedAerospikeBootstrapConfiguration {
4141

42+
private static final String AEROSPIKE_NETWORK_ALIAS = "aerospike.testcontainer.docker";
43+
4244
@Bean
4345
@ConditionalOnMissingBean
4446
public AerospikeWaitStrategy aerospikeStartupCheckStrategy(AerospikeProperties properties) {
@@ -84,6 +86,7 @@ public GenericContainer<?> aerospike(AerospikeWaitStrategy aerospikeWaitStrategy
8486
.withEnv("SERVICE_PORT", String.valueOf(properties.port))
8587
.withEnv("MEM_GB", String.valueOf(1))
8688
.withEnv("STORAGE_GB", String.valueOf(1))
89+
.withNetworkAliases(AEROSPIKE_NETWORK_ALIAS)
8790
.waitingFor(waitStrategy);
8891
network.ifPresent(aerospike::withNetwork);
8992
String featureKey = properties.featureKey;
@@ -108,6 +111,8 @@ private void registerAerospikeEnvironment(GenericContainer<?> aerospike,
108111
map.put("embedded.aerospike.host", host);
109112
map.put("embedded.aerospike.port", mappedPort);
110113
map.put("embedded.aerospike.namespace", properties.namespace);
114+
map.put("embedded.aerospike.networkAlias", AEROSPIKE_NETWORK_ALIAS);
115+
map.put("embedded.aerospike.internalPort", properties.port);
111116

112117
log.info("Started aerospike server. Connection details {}", map);
113118

embedded-artifactory/README.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@
3131
* `embedded.artifactory.password`
3232
* `embedded.artifactory.toxiproxy.host`
3333
* `embedded.artifactory.toxiproxy.port`
34+
* `embedded.artifactory.staticNetworkAlias`
35+
* `embedded.artifactory.internalRestApiPort`
36+
* `embedded.artifactory.internalGeneralPort`
3437
* Bean `ToxiproxyContainer.ContainerProxy artifactoryContainerProxy`

embedded-artifactory/src/main/java/com/playtika/testcontainer/artifactory/EmbeddedArtifactoryBootstrapConfiguration.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
@EnableConfigurationProperties(ArtifactoryProperties.class)
3636
public class EmbeddedArtifactoryBootstrapConfiguration {
3737

38+
private static final String ARTIFACTORY_NETWORK_ALIAS = "artifactory.testcontainer.docker";
39+
3840
@Bean
3941
@ConditionalOnMissingBean(name = "artifactoryWaitStrategy")
4042
public WaitStrategy artifactoryWaitStrategy(ArtifactoryProperties properties) {
@@ -74,7 +76,7 @@ public GenericContainer<?> artifactory(ConfigurableEnvironment environment,
7476
new GenericContainer<>(ContainerUtils.getDockerImageName(properties))
7577
.withExposedPorts(properties.getRestApiPort(), properties.getGeneralPort())
7678
.withNetwork(Network.SHARED)
77-
.withNetworkAliases(properties.getNetworkAlias())
79+
.withNetworkAliases(properties.getNetworkAlias(), ARTIFACTORY_NETWORK_ALIAS)
7880
.waitingFor(artifactoryWaitStrategy);
7981

8082
network.ifPresent(container::withNetwork);
@@ -97,6 +99,9 @@ private void registerEnvironment(GenericContainer<?> artifactory,
9799
map.put("embedded.artifactory.port", mappedPort);
98100
map.put("embedded.artifactory.username", properties.getUsername());
99101
map.put("embedded.artifactory.password", properties.getPassword());
102+
map.put("embedded.artifactory.staticNetworkAlias", ARTIFACTORY_NETWORK_ALIAS);
103+
map.put("embedded.artifactory.internalRestApiPort", properties.getRestApiPort());
104+
map.put("embedded.artifactory.internalGeneralPort", properties.getGeneralPort());
100105

101106
log.info("Started Artifactory server. Connection details: {}", map);
102107

embedded-azurite/README.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Account name and account key are hardcoded as of https://github.com/Azure/Azurit
3737
* `embedded.azurite.toxiproxy.blobStoragePort`
3838
* `embedded.azurite.toxiproxy.queueStoragePort`
3939
* `embedded.azurite.toxiproxy.tableStoragePort`
40+
* `embedded.azurite.networkAlias`
4041
* Bean `ToxiproxyContainer.ContainerProxy azuriteBlobContainerProxy`
4142
* Bean `ToxiproxyContainer.ContainerProxy azuriteQueueContainerProxy`
4243
* Bean `ToxiproxyContainer.ContainerProxy azuriteTableContainerProxy`

embedded-azurite/src/main/java/com/playtika/testcontainer/azurite/EmbeddedAzuriteBootstrapConfiguration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
@EnableConfigurationProperties(AzuriteProperties.class)
3333
public class EmbeddedAzuriteBootstrapConfiguration {
3434

35+
private static final String AZURITE_BLOB_NETWORK_ALIAS = "azurite-blob.testcontainer.docker";
36+
3537
@Bean
3638
@ConditionalOnToxiProxyEnabled(module = "azurite")
3739
ToxiproxyContainer.ContainerProxy azuriteBlobContainerProxy(ToxiproxyContainer toxiproxyContainer,
@@ -97,7 +99,8 @@ public GenericContainer<?> azurite(ConfigurableEnvironment environment,
9799
AzuriteProperties properties,
98100
Optional<Network> network) {
99101
GenericContainer<?> azuriteContainer = new GenericContainer<>(ContainerUtils.getDockerImageName(properties))
100-
.withExposedPorts(properties.getBlobStoragePort(), properties.getQueueStoragePort(), properties.getTableStoragePort());
102+
.withExposedPorts(properties.getBlobStoragePort(), properties.getQueueStoragePort(), properties.getTableStoragePort())
103+
.withNetworkAliases(AZURITE_BLOB_NETWORK_ALIAS);
101104

102105
network.ifPresent(azuriteContainer::withNetwork);
103106

@@ -125,6 +128,7 @@ private void registerEnvironment(GenericContainer<?> azurite,
125128
map.put("embedded.azurite.blob-endpoint", "http://" + host + ":" + mappedBlobStoragePort + "/" + AzuriteProperties.ACCOUNT_NAME);
126129
map.put("embedded.azurite.queue-endpoint", "http://" + host + ":" + mappedQueueStoragePort + "/" + AzuriteProperties.ACCOUNT_NAME);
127130
map.put("embedded.azurite.table-endpoint", "http://" + host + ":" + mappedTableStoragePort + "/" + AzuriteProperties.ACCOUNT_NAME);
131+
map.put("embedded.azurite.networkAlias", AZURITE_BLOB_NETWORK_ALIAS);
128132

129133
log.info("Started Azurite. Connection details: {}", map);
130134

embedded-cassandra/README.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
* `embedded.cassandra.keyspace-name`
3232
* `embedded.cassandra.toxiproxy.host`
3333
* `embedded.cassandra.toxiproxy.port`
34+
* `embedded.cassandra.networkAlias`
35+
* `embedded.cassandra.internalPort`
3436
* Bean `ToxiproxyContainer.ContainerProxy cassandraContainerProxy`
3537

3638
==== Example

embedded-cassandra/src/main/java/com/playtika/testcontainer/cassandra/EmbeddedCassandraBootstrapConfiguration.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
@RequiredArgsConstructor
4242
public class EmbeddedCassandraBootstrapConfiguration {
4343

44+
private static final String CASSANDRA_NETWORK_ALIAS = "cassandra.testcontainer.docker";
45+
4446
private final ResourceLoader resourceLoader;
4547

4648
@Bean
@@ -69,7 +71,8 @@ public CassandraContainer cassandra(ConfigurableEnvironment environment,
6971
Optional<Network> network) throws Exception {
7072

7173
CassandraContainer cassandra = new CassandraContainer<>(ContainerUtils.getDockerImageName(properties))
72-
.withExposedPorts(properties.getPort());
74+
.withExposedPorts(properties.getPort())
75+
.withNetworkAliases(CASSANDRA_NETWORK_ALIAS);
7376

7477
network.ifPresent(cassandra::withNetwork);
7578
cassandra = (CassandraContainer) configureCommonsAndStart(cassandra, properties, log);
@@ -89,6 +92,8 @@ static Map<String, Object> registerCassandraEnvironment(ConfigurableEnvironment
8992
cassandraEnv.put("embedded.cassandra.host", host);
9093
cassandraEnv.put("embedded.cassandra.datacenter", DEFAULT_DATACENTER);
9194
cassandraEnv.put("embedded.cassandra.keyspace-name", properties.keyspaceName);
95+
cassandraEnv.put("embedded.cassandra.networkAlias", CASSANDRA_NETWORK_ALIAS);
96+
cassandraEnv.put("embedded.cassandra.internalPort", properties.getPort());
9297
MapPropertySource propertySource = new MapPropertySource("embeddedCassandraInfo", cassandraEnv);
9398
environment.getPropertySources().addFirst(propertySource);
9499
return cassandraEnv;

embedded-clickhouse/README.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
* `embedded.clickhouse.password`
3434
* `embedded.clickhouse.toxiproxy.host`
3535
* `embedded.clickhouse.toxiproxy.port`
36+
* `embedded.clickhouse.networkAlias`
37+
* `embedded.clickhouse.internalPort`
3638
* Bean `ToxiproxyContainer.ContainerProxy clickhouseContainerProxy`
3739

3840
==== Example

embedded-clickhouse/src/main/java/com/playtika/testcontainer/clickhouse/EmbeddedClickHouseBootstrapConfiguration.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
@EnableConfigurationProperties(ClickHouseProperties.class)
3434
public class EmbeddedClickHouseBootstrapConfiguration {
3535

36+
private static final String CLICKHOUSE_NETWORK_ALIAS = "clickhouse.testcontainer.docker";
37+
3638
@Bean
3739
@ConditionalOnToxiProxyEnabled(module = "clickhouse")
3840
ToxiproxyContainer.ContainerProxy clickhouseContainerProxy(ToxiproxyContainer toxiproxyContainer,
@@ -58,7 +60,8 @@ public ClickHouseContainer clickHouseContainer(ConfigurableEnvironment environme
5860
ClickHouseProperties properties,
5961
Optional<Network> network) {
6062
ClickHouseContainer clickHouseContainer = new ClickHouseContainer(ContainerUtils.getDockerImageName(properties))
61-
.withInitScript(properties.getInitScriptPath());
63+
.withInitScript(properties.getInitScriptPath())
64+
.withNetworkAliases(CLICKHOUSE_NETWORK_ALIAS);
6265

6366
network.ifPresent(clickHouseContainer::withNetwork);
6467

@@ -87,6 +90,8 @@ private void registerClickHouseEnvironment(ClickHouseContainer clickHouseContain
8790
map.put("embedded.clickhouse.port", mappedPort);
8891
map.put("embedded.clickhouse.user", username);
8992
map.put("embedded.clickhouse.password", password);
93+
map.put("embedded.clickhouse.networkAlias", CLICKHOUSE_NETWORK_ALIAS);
94+
map.put("embedded.clickhouse.internalPort", properties.getPort());
9095

9196
log.info("Started ClickHouse server. Connection details: {}", map);
9297

0 commit comments

Comments
 (0)