@@ -102,12 +102,22 @@ private TestEnvironment(TestEnvironmentRequest request) {
102102 }
103103
104104 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+
105115 LOGGER .finest ("Building test env: " + request .getEnvPreCreateIndex ());
106116 preCreateEnvironment (request .getEnvPreCreateIndex ());
107117
108118 TestEnvironment env ;
109119
110- switch (request . getDatabaseEngineDeployment () ) {
120+ switch (deployment ) {
111121 case DOCKER :
112122 env = new TestEnvironment (request );
113123 initDatabaseParams (env );
@@ -894,7 +904,11 @@ public void close() throws Exception {
894904
895905 private void deleteDbCluster () {
896906 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+ }
898912 }
899913
900914 if (!this .reuseAuroraDbCluster ) {
0 commit comments