@@ -102,12 +102,22 @@ private TestEnvironment(TestEnvironmentRequest request) {
102
102
}
103
103
104
104
public static TestEnvironment build (TestEnvironmentRequest request ) throws IOException {
105
+ DatabaseEngineDeployment deployment = request .getDatabaseEngineDeployment ();
106
+ if (deployment == DatabaseEngineDeployment .AURORA
107
+ || deployment == DatabaseEngineDeployment .RDS
108
+ || deployment == DatabaseEngineDeployment .RDS_MULTI_AZ ) {
109
+ // These environment require creating external database cluster that should be publicly available.
110
+ // Corresponding AWS Security Groups should be configured and the test task runner IP address
111
+ // should be whitelisted.
112
+ ipAddressUsageRefCount .incrementAndGet ();
113
+ }
114
+
105
115
LOGGER .finest ("Building test env: " + request .getEnvPreCreateIndex ());
106
116
preCreateEnvironment (request .getEnvPreCreateIndex ());
107
117
108
118
TestEnvironment env ;
109
119
110
- switch (request . getDatabaseEngineDeployment () ) {
120
+ switch (deployment ) {
111
121
case DOCKER :
112
122
env = new TestEnvironment (request );
113
123
initDatabaseParams (env );
@@ -894,7 +904,11 @@ public void close() throws Exception {
894
904
895
905
private void deleteDbCluster () {
896
906
if (!this .reuseAuroraDbCluster && !StringUtils .isNullOrEmpty (this .runnerIP )) {
897
- auroraUtil .ec2DeauthorizesIP (runnerIP );
907
+ if (ipAddressUsageRefCount .decrementAndGet () == 0 ) {
908
+ // Another test environments are still in use of test task runner IP address.
909
+ // The last execute tst environment will do the cleanup.
910
+ auroraUtil .ec2DeauthorizesIP (runnerIP );
911
+ }
898
912
}
899
913
900
914
if (!this .reuseAuroraDbCluster ) {
0 commit comments