From 482f5ad84447bb4a045453d9d4c37631584bb130 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Mon, 13 Jan 2025 17:24:16 -0800 Subject: [PATCH 01/21] test: update mysql and testcontainers dependencies to fix flaky tests --- examples/HibernateExample/build.gradle | 2 +- wrapper/build.gradle.kts | 8 ++++---- wrapper/src/test/build.gradle.kts | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/HibernateExample/build.gradle b/examples/HibernateExample/build.gradle index ef3e74d45..2524a02ca 100644 --- a/examples/HibernateExample/build.gradle +++ b/examples/HibernateExample/build.gradle @@ -14,7 +14,7 @@ dependencies { implementation 'org.hibernate:hibernate-core:6.1.3.Final' implementation 'jakarta.persistence:jakarta.persistence-api:3.1.0' runtimeOnly 'org.postgresql:postgresql:42.7.4' - runtimeOnly 'com.mysql:mysql-connector-j:8.3.0' + runtimeOnly 'com.mysql:mysql-connector-j:9.1.0' implementation project(':aws-advanced-jdbc-wrapper') testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0' diff --git a/wrapper/build.gradle.kts b/wrapper/build.gradle.kts index 8a8d87459..f603a8bd5 100644 --- a/wrapper/build.gradle.kts +++ b/wrapper/build.gradle.kts @@ -69,11 +69,11 @@ dependencies { testImplementation("software.amazon.awssdk:ec2:2.29.34") testImplementation("software.amazon.awssdk:secretsmanager:2.29.34") testImplementation("software.amazon.awssdk:sts:2.29.34") - testImplementation("org.testcontainers:testcontainers:1.20.1") - testImplementation("org.testcontainers:mysql:1.20.1") - testImplementation("org.testcontainers:postgresql:1.20.3") + testImplementation("org.testcontainers:testcontainers:1.20.4") + testImplementation("org.testcontainers:mysql:1.20.4") + testImplementation("org.testcontainers:postgresql:1.20.4") testImplementation("org.testcontainers:mariadb:1.20.4") - testImplementation("org.testcontainers:junit-jupiter:1.20.1") + testImplementation("org.testcontainers:junit-jupiter:1.20.4") testImplementation("org.testcontainers:toxiproxy:1.20.4") testImplementation("eu.rekawek.toxiproxy:toxiproxy-java:2.1.7") testImplementation("org.apache.poi:poi-ooxml:5.3.0") diff --git a/wrapper/src/test/build.gradle.kts b/wrapper/src/test/build.gradle.kts index dccabde5b..b3bdaae4c 100644 --- a/wrapper/src/test/build.gradle.kts +++ b/wrapper/src/test/build.gradle.kts @@ -36,7 +36,7 @@ dependencies { testImplementation("org.apache.commons:commons-dbcp2:2.12.0") testImplementation("org.postgresql:postgresql:42.7.4") - testImplementation("com.mysql:mysql-connector-j:8.3.0") + testImplementation("com.mysql:mysql-connector-j:9.1.0") testImplementation("org.mariadb.jdbc:mariadb-java-client:3.4.1") testImplementation("com.zaxxer:HikariCP:4.0.3") // Version 4.+ is compatible with Java 8 testImplementation("org.springframework.boot:spring-boot-starter-jdbc:2.7.13") // 2.7.13 is the last version compatible with Java 8 @@ -44,12 +44,12 @@ dependencies { testImplementation("software.amazon.awssdk:ec2:2.29.34") testImplementation("software.amazon.awssdk:rds:2.29.34") testImplementation("software.amazon.awssdk:sts:2.29.34") - testImplementation("org.testcontainers:testcontainers:1.20.1") - testImplementation("org.testcontainers:mysql:1.20.1") - testImplementation("org.testcontainers:postgresql:1.20.3") - testImplementation("org.testcontainers:mariadb:1.20.2") - testImplementation("org.testcontainers:junit-jupiter:1.20.1") - testImplementation("org.testcontainers:toxiproxy:1.20.2") + testImplementation("org.testcontainers:testcontainers:1.20.4") + testImplementation("org.testcontainers:mysql:1.20.4") + testImplementation("org.testcontainers:postgresql:1.20.4") + testImplementation("org.testcontainers:mariadb:1.20.4") + testImplementation("org.testcontainers:junit-jupiter:1.20.4") + testImplementation("org.testcontainers:toxiproxy:1.20.4") testImplementation("org.apache.poi:poi-ooxml:5.3.0") testImplementation("org.slf4j:slf4j-simple:2.0.13") testImplementation("com.fasterxml.jackson.core:jackson-databind:2.17.1") From db91c854fdefcab0bac7436ecd9f7566d0349b4c Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Wed, 15 Jan 2025 14:59:07 -0800 Subject: [PATCH 02/21] fix: test if host is allowed using hostname equality --- .../java/software/amazon/jdbc/PluginServiceImpl.java | 5 +++-- .../jdbc/plugin/failover/FailoverConnectionPlugin.java | 2 +- .../plugin/failover2/FailoverConnectionPlugin.java | 5 ++--- .../jdbc/plugin/staledns/AuroraStaleDnsHelper.java | 6 ++++-- .../src/main/java/software/amazon/jdbc/util/Utils.java | 10 ++++++++++ .../container/tests/AuroraFailoverTest.java | 7 ++++--- .../container/tests/ReadWriteSplittingTests.java | 4 +--- 7 files changed, 25 insertions(+), 14 deletions(-) diff --git a/wrapper/src/main/java/software/amazon/jdbc/PluginServiceImpl.java b/wrapper/src/main/java/software/amazon/jdbc/PluginServiceImpl.java index 239c3d98f..e00b57356 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/PluginServiceImpl.java +++ b/wrapper/src/main/java/software/amazon/jdbc/PluginServiceImpl.java @@ -174,12 +174,13 @@ public HostSpec getCurrentHostSpec() { } this.currentHostSpec = this.getWriter(this.getAllHosts()); - if (!this.getHosts().contains(this.currentHostSpec)) { + final List allowedHosts = this.getHosts(); + if (!Utils.containsHost(allowedHosts, this.currentHostSpec.getHost())) { throw new RuntimeException( Messages.get("PluginServiceImpl.currentHostNotAllowed", new Object[] { currentHostSpec == null ? "" : currentHostSpec.getHost(), - Utils.logTopology(this.getHosts(), "")}) + Utils.logTopology(allowedHosts, "")}) ); } diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/failover/FailoverConnectionPlugin.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/failover/FailoverConnectionPlugin.java index 34d360ee8..d318a7fe6 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/failover/FailoverConnectionPlugin.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/failover/FailoverConnectionPlugin.java @@ -674,7 +674,7 @@ protected void failoverWriter() throws SQLException { } final List allowedHosts = this.pluginService.getHosts(); - if (!allowedHosts.contains(writerHostSpec)) { + if (!Utils.containsHost(allowedHosts, writerHostSpec.getHost())) { throwFailoverFailedException( Messages.get("Failover.newWriterNotAllowed", new Object[] {writerHostSpec.getHost(), Utils.logTopology(allowedHosts, "")})); diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/failover2/FailoverConnectionPlugin.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/failover2/FailoverConnectionPlugin.java index 269bab2ee..1b291d81a 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/failover2/FailoverConnectionPlugin.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/failover2/FailoverConnectionPlugin.java @@ -47,7 +47,6 @@ import software.amazon.jdbc.plugin.staledns.AuroraStaleDnsHelper; import software.amazon.jdbc.targetdriverdialect.TargetDriverDialect; import software.amazon.jdbc.util.Messages; -import software.amazon.jdbc.util.PropertyUtils; import software.amazon.jdbc.util.RdsUrlType; import software.amazon.jdbc.util.RdsUtils; import software.amazon.jdbc.util.SqlState; @@ -520,8 +519,8 @@ protected void failoverWriter() throws SQLException { throw new FailoverFailedSQLException(message); } - List allowedHosts = this.pluginService.getHosts(); - if (!allowedHosts.contains(writerCandidate)) { + final List allowedHosts = this.pluginService.getHosts(); + if (!Utils.containsHost(allowedHosts, writerCandidate.getHost())) { this.failoverWriterFailedCounter.inc(); String topologyString = Utils.logTopology(allowedHosts, ""); LOGGER.severe(Messages.get("Failover.newWriterNotAllowed", diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/staledns/AuroraStaleDnsHelper.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/staledns/AuroraStaleDnsHelper.java index 55e4bf656..13485b9c5 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/staledns/AuroraStaleDnsHelper.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/staledns/AuroraStaleDnsHelper.java @@ -21,6 +21,7 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.EnumSet; +import java.util.List; import java.util.Map; import java.util.Properties; import java.util.logging.Logger; @@ -135,12 +136,13 @@ public Connection getVerifiedConnection( new Object[]{this.writerHostSpec})); staleDNSDetectedCounter.inc(); - if (!this.pluginService.getHosts().contains(this.writerHostSpec)) { + final List allowedHosts = this.pluginService.getHosts(); + if (!Utils.containsHost(allowedHosts, this.writerHostSpec.getHost())) { throw new SQLException( Messages.get("AuroraStaleDnsHelper.currentWriterNotAllowed", new Object[] { this.writerHostSpec == null ? "" : this.writerHostSpec.getHost(), - Utils.logTopology(this.pluginService.getHosts(), "")}) + Utils.logTopology(allowedHosts, "")}) ); } diff --git a/wrapper/src/main/java/software/amazon/jdbc/util/Utils.java b/wrapper/src/main/java/software/amazon/jdbc/util/Utils.java index f54c32769..b81b91d55 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/util/Utils.java +++ b/wrapper/src/main/java/software/amazon/jdbc/util/Utils.java @@ -26,6 +26,16 @@ public static boolean isNullOrEmpty(final Collection c) { return c == null || c.isEmpty(); } + public static boolean containsHost(final List hosts, String host) { + for (final HostSpec hostSpec : hosts) { + if (hostSpec.getHost().equals(host)) { + return true; + } + } + + return false; + } + public static String logTopology(final @Nullable List hosts) { return logTopology(hosts, null); } diff --git a/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java b/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java index 6313f8a2e..8bccdc86d 100644 --- a/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java +++ b/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java @@ -63,6 +63,7 @@ import software.amazon.jdbc.hostlistprovider.AuroraHostListProvider; import software.amazon.jdbc.plugin.failover.FailoverSQLException; import software.amazon.jdbc.plugin.failover.FailoverSuccessSQLException; +import software.amazon.jdbc.plugin.failover.TransactionStateUnknownSQLException; import software.amazon.jdbc.util.SqlState; @TestMethodOrder(MethodOrderer.MethodName.class) @@ -236,7 +237,7 @@ public void test_writerFailWithinTransaction_setAutoCommitFalse() // If there is an active transaction, roll it back and return an error with SQLState 08007. final SQLException exception = assertThrows( - SQLException.class, + TransactionStateUnknownSQLException.class, () -> testStmt2.executeUpdate("INSERT INTO test3_2 VALUES (2, 'test field string 2')")); assertEquals( @@ -296,7 +297,7 @@ public void test_writerFailWithinTransaction_startTransaction() // If there is an active transaction, roll it back and return an error with SQLState 08007. final SQLException exception = assertThrows( - SQLException.class, + TransactionStateUnknownSQLException.class, () -> testStmt2.executeUpdate("INSERT INTO test3_3 VALUES (2, 'test field string 2')")); assertEquals( @@ -557,7 +558,7 @@ public void test_failFromWriterWhereKeepSessionStateOnFailoverIsTrue() // If there is an active transaction, roll it back and return an error with SQLState 08007. final SQLException exception = assertThrows( - SQLException.class, + TransactionStateUnknownSQLException.class, () -> testStmt2.executeUpdate("INSERT INTO test3_3 VALUES (2, 'test field string 2')")); assertEquals( diff --git a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java index ded354e83..cb019fb53 100644 --- a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java +++ b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java @@ -30,7 +30,6 @@ import com.zaxxer.hikari.pool.HikariPool; import integration.DatabaseEngine; import integration.DatabaseEngineDeployment; -import integration.DriverHelper; import integration.TestEnvironmentFeatures; import integration.TestEnvironmentInfo; import integration.TestInstanceInfo; @@ -57,7 +56,6 @@ import java.util.List; import java.util.Properties; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; import org.junit.jupiter.api.MethodOrderer; @@ -651,7 +649,7 @@ public void test_pooledConnectionFailover() throws SQLException, InterruptedExce auroraUtil.failoverClusterAndWaitUntilWriterChanged(); - assertThrows(SQLException.class, () -> auroraUtil.queryInstanceId(conn)); + assertThrows(FailoverSuccessSQLException.class, () -> auroraUtil.queryInstanceId(conn)); nextWriterId = auroraUtil.queryInstanceId(conn); LOGGER.finest("nextWriterId: " + nextWriterId); assertNotEquals(initialWriterId, nextWriterId); From 6f3132879f1dd85862d009e90cec4c4f2a998a7f Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Wed, 15 Jan 2025 16:40:03 -0800 Subject: [PATCH 03/21] test: close topology monitors before each test --- .../src/main/java/software/amazon/jdbc/Driver.java | 1 + .../monitoring/ClusterTopologyMonitorImpl.java | 3 +++ .../monitoring/MonitoringRdsHostListProvider.java | 11 +---------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/wrapper/src/main/java/software/amazon/jdbc/Driver.java b/wrapper/src/main/java/software/amazon/jdbc/Driver.java index 5c44dae6d..b66e216b4 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/Driver.java +++ b/wrapper/src/main/java/software/amazon/jdbc/Driver.java @@ -412,6 +412,7 @@ public static void releaseResources() { CustomEndpointPlugin.closeMonitors(); HikariPoolsHolder.closeAllPools(); HostResponseTimeServiceImpl.closeAllMonitors(); + MonitoringRdsHostListProvider.closeAllMonitors(); clearCaches(); } } diff --git a/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/monitoring/ClusterTopologyMonitorImpl.java b/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/monitoring/ClusterTopologyMonitorImpl.java index ee2d46511..24461916c 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/monitoring/ClusterTopologyMonitorImpl.java +++ b/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/monitoring/ClusterTopologyMonitorImpl.java @@ -265,6 +265,7 @@ protected List waitTillTopologyGetsUpdated(final long timeoutMs) throw @Override public void close() throws Exception { this.stop.set(true); + this.nodeThreadsStop.set(true); // It breaks a waiting/sleeping cycles in monitoring thread synchronized (this.requestToUpdateTopology) { @@ -276,6 +277,8 @@ public void close() throws Exception { if (!this.monitorExecutor.awaitTermination(30, TimeUnit.SECONDS)) { this.monitorExecutor.shutdownNow(); } + + this.nodeThreads.clear(); } @Override diff --git a/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/monitoring/MonitoringRdsHostListProvider.java b/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/monitoring/MonitoringRdsHostListProvider.java index 0dc9a46e9..398f9b605 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/monitoring/MonitoringRdsHostListProvider.java +++ b/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/monitoring/MonitoringRdsHostListProvider.java @@ -85,17 +85,8 @@ public MonitoringRdsHostListProvider( CLUSTER_TOPOLOGY_HIGH_REFRESH_RATE_MS.getLong(this.properties)); } - /** - * Clear topology cache for the current cluster. - */ - public void clear() { - topologyCache.remove(this.clusterId); - } - public static void clearCache() { - topologyCache.clear(); - primaryClusterIdCache.clear(); - suggestedPrimaryClusterIdCache.clear(); + clearAll(); } public static void closeAllMonitors() { From e277287b04143f8ca928f02200f23dfeb725457d Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Wed, 15 Jan 2025 17:47:59 -0800 Subject: [PATCH 04/21] Add note about org.testcontainers dependencies requiring the same versions --- wrapper/build.gradle.kts | 1 + wrapper/src/test/build.gradle.kts | 1 + 2 files changed, 2 insertions(+) diff --git a/wrapper/build.gradle.kts b/wrapper/build.gradle.kts index f603a8bd5..b142cdbbc 100644 --- a/wrapper/build.gradle.kts +++ b/wrapper/build.gradle.kts @@ -69,6 +69,7 @@ dependencies { testImplementation("software.amazon.awssdk:ec2:2.29.34") testImplementation("software.amazon.awssdk:secretsmanager:2.29.34") testImplementation("software.amazon.awssdk:sts:2.29.34") + // Note: all org.testcontainers dependencies should have the same version testImplementation("org.testcontainers:testcontainers:1.20.4") testImplementation("org.testcontainers:mysql:1.20.4") testImplementation("org.testcontainers:postgresql:1.20.4") diff --git a/wrapper/src/test/build.gradle.kts b/wrapper/src/test/build.gradle.kts index b3bdaae4c..89e63ddbf 100644 --- a/wrapper/src/test/build.gradle.kts +++ b/wrapper/src/test/build.gradle.kts @@ -44,6 +44,7 @@ dependencies { testImplementation("software.amazon.awssdk:ec2:2.29.34") testImplementation("software.amazon.awssdk:rds:2.29.34") testImplementation("software.amazon.awssdk:sts:2.29.34") + // Note: all org.testcontainers dependencies should have the same version testImplementation("org.testcontainers:testcontainers:1.20.4") testImplementation("org.testcontainers:mysql:1.20.4") testImplementation("org.testcontainers:postgresql:1.20.4") From 34540812bd4dd041277dfb54c4337d0bc572bfb4 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Thu, 16 Jan 2025 17:24:22 -0800 Subject: [PATCH 05/21] catch ClusterTopologyMonitorImpl.createHost exceptions, make sure proxied instances up --- docs/development-guide/IntegrationTests.md | 2 +- .../ClusterTopologyMonitorImpl.java | 19 +++-- ..._advanced_jdbc_wrapper_messages.properties | 1 + .../container/TestDriverProvider.java | 29 ++------ .../tests/AdvancedPerformanceTest.java | 2 +- .../tests/ReadWriteSplittingTests.java | 31 ++++---- .../integration/util/AuroraTestUtility.java | 70 +++++++++---------- .../integration/util/ContainerHelper.java | 3 +- 8 files changed, 69 insertions(+), 88 deletions(-) diff --git a/docs/development-guide/IntegrationTests.md b/docs/development-guide/IntegrationTests.md index 6b76f5b41..62cf5168f 100644 --- a/docs/development-guide/IntegrationTests.md +++ b/docs/development-guide/IntegrationTests.md @@ -28,7 +28,7 @@ PostgreSQL and MySQL tests are currently supported. ### Environment Variables -If the environment variable `REUSE_AURORA_CLUSTER` is set to true, the integration tests will use the existing cluster defined by your environment variables. Otherwise, the integration tests will create a new Aurora cluster and then delete it automatically when the tests are done. Note that you will need a valid Docker environment to run any of the integration tests because they are run using a Docker environment as a host. The appropriate Docker containers will be created automatically when you run the tests, so you will not need to execute any Docker commands manually. +If the environment variable `REUSE_RDS_CLUSTER` is set to true, the integration tests will use the existing cluster defined by your environment variables. Otherwise, the integration tests will create a new Aurora cluster and then delete it automatically when the tests are done. Note that you will need a valid Docker environment to run any of the integration tests because they are run using a Docker environment as a host. The appropriate Docker containers will be created automatically when you run the tests, so you will not need to execute any Docker commands manually. >**Note:** if you are running tests against an existing cluster, the tests will only run against the Aurora database engine of that cluster. For example, if you specify a MySQL cluster using the environment variables, only the MySQL tests will be run even if you pick test-all-aurora as the task. To run against Postgres instead, you will need to change your environment variables diff --git a/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/monitoring/ClusterTopologyMonitorImpl.java b/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/monitoring/ClusterTopologyMonitorImpl.java index 24461916c..43e6e8be5 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/monitoring/ClusterTopologyMonitorImpl.java +++ b/wrapper/src/main/java/software/amazon/jdbc/hostlistprovider/monitoring/ClusterTopologyMonitorImpl.java @@ -581,7 +581,7 @@ protected void delay(boolean useHighRefreshRate) throws InterruptedException { } try { final List hosts = this.queryForTopology(connection); - if (hosts != null) { + if (!Utils.isNullOrEmpty(hosts)) { this.updateTopologyCache(hosts); } return hosts; @@ -616,7 +616,7 @@ protected String getWriterNodeId(final Connection connection) throws SQLExceptio return null; } - protected List queryForTopology(final Connection conn) throws SQLException { + protected @Nullable List queryForTopology(final Connection conn) throws SQLException { int networkTimeout = -1; try { networkTimeout = conn.getNetworkTimeout(); @@ -647,7 +647,7 @@ protected String getSuggestedWriterNodeId(final Connection connection) throws SQ return null; // intentionally null } - protected List processQueryResults( + protected @Nullable List processQueryResults( final ResultSet resultSet, final String suggestedWriterNodeId) throws SQLException { @@ -656,8 +656,14 @@ protected List processQueryResults( // Data is result set is ordered by last updated time so the latest records go last. // When adding hosts to a map, the newer records replace the older ones. while (resultSet.next()) { - final HostSpec host = createHost(resultSet, suggestedWriterNodeId); - hostMap.put(host.getHost(), host); + try { + final HostSpec host = createHost(resultSet, suggestedWriterNodeId); + hostMap.put(host.getHost(), host); + } catch (Exception e) { + LOGGER.fine( + Messages.get("ClusterTopologyMonitorImpl.errorProcessingQueryResults", new Object[]{e.getMessage()})); + return null; + } } final List hosts = new ArrayList<>(); @@ -866,6 +872,9 @@ private void readerThreadFetchTopology(final Connection connection, final @Nulla List hosts; try { hosts = this.monitor.queryForTopology(connection); + if (hosts == null) { + return; + } } catch (SQLException ex) { return; } diff --git a/wrapper/src/main/resources/aws_advanced_jdbc_wrapper_messages.properties b/wrapper/src/main/resources/aws_advanced_jdbc_wrapper_messages.properties index 9e322d21a..ebdb43f2f 100644 --- a/wrapper/src/main/resources/aws_advanced_jdbc_wrapper_messages.properties +++ b/wrapper/src/main/resources/aws_advanced_jdbc_wrapper_messages.properties @@ -409,3 +409,4 @@ ClusterTopologyMonitorImpl.startingNodeMonitoringThreads=Starting node monitorin ClusterTopologyMonitorImpl.writerPickedUpFromNodeMonitors=The writer host detected by the node monitors was picked up by the topology monitor: ''{0}''. ClusterTopologyMonitorImpl.writerMonitoringConnection=The monitoring connection is connected to a writer: ''{0}''. ClusterTopologyMonitorImpl.errorFetchingTopology=An error occurred while querying for topology: {0} +ClusterTopologyMonitorImpl.errorProcessingQueryResults=An error occurred while processing the results from the topology query: {0} diff --git a/wrapper/src/test/java/integration/container/TestDriverProvider.java b/wrapper/src/test/java/integration/container/TestDriverProvider.java index 474ae4842..491d35447 100644 --- a/wrapper/src/test/java/integration/container/TestDriverProvider.java +++ b/wrapper/src/test/java/integration/container/TestDriverProvider.java @@ -31,8 +31,6 @@ import integration.TestEnvironmentInfo; import integration.TestEnvironmentRequest; import integration.TestInstanceInfo; -import integration.container.aurora.TestAuroraHostListProvider; -import integration.container.aurora.TestPluginServiceImpl; import integration.container.condition.EnableBasedOnEnvironmentFeatureExtension; import integration.container.condition.EnableBasedOnTestDriverExtension; import integration.container.condition.MakeSureFirstInstanceWriter; @@ -56,16 +54,7 @@ import org.junit.platform.commons.util.AnnotationUtils; import software.amazon.jdbc.ConnectionProviderManager; import software.amazon.jdbc.Driver; -import software.amazon.jdbc.HikariPoolsHolder; -import software.amazon.jdbc.dialect.DialectManager; -import software.amazon.jdbc.hostlistprovider.monitoring.MonitoringRdsHostListProvider; -import software.amazon.jdbc.plugin.OpenedConnectionTracker; -import software.amazon.jdbc.plugin.customendpoint.CustomEndpointMonitorImpl; -import software.amazon.jdbc.plugin.customendpoint.CustomEndpointPlugin; -import software.amazon.jdbc.plugin.efm.MonitorThreadContainer; -import software.amazon.jdbc.plugin.efm2.MonitorServiceImpl; import software.amazon.jdbc.targetdriverdialect.TargetDriverDialectManager; -import software.amazon.jdbc.util.RdsUtils; public class TestDriverProvider implements TestTemplateInvocationContextProvider { private static final Logger LOGGER = Logger.getLogger(TestDriverProvider.class.getName()); @@ -240,21 +229,11 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(testInfo); auroraUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); - List instanceIDs = - testInfo.getDatabaseInfo().getInstances() - .stream().map(TestInstanceInfo::getInstanceId) - .collect(Collectors.toList()); - - boolean allInstancesUp = auroraUtil.makeSureInstancesUp( - instanceIDs, false, TimeUnit.MINUTES.toSeconds(3)); - - if (!allInstancesUp) { - throw new RuntimeException("Not all instances are available"); - } + auroraUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(3)); if (makeSureFirstInstanceWriter) { - instanceIDs = new ArrayList<>(); + List instanceIDs = new ArrayList<>(); // Need to ensure that cluster details through API matches topology fetched through SQL // Wait up to 10min @@ -333,7 +312,7 @@ public static void rebootCluster() throws InterruptedException { auroraUtil.rebootCluster(testInfo.getAuroraClusterName()); auroraUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName(), "rebooting"); auroraUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); - auroraUtil.makeSureInstancesUp(instanceIDs, true, TimeUnit.MINUTES.toSeconds(10)); + auroraUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(10)); } public static void rebootAllClusterInstances() throws InterruptedException { @@ -357,6 +336,6 @@ public static void rebootAllClusterInstances() throws InterruptedException { auroraUtil.waitUntilInstanceHasRightState(instanceId); } - auroraUtil.makeSureInstancesUp(instanceIDs, true, TimeUnit.MINUTES.toSeconds(10)); + auroraUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(10)); } } diff --git a/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java b/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java index c91843320..22db0293d 100644 --- a/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java +++ b/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java @@ -683,7 +683,7 @@ private void ensureClusterHealthy() throws InterruptedException { TestEnvironment.getCurrent().getInfo().getDatabaseInfo().moveInstanceFirst(currentWriter); TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().moveInstanceFirst(currentWriter); - auroraUtil.makeSureInstancesUp(latestTopology); + auroraUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(5)); TestAuroraHostListProvider.clearCache(); TestPluginServiceImpl.clearHostAvailabilityCache(); diff --git a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java index cb019fb53..aa99253bb 100644 --- a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java +++ b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java @@ -779,26 +779,19 @@ public void test_pooledConnection_failoverInTransaction() assertNotSame(initialWriterConn1, newWriterConn); } - // Make ure all instances up after failover. + // Make sure all instances up after failover. // Old writer in RDS MultiAz clusters may be unavailable for quite long time. - List instanceIDs = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances() - .stream().map(TestInstanceInfo::getInstanceId) - .collect(Collectors.toList()); - boolean allInstancesUp = auroraUtil.makeSureInstancesUp( - instanceIDs, false, TimeUnit.MINUTES.toSeconds(15)); - - if (allInstancesUp) { - // It makes sense to run the following step when initial writer is up. - try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props)) { - // This should be a new connection to the initial writer instance (now a reader). - final String writerConnectionId = auroraUtil.queryInstanceId(conn); - assertEquals(initialWriterId, writerConnectionId); - initialWriterConn2 = conn.unwrap(Connection.class); - // The initial connection should have been evicted from the pool when failover occurred, so - // this should be a new connection even though it is connected to the same instance. - assertNotSame(initialWriterConn1, initialWriterConn2); - } + auroraUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(15)); + + // It makes sense to run the following step when initial writer is up. + try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props)) { + // This should be a new connection to the initial writer instance (now a reader). + final String writerConnectionId = auroraUtil.queryInstanceId(conn); + assertEquals(initialWriterId, writerConnectionId); + initialWriterConn2 = conn.unwrap(Connection.class); + // The initial connection should have been evicted from the pool when failover occurred, so + // this should be a new connection even though it is connected to the same instance. + assertNotSame(initialWriterConn1, initialWriterConn2); } } finally { ConnectionProviderManager.releaseResources(); diff --git a/wrapper/src/test/java/integration/util/AuroraTestUtility.java b/wrapper/src/test/java/integration/util/AuroraTestUtility.java index cb54ac0d0..b4cf18457 100644 --- a/wrapper/src/test/java/integration/util/AuroraTestUtility.java +++ b/wrapper/src/test/java/integration/util/AuroraTestUtility.java @@ -905,18 +905,19 @@ public List getDBClusterMemberList(String clusterId) { return dbCluster.dbClusterMembers(); } - public boolean makeSureInstancesUp(List instances) throws InterruptedException { - return makeSureInstancesUp(instances, true, TimeUnit.MINUTES.toSeconds(5)); + public void makeSureInstancesUp(long timeoutSec) { + List instances = new ArrayList<>(); + TestEnvironmentInfo envInfo = TestEnvironment.getCurrent().getInfo(); + instances.addAll(envInfo.getDatabaseInfo().getInstances()); + instances.addAll(envInfo.getProxyDatabaseInfo().getInstances()); + makeSureInstancesUp(instances, timeoutSec); } - public boolean makeSureInstancesUp(List instances, long timeoutSec) throws InterruptedException { - return makeSureInstancesUp(instances, true, timeoutSec); - } - - public boolean makeSureInstancesUp(List instances, boolean finalCheck, long timeoutSec) - throws InterruptedException { + public void makeSureInstancesUp(List instances, long timeoutSec) { final ConcurrentHashMap remainingInstances = new ConcurrentHashMap<>(); - instances.forEach((k) -> remainingInstances.put(k, true)); + final String dbName = TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(); + + instances.forEach((i) -> remainingInstances.put(i.getHost(), true)); final Properties props = ConnectionStringHelper.getDefaultProperties(); DriverHelper.setConnectTimeout(props, 30, TimeUnit.SECONDS); @@ -925,26 +926,28 @@ public boolean makeSureInstancesUp(List instances, boolean finalCheck, l final CountDownLatch latch = new CountDownLatch(instances.size()); final AtomicBoolean stop = new AtomicBoolean(false); - for (final String id : instances) { + for (final TestInstanceInfo instanceInfo : instances) { + String host = instanceInfo.getHost(); executorService.submit(() -> { while (!stop.get()) { - TestInstanceInfo instanceInfo = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(id); String url = ConnectionStringHelper.getUrl( - instanceInfo.getHost(), + host, instanceInfo.getPort(), - TestEnvironment.getCurrent() - .getInfo() - .getDatabaseInfo() - .getDefaultDbName()); + dbName); try (final Connection conn = DriverManager.getConnection(url, props)) { - LOGGER.finest("Instance " + id + " is up."); - remainingInstances.remove(id); + LOGGER.finest("Host " + instanceInfo.getHost() + " is up."); + if (instanceInfo.getHost().contains(".proxied")) { + LOGGER.finest( + "Proxied host " + instanceInfo.getHost() + " resolves to IP address " + + this.hostToIP(host, false)); + } + + remainingInstances.remove(instanceInfo.getHost()); latch.countDown(); break; } catch (final SQLException ex) { // Continue waiting until instance is up. - LOGGER.log(Level.FINEST, "Exception while trying to connect to instance " + id, ex); + LOGGER.log(Level.FINEST, "Exception while trying to connect to host " + instanceInfo.getHost(), ex); } catch (final Exception ex) { LOGGER.log(Level.SEVERE, "Exception:", ex); break; @@ -958,22 +961,17 @@ public boolean makeSureInstancesUp(List instances, boolean finalCheck, l }); } - latch.await(timeoutSec, TimeUnit.SECONDS); + try { + latch.await(timeoutSec, TimeUnit.SECONDS); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } stop.set(true); executorService.shutdownNow(); - if (finalCheck) { - assertTrue( - remainingInstances.isEmpty(), - "The following instances are still down: \n" - + String.join("\n", remainingInstances.keySet())); - } else { - if (!remainingInstances.isEmpty()) { - LOGGER.finest("The following instances are still down: \n" - + String.join("\n", remainingInstances.keySet())); - } + if (!remainingInstances.isEmpty()) { + fail("The following instances are still down: \n" + String.join("\n", remainingInstances.keySet())); } - return remainingInstances.isEmpty(); } // Attempt to run a query after the instance is down. @@ -1063,11 +1061,11 @@ public void failoverClusterToATargetAndWaitUntilWriterChanged( LOGGER.finest("Cluster endpoint resolves to (after wait): " + newClusterEndpointIp); // wait until all instances except initial writer instance to be available - makeSureInstancesUp(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances() + List instances = TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances() .stream() - .map(TestInstanceInfo::getInstanceId) - .filter(x -> !x.equalsIgnoreCase(initialWriterId)) - .collect(Collectors.toList())); + .filter(x -> !x.getInstanceId().equalsIgnoreCase(initialWriterId)) + .collect(Collectors.toList()); + makeSureInstancesUp(instances, TimeUnit.MINUTES.toSeconds(5)); } LOGGER.finest(String.format("finished failover from %s to target: %s", initialWriterId, targetWriterId)); } diff --git a/wrapper/src/test/java/integration/util/ContainerHelper.java b/wrapper/src/test/java/integration/util/ContainerHelper.java index f19dec9a1..dba52d2d3 100644 --- a/wrapper/src/test/java/integration/util/ContainerHelper.java +++ b/wrapper/src/test/java/integration/util/ContainerHelper.java @@ -53,8 +53,9 @@ public class ContainerHelper { private static final String MYSQL_CONTAINER_IMAGE_NAME = "mysql:8.0.36"; private static final String POSTGRES_CONTAINER_IMAGE_NAME = "postgres:latest"; private static final String MARIADB_CONTAINER_IMAGE_NAME = "mariadb:10"; + // Note: this image version may need to be occasionally updated to keep it up-to-date and prevent toxiproxy issues. private static final DockerImageName TOXIPROXY_IMAGE = - DockerImageName.parse("ghcr.io/shopify/toxiproxy:2.9.0"); + DockerImageName.parse("ghcr.io/shopify/toxiproxy:2.11.0"); private static final int PROXY_CONTROL_PORT = 8474; private static final int PROXY_PORT = 8666; From 515e2d780500d9cef977525f01bb5fd6d7cf491d Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Thu, 16 Jan 2025 15:36:38 -0800 Subject: [PATCH 06/21] wip --- .../container/TestDriverProvider.java | 8 +- .../tests/AdvancedPerformanceTest.java | 4 +- .../container/tests/AuroraFailoverTest.java | 4 +- .../container/tests/AutoscalingTests.java | 4 +- .../container/tests/CustomEndpointTest.java | 4 +- .../container/tests/HikariTests.java | 14 ++-- .../tests/ReadWriteSplittingTests.java | 4 +- .../integration/host/TestEnvironment.java | 6 +- ...uroraTestUtility.java => TestUtility.java} | 78 ++++++++----------- 9 files changed, 57 insertions(+), 69 deletions(-) rename wrapper/src/test/java/integration/util/{AuroraTestUtility.java => TestUtility.java} (96%) diff --git a/wrapper/src/test/java/integration/container/TestDriverProvider.java b/wrapper/src/test/java/integration/container/TestDriverProvider.java index 491d35447..e187f4db1 100644 --- a/wrapper/src/test/java/integration/container/TestDriverProvider.java +++ b/wrapper/src/test/java/integration/container/TestDriverProvider.java @@ -34,7 +34,7 @@ import integration.container.condition.EnableBasedOnEnvironmentFeatureExtension; import integration.container.condition.EnableBasedOnTestDriverExtension; import integration.container.condition.MakeSureFirstInstanceWriter; -import integration.util.AuroraTestUtility; +import integration.util.TestUtility; import java.lang.reflect.Method; import java.sql.SQLException; import java.util.ArrayList; @@ -226,7 +226,7 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); final TestEnvironmentRequest testRequest = testInfo.getRequest(); - final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(testInfo); + final TestUtility auroraUtil = TestUtility.getUtility(testInfo); auroraUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); auroraUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(3)); @@ -295,7 +295,7 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter public static void rebootCluster() throws InterruptedException { final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); - final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(testInfo); + final TestUtility auroraUtil = TestUtility.getUtility(testInfo); List instanceIDs = testInfo.getDatabaseInfo().getInstances().stream() .map(TestInstanceInfo::getInstanceId) @@ -318,7 +318,7 @@ public static void rebootCluster() throws InterruptedException { public static void rebootAllClusterInstances() throws InterruptedException { final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); - final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(testInfo); + final TestUtility auroraUtil = TestUtility.getUtility(testInfo); List instanceIDs = testInfo.getDatabaseInfo().getInstances().stream() .map(TestInstanceInfo::getInstanceId) diff --git a/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java b/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java index 22db0293d..16439c6e0 100644 --- a/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java +++ b/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java @@ -32,7 +32,7 @@ import integration.container.aurora.TestAuroraHostListProvider; import integration.container.aurora.TestPluginServiceImpl; import integration.container.condition.EnableOnTestFeature; -import integration.util.AuroraTestUtility; +import integration.util.TestUtility; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -99,7 +99,7 @@ public class AdvancedPerformanceTest { private static final ConcurrentLinkedQueue perfDataList = new ConcurrentLinkedQueue<>(); - protected static final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(); + protected static final TestUtility auroraUtil = TestUtility.getUtility(); private static void doWritePerfDataToFile( String fileName, ConcurrentLinkedQueue dataList) throws IOException { diff --git a/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java b/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java index 8bccdc86d..a1b089b82 100644 --- a/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java +++ b/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java @@ -39,7 +39,7 @@ import integration.container.condition.EnableOnTestDriver; import integration.container.condition.EnableOnTestFeature; import integration.container.condition.MakeSureFirstInstanceWriter; -import integration.util.AuroraTestUtility; +import integration.util.TestUtility; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; @@ -79,7 +79,7 @@ public class AuroraFailoverTest { private static final Logger LOGGER = Logger.getLogger(AuroraFailoverTest.class.getName()); - protected static final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(); + protected static final TestUtility auroraUtil = TestUtility.getUtility(); protected static final int IS_VALID_TIMEOUT = 5; protected String currentWriter; diff --git a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java index 5a4c61979..774713f3e 100644 --- a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java +++ b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java @@ -34,7 +34,7 @@ import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.EnableOnTestFeature; import integration.container.condition.MakeSureFirstInstanceWriter; -import integration.util.AuroraTestUtility; +import integration.util.TestUtility; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -63,7 +63,7 @@ @MakeSureFirstInstanceWriter @Order(17) public class AutoscalingTests { - protected static final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(); + protected static final TestUtility auroraUtil = TestUtility.getUtility(); protected static Properties getDefaultPropsNoPlugins() { final Properties props = ConnectionStringHelper.getDefaultProperties(); diff --git a/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java b/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java index 9c0fdaab4..85dede12a 100644 --- a/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java +++ b/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java @@ -34,7 +34,7 @@ import integration.container.condition.EnableOnDatabaseEngineDeployment; import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.MakeSureFirstInstanceWriter; -import integration.util.AuroraTestUtility; +import integration.util.TestUtility; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -81,7 +81,7 @@ public class CustomEndpointTest { protected static final String endpointId = "test-endpoint-1-" + UUID.randomUUID(); protected static DBClusterEndpoint endpointInfo; - protected static final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(); + protected static final TestUtility auroraUtil = TestUtility.getUtility(); protected static final boolean reuseExistingEndpoint = false; protected String currentWriter; diff --git a/wrapper/src/test/java/integration/container/tests/HikariTests.java b/wrapper/src/test/java/integration/container/tests/HikariTests.java index e1290c44e..c3c14c970 100644 --- a/wrapper/src/test/java/integration/container/tests/HikariTests.java +++ b/wrapper/src/test/java/integration/container/tests/HikariTests.java @@ -16,7 +16,7 @@ package integration.container.tests; -import static integration.util.AuroraTestUtility.executeWithTimeout; +import static integration.util.TestUtility.executeWithTimeout; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -45,7 +45,7 @@ import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.EnableOnTestFeature; import integration.container.condition.MakeSureFirstInstanceWriter; -import integration.util.AuroraTestUtility; +import integration.util.TestUtility; import java.sql.Connection; import java.sql.SQLException; import java.sql.SQLTransientConnectionException; @@ -175,7 +175,7 @@ public void testOpenConnectionWithDataSourceClassName() throws SQLException { @EnableOnNumOfInstances(min = 3) public void testFailoverLostConnection() throws SQLException { - final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(); + final TestUtility auroraUtil = TestUtility.getUtility(); final Properties customProps = new Properties(); PLUGINS.set(customProps, "failover"); FAILOVER_TIMEOUT_MS.set(customProps, Integer.toString(1)); @@ -218,7 +218,7 @@ public void testFailoverLostConnection() throws SQLException { @EnableOnNumOfInstances(min = 3) public void testEFMFailover() throws SQLException { - final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(); + final TestUtility auroraUtil = TestUtility.getUtility(); ProxyHelper.disableAllConnectivity(); final List instances = TestEnvironment.getCurrent() @@ -270,7 +270,7 @@ public void testEFMFailover() throws SQLException { @EnableOnNumOfInstances(min = 2) public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation() throws SQLException, InterruptedException { - final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(); + final TestUtility auroraUtil = TestUtility.getUtility(); final TestProxyDatabaseInfo proxyInfo = TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); final List instances = proxyInfo.getInstances(); final TestInstanceInfo reader = instances.get(1); @@ -312,7 +312,7 @@ public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation() @EnableOnNumOfInstances(min = 2) public void testInternalPools_driverReaderFailoverOnGetConnectionInvocation() throws SQLException, InterruptedException { - final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(); + final TestUtility auroraUtil = TestUtility.getUtility(); final TestProxyDatabaseInfo proxyInfo = TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); final List instances = proxyInfo.getInstances(); final TestInstanceInfo writer = instances.get(0); @@ -362,7 +362,7 @@ public void testInternalPools_driverReaderFailoverOnGetConnectionInvocation() @EnableOnNumOfInstances(max = 1) public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation_singleInstance() throws SQLException, InterruptedException { - final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(); + final TestUtility auroraUtil = TestUtility.getUtility(); final TestProxyDatabaseInfo proxyInfo = TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); final List instances = proxyInfo.getInstances(); final TestInstanceInfo writer = instances.get(0); diff --git a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java index aa99253bb..0b5cd1aa6 100644 --- a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java +++ b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java @@ -46,7 +46,7 @@ import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.EnableOnTestFeature; import integration.container.condition.MakeSureFirstInstanceWriter; -import integration.util.AuroraTestUtility; +import integration.util.TestUtility; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; @@ -89,7 +89,7 @@ @Order(12) public class ReadWriteSplittingTests { - protected static final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(); + protected static final TestUtility auroraUtil = TestUtility.getUtility(); private static final Logger LOGGER = Logger.getLogger(ReadWriteSplittingTests.class.getName()); protected static Properties getProxiedPropsWithFailover() { diff --git a/wrapper/src/test/java/integration/host/TestEnvironment.java b/wrapper/src/test/java/integration/host/TestEnvironment.java index cd727ff94..f51f1533b 100644 --- a/wrapper/src/test/java/integration/host/TestEnvironment.java +++ b/wrapper/src/test/java/integration/host/TestEnvironment.java @@ -32,7 +32,7 @@ import integration.TestProxyDatabaseInfo; import integration.TestTelemetryInfo; import integration.host.TestEnvironmentProvider.EnvPreCreateInfo; -import integration.util.AuroraTestUtility; +import integration.util.TestUtility; import integration.util.ContainerHelper; import java.io.IOException; import java.net.URISyntaxException; @@ -104,7 +104,7 @@ public class TestEnvironment implements AutoCloseable { private final Network network = Network.newNetwork(); - private AuroraTestUtility auroraUtil; + private TestUtility auroraUtil; private TestEnvironment(TestEnvironmentRequest request) { this.info.setRequest(request); @@ -365,7 +365,7 @@ private static void createDbCluster(TestEnvironment env, int numOfInstances) thr env.info.setRdsEndpoint(env.rdsEndpoint); env.auroraUtil = - new AuroraTestUtility( + new TestUtility( env.info.getRegion(), env.rdsEndpoint, env.awsAccessKeyId, diff --git a/wrapper/src/test/java/integration/util/AuroraTestUtility.java b/wrapper/src/test/java/integration/util/TestUtility.java similarity index 96% rename from wrapper/src/test/java/integration/util/AuroraTestUtility.java rename to wrapper/src/test/java/integration/util/TestUtility.java index b4cf18457..0256a017b 100644 --- a/wrapper/src/test/java/integration/util/AuroraTestUtility.java +++ b/wrapper/src/test/java/integration/util/TestUtility.java @@ -104,9 +104,9 @@ * Creates and destroys AWS RDS Clusters and Instances. To use this functionality the following environment variables * must be defined: - AWS_ACCESS_KEY_ID - AWS_SECRET_ACCESS_KEY */ -public class AuroraTestUtility { +public class TestUtility { - private static final Logger LOGGER = Logger.getLogger(AuroraTestUtility.class.getName()); + private static final Logger LOGGER = Logger.getLogger(TestUtility.class.getName()); // Default values private String dbUsername = "my_test_username"; @@ -117,9 +117,6 @@ public class AuroraTestUtility { private String dbEngine = "aurora-postgresql"; private String dbEngineVersion = "13.9"; private String dbInstanceClass = "db.r5.large"; - private final String storageType = "io1"; - private final int allocatedStorage = 100; - private final int iops = 1000; private final Region dbRegion; private final String dbSecGroup = "default"; private int numOfInstances = 5; @@ -129,20 +126,18 @@ public class AuroraTestUtility { private Ec2Client ec2Client; private static final Random rand = new Random(); - private String rdsEndpoint; + private final String rdsEndpoint; - private AwsCredentialsProvider credentialsProvider; + private final AwsCredentialsProvider credentialsProvider; private static final String DUPLICATE_IP_ERROR_CODE = "InvalidPermission.Duplicate"; - public AuroraTestUtility(String region, String endpoint) throws URISyntaxException { + public TestUtility(String region, String endpoint) throws URISyntaxException { this(getRegionInternal(region), endpoint, DefaultCredentialsProvider.create()); } - public AuroraTestUtility( - String region, String rdsEndpoint, String awsAccessKeyId, String awsSecretAccessKey, String awsSessionToken) - throws URISyntaxException { - + public TestUtility( + String region, String rdsEndpoint, String awsAccessKeyId, String awsSecretAccessKey, String awsSessionToken) { this( getRegionInternal(region), rdsEndpoint, @@ -161,8 +156,7 @@ public AuroraTestUtility( * Availability Zones, and Local Zones * @param credentialsProvider Specific AWS credential provider */ - public AuroraTestUtility(Region region, String rdsEndpoint, AwsCredentialsProvider credentialsProvider) - throws URISyntaxException { + public TestUtility(Region region, String rdsEndpoint, AwsCredentialsProvider credentialsProvider) { this.dbRegion = region; this.rdsEndpoint = rdsEndpoint; this.credentialsProvider = credentialsProvider; @@ -347,10 +341,10 @@ public String createMultiAzCluster() throws InterruptedException { .tags(testRunnerTag); clusterBuilder = - clusterBuilder.allocatedStorage(allocatedStorage) + clusterBuilder.allocatedStorage(100) .dbClusterInstanceClass(dbInstanceClass) - .storageType(storageType) - .iops(iops); + .storageType("io1") + .iops(1000); rdsClient.createDBCluster(clusterBuilder.build()); @@ -740,6 +734,11 @@ public DBCluster getDBCluster(String clusterId) { this.initClient(); } } + + if (dbClustersResult == null) { + fail("Unable to get DB cluster info for cluster with ID " + clusterId); + } + final List dbClusterList = dbClustersResult.dbClusters(); return dbClusterList.get(0); } @@ -758,6 +757,11 @@ public DBInstance getDBInstance(String instanceId) { this.initClient(); } } + + if (dbInstanceResult == null) { + fail("Unable to get DB instance info for instance with ID " + instanceId); + } + final List dbClusterList = dbInstanceResult.dbInstances(); return dbClusterList.get(0); } @@ -961,11 +965,11 @@ public void makeSureInstancesUp(List instances, long timeoutSe }); } - try { - latch.await(timeoutSec, TimeUnit.SECONDS); - } catch (InterruptedException e) { - throw new RuntimeException(e); + boolean timedOut = !latch.await(timeoutSec, TimeUnit.SECONDS); + if (timedOut) { + LOGGER.warning("Timed out while waiting for instances to come up."); } + stop.set(true); executorService.shutdownNow(); @@ -977,7 +981,7 @@ public void makeSureInstancesUp(List instances, long timeoutSe // Attempt to run a query after the instance is down. // This should initiate the driver failover, first query after a failover // should always throw with the expected error message. - public void assertFirstQueryThrows(Connection connection, Class expectedSQLExceptionClass) { + public void assertFirstQueryThrows(Connection connection, Class expectedSQLExceptionClass) { assertThrows( expectedSQLExceptionClass, () -> { @@ -1070,22 +1074,6 @@ public void failoverClusterToATargetAndWaitUntilWriterChanged( LOGGER.finest(String.format("finished failover from %s to target: %s", initialWriterId, targetWriterId)); } - private boolean hasWriterChanged(String initialWriterId, long timeoutNanos) - throws InterruptedException { - final long waitUntil = System.nanoTime() + timeoutNanos; - - String currentWriterId = getDBClusterWriterInstanceId(); - while (initialWriterId.equals(currentWriterId)) { - if (waitUntil < System.nanoTime()) { - return false; - } - TimeUnit.MILLISECONDS.sleep(3000); - // Calling the RDS API to get writer Id. - currentWriterId = getDBClusterWriterInstanceId(); - } - return true; - } - public void failoverClusterToTarget(String clusterId, @Nullable String targetInstanceId) throws InterruptedException { waitUntilClusterHasRightState(clusterId); @@ -1189,7 +1177,7 @@ public boolean waitDnsEqual( long startTimeNano = System.nanoTime(); while (hostIpAddress == null && TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTimeNano) < timeoutSec) { - Thread.sleep(5000); + TimeUnit.SECONDS.sleep(5); hostIpAddress = this.hostToIP(hostToCheck, false); } if (hostIpAddress == null) { @@ -1207,7 +1195,7 @@ public boolean waitDnsEqual( long startTimeNano = System.nanoTime(); while (!expectedHostIpAddress.equals(hostIpAddress) && TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTimeNano) < timeoutSec) { - Thread.sleep(5000); + TimeUnit.SECONDS.sleep(5); hostIpAddress = this.hostToIP(hostToCheck, false); LOGGER.finest(String.format("%s resolves to %s", hostToCheck, hostIpAddress)); } @@ -1233,7 +1221,7 @@ public boolean waitDnsNotEqual( long startTimeNano = System.nanoTime(); while (hostIpAddress == null && TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTimeNano) < timeoutSec) { - Thread.sleep(5000); + TimeUnit.SECONDS.sleep(5); hostIpAddress = this.hostToIP(hostToCheck, false); } if (hostIpAddress == null) { @@ -1252,7 +1240,7 @@ public boolean waitDnsNotEqual( long startTimeNano = System.nanoTime(); while (expectedHostIpAddress.equals(hostIpAddress) && TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startTimeNano) < timeoutSec) { - Thread.sleep(5000); + TimeUnit.SECONDS.sleep(5); hostIpAddress = this.hostToIP(hostToCheck, false); LOGGER.finest(String.format("%s resolves to %s", hostToCheck, hostIpAddress)); } @@ -1429,17 +1417,17 @@ public String getDefaultVersion(String engine) { throw new RuntimeException("Failed to find default version"); } - public static AuroraTestUtility getUtility() { + public static TestUtility getUtility() { return getUtility(null); } - public static AuroraTestUtility getUtility(TestEnvironmentInfo info) { + public static TestUtility getUtility(TestEnvironmentInfo info) { if (info == null) { info = TestEnvironment.getCurrent().getInfo(); } try { - return new AuroraTestUtility(info.getRegion(), info.getRdsEndpoint()); + return new TestUtility(info.getRegion(), info.getRdsEndpoint()); } catch (URISyntaxException e) { throw new RuntimeException(e); } From 83775e81c3ac841005c4e91503f36de55b064211 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Fri, 17 Jan 2025 13:34:33 -0800 Subject: [PATCH 07/21] Address warnings --- .../java/integration/util/TestUtility.java | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/wrapper/src/test/java/integration/util/TestUtility.java b/wrapper/src/test/java/integration/util/TestUtility.java index 0256a017b..dec6627ca 100644 --- a/wrapper/src/test/java/integration/util/TestUtility.java +++ b/wrapper/src/test/java/integration/util/TestUtility.java @@ -75,6 +75,8 @@ import software.amazon.awssdk.services.ec2.Ec2Client; import software.amazon.awssdk.services.ec2.model.DescribeSecurityGroupsResponse; import software.amazon.awssdk.services.ec2.model.Ec2Exception; +import software.amazon.awssdk.services.ec2.model.IpPermission; +import software.amazon.awssdk.services.ec2.model.IpRange; import software.amazon.awssdk.services.rds.RdsClient; import software.amazon.awssdk.services.rds.RdsClientBuilder; import software.amazon.awssdk.services.rds.model.CreateDbClusterRequest; @@ -480,7 +482,7 @@ public void deleteInstance(TestInstanceInfo instanceToDelete) throws Interrupted public String getPublicIPAddress() throws UnknownHostException { String ip; try { - URL ipChecker = new URL("http://checkip.amazonaws.com"); + URL ipChecker = new URL("https://checkip.amazonaws.com"); BufferedReader reader = new BufferedReader(new InputStreamReader(ipChecker.openStream())); ip = reader.readLine(); } catch (Exception e) { @@ -502,18 +504,18 @@ public void ec2AuthorizeIP(String ipAddress) { } try { + IpRange ipRange = IpRange.builder() + .cidrIp(ipAddress + "/32") + .description("Test run at " + Instant.now()) + .build(); + IpPermission ipPermission = IpPermission.builder() + .ipRanges(ipRange) + .ipProtocol("-1") // All protocols + .fromPort(0) // For all ports + .toPort(65535) + .build(); ec2Client.authorizeSecurityGroupIngress( - (builder) -> - builder - .groupName(dbSecGroup) - .ipPermissions((permissionBuilder) -> - permissionBuilder.ipRanges((ipRangeBuilder) -> - ipRangeBuilder - .cidrIp(ipAddress + "/32") - .description("Test run at " + Instant.now())) - .ipProtocol("-1") // All protocols - .fromPort(0) // For all ports - .toPort(65535))); + (builder) -> builder.groupName(dbSecGroup).ipPermissions(ipPermission)); } catch (Ec2Exception exception) { if (!DUPLICATE_IP_ERROR_CODE.equalsIgnoreCase(exception.awsErrorDetails().errorCode())) { throw exception; @@ -938,7 +940,7 @@ public void makeSureInstancesUp(List instances, long timeoutSe host, instanceInfo.getPort(), dbName); - try (final Connection conn = DriverManager.getConnection(url, props)) { + try (final Connection ignored = DriverManager.getConnection(url, props)) { LOGGER.finest("Host " + instanceInfo.getHost() + " is up."); if (instanceInfo.getHost().contains(".proxied")) { LOGGER.finest( @@ -965,11 +967,16 @@ public void makeSureInstancesUp(List instances, long timeoutSe }); } - boolean timedOut = !latch.await(timeoutSec, TimeUnit.SECONDS); - if (timedOut) { - LOGGER.warning("Timed out while waiting for instances to come up."); + try { + boolean timedOut = !latch.await(timeoutSec, TimeUnit.SECONDS); + if (timedOut) { + LOGGER.warning("Timed out while waiting for instances to come up."); + } + } catch (InterruptedException e) { + throw new RuntimeException(e); } + stop.set(true); executorService.shutdownNow(); @@ -1402,8 +1409,7 @@ public List getEngineVersions(String engine) { public String getLatestVersion(String engine) { return getEngineVersions(engine).stream() .filter(version -> !version.contains("limitless")) - .sorted(Comparator.reverseOrder()) - .findFirst() + .max(Comparator.naturalOrder()) .orElse(null); } @@ -1438,8 +1444,6 @@ public static T executeWithTimeout(final Callable callable, long timeoutM Future future = executorService.submit(callable); try { return future.get(timeoutMs, TimeUnit.MILLISECONDS); - } catch (InterruptedException interruptedException) { - throw interruptedException; } catch (ExecutionException executionException) { if (executionException.getCause() != null) { throw executionException.getCause(); @@ -1455,11 +1459,9 @@ public static T executeWithTimeout(final Callable callable, long timeoutM public static void executeWithTimeout(final Runnable runnable, long timeoutMs) throws Throwable { final ExecutorService executorService = Executors.newSingleThreadExecutor(); - Future future = executorService.submit(runnable); + Future future = executorService.submit(runnable); try { future.get(timeoutMs, TimeUnit.MILLISECONDS); - } catch (InterruptedException interruptedException) { - throw interruptedException; } catch (ExecutionException executionException) { if (executionException.getCause() != null) { throw executionException.getCause(); From 0188dabd64401d18d2c0fa48e9034f1d7b395c1f Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Mon, 20 Jan 2025 10:07:31 -0800 Subject: [PATCH 08/21] wip --- .../container/tests/AutoscalingTests.java | 3 +- .../integration/host/TestEnvironment.java | 1 + .../java/integration/util/TestUtility.java | 140 +++++++++--------- 3 files changed, 76 insertions(+), 68 deletions(-) diff --git a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java index 774713f3e..184643f9e 100644 --- a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java +++ b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java @@ -48,6 +48,7 @@ import org.junit.jupiter.api.TestTemplate; import org.junit.jupiter.api.extension.ExtendWith; import software.amazon.jdbc.ConnectionProviderManager; +import software.amazon.jdbc.Driver; import software.amazon.jdbc.HikariPoolConfigurator; import software.amazon.jdbc.HikariPooledConnectionProvider; import software.amazon.jdbc.PropertyDefinition; @@ -116,7 +117,7 @@ public void test_pooledConnectionAutoScaling_setReadOnlyOnOldConnection() null, poolExpirationNanos, TimeUnit.MINUTES.toNanos(10)); - ConnectionProviderManager.setConnectionProvider(provider); + Driver.setCustomConnectionProvider(provider); final List connections = new ArrayList<>(); try { diff --git a/wrapper/src/test/java/integration/host/TestEnvironment.java b/wrapper/src/test/java/integration/host/TestEnvironment.java index f51f1533b..dc26f11de 100644 --- a/wrapper/src/test/java/integration/host/TestEnvironment.java +++ b/wrapper/src/test/java/integration/host/TestEnvironment.java @@ -443,6 +443,7 @@ private static void createDbCluster(TestEnvironment env, int numOfInstances) thr env.info.getDatabaseInfo().getDefaultDbName(), env.auroraClusterName, env.info.getRequest().getDatabaseEngineDeployment(), + env.info.getRegion(), engine, instanceClass, engineVersion, diff --git a/wrapper/src/test/java/integration/util/TestUtility.java b/wrapper/src/test/java/integration/util/TestUtility.java index dec6627ca..b7274bdcb 100644 --- a/wrapper/src/test/java/integration/util/TestUtility.java +++ b/wrapper/src/test/java/integration/util/TestUtility.java @@ -111,26 +111,26 @@ public class TestUtility { private static final Logger LOGGER = Logger.getLogger(TestUtility.class.getName()); // Default values - private String dbUsername = "my_test_username"; - private String dbPassword = "my_test_password"; - private String dbName = "test"; - private String dbIdentifier = "test-identifier"; - private DatabaseEngineDeployment dbEngineDeployment; - private String dbEngine = "aurora-postgresql"; - private String dbEngineVersion = "13.9"; - private String dbInstanceClass = "db.r5.large"; - private final Region dbRegion; - private final String dbSecGroup = "default"; - private int numOfInstances = 5; - private ArrayList instances = new ArrayList<>(); +// private String dbUsername = "my_test_username"; +// private String dbPassword = "my_test_password"; +// private String dbName = "test"; +// private String dbIdentifier = "test-identifier"; +// private DatabaseEngineDeployment dbEngineDeployment; +// private String dbEngine = "aurora-postgresql"; +// private String dbEngineVersion = "13.9"; +// private String dbInstanceClass = "db.r5.large"; +// private final Region dbRegion; +// private final String dbSecGroup = "default"; +// private int numOfInstances = 5; +// private ArrayList instances = new ArrayList<>(); private RdsClient rdsClient; private Ec2Client ec2Client; private static final Random rand = new Random(); - private final String rdsEndpoint; +// private final String rdsEndpoint; - private final AwsCredentialsProvider credentialsProvider; +// private final AwsCredentialsProvider credentialsProvider; private static final String DUPLICATE_IP_ERROR_CODE = "InvalidPermission.Duplicate"; @@ -159,15 +159,8 @@ public TestUtility( * @param credentialsProvider Specific AWS credential provider */ public TestUtility(Region region, String rdsEndpoint, AwsCredentialsProvider credentialsProvider) { - this.dbRegion = region; - this.rdsEndpoint = rdsEndpoint; - this.credentialsProvider = credentialsProvider; - initClient(); - } - - protected void initClient() { final RdsClientBuilder rdsClientBuilder = RdsClient.builder() - .region(dbRegion) + .region(region) .credentialsProvider(credentialsProvider); if (!StringUtils.isNullOrEmpty(rdsEndpoint)) { @@ -180,7 +173,7 @@ protected void initClient() { rdsClient = rdsClientBuilder.build(); ec2Client = Ec2Client.builder() - .region(dbRegion) + .region(region) .credentialsProvider(credentialsProvider) .build(); } @@ -216,30 +209,23 @@ public String createCluster( String dbName, String identifier, DatabaseEngineDeployment deployment, + String region, String engine, String instanceClass, String version, - int numOfInstances, + int numInstances, ArrayList instances) throws InterruptedException { - this.dbUsername = username; - this.dbPassword = password; - this.dbName = dbName; - this.dbIdentifier = identifier; - this.dbEngineDeployment = deployment; - this.dbEngine = engine; - this.dbInstanceClass = instanceClass; - this.dbEngineVersion = version; - this.numOfInstances = numOfInstances; - this.instances = instances; - switch (this.dbEngineDeployment) { + switch (deployment) { case AURORA: - return createAuroraCluster(); + return createAuroraCluster( + username, password, dbName, identifier, region, engine, instanceClass, version, numInstances, instances); case RDS_MULTI_AZ_CLUSTER: - return createMultiAzCluster(); + return createMultiAzCluster( + username, password, dbName, identifier, region, engine, instanceClass, version, instances); default: - throw new UnsupportedOperationException(this.dbEngineDeployment.toString()); + throw new UnsupportedOperationException(deployment.toString()); } } @@ -249,20 +235,31 @@ public String createCluster( * @return An endpoint for one of the instances * @throws InterruptedException when clusters have not started after 30 minutes */ - public String createAuroraCluster() throws InterruptedException { + public String createAuroraCluster( + String username, + String password, + String dbName, + String identifier, + String region, + String engine, + String instanceClass, + String version, + int numInstances, + ArrayList instances) + throws InterruptedException { // Create Cluster final Tag testRunnerTag = Tag.builder().key("env").value("test-runner").build(); final CreateDbClusterRequest dbClusterRequest = CreateDbClusterRequest.builder() - .dbClusterIdentifier(dbIdentifier) + .dbClusterIdentifier(identifier) .databaseName(dbName) - .masterUsername(dbUsername) - .masterUserPassword(dbPassword) - .sourceRegion(dbRegion.id()) + .masterUsername(username) + .masterUserPassword(password) + .sourceRegion(region) .enableIAMDatabaseAuthentication(true) - .engine(dbEngine) - .engineVersion(dbEngineVersion) + .engine(engine) + .engineVersion(version) .storageEncrypted(true) .tags(testRunnerTag) .build(); @@ -270,15 +267,15 @@ public String createAuroraCluster() throws InterruptedException { rdsClient.createDBCluster(dbClusterRequest); // Create Instances - for (int i = 1; i <= numOfInstances; i++) { - final String instanceName = dbIdentifier + "-" + i; + for (int i = 1; i <= numInstances; i++) { + final String instanceName = identifier + "-" + i; rdsClient.createDBInstance( CreateDbInstanceRequest.builder() - .dbClusterIdentifier(dbIdentifier) + .dbClusterIdentifier(identifier) .dbInstanceIdentifier(instanceName) - .dbInstanceClass(dbInstanceClass) - .engine(dbEngine) - .engineVersion(dbEngineVersion) + .dbInstanceClass(instanceClass) + .engine(engine) + .engineVersion(version) .publiclyAccessible(true) .tags(testRunnerTag) .build()); @@ -290,7 +287,7 @@ public String createAuroraCluster() throws InterruptedException { waiter.waitUntilDBInstanceAvailable( (requestBuilder) -> requestBuilder.filters( - Filter.builder().name("db-cluster-id").values(dbIdentifier).build()), + Filter.builder().name("db-cluster-id").values(identifier).build()), (configurationBuilder) -> configurationBuilder.waitTimeout(Duration.ofMinutes(30))); if (waiterResponse.matched().exception().isPresent()) { @@ -303,12 +300,12 @@ public String createAuroraCluster() throws InterruptedException { rdsClient.describeDBInstances( (builder) -> builder.filters( - Filter.builder().name("db-cluster-id").values(dbIdentifier).build())); + Filter.builder().name("db-cluster-id").values(identifier).build())); final String endpoint = dbInstancesResult.dbInstances().get(0).endpoint().address(); final String clusterDomainPrefix = endpoint.substring(endpoint.indexOf('.') + 1); for (DBInstance instance : dbInstancesResult.dbInstances()) { - this.instances.add( + instances.add( new TestInstanceInfo( instance.dbInstanceIdentifier(), instance.endpoint().address(), @@ -324,19 +321,28 @@ public String createAuroraCluster() throws InterruptedException { * @return An endpoint for one of the instances * @throws InterruptedException when clusters have not started after 30 minutes */ - public String createMultiAzCluster() throws InterruptedException { + public String createMultiAzCluster(String username, + String password, + String dbName, + String identifier, + String region, + String engine, + String instanceClass, + String version, + ArrayList instances) + throws InterruptedException { // Create Cluster final Tag testRunnerTag = Tag.builder().key("env").value("test-runner").build(); CreateDbClusterRequest.Builder clusterBuilder = CreateDbClusterRequest.builder() - .dbClusterIdentifier(dbIdentifier) + .dbClusterIdentifier(identifier) .publiclyAccessible(true) .databaseName(dbName) - .masterUsername(dbUsername) - .masterUserPassword(dbPassword) - .sourceRegion(dbRegion.id()) - .engine(dbEngine) - .engineVersion(dbEngineVersion) + .masterUsername(username) + .masterUserPassword(password) + .sourceRegion(region) + .engine(engine) + .engineVersion(version) .enablePerformanceInsights(false) .backupRetentionPeriod(1) .storageEncrypted(true) @@ -344,7 +350,7 @@ public String createMultiAzCluster() throws InterruptedException { clusterBuilder = clusterBuilder.allocatedStorage(100) - .dbClusterInstanceClass(dbInstanceClass) + .dbClusterInstanceClass(instanceClass) .storageType("io1") .iops(1000); @@ -358,7 +364,7 @@ public String createMultiAzCluster() throws InterruptedException { waiter.waitUntilDBInstanceAvailable( (requestBuilder) -> requestBuilder.filters( - Filter.builder().name("db-cluster-id").values(dbIdentifier).build()), + Filter.builder().name("db-cluster-id").values(identifier).build()), (configurationBuilder) -> configurationBuilder.waitTimeout(Duration.ofMinutes(30))); if (waiterResponse.matched().exception().isPresent()) { @@ -371,12 +377,12 @@ public String createMultiAzCluster() throws InterruptedException { rdsClient.describeDBInstances( (builder) -> builder.filters( - Filter.builder().name("db-cluster-id").values(dbIdentifier).build())); + Filter.builder().name("db-cluster-id").values(identifier).build())); final String endpoint = dbInstancesResult.dbInstances().get(0).endpoint().address(); final String clusterDomainPrefix = endpoint.substring(endpoint.indexOf('.') + 1); for (DBInstance instance : dbInstancesResult.dbInstances()) { - this.instances.add( + instances.add( new TestInstanceInfo( instance.dbInstanceIdentifier(), instance.endpoint().address(), @@ -393,7 +399,7 @@ public String createMultiAzCluster() throws InterruptedException { * @return the instance info of the new instance * @throws InterruptedException if the new instance is not available within 5 minutes */ - public TestInstanceInfo createInstance(String instanceId) throws InterruptedException { + public TestInstanceInfo createInstance(String instanceClass, String instanceId) throws InterruptedException { final Tag testRunnerTag = Tag.builder().key("env").value("test-runner").build(); final TestEnvironmentInfo info = TestEnvironment.getCurrent().getInfo(); @@ -401,7 +407,7 @@ public TestInstanceInfo createInstance(String instanceId) throws InterruptedExce CreateDbInstanceRequest.builder() .dbClusterIdentifier(info.getAuroraClusterName()) .dbInstanceIdentifier(instanceId) - .dbInstanceClass(dbInstanceClass) + .dbInstanceClass(instanceClass) .engine(info.getDatabaseEngine()) .engineVersion(info.getDatabaseEngineVersion()) .publiclyAccessible(true) From fe81eb9a35bfc51b16049ab7f405d33a9da89020 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Mon, 20 Jan 2025 10:17:31 -0800 Subject: [PATCH 09/21] Rename TestEnvironment classes --- .../test/java/integration/DriverHelper.java | 36 +++--- .../container/ConnectionStringHelper.java | 72 ++++++------ ...ronment.java => ContainerEnvironment.java} | 16 +-- .../integration/container/ProxyHelper.java | 8 +- .../container/TestDriverProvider.java | 30 ++--- .../DisableOnTestFeatureCondition.java | 4 +- ...bleBasedOnEnvironmentFeatureExtension.java | 4 +- .../EnableOnDatabaseEngineCondition.java | 4 +- ...leOnDatabaseEngineDeploymentCondition.java | 4 +- .../EnableOnNumOfInstancesCondition.java | 4 +- .../EnableOnTestFeatureCondition.java | 4 +- .../tests/AdvancedPerformanceTest.java | 60 +++++----- .../tests/AuroraConnectivityTests.java | 6 +- .../container/tests/AuroraFailoverTest.java | 110 +++++++++--------- .../container/tests/AutoscalingTests.java | 6 +- .../tests/AwsIamIntegrationTest.java | 41 ++++--- .../tests/BasicConnectivityTests.java | 68 +++++------ .../container/tests/CustomEndpointTest.java | 12 +- .../container/tests/DataSourceTests.java | 26 ++--- .../container/tests/HikariTests.java | 44 +++---- .../container/tests/PerformanceTest.java | 32 ++--- .../ReadWriteSplittingPerformanceTest.java | 11 +- .../tests/ReadWriteSplittingTests.java | 28 ++--- .../container/tests/SpringTests.java | 6 +- ...tEnvironment.java => HostEnvironment.java} | 56 ++++----- .../java/integration/host/TestRunner.java | 4 +- .../java/integration/util/TestUtility.java | 42 +++---- .../test/resources/logging-test.properties | 2 +- 28 files changed, 369 insertions(+), 371 deletions(-) rename wrapper/src/test/java/integration/container/{TestEnvironment.java => ContainerEnvironment.java} (95%) rename wrapper/src/test/java/integration/host/{TestEnvironment.java => HostEnvironment.java} (96%) diff --git a/wrapper/src/test/java/integration/DriverHelper.java b/wrapper/src/test/java/integration/DriverHelper.java index 4175b6cc9..0781c4f64 100644 --- a/wrapper/src/test/java/integration/DriverHelper.java +++ b/wrapper/src/test/java/integration/DriverHelper.java @@ -18,7 +18,7 @@ import com.mysql.cj.conf.PropertyKey; import integration.container.TestDriver; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManager; @@ -38,8 +38,8 @@ public class DriverHelper { public static String getDriverProtocol() { return getDriverProtocol( - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - TestEnvironment.getCurrent().getCurrentDriver()); + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + ContainerEnvironment.getCurrent().getCurrentDriver()); } public static String getDriverProtocol(DatabaseEngine databaseEngine) { @@ -75,13 +75,13 @@ public static String getDriverProtocol(DatabaseEngine databaseEngine, TestDriver public static String getWrapperDriverProtocol() { return getWrapperDriverProtocol( - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - TestEnvironment.getCurrent().getCurrentDriver()); + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + ContainerEnvironment.getCurrent().getCurrentDriver()); } public static String getWrapperDriverProtocol(TestDriver testDriver) { return getWrapperDriverProtocol( - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), testDriver); + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), testDriver); } public static String getWrapperDriverProtocol( @@ -117,7 +117,7 @@ public static String getDriverClassname(DatabaseEngine databaseEngine) { } public static String getDriverClassname() { - return getDriverClassname(TestEnvironment.getCurrent().getCurrentDriver()); + return getDriverClassname(ContainerEnvironment.getCurrent().getCurrentDriver()); } public static String getDriverClassname(TestDriver testDriver) { @@ -134,7 +134,7 @@ public static String getDriverClassname(TestDriver testDriver) { } public static String getDataSourceClassname() { - return getDataSourceClassname(TestEnvironment.getCurrent().getCurrentDriver()); + return getDataSourceClassname(ContainerEnvironment.getCurrent().getCurrentDriver()); } public static String getDataSourceClassname(TestDriver testDriver) { @@ -151,7 +151,7 @@ public static String getDataSourceClassname(TestDriver testDriver) { } public static Class getConnectionClass() { - return getConnectionClass(TestEnvironment.getCurrent().getCurrentDriver()); + return getConnectionClass(ContainerEnvironment.getCurrent().getCurrentDriver()); } public static Class getConnectionClass(TestDriver testDriver) { @@ -169,13 +169,13 @@ public static Class getConnectionClass(TestDriver testDriver) { public static String getDriverRequiredParameters() { return getDriverRequiredParameters( - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - TestEnvironment.getCurrent().getCurrentDriver()); + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + ContainerEnvironment.getCurrent().getCurrentDriver()); } public static String getDriverRequiredParameters(TestDriver testDriver) { return getDriverRequiredParameters( - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), testDriver); + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), testDriver); } public static String getDriverRequiredParameters( @@ -187,7 +187,7 @@ public static String getDriverRequiredParameters( } public static String getHostnameSql() { - return getHostnameSql(TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine()); + return getHostnameSql(ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine()); } public static String getHostnameSql(DatabaseEngine databaseEngine) { @@ -204,7 +204,7 @@ public static String getHostnameSql(DatabaseEngine databaseEngine) { // This method should be used on connections with a target driver ONLY! public static void setConnectTimeout(Properties props, long timeout, TimeUnit timeUnit) { - setConnectTimeout(TestEnvironment.getCurrent().getCurrentDriver(), props, timeout, timeUnit); + setConnectTimeout(ContainerEnvironment.getCurrent().getCurrentDriver(), props, timeout, timeUnit); } // This method should be used on connections with a target driver ONLY! @@ -229,7 +229,7 @@ public static void setConnectTimeout( // This method should be used on connections with a target driver ONLY! public static void setSocketTimeout(Properties props, long timeout, TimeUnit timeUnit) { - setSocketTimeout(TestEnvironment.getCurrent().getCurrentDriver(), props, timeout, timeUnit); + setSocketTimeout(ContainerEnvironment.getCurrent().getCurrentDriver(), props, timeout, timeUnit); } // This method should be used on connections with a target driver ONLY! @@ -254,7 +254,7 @@ public static void setSocketTimeout( // This method should be used on connections with a target driver ONLY! public static void setTcpKeepAlive(Properties props, boolean enabled) { - setTcpKeepAlive(TestEnvironment.getCurrent().getCurrentDriver(), props, enabled); + setTcpKeepAlive(ContainerEnvironment.getCurrent().getCurrentDriver(), props, enabled); } // This method should be used on connections with a target driver ONLY! @@ -278,7 +278,7 @@ public static void setTcpKeepAlive(TestDriver testDriver, Properties props, bool public static void setMonitoringConnectTimeout( Properties props, long timeout, TimeUnit timeUnit) { setMonitoringConnectTimeout( - TestEnvironment.getCurrent().getCurrentDriver(), props, timeout, timeUnit); + ContainerEnvironment.getCurrent().getCurrentDriver(), props, timeout, timeUnit); } // This method should be used on connections with a target driver ONLY! @@ -306,7 +306,7 @@ public static void setMonitoringConnectTimeout( // This method should be used on connections with a target driver ONLY! public static void setMonitoringSocketTimeout(Properties props, long timeout, TimeUnit timeUnit) { setMonitoringSocketTimeout( - TestEnvironment.getCurrent().getCurrentDriver(), props, timeout, timeUnit); + ContainerEnvironment.getCurrent().getCurrentDriver(), props, timeout, timeUnit); } // This method should be used on connections with a target driver ONLY! diff --git a/wrapper/src/test/java/integration/container/ConnectionStringHelper.java b/wrapper/src/test/java/integration/container/ConnectionStringHelper.java index 5867270a9..35e35ad04 100644 --- a/wrapper/src/test/java/integration/container/ConnectionStringHelper.java +++ b/wrapper/src/test/java/integration/container/ConnectionStringHelper.java @@ -29,24 +29,24 @@ public class ConnectionStringHelper { public static String getUrl() { return getUrl( - TestEnvironment.getCurrent().getCurrentDriver(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent().getCurrentDriver(), + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); } public static String getUrl(String host, int port, String databaseName) { - return getUrl(TestEnvironment.getCurrent().getCurrentDriver(), host, port, databaseName); + return getUrl(ContainerEnvironment.getCurrent().getCurrentDriver(), host, port, databaseName); } public static String getUrl( @@ -54,7 +54,7 @@ public static String getUrl( String host, int port, String databaseName) { - final DatabaseEngine databaseEngine = TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(); + final DatabaseEngine databaseEngine = ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(); final String requiredParameters = DriverHelper.getDriverRequiredParameters(databaseEngine, testDriver); final String url = DriverHelper.getDriverProtocol(databaseEngine, testDriver) + host @@ -67,7 +67,7 @@ public static String getUrl( } public static String getUrlWithPlugins(String host, int port, String databaseName, String wrapperPlugins) { - final String url = getUrl(TestEnvironment.getCurrent().getCurrentDriver(), host, port, databaseName); + final String url = getUrl(ContainerEnvironment.getCurrent().getCurrentDriver(), host, port, databaseName); return url + (url.contains("?") ? "&" : "?") + "wrapperPlugins=" @@ -94,125 +94,125 @@ public static String getUrlWithPlugins( */ public static String getWrapperUrl() { return getWrapperUrl( - TestEnvironment.getCurrent().getCurrentDriver(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent().getCurrentDriver(), + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); } public static String getWrapperUrl(TestInstanceInfo instance) { return getWrapperUrl( - TestEnvironment.getCurrent().getCurrentDriver(), + ContainerEnvironment.getCurrent().getCurrentDriver(), instance.getHost(), instance.getPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); } public static String getWrapperUrl(String host, int port, String databaseName) { - return getWrapperUrl(TestEnvironment.getCurrent().getCurrentDriver(), host, port, databaseName); + return getWrapperUrl(ContainerEnvironment.getCurrent().getCurrentDriver(), host, port, databaseName); } public static String getWrapperUrl( TestDriver testDriver, String host, int port, String databaseName) { return DriverHelper.getWrapperDriverProtocol( - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), testDriver) + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), testDriver) + host + ":" + port + "/" + databaseName + DriverHelper.getDriverRequiredParameters( - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), testDriver); + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), testDriver); } public static String getWrapperReaderClusterUrl() { return ConnectionStringHelper.getWrapperUrl( - TestEnvironment.getCurrent().getCurrentDriver(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent().getCurrentDriver(), + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterReadOnlyEndpoint(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterReadOnlyEndpointPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); } public static String getProxyWrapperUrl() { return getWrapperUrl( - TestEnvironment.getCurrent().getCurrentDriver(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent().getCurrentDriver(), + ContainerEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances() .get(0) .getHost(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances() .get(0) .getPort(), - TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()); + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()); } public static String getProxyUrl() { return getUrl( - TestEnvironment.getCurrent().getCurrentDriver(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent().getCurrentDriver(), + ContainerEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances() .get(0) .getHost(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances() .get(0) .getPort(), - TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()); + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()); } public static String getWrapperClusterEndpointUrl() { - if (StringUtils.isNullOrEmpty(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint())) { + if (StringUtils.isNullOrEmpty(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint())) { throw new RuntimeException("Cluster Endpoint is not available in this test environment."); } return getWrapperUrl( - TestEnvironment.getCurrent().getCurrentDriver(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent().getCurrentDriver(), + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpoint(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpointPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); } public static Properties getDefaultProperties() { final Properties props = new Properties(); props.setProperty( PropertyDefinition.USER.name, - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); props.setProperty( PropertyDefinition.PASSWORD.name, - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); final Set features = - TestEnvironment.getCurrent().getInfo().getRequest().getFeatures(); + ContainerEnvironment.getCurrent().getInfo().getRequest().getFeatures(); props.setProperty(PropertyDefinition.ENABLE_TELEMETRY.name, "true"); props.setProperty(PropertyDefinition.TELEMETRY_SUBMIT_TOPLEVEL.name, "true"); props.setProperty( diff --git a/wrapper/src/test/java/integration/container/TestEnvironment.java b/wrapper/src/test/java/integration/container/ContainerEnvironment.java similarity index 95% rename from wrapper/src/test/java/integration/container/TestEnvironment.java rename to wrapper/src/test/java/integration/container/ContainerEnvironment.java index 55054c9d7..7bdbf3b2c 100644 --- a/wrapper/src/test/java/integration/container/TestEnvironment.java +++ b/wrapper/src/test/java/integration/container/ContainerEnvironment.java @@ -45,27 +45,27 @@ import software.amazon.jdbc.Driver; import software.amazon.jdbc.util.StringUtils; -public class TestEnvironment { +public class ContainerEnvironment { - private static final Logger LOGGER = Logger.getLogger(TestEnvironment.class.getName()); + private static final Logger LOGGER = Logger.getLogger(ContainerEnvironment.class.getName()); - private static TestEnvironment env; + private static ContainerEnvironment env; private TestEnvironmentInfo info; private HashMap proxies; private TestDriver currentDriver; - private TestEnvironment() {} + private ContainerEnvironment() {} - public static synchronized TestEnvironment getCurrent() { + public static synchronized ContainerEnvironment getCurrent() { if (env == null) { env = create(); } return env; } - private static TestEnvironment create() { - TestEnvironment environment = new TestEnvironment(); + private static ContainerEnvironment create() { + ContainerEnvironment environment = new ContainerEnvironment(); String infoJson = System.getenv("TEST_ENV_INFO_JSON"); @@ -154,7 +154,7 @@ private static TestEnvironment create() { return environment; } - private static void initProxies(TestEnvironment environment) { + private static void initProxies(ContainerEnvironment environment) { environment.proxies = new HashMap<>(); int proxyControlPort = environment.info.getProxyDatabaseInfo().getControlPort(); diff --git a/wrapper/src/test/java/integration/container/ProxyHelper.java b/wrapper/src/test/java/integration/container/ProxyHelper.java index 76fbd3e68..eae726321 100644 --- a/wrapper/src/test/java/integration/container/ProxyHelper.java +++ b/wrapper/src/test/java/integration/container/ProxyHelper.java @@ -27,14 +27,14 @@ public class ProxyHelper { /** Stops all traffic to and from server. */ public static void disableAllConnectivity() { - for (Proxy proxy : TestEnvironment.getCurrent().getProxies()) { + for (Proxy proxy : ContainerEnvironment.getCurrent().getProxies()) { disableConnectivity(proxy); } } /** Stops all traffic to and from server. */ public static void disableConnectivity(String instanceName) { - Proxy proxy = TestEnvironment.getCurrent().getProxy(instanceName); + Proxy proxy = ContainerEnvironment.getCurrent().getProxy(instanceName); if (proxy == null) { throw new RuntimeException("Proxy for instance " + instanceName + " not found."); } @@ -65,14 +65,14 @@ private static void disableConnectivity(Proxy proxy) { /** Allow traffic to and from server. */ public static void enableAllConnectivity() { - for (Proxy proxy : TestEnvironment.getCurrent().getProxies()) { + for (Proxy proxy : ContainerEnvironment.getCurrent().getProxies()) { enableConnectivity(proxy); } } /** Allow traffic to and from server. */ public static void enableConnectivity(String instanceName) { - Proxy proxy = TestEnvironment.getCurrent().getProxy(instanceName); + Proxy proxy = ContainerEnvironment.getCurrent().getProxy(instanceName); if (proxy == null) { throw new RuntimeException("Proxy for instance " + instanceName + " not found."); } diff --git a/wrapper/src/test/java/integration/container/TestDriverProvider.java b/wrapper/src/test/java/integration/container/TestDriverProvider.java index e187f4db1..de9919ef9 100644 --- a/wrapper/src/test/java/integration/container/TestDriverProvider.java +++ b/wrapper/src/test/java/integration/container/TestDriverProvider.java @@ -71,7 +71,7 @@ public Stream provideTestTemplateInvocationContex ExtensionContext context) { ArrayList resultContextList = new ArrayList<>(); - for (TestDriver testDriver : TestEnvironment.getCurrent().getAllowedTestDrivers()) { + for (TestDriver testDriver : ContainerEnvironment.getCurrent().getAllowedTestDrivers()) { TestTemplateInvocationContext testTemplateInvocationContext = getEnvironment(context, testDriver); resultContextList.add(testTemplateInvocationContext); @@ -89,7 +89,7 @@ public String getDisplayName(int invocationIndex) { invocationIndex, context.getDisplayName(), testDriver, - TestEnvironment.getCurrent().getInfo().getRequest().getDisplayName()); + ContainerEnvironment.getCurrent().getInfo().getRequest().getDisplayName()); } @Override @@ -101,7 +101,7 @@ public List getAdditionalExtensions() { new BeforeEachCallback() { @Override public void beforeEach(ExtensionContext context) throws Exception { - boolean tracesEnabled = TestEnvironment.getCurrent() + boolean tracesEnabled = ContainerEnvironment.getCurrent() .getInfo() .getRequest() .getFeatures() @@ -116,11 +116,11 @@ public void beforeEach(ExtensionContext context) throws Exception { Segment segment = AWSXRay.beginSegment("test: setup"); segment.putAnnotation("engine", - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine().toString()); + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine().toString()); segment.putAnnotation("deployment", - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment().toString()); + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment().toString()); segment.putAnnotation("targetJVM", - TestEnvironment.getCurrent().getInfo().getRequest().getTargetJvm().toString()); + ContainerEnvironment.getCurrent().getInfo().getRequest().getTargetJvm().toString()); if (testName != null) { segment.putAnnotation("testName", testName); } @@ -129,7 +129,7 @@ public void beforeEach(ExtensionContext context) throws Exception { registerDrivers(testDriver); - if (TestEnvironment.getCurrent().getInfo().getRequest().getFeatures() + if (ContainerEnvironment.getCurrent().getInfo().getRequest().getFeatures() .contains(TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED)) { // Enable all proxies ProxyHelper.enableAllConnectivity(); @@ -140,7 +140,7 @@ public void beforeEach(ExtensionContext context) throws Exception { || isAnnotated(context.getTestClass(), MakeSureFirstInstanceWriter.class); final DatabaseEngineDeployment deployment = - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(); + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(); if (deployment == DatabaseEngineDeployment.AURORA || deployment == DatabaseEngineDeployment.RDS_MULTI_AZ_CLUSTER) { @@ -168,11 +168,11 @@ public void beforeEach(ExtensionContext context) throws Exception { } if (!success) { fail("Cluster " - + TestEnvironment.getCurrent().getInfo().getAuroraClusterName() + + ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName() + " is not healthy."); } LOGGER.finest("Cluster " - + TestEnvironment.getCurrent().getInfo().getAuroraClusterName() + + ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName() + " is healthy."); } @@ -188,7 +188,7 @@ public void beforeEach(ExtensionContext context) throws Exception { @Override public void afterEach(ExtensionContext context) throws Exception { - Set features = TestEnvironment.getCurrent() + Set features = ContainerEnvironment.getCurrent() .getInfo() .getRequest() .getFeatures(); @@ -209,7 +209,7 @@ public void afterEach(ExtensionContext context) throws Exception { private static void registerDrivers(final TestDriver testDriver) throws SQLException { DriverHelper.unregisterAllDrivers(); DriverHelper.registerDriver(testDriver); - TestEnvironment.getCurrent().setCurrentDriver(testDriver); + ContainerEnvironment.getCurrent().setCurrentDriver(testDriver); LOGGER.finest("Registered " + testDriver + " driver."); } @@ -223,7 +223,7 @@ private static void clearCaches() { private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter) throws InterruptedException, SQLException { - final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); + final TestEnvironmentInfo testInfo = ContainerEnvironment.getCurrent().getInfo(); final TestEnvironmentRequest testRequest = testInfo.getRequest(); final TestUtility auroraUtil = TestUtility.getUtility(testInfo); @@ -294,7 +294,7 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter public static void rebootCluster() throws InterruptedException { - final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); + final TestEnvironmentInfo testInfo = ContainerEnvironment.getCurrent().getInfo(); final TestUtility auroraUtil = TestUtility.getUtility(testInfo); List instanceIDs = testInfo.getDatabaseInfo().getInstances().stream() @@ -317,7 +317,7 @@ public static void rebootCluster() throws InterruptedException { public static void rebootAllClusterInstances() throws InterruptedException { - final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); + final TestEnvironmentInfo testInfo = ContainerEnvironment.getCurrent().getInfo(); final TestUtility auroraUtil = TestUtility.getUtility(testInfo); List instanceIDs = testInfo.getDatabaseInfo().getInstances().stream() diff --git a/wrapper/src/test/java/integration/container/condition/DisableOnTestFeatureCondition.java b/wrapper/src/test/java/integration/container/condition/DisableOnTestFeatureCondition.java index 841383cae..0f2b27da3 100644 --- a/wrapper/src/test/java/integration/container/condition/DisableOnTestFeatureCondition.java +++ b/wrapper/src/test/java/integration/container/condition/DisableOnTestFeatureCondition.java @@ -19,7 +19,7 @@ import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation; import integration.TestEnvironmentFeatures; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import java.util.Arrays; import java.util.Set; import org.junit.jupiter.api.extension.ConditionEvaluationResult; @@ -34,7 +34,7 @@ public DisableOnTestFeatureCondition() {} public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { Set features = - TestEnvironment.getCurrent().getInfo().getRequest().getFeatures(); + ContainerEnvironment.getCurrent().getInfo().getRequest().getFeatures(); boolean disabled = findAnnotation(context.getElement(), DisableOnTestFeature.class) diff --git a/wrapper/src/test/java/integration/container/condition/EnableBasedOnEnvironmentFeatureExtension.java b/wrapper/src/test/java/integration/container/condition/EnableBasedOnEnvironmentFeatureExtension.java index ff8c07e67..2d725b08d 100644 --- a/wrapper/src/test/java/integration/container/condition/EnableBasedOnEnvironmentFeatureExtension.java +++ b/wrapper/src/test/java/integration/container/condition/EnableBasedOnEnvironmentFeatureExtension.java @@ -17,7 +17,7 @@ package integration.container.condition; import integration.container.TestDriver; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import java.util.logging.Logger; import org.junit.jupiter.api.extension.ConditionEvaluationResult; import org.junit.jupiter.api.extension.ExecutionCondition; @@ -36,7 +36,7 @@ public EnableBasedOnEnvironmentFeatureExtension(TestDriver testDriver) { @Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { - if (!TestEnvironment.getCurrent().isTestDriverAllowed(this.testDriver)) { + if (!ContainerEnvironment.getCurrent().isTestDriverAllowed(this.testDriver)) { return ConditionEvaluationResult.disabled("Disabled by test environment features."); } return ConditionEvaluationResult.enabled("Test enabled"); diff --git a/wrapper/src/test/java/integration/container/condition/EnableOnDatabaseEngineCondition.java b/wrapper/src/test/java/integration/container/condition/EnableOnDatabaseEngineCondition.java index 9cca39f2b..a5b6fb9dd 100644 --- a/wrapper/src/test/java/integration/container/condition/EnableOnDatabaseEngineCondition.java +++ b/wrapper/src/test/java/integration/container/condition/EnableOnDatabaseEngineCondition.java @@ -19,7 +19,7 @@ import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation; import integration.DatabaseEngine; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import java.util.Arrays; import java.util.logging.Logger; import org.junit.jupiter.api.extension.ConditionEvaluationResult; @@ -37,7 +37,7 @@ public EnableOnDatabaseEngineCondition() {} public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { final DatabaseEngine databaseEngine = - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(); + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(); boolean enabled = findAnnotation(context.getElement(), EnableOnDatabaseEngine.class) diff --git a/wrapper/src/test/java/integration/container/condition/EnableOnDatabaseEngineDeploymentCondition.java b/wrapper/src/test/java/integration/container/condition/EnableOnDatabaseEngineDeploymentCondition.java index c927ec02f..b13cfa45f 100644 --- a/wrapper/src/test/java/integration/container/condition/EnableOnDatabaseEngineDeploymentCondition.java +++ b/wrapper/src/test/java/integration/container/condition/EnableOnDatabaseEngineDeploymentCondition.java @@ -19,7 +19,7 @@ import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation; import integration.DatabaseEngineDeployment; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import java.util.Arrays; import java.util.logging.Logger; import org.junit.jupiter.api.extension.ConditionEvaluationResult; @@ -37,7 +37,7 @@ public EnableOnDatabaseEngineDeploymentCondition() {} public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { final DatabaseEngineDeployment databaseEngineDeployment = - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(); + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(); boolean enabled = findAnnotation(context.getElement(), EnableOnDatabaseEngineDeployment.class) diff --git a/wrapper/src/test/java/integration/container/condition/EnableOnNumOfInstancesCondition.java b/wrapper/src/test/java/integration/container/condition/EnableOnNumOfInstancesCondition.java index c33a3359d..7f783f9ee 100644 --- a/wrapper/src/test/java/integration/container/condition/EnableOnNumOfInstancesCondition.java +++ b/wrapper/src/test/java/integration/container/condition/EnableOnNumOfInstancesCondition.java @@ -18,7 +18,7 @@ import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import java.util.logging.Logger; import org.junit.jupiter.api.extension.ConditionEvaluationResult; import org.junit.jupiter.api.extension.ExecutionCondition; @@ -35,7 +35,7 @@ public EnableOnNumOfInstancesCondition() {} public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { final int actualNumOfInstances = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().size(); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().size(); boolean enabled = findAnnotation(context.getElement(), EnableOnNumOfInstances.class) diff --git a/wrapper/src/test/java/integration/container/condition/EnableOnTestFeatureCondition.java b/wrapper/src/test/java/integration/container/condition/EnableOnTestFeatureCondition.java index 673a3379e..db6373051 100644 --- a/wrapper/src/test/java/integration/container/condition/EnableOnTestFeatureCondition.java +++ b/wrapper/src/test/java/integration/container/condition/EnableOnTestFeatureCondition.java @@ -19,7 +19,7 @@ import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation; import integration.TestEnvironmentFeatures; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import java.util.Arrays; import java.util.Set; import java.util.logging.Logger; @@ -38,7 +38,7 @@ public EnableOnTestFeatureCondition() {} public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { final Set features = - TestEnvironment.getCurrent().getInfo().getRequest().getFeatures(); + ContainerEnvironment.getCurrent().getInfo().getRequest().getFeatures(); boolean enabled = findAnnotation(context.getElement(), EnableOnTestFeature.class) diff --git a/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java b/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java index 16439c6e0..ff9eb628f 100644 --- a/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java +++ b/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java @@ -28,7 +28,7 @@ import integration.TestEnvironmentFeatures; import integration.container.ConnectionStringHelper; import integration.container.TestDriverProvider; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import integration.container.aurora.TestAuroraHostListProvider; import integration.container.aurora.TestPluginServiceImpl; import integration.container.condition.EnableOnTestFeature; @@ -188,9 +188,9 @@ public void test_AdvancedPerformance() throws IOException { String.format( "./build/reports/tests/AdvancedPerformanceResults_" + "Db_%s_Driver_%s_Instances_%d.xlsx", - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - TestEnvironment.getCurrent().getCurrentDriver(), - TestEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances()), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + ContainerEnvironment.getCurrent().getCurrentDriver(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances()), perfDataList); perfDataList.clear(); } @@ -238,7 +238,7 @@ private void doMeasurePerformance(int sleepDelayMillis) throws InterruptedExcept private void ensureDnsHealthy() throws UnknownHostException, InterruptedException { LOGGER.finest( "Writer is " - + TestEnvironment.getCurrent() + + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() @@ -246,7 +246,7 @@ private void ensureDnsHealthy() throws UnknownHostException, InterruptedExceptio .getInstanceId()); final String writerIpAddress = InetAddress.getByName( - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() @@ -256,10 +256,10 @@ private void ensureDnsHealthy() throws UnknownHostException, InterruptedExceptio LOGGER.finest("Writer resolves to " + writerIpAddress); LOGGER.finest( "Cluster Endpoint is " - + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint()); + + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint()); String clusterIpAddress = InetAddress.getByName( - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint()) + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint()) .getHostAddress(); LOGGER.finest("Cluster Endpoint resolves to " + clusterIpAddress); @@ -269,7 +269,7 @@ private void ensureDnsHealthy() throws UnknownHostException, InterruptedExceptio Thread.sleep(1000); clusterIpAddress = InetAddress.getByName( - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint()) + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint()) .getHostAddress(); LOGGER.finest("Cluster Endpoint resolves to " + clusterIpAddress); } @@ -328,15 +328,15 @@ private Thread getThread_DirectDriver( final Connection conn = openConnectionWithRetry( ConnectionStringHelper.getUrlWithPlugins( - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpoint(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpointPort(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getDefaultDbName(), @@ -369,7 +369,7 @@ private Thread getThread_DirectDriver( PerfStat data = new PerfStat(); data.paramFailoverDelayMillis = sleepDelayMillis; data.paramDriverName = - "DirectDriver - " + TestEnvironment.getCurrent().getCurrentDriver(); + "DirectDriver - " + ContainerEnvironment.getCurrent().getCurrentDriver(); data.failureDetectionTimeMillis = TimeUnit.NANOSECONDS.toMillis(failureTimeNano); LOGGER.finest("DirectDriver Collected data: " + data); perfDataList.add(data); @@ -410,15 +410,15 @@ private Thread getThread_WrapperEfm( final Connection conn = openConnectionWithRetry( ConnectionStringHelper.getWrapperUrl( - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpoint(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpointPort(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getDefaultDbName()), @@ -452,7 +452,7 @@ private Thread getThread_WrapperEfm( data.paramFailoverDelayMillis = sleepDelayMillis; data.paramDriverName = String.format( - "AWS Wrapper (%s, EFM)", TestEnvironment.getCurrent().getCurrentDriver()); + "AWS Wrapper (%s, EFM)", ContainerEnvironment.getCurrent().getCurrentDriver()); data.failureDetectionTimeMillis = TimeUnit.NANOSECONDS.toMillis(failureTimeNano); LOGGER.finest("WrapperEfm Collected data: " + data); perfDataList.add(data); @@ -494,15 +494,15 @@ private Thread getThread_WrapperEfmFailover( final Connection conn = openConnectionWithRetry( ConnectionStringHelper.getWrapperUrl( - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpoint(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpointPort(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getDefaultDbName()), @@ -538,7 +538,7 @@ private Thread getThread_WrapperEfmFailover( data.paramDriverName = String.format( "AWS Wrapper (%s, EFM, Failover)", - TestEnvironment.getCurrent().getCurrentDriver()); + ContainerEnvironment.getCurrent().getCurrentDriver()); data.reconnectTimeMillis = TimeUnit.NANOSECONDS.toMillis(failureTimeNano); LOGGER.finest("WrapperEfmFailover Collected data: " + data); perfDataList.add(data); @@ -565,7 +565,7 @@ private Thread getThread_DNS( try { currentClusterIpAddress = InetAddress.getByName( - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpoint()) @@ -579,7 +579,7 @@ private Thread getThread_DNS( String clusterIpAddress = InetAddress.getByName( - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpoint()) @@ -591,7 +591,7 @@ private Thread getThread_DNS( Thread.sleep(1000); clusterIpAddress = InetAddress.getByName( - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpoint()) @@ -644,7 +644,7 @@ private Connection openConnectionWithRetry(String url, Properties props) { } private void failoverCluster() throws InterruptedException { - String clusterId = TestEnvironment.getCurrent().getInfo().getAuroraClusterName(); + String clusterId = ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName(); String randomNode = auroraUtil.getRandomDBClusterReaderInstanceId(clusterId); auroraUtil.failoverClusterToTarget(clusterId, randomNode); } @@ -652,7 +652,7 @@ private void failoverCluster() throws InterruptedException { private void ensureClusterHealthy() throws InterruptedException { auroraUtil.waitUntilClusterHasRightState( - TestEnvironment.getCurrent().getInfo().getAuroraClusterName()); + ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName()); // Always get the latest topology info with writer as first List latestTopology = new ArrayList<>(); @@ -661,7 +661,7 @@ private void ensureClusterHealthy() throws InterruptedException { // Wait up to 5min long startTimeNano = System.nanoTime(); while ((latestTopology.size() - != TestEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances() + != ContainerEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances() || !auroraUtil.isDBInstanceWriter(latestTopology.get(0))) && TimeUnit.NANOSECONDS.toMinutes(System.nanoTime() - startTimeNano) < 5) { @@ -675,13 +675,13 @@ private void ensureClusterHealthy() throws InterruptedException { } assertTrue( auroraUtil.isDBInstanceWriter( - TestEnvironment.getCurrent().getInfo().getAuroraClusterName(), latestTopology.get(0))); + ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName(), latestTopology.get(0))); String currentWriter = latestTopology.get(0); // Adjust database info to reflect a current writer and to move corresponding instance to // position 0. - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().moveInstanceFirst(currentWriter); - TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().moveInstanceFirst(currentWriter); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().moveInstanceFirst(currentWriter); + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().moveInstanceFirst(currentWriter); auroraUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(5)); diff --git a/wrapper/src/test/java/integration/container/tests/AuroraConnectivityTests.java b/wrapper/src/test/java/integration/container/tests/AuroraConnectivityTests.java index 2d450b32f..473697cd9 100644 --- a/wrapper/src/test/java/integration/container/tests/AuroraConnectivityTests.java +++ b/wrapper/src/test/java/integration/container/tests/AuroraConnectivityTests.java @@ -24,7 +24,7 @@ import integration.container.ConnectionStringHelper; import integration.container.TestDriver; import integration.container.TestDriverProvider; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import integration.container.condition.DisableOnTestFeature; import integration.container.condition.EnableOnDatabaseEngineDeployment; import integration.container.condition.EnableOnNumOfInstances; @@ -63,10 +63,10 @@ public void test_WrapperConnectionReaderClusterWithEfmEnabled(TestDriver testDri final Properties props = new Properties(); props.setProperty( PropertyDefinition.USER.name, - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); props.setProperty( PropertyDefinition.PASSWORD.name, - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); props.setProperty(PropertyDefinition.CONNECT_TIMEOUT.name, "10000"); props.setProperty(PropertyDefinition.SOCKET_TIMEOUT.name, "10000"); props.setProperty(PropertyDefinition.PLUGINS.name, "efm"); diff --git a/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java b/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java index a1b089b82..5c0723040 100644 --- a/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java +++ b/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java @@ -33,7 +33,7 @@ import integration.container.ProxyHelper; import integration.container.TestDriver; import integration.container.TestDriverProvider; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import integration.container.condition.DisableOnTestFeature; import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.EnableOnTestDriver; @@ -88,7 +88,7 @@ public class AuroraFailoverTest { @BeforeEach public void setUpEach() { this.currentWriter = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(0) + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(0) .getInstanceId(); } @@ -103,7 +103,7 @@ public void test_failFromWriterToNewWriter_failOnConnectionInvocation() final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProps(); @@ -112,7 +112,7 @@ public void test_failFromWriterToNewWriter_failOnConnectionInvocation() ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { // Crash Instance1 and nominate a new writer @@ -140,7 +140,7 @@ public void test_failFromWriterToNewWriter_failOnConnectionBoundObjectInvocation final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProps(); @@ -149,7 +149,7 @@ public void test_failFromWriterToNewWriter_failOnConnectionBoundObjectInvocation ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { final Statement stmt = conn.createStatement(); @@ -176,7 +176,7 @@ public void test_failFromWriterToNewWriter_failOnConnectionBoundObjectInvocation public void test_failFromReaderToWriter() throws SQLException { // Connect to the only available reader instance final TestInstanceInfo instanceInfo = - TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstances().get(1); + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstances().get(1); final String instanceId = instanceInfo.getInstanceId(); final Properties props = initDefaultProxiedProps(); @@ -185,7 +185,7 @@ public void test_failFromReaderToWriter() throws SQLException { ConnectionStringHelper.getWrapperUrl( instanceInfo.getHost(), instanceInfo.getPort(), - TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()), + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()), props)) { // Crash the reader instance @@ -211,7 +211,7 @@ public void test_writerFailWithinTransaction_setAutoCommitFalse() final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProps(); @@ -220,7 +220,7 @@ public void test_writerFailWithinTransaction_setAutoCommitFalse() ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { final Statement testStmt1 = conn.createStatement(); @@ -271,7 +271,7 @@ public void test_writerFailWithinTransaction_startTransaction() final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProps(); @@ -280,7 +280,7 @@ public void test_writerFailWithinTransaction_startTransaction() ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { final Statement testStmt1 = conn.createStatement(); @@ -331,8 +331,8 @@ public void test_writerFailWithinTransaction_startTransaction() @EnableOnTestFeature(TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED) public void testServerFailoverWithIdleConnections() throws SQLException, InterruptedException { final List idleConnections = new ArrayList<>(); - final String clusterEndpoint = TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint(); - final int clusterEndpointPort = TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpointPort(); + final String clusterEndpoint = ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint(); + final int clusterEndpointPort = ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpointPort(); final Properties props = initDefaultProps(); props.setProperty(PropertyDefinition.PLUGINS.name, "auroraConnectionTracker,failover"); @@ -343,7 +343,7 @@ public void testServerFailoverWithIdleConnections() throws SQLException, Interru ConnectionStringHelper.getWrapperUrl( clusterEndpoint, clusterEndpointPort, - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)); } @@ -352,12 +352,12 @@ public void testServerFailoverWithIdleConnections() throws SQLException, Interru ConnectionStringHelper.getWrapperUrl( clusterEndpoint, clusterEndpointPort, - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { final String instanceId = auroraUtil.queryInstanceId( - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), conn); assertEquals(this.currentWriter, instanceId); @@ -373,8 +373,8 @@ public void testServerFailoverWithIdleConnections() throws SQLException, Interru assertThrows( FailoverSQLException.class, () -> auroraUtil.queryInstanceId( - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), conn)); } @@ -385,12 +385,12 @@ public void testServerFailoverWithIdleConnections() throws SQLException, Interru ConnectionStringHelper.getWrapperUrl( clusterEndpoint, clusterEndpointPort, - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { final String instanceId = auroraUtil.queryInstanceId( - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), conn); if (this.currentWriter.equals(instanceId)) { @@ -414,9 +414,9 @@ public void test_DataSourceWriterConnection_BasicFailover() throws SQLException, InterruptedException { TestInstanceInfo initialWriterInstanceInfo = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(0); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(0); TestInstanceInfo nominatedWriterInstanceInfo = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(1); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(1); final String nominatedWriterId = nominatedWriterInstanceInfo.getInstanceId(); try (final Connection conn = @@ -435,9 +435,9 @@ public void test_DataSourceWriterConnection_BasicFailover() // Assert that we are connected to the new writer after failover happens. List instanceIDs = null; - for (TestInstanceInfo instanceInfo : TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances()) { + for (TestInstanceInfo instanceInfo : ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances()) { if (instanceInfo == initialWriterInstanceInfo - && TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment() + && ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment() == DatabaseEngineDeployment.RDS_MULTI_AZ_CLUSTER) { // Old writer node for RDS MultiAz clusters (usually) isn't available for a long time after failover. // Let's skip this node and fetch topology from another node. @@ -445,13 +445,13 @@ public void test_DataSourceWriterConnection_BasicFailover() } try { instanceIDs = auroraUtil.getAuroraInstanceIds( - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), ConnectionStringHelper.getUrl( instanceInfo.getHost(), instanceInfo.getPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); if (!instanceIDs.isEmpty()) { break; } @@ -488,9 +488,9 @@ public void test_takeOverConnectionProperties() throws SQLException, Interrupted final Connection establishCacheConnection = DriverManager.getConnection( ConnectionStringHelper.getWrapperUrl( - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpointPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint(), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpointPort(), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props); establishCacheConnection.close(); @@ -499,9 +499,9 @@ public void test_takeOverConnectionProperties() throws SQLException, Interrupted try (final Connection conn = DriverManager.getConnection( ConnectionStringHelper.getWrapperUrl( - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpointPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint(), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpointPort(), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { // Verify that connection accepts multi-statement sql @@ -530,7 +530,7 @@ public void test_failFromWriterWhereKeepSessionStateOnFailoverIsTrue() final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProps(); @@ -539,7 +539,7 @@ public void test_failFromWriterWhereKeepSessionStateOnFailoverIsTrue() ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { conn.setAutoCommit(false); @@ -593,7 +593,7 @@ public void test_failFromWriterWhereKeepSessionStateOnFailoverIsTrue() public void test_writerFailover_writerReelected() throws SQLException, InterruptedException { final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstance(initialWriterId); + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProxiedProps(); PropertyDefinition.SOCKET_TIMEOUT.set(props, "2000"); @@ -603,7 +603,7 @@ public void test_writerFailover_writerReelected() throws SQLException, Interrupt ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { ExecutorService executor = Executors.newFixedThreadPool(1, r -> { @@ -646,7 +646,7 @@ public void test_writerFailover_writerReelected() throws SQLException, Interrupt public void test_readerFailover_readerOrWriter() throws SQLException, InterruptedException { final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProps(); props.setProperty("failoverMode", "reader-or-writer"); @@ -656,7 +656,7 @@ public void test_readerFailover_readerOrWriter() throws SQLException, Interrupte ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { // Crash Instance1 and nominate a new writer @@ -672,7 +672,7 @@ public void test_readerFailover_readerOrWriter() throws SQLException, Interrupte public void test_readerFailover_strictReader() throws SQLException, InterruptedException { final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProps(); props.setProperty("failoverMode", "strict-reader"); @@ -682,7 +682,7 @@ public void test_readerFailover_strictReader() throws SQLException, InterruptedE ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { // Crash Instance1 and nominate a new writer @@ -701,7 +701,7 @@ public void test_readerFailover_strictReader() throws SQLException, InterruptedE public void test_readerFailover_writerReelected() throws SQLException, InterruptedException { final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstance(initialWriterId); + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProxiedProps(); PropertyDefinition.SOCKET_TIMEOUT.set(props, "2000"); @@ -712,7 +712,7 @@ public void test_readerFailover_writerReelected() throws SQLException, Interrupt ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { ExecutorService executor = Executors.newFixedThreadPool(1, r -> { @@ -766,8 +766,8 @@ protected Properties initDefaultProxiedProps() { PropertyDefinition.SOCKET_TIMEOUT.set(props, "10000"); AuroraHostListProvider.CLUSTER_INSTANCE_HOST_PATTERN.set( props, - "?." + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointSuffix() - + ":" + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointPort()); + "?." + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointSuffix() + + ":" + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointPort()); return props; } @@ -779,7 +779,7 @@ protected Connection createDataSourceConnectionWithFailoverUsingInstanceId( // Configure the property names for the underlying driver-specific data source: ds.setJdbcProtocol(DriverHelper.getDriverProtocol()); ds.setServerName(instanceEndpoint); - ds.setDatabase(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + ds.setDatabase(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); // Specify the driver-specific data source: ds.setTargetDataSourceClassName(DriverHelper.getDataSourceClassname()); @@ -788,8 +788,8 @@ protected Connection createDataSourceConnectionWithFailoverUsingInstanceId( Properties targetDataSourceProps = ConnectionStringHelper.getDefaultProperties(); targetDataSourceProps.setProperty("wrapperPlugins", this.getFailoverPlugin()); - if (TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB - && TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() + if (ContainerEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB + && ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() == DatabaseEngine.MYSQL) { // Connecting to Mysql database with MariaDb driver requires a configuration parameter // "permitMysqlScheme" @@ -802,7 +802,7 @@ protected Connection createDataSourceConnectionWithFailoverUsingInstanceId( ds.setTargetDataSourceProperties(targetDataSourceProps); return ds.getConnection( - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); } } diff --git a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java index 184643f9e..cd082b97a 100644 --- a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java +++ b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java @@ -29,7 +29,7 @@ import integration.TestInstanceInfo; import integration.container.ConnectionStringHelper; import integration.container.TestDriverProvider; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import integration.container.condition.EnableOnDatabaseEngineDeployment; import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.EnableOnTestFeature; @@ -107,7 +107,7 @@ public void test_pooledConnectionAutoScaling_setReadOnlyOnOldConnection() AuroraHostListProvider.CLUSTER_TOPOLOGY_REFRESH_RATE_MS.set(props, Long.toString(topologyRefreshRateMs)); - final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); + final TestEnvironmentInfo testInfo = ContainerEnvironment.getCurrent().getInfo(); final List instances = testInfo.getDatabaseInfo().getInstances(); final int originalClusterSize = instances.size(); final long poolExpirationNanos = TimeUnit.MINUTES.toNanos(3); @@ -185,7 +185,7 @@ public void test_pooledConnectionAutoScaling_failoverFromDeletedReader() AuroraHostListProvider.CLUSTER_TOPOLOGY_REFRESH_RATE_MS.set(props, Long.toString(topologyRefreshRateMs)); - final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); + final TestEnvironmentInfo testInfo = ContainerEnvironment.getCurrent().getInfo(); final List instances = testInfo.getDatabaseInfo().getInstances(); final HikariPooledConnectionProvider provider = new HikariPooledConnectionProvider(getHikariConfig(instances.size() * 5)); diff --git a/wrapper/src/test/java/integration/container/tests/AwsIamIntegrationTest.java b/wrapper/src/test/java/integration/container/tests/AwsIamIntegrationTest.java index 96ddcfbd3..d49ba3dfb 100644 --- a/wrapper/src/test/java/integration/container/tests/AwsIamIntegrationTest.java +++ b/wrapper/src/test/java/integration/container/tests/AwsIamIntegrationTest.java @@ -24,7 +24,7 @@ import integration.container.ConnectionStringHelper; import integration.container.TestDriver; import integration.container.TestDriverProvider; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import integration.container.condition.DisableOnTestDriver; import integration.container.condition.DisableOnTestFeature; import integration.container.condition.EnableOnTestFeature; @@ -40,7 +40,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.TestTemplate; import org.junit.jupiter.api.extension.ExtendWith; @@ -89,9 +88,9 @@ public void test_AwsIam_WrongDatabaseUsername() { final Properties props = initAwsIamProps( "WRONG_" - + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername() + + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername() + "_USER", - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); Assertions.assertThrows( SQLException.class, @@ -103,7 +102,7 @@ public void test_AwsIam_WrongDatabaseUsername() { @DisableOnTestDriver(TestDriver.MARIADB) public void test_AwsIam_NoDatabaseUsername() { final Properties props = - initAwsIamProps("", TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + initAwsIamProps("", ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); Assertions.assertThrows( SQLException.class, @@ -115,11 +114,11 @@ public void test_AwsIam_NoDatabaseUsername() { @DisableOnTestDriver(TestDriver.MARIADB) public void test_AwsIam_UsingIPAddress() throws UnknownHostException, SQLException { final Properties props = - initAwsIamProps(TestEnvironment.getCurrent().getInfo().getIamUsername(), ""); + initAwsIamProps(ContainerEnvironment.getCurrent().getInfo().getIamUsername(), ""); final String hostIp = hostToIP( - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() @@ -127,7 +126,7 @@ public void test_AwsIam_UsingIPAddress() throws UnknownHostException, SQLExcepti .getHost()); props.setProperty( "iamHost", - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() @@ -138,13 +137,13 @@ public void test_AwsIam_UsingIPAddress() throws UnknownHostException, SQLExcepti DriverManager.getConnection( ConnectionStringHelper.getWrapperUrl( hostIp, - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props); Assertions.assertDoesNotThrow(conn::close); } @@ -154,7 +153,7 @@ public void test_AwsIam_UsingIPAddress() throws UnknownHostException, SQLExcepti @DisableOnTestDriver(TestDriver.MARIADB) public void test_AwsIam_ValidConnectionProperties() throws SQLException { final Properties props = - initAwsIamProps(TestEnvironment.getCurrent().getInfo().getIamUsername(), ""); + initAwsIamProps(ContainerEnvironment.getCurrent().getInfo().getIamUsername(), ""); final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props); @@ -168,7 +167,7 @@ public void test_AwsIam_ValidConnectionProperties() throws SQLException { @DisableOnTestDriver(TestDriver.MARIADB) public void test_AwsIam_ValidConnectionPropertiesNoPassword() throws SQLException { final Properties props = - initAwsIamProps(TestEnvironment.getCurrent().getInfo().getIamUsername(), ""); + initAwsIamProps(ContainerEnvironment.getCurrent().getInfo().getIamUsername(), ""); final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props); conn.close(); @@ -183,14 +182,14 @@ public void test_AwsIam_ValidConnectionPropertiesNoPassword() throws SQLExceptio void test_AwsIam_NoAwsProtocolConnection() throws SQLException { final String dbConn = ConnectionStringHelper.getWrapperUrl(); final Properties validProp = - initAwsIamProps(TestEnvironment.getCurrent().getInfo().getIamUsername(), ""); + initAwsIamProps(ContainerEnvironment.getCurrent().getInfo().getIamUsername(), ""); final Connection conn = DriverManager.getConnection(dbConn, validProp); conn.close(); final Properties invalidProp = initAwsIamProps( - "WRONG_" + TestEnvironment.getCurrent().getInfo().getIamUsername() + "_USER", + "WRONG_" + ContainerEnvironment.getCurrent().getInfo().getIamUsername() + "_USER", ""); Assertions.assertThrows( @@ -205,7 +204,7 @@ void test_AwsIam_NoAwsProtocolConnection() throws SQLException { void test_AwsIam_UserInConnStr() throws SQLException { final String dbConn = ConnectionStringHelper.getWrapperUrl(); final Properties awsIamProp = - initAwsIamProps(TestEnvironment.getCurrent().getInfo().getIamUsername(), ""); + initAwsIamProps(ContainerEnvironment.getCurrent().getInfo().getIamUsername(), ""); awsIamProp.remove(PropertyDefinition.USER.name); final Connection validConn = @@ -214,7 +213,7 @@ void test_AwsIam_UserInConnStr() throws SQLException { + (dbConn.contains("?") ? "&" : "?") + PropertyDefinition.USER.name + "=" - + TestEnvironment.getCurrent().getInfo().getIamUsername(), + + ContainerEnvironment.getCurrent().getInfo().getIamUsername(), awsIamProp); Assertions.assertNotNull(validConn); Assertions.assertThrows( @@ -226,7 +225,7 @@ void test_AwsIam_UserInConnStr() throws SQLException { + PropertyDefinition.USER.name + "=" + "WRONG_" - + TestEnvironment.getCurrent().getInfo().getIamUsername(), + + ContainerEnvironment.getCurrent().getInfo().getIamUsername(), awsIamProp)); } @@ -239,12 +238,12 @@ void test_AwsIam_UserInConnStr() throws SQLException { void test_AwsIam_UserAndPasswordPropertiesArePreserved() throws SQLException { final AwsWrapperDataSource ds = new AwsWrapperDataSource(); ds.setJdbcProtocol(DriverHelper.getDriverProtocol()); - ds.setServerName(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint()); - ds.setDatabase(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + ds.setServerName(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint()); + ds.setDatabase(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); ds.setTargetDataSourceClassName(DriverHelper.getDataSourceClassname()); final Properties props = - initAwsIamProps(TestEnvironment.getCurrent().getInfo().getIamUsername(), ""); + initAwsIamProps(ContainerEnvironment.getCurrent().getInfo().getIamUsername(), ""); ds.setTargetDataSourceProperties(props); try (final Connection conn = ds.getConnection()) { @@ -304,7 +303,7 @@ protected Properties initAwsIamProps(String user, String password) { props.setProperty(PropertyDefinition.PLUGINS.name, "iam"); props.setProperty( IamAuthConnectionPlugin.IAM_REGION.name, - TestEnvironment.getCurrent().getInfo().getRegion()); + ContainerEnvironment.getCurrent().getInfo().getRegion()); props.setProperty(PropertyDefinition.USER.name, user); props.setProperty(PropertyDefinition.PASSWORD.name, password); props.setProperty(PropertyDefinition.TCP_KEEP_ALIVE.name, "false"); diff --git a/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java b/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java index c29cd2cce..949ede922 100644 --- a/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java +++ b/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java @@ -30,7 +30,7 @@ import integration.container.ProxyHelper; import integration.container.TestDriver; import integration.container.TestDriverProvider; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import integration.container.condition.DisableOnTestFeature; import integration.container.condition.EnableOnTestFeature; import java.sql.Connection; @@ -77,19 +77,19 @@ public void test_DirectConnection(TestDriver testDriver) throws SQLException { String url = ConnectionStringHelper.getUrlWithPlugins( testDriver, - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(), ""); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(), ""); LOGGER.finest("Connecting to " + url); final Connection conn = DriverManager.getConnection(url, props); @@ -116,19 +116,19 @@ public void test_WrapperConnection(TestDriver testDriver) throws SQLException { String url = ConnectionStringHelper.getWrapperUrl( testDriver, - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost(), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getPort(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); LOGGER.finest("Connecting to " + url); final Connection conn = DriverManager.getConnection(url, props); @@ -154,14 +154,14 @@ public void test_ProxiedDirectConnection(TestDriver testDriver) throws SQLExcept DriverHelper.setSocketTimeout(testDriver, props, 10, TimeUnit.SECONDS); TestInstanceInfo instanceInfo = - TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstances().get(0); + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstances().get(0); String url = ConnectionStringHelper.getUrlWithPlugins( testDriver, instanceInfo.getHost(), instanceInfo.getPort(), - TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName(), ""); + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName(), ""); LOGGER.finest("Connecting to " + url); final Connection conn = DriverManager.getConnection(url, props); @@ -186,20 +186,20 @@ public void test_ProxiedDirectConnection(TestDriver testDriver) throws SQLExcept @ExtendWith(TestDriverProvider.class) @EnableOnTestFeature(TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED) public void test_ProxiedWrapperConnection() throws SQLException { - LOGGER.info(TestEnvironment.getCurrent().getCurrentDriver().toString()); + LOGGER.info(ContainerEnvironment.getCurrent().getCurrentDriver().toString()); final Properties props = ConnectionStringHelper.getDefaultPropertiesWithNoPlugins(); PropertyDefinition.CONNECT_TIMEOUT.set(props, "10000"); PropertyDefinition.SOCKET_TIMEOUT.set(props, "10000"); TestInstanceInfo instanceInfo = - TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstances().get(0); + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstances().get(0); String url = ConnectionStringHelper.getWrapperUrl( instanceInfo.getHost(), instanceInfo.getPort(), - TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()); + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()); LOGGER.finest("Connecting to " + url); final Connection conn = DriverManager.getConnection(url, props); @@ -225,14 +225,14 @@ public void test_ProxiedWrapperConnection() throws SQLException { public void testSuccessOpenConnectionNoPort() throws SQLException { String url = DriverHelper.getWrapperDriverProtocol() - + TestEnvironment.getCurrent() + + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost() + "/" - + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName() + + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName() + DriverHelper.getDriverRequiredParameters(); LOGGER.finest("Connecting to " + url); @@ -250,7 +250,7 @@ public void testSuccessOpenConnectionNoPort() throws SQLException { public void testFailedConnection(TestDriver testDriver, String url) throws SQLException { DriverHelper.unregisterAllDrivers(); DriverHelper.registerDriver(testDriver); - TestEnvironment.getCurrent().setCurrentDriver(testDriver); + ContainerEnvironment.getCurrent().setCurrentDriver(testDriver); LOGGER.finest("Connecting to " + url); @@ -269,12 +269,12 @@ public void testFailedProperties( TestDriver testDriver, String url, String username, String password) throws SQLException { DriverHelper.unregisterAllDrivers(); DriverHelper.registerDriver(testDriver); - TestEnvironment.getCurrent().setCurrentDriver(testDriver); + ContainerEnvironment.getCurrent().setCurrentDriver(testDriver); - if (TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() + if (ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() == DatabaseEngine.MARIADB - && TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB - && TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment() + && ContainerEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB + && ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment() == DatabaseEngineDeployment.DOCKER && StringUtils.isNullOrEmpty(username)) { // MariaDb driver uses "root" username if no username is provided. Since MariaDb database in @@ -310,7 +310,7 @@ protected static String buildConnectionString( private static Stream testConnectionParameters() { ArrayList results = new ArrayList<>(); - for (TestDriver testDriver : TestEnvironment.getCurrent().getAllowedTestDrivers()) { + for (TestDriver testDriver : ContainerEnvironment.getCurrent().getAllowedTestDrivers()) { // missing connection prefix results.add( @@ -318,20 +318,20 @@ private static Stream testConnectionParameters() { testDriver, buildConnectionString( "", - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost(), String.valueOf( - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getPort()), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(), DriverHelper.getDriverRequiredParameters(testDriver)))); // incorrect database name @@ -340,14 +340,14 @@ private static Stream testConnectionParameters() { testDriver, buildConnectionString( DriverHelper.getWrapperDriverProtocol(testDriver), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost(), String.valueOf( - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() @@ -361,7 +361,7 @@ private static Stream testConnectionParameters() { private static Stream testPropertiesParameters() { ArrayList results = new ArrayList<>(); - for (TestDriver testDriver : TestEnvironment.getCurrent().getAllowedTestDrivers()) { + for (TestDriver testDriver : ContainerEnvironment.getCurrent().getAllowedTestDrivers()) { // missing username results.add( @@ -369,23 +369,23 @@ private static Stream testPropertiesParameters() { testDriver, buildConnectionString( DriverHelper.getWrapperDriverProtocol(testDriver), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost(), String.valueOf( - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getPort()), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(), DriverHelper.getDriverRequiredParameters(testDriver)), "", - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword())); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword())); // missing password results.add( @@ -393,22 +393,22 @@ private static Stream testPropertiesParameters() { testDriver, buildConnectionString( DriverHelper.getWrapperDriverProtocol(testDriver), - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost(), String.valueOf( - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getPort()), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(), DriverHelper.getDriverRequiredParameters(testDriver)), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), "")); } return results.stream(); diff --git a/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java b/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java index 85dede12a..c85491ca5 100644 --- a/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java +++ b/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java @@ -29,7 +29,7 @@ import integration.TestInstanceInfo; import integration.container.ConnectionStringHelper; import integration.container.TestDriverProvider; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import integration.container.condition.DisableOnTestFeature; import integration.container.condition.EnableOnDatabaseEngineDeployment; import integration.container.condition.EnableOnNumOfInstances; @@ -88,7 +88,7 @@ public class CustomEndpointTest { @BeforeAll public static void setupEndpoint() { - TestEnvironmentInfo envInfo = TestEnvironment.getCurrent().getInfo(); + TestEnvironmentInfo envInfo = ContainerEnvironment.getCurrent().getInfo(); String clusterId = envInfo.getAuroraClusterName(); String region = envInfo.getRegion(); @@ -196,7 +196,7 @@ public static void waitUntilEndpointHasMembers(RdsClient client, String endpoint @BeforeEach public void identifyWriter() { this.currentWriter = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(0) + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(0) .getInstanceId(); } @@ -206,7 +206,7 @@ public static void cleanup() { return; } - String region = TestEnvironment.getCurrent().getInfo().getRegion(); + String region = ContainerEnvironment.getCurrent().getInfo().getRegion(); try (RdsClient client = RdsClient.builder().region(Region.of(region)).build()) { deleteEndpoint(client); } @@ -230,7 +230,7 @@ protected Properties initDefaultProps() { @TestTemplate public void testCustomEndpointFailover() throws SQLException, InterruptedException { - final TestDatabaseInfo dbInfo = TestEnvironment.getCurrent().getInfo().getDatabaseInfo(); + final TestDatabaseInfo dbInfo = ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo(); final int port = dbInfo.getClusterEndpointPort(); final Properties props = initDefaultProps(); props.setProperty("failoverMode", "reader-or-writer"); @@ -258,7 +258,7 @@ public void testCustomEndpointFailover() throws SQLException, InterruptedExcepti @TestTemplate public void testCustomEndpointReadWriteSplitting_withCustomEndpointChanges() throws SQLException { - TestEnvironmentInfo envInfo = TestEnvironment.getCurrent().getInfo(); + TestEnvironmentInfo envInfo = ContainerEnvironment.getCurrent().getInfo(); final TestDatabaseInfo dbInfo = envInfo.getDatabaseInfo(); final int port = dbInfo.getClusterEndpointPort(); final Properties props = initDefaultProps(); diff --git a/wrapper/src/test/java/integration/container/tests/DataSourceTests.java b/wrapper/src/test/java/integration/container/tests/DataSourceTests.java index 8f547e639..62fc4404e 100644 --- a/wrapper/src/test/java/integration/container/tests/DataSourceTests.java +++ b/wrapper/src/test/java/integration/container/tests/DataSourceTests.java @@ -26,7 +26,7 @@ import integration.container.ConnectionStringHelper; import integration.container.TestDriver; import integration.container.TestDriverProvider; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import integration.container.condition.DisableOnTestDriver; import integration.container.condition.DisableOnTestFeature; import integration.util.SimpleJndiContextFactory; @@ -65,15 +65,15 @@ public void testConnectionWithDataSourceClassNameAndServerNameFromJndiLookup() throws SQLException, NamingException, IllegalAccessException { final AwsWrapperDataSource ds = new AwsWrapperDataSource(); ds.setJdbcProtocol(DriverHelper.getDriverProtocol()); - ds.setServerName(TestEnvironment.getCurrent() + ds.setServerName(ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost()); - ds.setDatabase(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); - ds.setUser(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); - ds.setPassword(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + ds.setDatabase(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + ds.setUser(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); + ds.setPassword(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); ds.setTargetDataSourceClassName(DriverHelper.getDataSourceClassname()); final Properties targetDataSourceProps = ConnectionStringHelper.getDefaultPropertiesWithNoPlugins(); @@ -105,13 +105,13 @@ public void testConnectionWithDataSourceClassNameAndServerNameFromJndiLookup() try (final Connection conn = dsFromJndiLookup.getConnection( - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword())) { + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword())) { assertTrue(conn.isWrapperFor(DriverHelper.getConnectionClass())); assertEquals( conn.getCatalog(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); assertTrue(conn.isValid(10)); } @@ -125,8 +125,8 @@ public void testConnectionWithDataSourceClassNameAndUrlFromJndiLookup() ds.setTargetDataSourceClassName(DriverHelper.getDataSourceClassname()); ds.setJdbcProtocol(DriverHelper.getDriverProtocol()); ds.setJdbcUrl(ConnectionStringHelper.getUrl()); - ds.setUser(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); - ds.setPassword(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + ds.setUser(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); + ds.setPassword(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); final Properties targetDataSourceProps = new Properties(); targetDataSourceProps.setProperty(PropertyDefinition.PLUGINS.name, ""); @@ -158,14 +158,14 @@ public void testConnectionWithDataSourceClassNameAndUrlFromJndiLookup() try (final Connection conn = dsFromJndiLookup.getConnection( - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword())) { + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword())) { assertTrue(conn instanceof ConnectionWrapper); assertTrue(conn.isWrapperFor(DriverHelper.getConnectionClass())); assertEquals( conn.getCatalog(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); assertTrue(conn.isValid(10)); } diff --git a/wrapper/src/test/java/integration/container/tests/HikariTests.java b/wrapper/src/test/java/integration/container/tests/HikariTests.java index c3c14c970..0608e7946 100644 --- a/wrapper/src/test/java/integration/container/tests/HikariTests.java +++ b/wrapper/src/test/java/integration/container/tests/HikariTests.java @@ -39,7 +39,7 @@ import integration.container.ProxyHelper; import integration.container.TestDriver; import integration.container.TestDriverProvider; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import integration.container.condition.DisableOnTestFeature; import integration.container.condition.EnableOnDatabaseEngineDeployment; import integration.container.condition.EnableOnNumOfInstances; @@ -93,8 +93,8 @@ public void testOpenConnectionWithUrl() throws SQLException { try (final HikariDataSource dataSource = new HikariDataSource()) { final String url = ConnectionStringHelper.getWrapperUrl(); dataSource.setJdbcUrl(url); - dataSource.setUsername(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); - dataSource.setPassword(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + dataSource.setUsername(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); + dataSource.setPassword(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); dataSource.addDataSourceProperty(PLUGINS.name, ""); final Connection conn = dataSource.getConnection(); @@ -119,20 +119,20 @@ public void testOpenConnectionWithDataSourceClassName() throws SQLException { dataSource.setDataSourceClassName(AwsWrapperDataSource.class.getName()); // Configure the connection pool: - dataSource.setUsername(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); - dataSource.setPassword(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + dataSource.setUsername(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); + dataSource.setPassword(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); // Configure AwsWrapperDataSource: dataSource.addDataSourceProperty("jdbcProtocol", DriverHelper.getDriverProtocol()); dataSource.addDataSourceProperty("serverName", - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost()); dataSource.addDataSourceProperty(PropertyDefinition.DATABASE.name, - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); // Specify the driver-specific DataSource for AwsWrapperDataSource: dataSource.addDataSourceProperty("targetDataSourceClassName", @@ -142,8 +142,8 @@ public void testOpenConnectionWithDataSourceClassName() throws SQLException { final Properties targetDataSourceProps = new Properties(); targetDataSourceProps.setProperty(PLUGINS.name, ""); - if (TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB - && TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() + if (ContainerEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB + && ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() == DatabaseEngine.MYSQL) { // Connecting to Mysql database with MariaDb driver requires a configuration parameter // "permitMysqlScheme" @@ -221,7 +221,7 @@ public void testEFMFailover() throws SQLException { final TestUtility auroraUtil = TestUtility.getUtility(); ProxyHelper.disableAllConnectivity(); - final List instances = TestEnvironment.getCurrent() + final List instances = ContainerEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances(); @@ -271,7 +271,7 @@ public void testEFMFailover() throws SQLException { public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation() throws SQLException, InterruptedException { final TestUtility auroraUtil = TestUtility.getUtility(); - final TestProxyDatabaseInfo proxyInfo = TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); + final TestProxyDatabaseInfo proxyInfo = ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); final List instances = proxyInfo.getInstances(); final TestInstanceInfo reader = instances.get(1); final String readerId = reader.getInstanceId(); @@ -313,7 +313,7 @@ public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation() public void testInternalPools_driverReaderFailoverOnGetConnectionInvocation() throws SQLException, InterruptedException { final TestUtility auroraUtil = TestUtility.getUtility(); - final TestProxyDatabaseInfo proxyInfo = TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); + final TestProxyDatabaseInfo proxyInfo = ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); final List instances = proxyInfo.getInstances(); final TestInstanceInfo writer = instances.get(0); final String writerId = writer.getInstanceId(); @@ -363,7 +363,7 @@ public void testInternalPools_driverReaderFailoverOnGetConnectionInvocation() public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation_singleInstance() throws SQLException, InterruptedException { final TestUtility auroraUtil = TestUtility.getUtility(); - final TestProxyDatabaseInfo proxyInfo = TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); + final TestProxyDatabaseInfo proxyInfo = ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); final List instances = proxyInfo.getInstances(); final TestInstanceInfo writer = instances.get(0); final String writerId = writer.getInstanceId(); @@ -413,8 +413,8 @@ private AwsWrapperDataSource createWrapperDataSource(TestInstanceInfo instanceIn "?." + proxyInfo.getInstanceEndpointSuffix()); targetDataSourceProps.setProperty(RdsHostListProvider.CLUSTER_ID.name, "HikariTestsCluster"); - if (TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB - && TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() == DatabaseEngine.MYSQL) { + if (ContainerEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB + && ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() == DatabaseEngine.MYSQL) { targetDataSourceProps.setProperty("permitMysqlScheme", "1"); } @@ -474,7 +474,7 @@ private HikariDataSource createHikariDataSource(final Properties customProps) { private HikariConfig getConfig(final Properties customProps) { final HikariConfig config = new HikariConfig(); final TestProxyDatabaseInfo proxyDatabaseInfo = - TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); config.setUsername(proxyDatabaseInfo.getUsername()); config.setPassword(proxyDatabaseInfo.getPassword()); @@ -495,16 +495,16 @@ configured host (provider with "serverName" property), these attempts may fail. DriverHelper.getDataSourceClassname()); config.addDataSourceProperty("jdbcProtocol", DriverHelper.getDriverProtocol()); config.addDataSourceProperty("serverName", - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances() .get(0) .getHost()); config.addDataSourceProperty("database", - TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()); + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()); config.addDataSourceProperty("serverPort", - Integer.toString(TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo() + Integer.toString(ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo() .getClusterEndpointPort())); final Properties targetDataSourceProps = ConnectionStringHelper.getDefaultProperties(); @@ -513,7 +513,7 @@ configured host (provider with "serverName" property), these attempts may fail. targetDataSourceProps.setProperty( "clusterInstanceHostPattern", "?." - + TestEnvironment.getCurrent() + + ContainerEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstanceEndpointSuffix()); @@ -527,8 +527,8 @@ configured host (provider with "serverName" property), these attempts may fail. targetDataSourceProps.setProperty( HostMonitoringConnectionPlugin.FAILURE_DETECTION_COUNT.name, "1"); - if (TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB - && TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() == DatabaseEngine.MYSQL) { + if (ContainerEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB + && ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() == DatabaseEngine.MYSQL) { // Connecting to Mysql database with MariaDb driver requires a configuration parameter // "permitMysqlScheme" targetDataSourceProps.setProperty("permitMysqlScheme", "1"); diff --git a/wrapper/src/test/java/integration/container/tests/PerformanceTest.java b/wrapper/src/test/java/integration/container/tests/PerformanceTest.java index 8df6c1669..7feef4d3d 100644 --- a/wrapper/src/test/java/integration/container/tests/PerformanceTest.java +++ b/wrapper/src/test/java/integration/container/tests/PerformanceTest.java @@ -30,7 +30,7 @@ import integration.container.ConnectionStringHelper; import integration.container.ProxyHelper; import integration.container.TestDriverProvider; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import integration.container.condition.EnableOnTestFeature; import java.io.File; import java.io.FileOutputStream; @@ -172,9 +172,9 @@ public void test_FailureDetectionTime_EnhancedMonitoringEnabled(final String efm String.format( "./build/reports/tests/EnhancedMonitoringOnly_" + "Db_%s_Driver_%s_Instances_%d_Plugin_%s.xlsx", - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - TestEnvironment.getCurrent().getCurrentDriver(), - TestEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + ContainerEnvironment.getCurrent().getCurrentDriver(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances(), efmPlugin), enhancedFailureMonitoringPerfDataList); enhancedFailureMonitoringPerfDataList.clear(); @@ -254,9 +254,9 @@ public void test_FailureDetectionTime_FailoverAndEnhancedMonitoringEnabled(final String.format( "./build/reports/tests/FailoverWithEnhancedMonitoring_" + "Db_%s_Driver_%s_Instances_%d_Plugin_%s.xlsx", - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - TestEnvironment.getCurrent().getCurrentDriver(), - TestEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + ContainerEnvironment.getCurrent().getCurrentDriver(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances(), plugins.replace(",", "_")), failoverWithEfmPerfDataList); failoverWithEfmPerfDataList.clear(); @@ -290,7 +290,7 @@ private void execute_FailureDetectionTime_FailoverAndEnhancedMonitoringEnabled( props.setProperty( "clusterInstanceHostPattern", "?." - + TestEnvironment.getCurrent() + + ContainerEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstanceEndpointSuffix()); @@ -341,9 +341,9 @@ private void test_FailoverTime_SocketTimeout(final String plugins) throws IOExce String.format( "./build/reports/tests/FailoverWithSocketTimeout_" + "Db_%s_Driver_%s_Instances_%d_Plugins_%s.xlsx", - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - TestEnvironment.getCurrent().getCurrentDriver(), - TestEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + ContainerEnvironment.getCurrent().getCurrentDriver(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances(), plugins.replace(",", "_")), failoverWithSocketTimeoutPerfDataList); failoverWithSocketTimeoutPerfDataList.clear(); @@ -363,7 +363,7 @@ private void execute_FailoverTime_SocketTimeout(final String plugins, int socket props.setProperty( "clusterInstanceHostPattern", "?." - + TestEnvironment.getCurrent() + + ContainerEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstanceEndpointSuffix()); @@ -409,7 +409,7 @@ private void doMeasurePerformance( Thread.sleep(sleepDelayMillis); // Kill network ProxyHelper.disableConnectivity( - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances() @@ -447,7 +447,7 @@ private void doMeasurePerformance( } finally { thread.interrupt(); // Ensure thread has stopped running ProxyHelper.enableConnectivity( - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances() @@ -480,7 +480,7 @@ private Connection openConnectionWithRetry(Properties props) { if (conn == null) { fail( "Can't connect to " - + TestEnvironment.getCurrent() + + ContainerEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances() @@ -497,7 +497,7 @@ private Connection connectToInstance(Properties props) throws SQLException { private String getQuerySql(final int seconds) { final DatabaseEngine databaseEngine = - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(); + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(); switch (databaseEngine) { case PG: return String.format("SELECT pg_sleep(%d)", seconds); diff --git a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingPerformanceTest.java b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingPerformanceTest.java index 1300895c6..11b21e9f7 100644 --- a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingPerformanceTest.java +++ b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingPerformanceTest.java @@ -17,11 +17,10 @@ package integration.container.tests; import com.zaxxer.hikari.HikariConfig; -import integration.DriverHelper; import integration.TestEnvironmentFeatures; import integration.container.ConnectionStringHelper; import integration.container.TestDriverProvider; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.EnableOnTestFeature; import java.io.File; @@ -125,8 +124,8 @@ public void test_switchReaderWriterConnection() "./build/reports/tests/" + "DbEngine_%s_Driver_%s_ReadWriteSplittingPerformanceResults_" + "SwitchReaderWriterConnection.xlsx", - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - TestEnvironment.getCurrent().getCurrentDriver()) + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + ContainerEnvironment.getCurrent().getCurrentDriver()) ); setReadOnlyPerfDataList.clear(); @@ -165,8 +164,8 @@ public void test_switchReaderWriterConnection() "./build/reports/tests/" + "DbEngine_%s_Driver_%s_ReadWriteSplittingPerformanceResults_" + "InternalConnectionPools_SwitchReaderWriterConnection.xlsx", - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - TestEnvironment.getCurrent().getCurrentDriver()) + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + ContainerEnvironment.getCurrent().getCurrentDriver()) ); } diff --git a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java index 0b5cd1aa6..8018123df 100644 --- a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java +++ b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java @@ -37,7 +37,7 @@ import integration.container.ProxyHelper; import integration.container.TestDriver; import integration.container.TestDriverProvider; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import integration.container.aurora.TestPluginServiceImpl; import integration.container.condition.DisableOnTestDriver; import integration.container.condition.DisableOnTestFeature; @@ -95,16 +95,16 @@ public class ReadWriteSplittingTests { protected static Properties getProxiedPropsWithFailover() { final Properties props = getPropsWithFailover(); AuroraHostListProvider.CLUSTER_INSTANCE_HOST_PATTERN.set(props, - "?." + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointSuffix() - + ":" + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointPort()); + "?." + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointSuffix() + + ":" + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointPort()); return props; } protected static Properties getProxiedProps() { final Properties props = getProps(); AuroraHostListProvider.CLUSTER_INSTANCE_HOST_PATTERN.set(props, - "?." + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointSuffix() - + ":" + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointPort()); + "?." + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointSuffix() + + ":" + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointPort()); return props; } @@ -183,7 +183,7 @@ public void test_connectToReader_setReadOnlyTrueFalse() throws SQLException { // Assumes the writer is stored as the first instance and all other instances are readers. protected String getWrapperReaderInstanceUrl() { TestInstanceInfo readerInstance = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(1); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(1); return ConnectionStringHelper.getWrapperUrl(readerInstance); } @@ -310,7 +310,7 @@ public void test_setReadOnlyTrue_allReadersDown() throws SQLException { // Kill all reader instances final List instanceIDs = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().stream() + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().stream() .map(TestInstanceInfo::getInstanceId).collect(Collectors.toList()); for (int i = 1; i < instanceIDs.size(); i++) { ProxyHelper.disableConnectivity(instanceIDs.get(i)); @@ -423,10 +423,10 @@ public void test_failoverToNewWriter_setReadOnlyTrueFalse() // Kill all reader instances final int numOfInstances = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().size(); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().size(); for (int i = 1; i < numOfInstances; i++) { ProxyHelper.disableConnectivity( - TestEnvironment.getCurrent() + ContainerEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() @@ -482,7 +482,7 @@ public void test_failoverToNewReader_setReadOnlyFalseTrue() throws SQLException assertNotEquals(writerConnectionId, readerConnectionId); String otherReaderId = ""; - final List instances = TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances(); + final List instances = ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances(); for (int i = 1; i < instances.size(); i++) { if (!instances.get(i).getInstanceId().equals(readerConnectionId)) { @@ -538,7 +538,7 @@ public void test_failoverReaderToWriter_setReadOnlyTrueFalse() LOGGER.finest("readerConnectionId=" + readerConnectionId); assertNotEquals(writerConnectionId, readerConnectionId); - final List instances = TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo() + final List instances = ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo() .getInstances(); // Kill all instances except the writer @@ -825,7 +825,7 @@ public void test_pooledConnection_differentUsers() throws SQLException { privilegedUserProps); Statement stmt = conn.createStatement()) { stmt.execute("DROP USER IF EXISTS " + limitedUserName); auroraUtil.createUser(conn, limitedUserName, limitedUserPassword); - TestEnvironmentInfo info = TestEnvironment.getCurrent().getInfo(); + TestEnvironmentInfo info = ContainerEnvironment.getCurrent().getInfo(); DatabaseEngine engine = info.getRequest().getDatabaseEngine(); if (DatabaseEngine.MYSQL.equals(engine)) { String db = info.getDatabaseInfo().getDefaultDbName(); @@ -868,7 +868,7 @@ public void test_pooledConnection_leastConnectionsStrategy() throws SQLException ReadWriteSplittingPlugin.READER_HOST_SELECTOR_STRATEGY.set(props, "leastConnections"); final List instances = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances(); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances(); final HikariPooledConnectionProvider provider = new HikariPooledConnectionProvider(getHikariConfig(instances.size())); ConnectionProviderManager.setConnectionProvider(provider); @@ -917,7 +917,7 @@ public void test_pooledConnection_leastConnectionsWithPoolMapping() throws SQLEx } final List instances = - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances(); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances(); // We will be testing all instances excluding the writer and overloaded reader. Each instance // should be tested numOverloadedReaderConnections times to increase the pool connection count // until it equals the connection count of the overloaded reader. diff --git a/wrapper/src/test/java/integration/container/tests/SpringTests.java b/wrapper/src/test/java/integration/container/tests/SpringTests.java index 3a1cb9e3a..74a1f4011 100644 --- a/wrapper/src/test/java/integration/container/tests/SpringTests.java +++ b/wrapper/src/test/java/integration/container/tests/SpringTests.java @@ -21,7 +21,7 @@ import integration.TestEnvironmentFeatures; import integration.container.ConnectionStringHelper; import integration.container.TestDriverProvider; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import integration.container.condition.DisableOnTestFeature; import java.util.Properties; import java.util.Random; @@ -58,8 +58,8 @@ private DataSource getDataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("software.amazon.jdbc.Driver"); dataSource.setUrl(ConnectionStringHelper.getWrapperUrl()); - dataSource.setUsername(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); - dataSource.setPassword(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + dataSource.setUsername(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); + dataSource.setPassword(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); Properties props = ConnectionStringHelper.getDefaultPropertiesWithNoPlugins(); props.setProperty(PropertyDefinition.LOGGER_LEVEL.name, "ALL"); diff --git a/wrapper/src/test/java/integration/host/TestEnvironment.java b/wrapper/src/test/java/integration/host/HostEnvironment.java similarity index 96% rename from wrapper/src/test/java/integration/host/TestEnvironment.java rename to wrapper/src/test/java/integration/host/HostEnvironment.java index dc26f11de..3533447bb 100644 --- a/wrapper/src/test/java/integration/host/TestEnvironment.java +++ b/wrapper/src/test/java/integration/host/HostEnvironment.java @@ -57,9 +57,9 @@ import software.amazon.awssdk.services.rds.model.DBCluster; import software.amazon.jdbc.util.StringUtils; -public class TestEnvironment implements AutoCloseable { +public class HostEnvironment implements AutoCloseable { - private static final Logger LOGGER = Logger.getLogger(TestEnvironment.class.getName()); + private static final Logger LOGGER = Logger.getLogger(HostEnvironment.class.getName()); private static final int NUM_OR_ENV_PRE_CREATE = 1; // create this number of environments in advance private static final ExecutorService envPreCreateExecutor = Executors.newCachedThreadPool(); @@ -106,11 +106,11 @@ public class TestEnvironment implements AutoCloseable { private TestUtility auroraUtil; - private TestEnvironment(TestEnvironmentRequest request) { + private HostEnvironment(TestEnvironmentRequest request) { this.info.setRequest(request); } - public static TestEnvironment build(TestEnvironmentRequest request) throws IOException, URISyntaxException { + public static HostEnvironment build(TestEnvironmentRequest request) throws IOException, URISyntaxException { DatabaseEngineDeployment deployment = request.getDatabaseEngineDeployment(); if (deployment == DatabaseEngineDeployment.AURORA @@ -125,11 +125,11 @@ public static TestEnvironment build(TestEnvironmentRequest request) throws IOExc LOGGER.finest("Building test env: " + request.getEnvPreCreateIndex()); preCreateEnvironment(request.getEnvPreCreateIndex()); - TestEnvironment env; + HostEnvironment env; switch (deployment) { case DOCKER: - env = new TestEnvironment(request); + env = new HostEnvironment(request); initDatabaseParams(env); createDatabaseContainers(env); @@ -174,7 +174,7 @@ public static TestEnvironment build(TestEnvironmentRequest request) throws IOExc return env; } - private static TestEnvironment createAuroraOrMultiAzEnvironment(TestEnvironmentRequest request) + private static HostEnvironment createAuroraOrMultiAzEnvironment(TestEnvironmentRequest request) throws URISyntaxException { EnvPreCreateInfo preCreateInfo = @@ -206,18 +206,18 @@ private static TestEnvironment createAuroraOrMultiAzEnvironment(TestEnvironmentR if (result instanceof Exception) { throw new RuntimeException((Exception) result); } - if (result instanceof TestEnvironment) { - TestEnvironment resultTestEnvironment = (TestEnvironment) result; + if (result instanceof HostEnvironment) { + HostEnvironment resultHostEnvironment = (HostEnvironment) result; LOGGER.finer(() -> String.format("Use pre-created DB cluster: %s.cluster-%s", - resultTestEnvironment.auroraClusterName, resultTestEnvironment.auroraClusterDomain)); + resultHostEnvironment.auroraClusterName, resultHostEnvironment.auroraClusterDomain)); - return resultTestEnvironment; + return resultHostEnvironment; } throw new RuntimeException( "Test environment create error. Unrecognized result type: " + result.getClass().getName()); } else { - TestEnvironment env = new TestEnvironment(request); + HostEnvironment env = new HostEnvironment(request); initDatabaseParams(env); createDbCluster(env); @@ -233,7 +233,7 @@ private static TestEnvironment createAuroraOrMultiAzEnvironment(TestEnvironmentR } - private static void createDatabaseContainers(TestEnvironment env) { + private static void createDatabaseContainers(HostEnvironment env) { ContainerHelper containerHelper = new ContainerHelper(); switch (env.info.getRequest().getDatabaseInstances()) { @@ -325,7 +325,7 @@ private static void createDatabaseContainers(TestEnvironment env) { } } - private static void createDbCluster(TestEnvironment env) throws URISyntaxException { + private static void createDbCluster(HostEnvironment env) throws URISyntaxException { switch (env.info.getRequest().getDatabaseInstances()) { case SINGLE_INSTANCE: @@ -351,7 +351,7 @@ private static void createDbCluster(TestEnvironment env) throws URISyntaxExcepti } } - private static void createDbCluster(TestEnvironment env, int numOfInstances) throws URISyntaxException { + private static void createDbCluster(HostEnvironment env, int numOfInstances) throws URISyntaxException { env.info.setRegion( !StringUtils.isNullOrEmpty(config.rdsDbRegion) @@ -498,7 +498,7 @@ private static void createDbCluster(TestEnvironment env, int numOfInstances) thr } } - private static void authorizeIP(TestEnvironment env) { + private static void authorizeIP(HostEnvironment env) { try { env.runnerIP = env.auroraUtil.getPublicIPAddress(); LOGGER.finest("Test runner IP: " + env.runnerIP); @@ -553,7 +553,7 @@ private static String getRdsEngine(TestEnvironmentRequest request) { } } - private static String getDbEngineVersion(TestEnvironment env) { + private static String getDbEngineVersion(HostEnvironment env) { switch (env.info.getRequest().getDatabaseEngineDeployment()) { case AURORA: return getAuroraDbEngineVersion(env); @@ -565,7 +565,7 @@ private static String getDbEngineVersion(TestEnvironment env) { } } - private static String getAuroraDbEngineVersion(TestEnvironment env) { + private static String getAuroraDbEngineVersion(HostEnvironment env) { String engineName; String systemPropertyVersion; TestEnvironmentRequest request = env.info.getRequest(); @@ -596,7 +596,7 @@ private static String getRdsEngineVersion(TestEnvironmentRequest request) { } private static String findAuroraDbEngineVersion( - TestEnvironment env, + HostEnvironment env, String engineName, String systemPropertyVersion) { @@ -637,7 +637,7 @@ private static int getPort(TestEnvironmentRequest request) { } } - private static void initDatabaseParams(TestEnvironment env) { + private static void initDatabaseParams(HostEnvironment env) { final String dbName = !StringUtils.isNullOrEmpty(config.dbName) ? config.dbName @@ -657,7 +657,7 @@ private static void initDatabaseParams(TestEnvironment env) { env.info.getDatabaseInfo().setDefaultDbName(dbName); } - private static void initAwsCredentials(TestEnvironment env) { + private static void initAwsCredentials(HostEnvironment env) { env.awsAccessKeyId = config.awsAccessKeyId; env.awsSecretAccessKey = config.awsSecretAccessKey; env.awsSessionToken = config.awsSessionToken; @@ -681,7 +681,7 @@ private static void initAwsCredentials(TestEnvironment env) { } } - private static void createProxyContainers(TestEnvironment env) throws IOException { + private static void createProxyContainers(HostEnvironment env) throws IOException { ContainerHelper containerHelper = new ContainerHelper(); int port = getPort(env.info.getRequest()); @@ -760,7 +760,7 @@ private static void createProxyContainers(TestEnvironment env) throws IOExceptio } } - private static void createTestContainer(TestEnvironment env) { + private static void createTestContainer(HostEnvironment env) { final ContainerHelper containerHelper = new ContainerHelper(); if (env.info.getRequest().getFeatures().contains(TestEnvironmentFeatures.RUN_HIBERNATE_TESTS_ONLY)) { @@ -810,7 +810,7 @@ private static void createTestContainer(TestEnvironment env) { env.testContainer.start(); } - private static void createTelemetryXRayContainer(TestEnvironment env) { + private static void createTelemetryXRayContainer(HostEnvironment env) { String xrayAwsRegion = !StringUtils.isNullOrEmpty(System.getenv("XRAY_AWS_REGION")) ? System.getenv("XRAY_AWS_REGION") @@ -841,7 +841,7 @@ private static void createTelemetryXRayContainer(TestEnvironment env) { env.telemetryXRayContainer.start(); } - private static void createTelemetryOtlpContainer(TestEnvironment env) { + private static void createTelemetryOtlpContainer(HostEnvironment env) { LOGGER.finest("Creating OTLP telemetry container"); final ContainerHelper containerHelper = new ContainerHelper(); @@ -889,7 +889,7 @@ private static String getContainerBaseImageName(TestEnvironmentRequest request) } } - private static void configureIamAccess(TestEnvironment env) { + private static void configureIamAccess(HostEnvironment env) { if (env.info.getRequest().getDatabaseEngineDeployment() != DatabaseEngineDeployment.AURORA) { throw new UnsupportedOperationException( @@ -934,7 +934,7 @@ private static void configureIamAccess(TestEnvironment env) { } } - private static String getEnvironmentInfoAsString(TestEnvironment env) { + private static String getEnvironmentInfoAsString(HostEnvironment env) { try { final ObjectMapper mapper = new ObjectMapper(); return mapper.writeValueAsString(env.info); @@ -1087,7 +1087,7 @@ private static void preCreateEnvironment(int currentEnvIndex) { LOGGER.finest(() -> String.format("Pre-create environment for [%d] - %s", finalIndex, preCreateInfo.request.getDisplayName())); - final TestEnvironment env = new TestEnvironment(preCreateInfo.request); + final HostEnvironment env = new HostEnvironment(preCreateInfo.request); preCreateInfo.envPreCreateFuture = envPreCreateExecutor.submit(() -> { final long startTime = System.nanoTime(); diff --git a/wrapper/src/test/java/integration/host/TestRunner.java b/wrapper/src/test/java/integration/host/TestRunner.java index 718304873..1337ac66d 100644 --- a/wrapper/src/test/java/integration/host/TestRunner.java +++ b/wrapper/src/test/java/integration/host/TestRunner.java @@ -26,7 +26,7 @@ public class TestRunner { @TestTemplate public void runTests(TestEnvironmentRequest testEnvironmentRequest) throws Exception { - try (final TestEnvironment env = TestEnvironment.build(testEnvironmentRequest)) { + try (final HostEnvironment env = HostEnvironment.build(testEnvironmentRequest)) { env.runTests("in-container"); } } @@ -34,7 +34,7 @@ public void runTests(TestEnvironmentRequest testEnvironmentRequest) throws Excep @TestTemplate public void debugTests(TestEnvironmentRequest testEnvironmentRequest) throws Exception { - try (final TestEnvironment env = TestEnvironment.build(testEnvironmentRequest)) { + try (final HostEnvironment env = HostEnvironment.build(testEnvironmentRequest)) { env.debugTests("in-container"); } } diff --git a/wrapper/src/test/java/integration/util/TestUtility.java b/wrapper/src/test/java/integration/util/TestUtility.java index b7274bdcb..4b8d2065c 100644 --- a/wrapper/src/test/java/integration/util/TestUtility.java +++ b/wrapper/src/test/java/integration/util/TestUtility.java @@ -27,7 +27,7 @@ import integration.TestEnvironmentInfo; import integration.TestInstanceInfo; import integration.container.ConnectionStringHelper; -import integration.container.TestEnvironment; +import integration.container.ContainerEnvironment; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.InetAddress; @@ -401,7 +401,7 @@ public String createMultiAzCluster(String username, */ public TestInstanceInfo createInstance(String instanceClass, String instanceId) throws InterruptedException { final Tag testRunnerTag = Tag.builder().key("env").value("test-runner").build(); - final TestEnvironmentInfo info = TestEnvironment.getCurrent().getInfo(); + final TestEnvironmentInfo info = ContainerEnvironment.getCurrent().getInfo(); rdsClient.createDBInstance( CreateDbInstanceRequest.builder() @@ -797,11 +797,11 @@ public void waitUntilInstanceHasRightState(String instanceId, String... allowedS public List getAuroraInstanceIds() throws SQLException { return getAuroraInstanceIds( - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), ConnectionStringHelper.getUrl(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), - TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); } // The first instance in topology should be a writer! @@ -893,7 +893,7 @@ private String getMultiAzMysqlReplicaWriterInstanceId( public Boolean isDBInstanceWriter(String instanceId) { return isDBInstanceWriter( - TestEnvironment.getCurrent().getInfo().getAuroraClusterName(), instanceId); + ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName(), instanceId); } public Boolean isDBInstanceWriter(String clusterId, String instanceId) { @@ -919,7 +919,7 @@ public List getDBClusterMemberList(String clusterId) { public void makeSureInstancesUp(long timeoutSec) { List instances = new ArrayList<>(); - TestEnvironmentInfo envInfo = TestEnvironment.getCurrent().getInfo(); + TestEnvironmentInfo envInfo = ContainerEnvironment.getCurrent().getInfo(); instances.addAll(envInfo.getDatabaseInfo().getInstances()); instances.addAll(envInfo.getProxyDatabaseInfo().getInstances()); makeSureInstancesUp(instances, timeoutSec); @@ -927,7 +927,7 @@ public void makeSureInstancesUp(long timeoutSec) { public void makeSureInstancesUp(List instances, long timeoutSec) { final ConcurrentHashMap remainingInstances = new ConcurrentHashMap<>(); - final String dbName = TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(); + final String dbName = ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(); instances.forEach((i) -> remainingInstances.put(i.getHost(), true)); @@ -999,15 +999,15 @@ public void assertFirstQueryThrows(Connection connection, Class { String instanceId = queryInstanceId( - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), connection); LOGGER.finest(() -> "Instance ID: " + instanceId); }); } public void failoverClusterAndWaitUntilWriterChanged() throws InterruptedException { - String clusterId = TestEnvironment.getCurrent().getInfo().getAuroraClusterName(); + String clusterId = ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName(); failoverClusterToATargetAndWaitUntilWriterChanged( clusterId, getDBClusterWriterInstanceId(clusterId), @@ -1017,7 +1017,7 @@ public void failoverClusterAndWaitUntilWriterChanged() throws InterruptedExcepti public void failoverClusterToATargetAndWaitUntilWriterChanged( String initialWriterId, String targetWriterId) throws InterruptedException { failoverClusterToATargetAndWaitUntilWriterChanged( - TestEnvironment.getCurrent().getInfo().getAuroraClusterName(), + ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName(), initialWriterId, targetWriterId); } @@ -1027,13 +1027,13 @@ public void failoverClusterToATargetAndWaitUntilWriterChanged( throws InterruptedException { DatabaseEngineDeployment deployment = - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(); + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(); if (deployment == DatabaseEngineDeployment.RDS_MULTI_AZ_CLUSTER) { LOGGER.finest(String.format("failover from: %s", initialWriterId)); } else { LOGGER.finest(String.format("failover from %s to target: %s", initialWriterId, targetWriterId)); } - final TestDatabaseInfo dbInfo = TestEnvironment.getCurrent().getInfo().getDatabaseInfo(); + final TestDatabaseInfo dbInfo = ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo(); final String clusterEndpoint = dbInfo.getClusterEndpoint(); failoverClusterToTarget( @@ -1078,7 +1078,7 @@ public void failoverClusterToATargetAndWaitUntilWriterChanged( LOGGER.finest("Cluster endpoint resolves to (after wait): " + newClusterEndpointIp); // wait until all instances except initial writer instance to be available - List instances = TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances() + List instances = ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances() .stream() .filter(x -> !x.getInstanceId().equalsIgnoreCase(initialWriterId)) .collect(Collectors.toList()); @@ -1283,7 +1283,7 @@ public String getRandomDBClusterReaderInstanceId(String clusterId) { public String getDBClusterWriterInstanceId() { return getDBClusterWriterInstanceId( - TestEnvironment.getCurrent().getInfo().getAuroraClusterName()); + ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName()); } public String getDBClusterWriterInstanceId(String clusterId) { @@ -1327,8 +1327,8 @@ protected String getInstanceIdSql(DatabaseEngine databaseEngine, DatabaseEngineD public String queryInstanceId(Connection connection) throws SQLException { return queryInstanceId( - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), connection); } @@ -1352,7 +1352,7 @@ protected String executeInstanceIdQuery( } public void createUser(Connection conn, String username, String password) throws SQLException { - DatabaseEngine engine = TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(); + DatabaseEngine engine = ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(); String dropUserSql = getCreateUserSql(engine, username, password); try (Statement stmt = conn.createStatement()) { stmt.execute(dropUserSql); @@ -1435,7 +1435,7 @@ public static TestUtility getUtility() { public static TestUtility getUtility(TestEnvironmentInfo info) { if (info == null) { - info = TestEnvironment.getCurrent().getInfo(); + info = ContainerEnvironment.getCurrent().getInfo(); } try { diff --git a/wrapper/src/test/resources/logging-test.properties b/wrapper/src/test/resources/logging-test.properties index 02aab1b46..c736e12fb 100644 --- a/wrapper/src/test/resources/logging-test.properties +++ b/wrapper/src/test/resources/logging-test.properties @@ -26,6 +26,6 @@ software.amazon.jdbc.states.level=INFO integration.level=FINEST integration.container.level=FINEST -integration.host.TestEnvironment.level=FINEST +integration.host.HostEnvironment.level=FINEST io.opentelemetry.sdk.level=SEVERE From 1cc6436d817ec19fcfbc2c89988acab250e937e9 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Mon, 20 Jan 2025 14:07:21 -0800 Subject: [PATCH 10/21] wip --- .../container/tests/AutoscalingTests.java | 14 ++- .../integration/host/HostEnvironment.java | 39 ++----- .../java/integration/util/TestUtility.java | 104 ++++++++---------- 3 files changed, 67 insertions(+), 90 deletions(-) diff --git a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java index cd082b97a..d1773ff05 100644 --- a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java +++ b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java @@ -28,8 +28,8 @@ import integration.TestEnvironmentInfo; import integration.TestInstanceInfo; import integration.container.ConnectionStringHelper; -import integration.container.TestDriverProvider; import integration.container.ContainerEnvironment; +import integration.container.TestDriverProvider; import integration.container.condition.EnableOnDatabaseEngineDeployment; import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.EnableOnTestFeature; @@ -128,8 +128,10 @@ public void test_pooledConnectionAutoScaling_setReadOnlyOnOldConnection() } final Connection newInstanceConn; + final String instanceClass = + auroraUtil.getDbInstanceClass(ContainerEnvironment.getCurrent().getInfo().getRequest()); final TestInstanceInfo newInstance = - auroraUtil.createInstance("auto-scaling-instance"); + auroraUtil.createInstance(instanceClass, "auto-scaling-instance", instances); try { newInstanceConn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props); @@ -144,7 +146,7 @@ public void test_pooledConnectionAutoScaling_setReadOnlyOnOldConnection() .anyMatch((url) -> url.equals(newInstance.getUrl()))); newInstanceConn.setReadOnly(false); } finally { - auroraUtil.deleteInstance(newInstance); + auroraUtil.deleteInstance(newInstance, instances); } final long deletionCheckTimeout = System.nanoTime() + TimeUnit.MINUTES.toNanos(5); @@ -201,8 +203,10 @@ public void test_pooledConnectionAutoScaling_failoverFromDeletedReader() } final Connection newInstanceConn; + final String instanceClass = + auroraUtil.getDbInstanceClass(ContainerEnvironment.getCurrent().getInfo().getRequest()); final TestInstanceInfo newInstance = - auroraUtil.createInstance("auto-scaling-instance"); + auroraUtil.createInstance(instanceClass, "auto-scaling-instance", instances); try { newInstanceConn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(newInstance), props); @@ -214,7 +218,7 @@ public void test_pooledConnectionAutoScaling_failoverFromDeletedReader() assertTrue(provider.getHosts().stream() .anyMatch((url) -> url.equals(newInstance.getUrl()))); } finally { - auroraUtil.deleteInstance(newInstance); + auroraUtil.deleteInstance(newInstance, instances); } auroraUtil.assertFirstQueryThrows(newInstanceConn, FailoverSuccessSQLException.class); diff --git a/wrapper/src/test/java/integration/host/HostEnvironment.java b/wrapper/src/test/java/integration/host/HostEnvironment.java index 3533447bb..6b14eb72d 100644 --- a/wrapper/src/test/java/integration/host/HostEnvironment.java +++ b/wrapper/src/test/java/integration/host/HostEnvironment.java @@ -174,8 +174,7 @@ public static HostEnvironment build(TestEnvironmentRequest request) throws IOExc return env; } - private static HostEnvironment createAuroraOrMultiAzEnvironment(TestEnvironmentRequest request) - throws URISyntaxException { + private static HostEnvironment createAuroraOrMultiAzEnvironment(TestEnvironmentRequest request) { EnvPreCreateInfo preCreateInfo = TestEnvironmentProvider.preCreateInfos.get(request.getEnvPreCreateIndex()); @@ -325,7 +324,7 @@ private static void createDatabaseContainers(HostEnvironment env) { } } - private static void createDbCluster(HostEnvironment env) throws URISyntaxException { + private static void createDbCluster(HostEnvironment env) { switch (env.info.getRequest().getDatabaseInstances()) { case SINGLE_INSTANCE: @@ -351,7 +350,7 @@ private static void createDbCluster(HostEnvironment env) throws URISyntaxExcepti } } - private static void createDbCluster(HostEnvironment env, int numOfInstances) throws URISyntaxException { + private static void createDbCluster(HostEnvironment env, int numOfInstances) { env.info.setRegion( !StringUtils.isNullOrEmpty(config.rdsDbRegion) @@ -431,7 +430,7 @@ private static void createDbCluster(HostEnvironment env, int numOfInstances) thr if (StringUtils.isNullOrEmpty(engineVersion)) { throw new RuntimeException("Failed to get engine version."); } - String instanceClass = getDbInstanceClass(env.info.getRequest()); + String instanceClass = env.auroraUtil.getDbInstanceClass(env.info.getRequest()); LOGGER.finer( "Using " + engine + " " + engineVersion); @@ -459,7 +458,7 @@ private static void createDbCluster(HostEnvironment env, int numOfInstances) thr // remove cluster and instances LOGGER.finer("Deleting cluster " + env.auroraClusterName); - env.auroraUtil.deleteCluster(env.auroraClusterName); + env.auroraUtil.deleteCluster(env.auroraClusterName, env.info.getRequest().getDatabaseEngineDeployment()); LOGGER.finer("Deleted cluster " + env.auroraClusterName); throw new RuntimeException(e); @@ -613,18 +612,6 @@ private static String findAuroraDbEngineVersion( } } - private static String getDbInstanceClass(TestEnvironmentRequest request) { - switch (request.getDatabaseEngineDeployment()) { - case AURORA: - return "db.r5.large"; - case RDS: - case RDS_MULTI_AZ_CLUSTER: - return "db.m5d.large"; - default: - throw new NotImplementedException(request.getDatabaseEngine().toString()); - } - } - private static int getPort(TestEnvironmentRequest request) { switch (request.getDatabaseEngine()) { case MYSQL: @@ -1006,16 +993,14 @@ private String[] buildHibernateCommands(boolean debugMode) { @Override public void close() throws Exception { - if (this.databaseContainers != null) { - for (GenericContainer container : this.databaseContainers) { - try { - container.stop(); - } catch (Exception ex) { - // ignore - } + for (GenericContainer container : this.databaseContainers) { + try { + container.stop(); + } catch (Exception ex) { + // ignore } - this.databaseContainers.clear(); } + this.databaseContainers.clear(); if (this.telemetryXRayContainer != null) { this.telemetryXRayContainer.stop(); @@ -1062,7 +1047,7 @@ private void deleteDbCluster() { if (!this.reuseAuroraDbCluster) { LOGGER.finest("Deleting cluster " + this.auroraClusterName + ".cluster-" + this.auroraClusterDomain); - auroraUtil.deleteCluster(this.auroraClusterName); + auroraUtil.deleteCluster(this.auroraClusterName, this.info.getRequest().getDatabaseEngineDeployment()); LOGGER.finest("Deleted cluster " + this.auroraClusterName + ".cluster-" + this.auroraClusterDomain); } } diff --git a/wrapper/src/test/java/integration/util/TestUtility.java b/wrapper/src/test/java/integration/util/TestUtility.java index 4b8d2065c..abdbfbfa7 100644 --- a/wrapper/src/test/java/integration/util/TestUtility.java +++ b/wrapper/src/test/java/integration/util/TestUtility.java @@ -25,6 +25,7 @@ import integration.DriverHelper; import integration.TestDatabaseInfo; import integration.TestEnvironmentInfo; +import integration.TestEnvironmentRequest; import integration.TestInstanceInfo; import integration.container.ConnectionStringHelper; import integration.container.ContainerEnvironment; @@ -64,6 +65,7 @@ import java.util.logging.Logger; import java.util.stream.Collectors; import org.checkerframework.checker.nullness.qual.Nullable; +import org.testcontainers.shaded.org.apache.commons.lang3.NotImplementedException; import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; import software.amazon.awssdk.auth.credentials.AwsSessionCredentials; @@ -109,30 +111,12 @@ public class TestUtility { private static final Logger LOGGER = Logger.getLogger(TestUtility.class.getName()); - - // Default values -// private String dbUsername = "my_test_username"; -// private String dbPassword = "my_test_password"; -// private String dbName = "test"; -// private String dbIdentifier = "test-identifier"; -// private DatabaseEngineDeployment dbEngineDeployment; -// private String dbEngine = "aurora-postgresql"; -// private String dbEngineVersion = "13.9"; -// private String dbInstanceClass = "db.r5.large"; -// private final Region dbRegion; -// private final String dbSecGroup = "default"; -// private int numOfInstances = 5; -// private ArrayList instances = new ArrayList<>(); - - private RdsClient rdsClient; - private Ec2Client ec2Client; + private static final String DEFAULT_SECURITY_GROUP = "default"; + private static final String DUPLICATE_IP_ERROR_CODE = "InvalidPermission.Duplicate"; private static final Random rand = new Random(); -// private final String rdsEndpoint; - -// private final AwsCredentialsProvider credentialsProvider; - - private static final String DUPLICATE_IP_ERROR_CODE = "InvalidPermission.Duplicate"; + private final RdsClient rdsClient; + private final Ec2Client ec2Client; public TestUtility(String region, String endpoint) throws URISyntaxException { this(getRegionInternal(region), endpoint, DefaultCredentialsProvider.create()); @@ -291,7 +275,7 @@ public String createAuroraCluster( (configurationBuilder) -> configurationBuilder.waitTimeout(Duration.ofMinutes(30))); if (waiterResponse.matched().exception().isPresent()) { - deleteCluster(); + deleteCluster(identifier, DatabaseEngineDeployment.AURORA); throw new InterruptedException( "Unable to start AWS RDS Cluster & Instances after waiting for 30 minutes"); } @@ -368,7 +352,7 @@ public String createMultiAzCluster(String username, (configurationBuilder) -> configurationBuilder.waitTimeout(Duration.ofMinutes(30))); if (waiterResponse.matched().exception().isPresent()) { - deleteCluster(); + deleteCluster(identifier, DatabaseEngineDeployment.RDS_MULTI_AZ_CLUSTER); throw new InterruptedException( "Unable to start AWS RDS Cluster & Instances after waiting for 30 minutes"); } @@ -399,7 +383,8 @@ public String createMultiAzCluster(String username, * @return the instance info of the new instance * @throws InterruptedException if the new instance is not available within 5 minutes */ - public TestInstanceInfo createInstance(String instanceClass, String instanceId) throws InterruptedException { + public TestInstanceInfo createInstance(String instanceClass, String instanceId, List instances) + throws InterruptedException { final Tag testRunnerTag = Tag.builder().key("env").value("test-runner").build(); final TestEnvironmentInfo info = ContainerEnvironment.getCurrent().getInfo(); @@ -447,7 +432,7 @@ public TestInstanceInfo createInstance(String instanceClass, String instanceId) instance.dbInstanceIdentifier(), instance.endpoint().address(), instance.endpoint().port()); - this.instances.add(instanceInfo); + instances.add(instanceInfo); return instanceInfo; } @@ -457,13 +442,14 @@ public TestInstanceInfo createInstance(String instanceClass, String instanceId) * @param instanceToDelete the info for the instance to delete * @throws InterruptedException if the instance has not been deleted within 5 minutes */ - public void deleteInstance(TestInstanceInfo instanceToDelete) throws InterruptedException { + public void deleteInstance(TestInstanceInfo instanceToDelete, List instances) + throws InterruptedException { rdsClient.deleteDBInstance( DeleteDbInstanceRequest.builder() .dbInstanceIdentifier(instanceToDelete.getInstanceId()) .skipFinalSnapshot(true) .build()); - this.instances.remove(instanceToDelete); + instances.remove(instanceToDelete); final RdsWaiter waiter = rdsClient.waiter(); WaiterResponse waiterResponse = waiter.waitUntilDBInstanceDeleted( @@ -521,7 +507,7 @@ public void ec2AuthorizeIP(String ipAddress) { .toPort(65535) .build(); ec2Client.authorizeSecurityGroupIngress( - (builder) -> builder.groupName(dbSecGroup).ipPermissions(ipPermission)); + (builder) -> builder.groupName(DEFAULT_SECURITY_GROUP).ipPermissions(ipPermission)); } catch (Ec2Exception exception) { if (!DUPLICATE_IP_ERROR_CODE.equalsIgnoreCase(exception.awsErrorDetails().errorCode())) { throw exception; @@ -534,7 +520,7 @@ private boolean ipExists(String ipAddress) { ec2Client.describeSecurityGroups( (builder) -> builder - .groupNames(dbSecGroup) + .groupNames(DEFAULT_SECURITY_GROUP) .filters( software.amazon.awssdk.services.ec2.model.Filter.builder() .name("ip-permission.cidr") @@ -555,7 +541,7 @@ public void ec2DeauthorizesIP(String ipAddress) { ec2Client.revokeSecurityGroupIngress( (builder) -> builder - .groupName(dbSecGroup) + .groupName(DEFAULT_SECURITY_GROUP) .cidrIp(ipAddress + "/32") .ipProtocol("-1") // All protocols .fromPort(0) // For all ports @@ -566,47 +552,39 @@ public void ec2DeauthorizesIP(String ipAddress) { } /** - * Destroys all instances and clusters. Removes IP from EC2 whitelist. + * Deletes the specified cluster. Removes IP from EC2 whitelist. * * @param identifier database identifier to delete */ - public void deleteCluster(String identifier) { - dbIdentifier = identifier; - deleteCluster(); - } - - /** - * Destroys all instances and clusters. Removes IP from EC2 whitelist. - * - */ - public void deleteCluster() { - - switch (this.dbEngineDeployment) { + public void deleteCluster(String identifier, DatabaseEngineDeployment deployment) { + switch (deployment) { case AURORA: - this.deleteAuroraCluster(); + this.deleteAuroraCluster(identifier); break; case RDS_MULTI_AZ_CLUSTER: - this.deleteMultiAzCluster(); + this.deleteMultiAzCluster(identifier); break; default: - throw new UnsupportedOperationException(this.dbEngineDeployment.toString()); + throw new UnsupportedOperationException(deployment.toString()); } } /** * Destroys all instances and clusters. Removes IP from EC2 whitelist. */ - public void deleteAuroraCluster() { + public void deleteAuroraCluster(String identifier) { + List members = getDBCluster(identifier).dbClusterMembers(); + // Tear down instances - for (int i = 1; i <= numOfInstances; i++) { + for (DBClusterMember member : members) { try { rdsClient.deleteDBInstance( DeleteDbInstanceRequest.builder() - .dbInstanceIdentifier(dbIdentifier + "-" + i) + .dbInstanceIdentifier(member.dbInstanceIdentifier()) .skipFinalSnapshot(true) .build()); } catch (Exception ex) { - LOGGER.finest("Error deleting instance " + dbIdentifier + "-" + i + ". " + ex.getMessage()); + LOGGER.finest("Error deleting instance '" + member.dbInstanceIdentifier() + "': " + ex.getMessage()); // Ignore this error and continue with other instances } } @@ -616,7 +594,7 @@ public void deleteAuroraCluster() { while (--remainingAttempts > 0) { try { DeleteDbClusterResponse response = rdsClient.deleteDBCluster( - (builder -> builder.skipFinalSnapshot(true).dbClusterIdentifier(dbIdentifier))); + (builder -> builder.skipFinalSnapshot(true).dbClusterIdentifier(identifier))); if (response.sdkHttpResponse().isSuccessful()) { break; } @@ -625,7 +603,7 @@ public void deleteAuroraCluster() { } catch (DbClusterNotFoundException ex) { // ignore } catch (Exception ex) { - LOGGER.warning("Error deleting db cluster " + dbIdentifier + ": " + ex); + LOGGER.warning("Error deleting db cluster " + identifier + ": " + ex); } } } @@ -633,14 +611,14 @@ public void deleteAuroraCluster() { /** * Destroys all instances and clusters. */ - public void deleteMultiAzCluster() { + public void deleteMultiAzCluster(String identifier) { // deleteDBinstance requests are not necessary to delete a multi-az cluster. // Tear down cluster int remainingAttempts = 5; while (--remainingAttempts > 0) { try { DeleteDbClusterResponse response = rdsClient.deleteDBCluster( - (builder -> builder.skipFinalSnapshot(true).dbClusterIdentifier(dbIdentifier))); + (builder -> builder.skipFinalSnapshot(true).dbClusterIdentifier(identifier))); if (response.sdkHttpResponse().isSuccessful()) { break; } @@ -649,7 +627,7 @@ public void deleteMultiAzCluster() { } catch (DbClusterNotFoundException ex) { // ignore } catch (Exception ex) { - LOGGER.warning("Error deleting db cluster " + dbIdentifier + ": " + ex); + LOGGER.warning("Error deleting db cluster " + identifier + ": " + ex); } } } @@ -689,6 +667,18 @@ public DatabaseEngine getClusterEngine(final DBCluster cluster) { } } + public String getDbInstanceClass(TestEnvironmentRequest request) { + switch (request.getDatabaseEngineDeployment()) { + case AURORA: + return "db.r5.large"; + case RDS: + case RDS_MULTI_AZ_CLUSTER: + return "db.m5d.large"; + default: + throw new NotImplementedException(request.getDatabaseEngine().toString()); + } + } + public List getClusterInstanceIds(final String clusterId) { final DescribeDbInstancesResponse dbInstancesResult = rdsClient.describeDBInstances( @@ -739,7 +729,6 @@ public DBCluster getDBCluster(String clusterId) { if (remainingTries == 0) { throw sdkClientException; } - this.initClient(); } } @@ -762,7 +751,6 @@ public DBInstance getDBInstance(String instanceId) { if (remainingTries == 0) { throw sdkClientException; } - this.initClient(); } } From 1eb072da85e6e57be6a9a34de250dbeb3b97c623 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Mon, 20 Jan 2025 14:38:18 -0800 Subject: [PATCH 11/21] Rename auroraUtil to testUtil --- .../container/TestDriverProvider.java | 42 ++--- .../tests/AdvancedPerformanceTest.java | 16 +- .../container/tests/AuroraFailoverTest.java | 88 +++++----- .../container/tests/AutoscalingTests.java | 28 ++-- .../container/tests/CustomEndpointTest.java | 20 +-- .../container/tests/HikariTests.java | 24 +-- .../ReadWriteSplittingPerformanceTest.java | 2 +- .../tests/ReadWriteSplittingTests.java | 156 +++++++++--------- .../integration/host/HostEnvironment.java | 36 ++-- .../java/integration/util/TestUtility.java | 30 ++-- 10 files changed, 216 insertions(+), 226 deletions(-) diff --git a/wrapper/src/test/java/integration/container/TestDriverProvider.java b/wrapper/src/test/java/integration/container/TestDriverProvider.java index de9919ef9..dfa0cdf3b 100644 --- a/wrapper/src/test/java/integration/container/TestDriverProvider.java +++ b/wrapper/src/test/java/integration/container/TestDriverProvider.java @@ -226,10 +226,10 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter final TestEnvironmentInfo testInfo = ContainerEnvironment.getCurrent().getInfo(); final TestEnvironmentRequest testRequest = testInfo.getRequest(); - final TestUtility auroraUtil = TestUtility.getUtility(testInfo); - auroraUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); + final TestUtility testUtil = TestUtility.getUtility(testInfo); + testUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); - auroraUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(3)); + testUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(3)); if (makeSureFirstInstanceWriter) { @@ -240,13 +240,13 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter long startTimeNano = System.nanoTime(); while ((instanceIDs.size() != testRequest.getNumOfInstances() || instanceIDs.isEmpty() - || !auroraUtil.isDBInstanceWriter(instanceIDs.get(0))) + || !testUtil.isDBInstanceWriter(instanceIDs.get(0))) && TimeUnit.NANOSECONDS.toMinutes(System.nanoTime() - startTimeNano) < 10) { Thread.sleep(5000); try { - instanceIDs = auroraUtil.getAuroraInstanceIds(); + instanceIDs = testUtil.getAuroraInstanceIds(); } catch (SQLException ex) { if (POSTGRES_AUTH_ERROR_CODE.equals(ex.getSQLState())) { // This authentication error for PG is caused by test environment configuration. @@ -257,7 +257,7 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter } assertTrue(instanceIDs.size() > 0); assertTrue( - auroraUtil.isDBInstanceWriter( + testUtil.isDBInstanceWriter( testInfo.getAuroraClusterName(), instanceIDs.get(0))); String currentWriter = instanceIDs.get(0); @@ -269,7 +269,7 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter testInfo.getProxyDatabaseInfo().moveInstanceFirst(currentWriter); // Wait for cluster endpoint to resolve to the writer - final boolean dnsOk = auroraUtil.waitDnsEqual( + final boolean dnsOk = testUtil.waitDnsEqual( dbInfo.getClusterEndpoint(), dbInfo.getInstances().get(0).getHost(), TimeUnit.MINUTES.toSeconds(5), @@ -280,7 +280,7 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter if (instanceIDs.size() > 1) { // Wait for cluster RO endpoint to resolve NOT to the writer - final boolean dnsROOk = auroraUtil.waitDnsNotEqual( + final boolean dnsROOk = testUtil.waitDnsNotEqual( dbInfo.getClusterReadOnlyEndpoint(), dbInfo.getInstances().get(0).getHost(), TimeUnit.MINUTES.toSeconds(5), @@ -295,47 +295,47 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter public static void rebootCluster() throws InterruptedException { final TestEnvironmentInfo testInfo = ContainerEnvironment.getCurrent().getInfo(); - final TestUtility auroraUtil = TestUtility.getUtility(testInfo); + final TestUtility testUtil = TestUtility.getUtility(testInfo); List instanceIDs = testInfo.getDatabaseInfo().getInstances().stream() .map(TestInstanceInfo::getInstanceId) .collect(Collectors.toList()); - auroraUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); + testUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); // Instances should have one of the following statuses to allow reboot a cluster. for (String instanceId : instanceIDs) { - auroraUtil.waitUntilInstanceHasRightState(instanceId, + testUtil.waitUntilInstanceHasRightState(instanceId, "available", "storage-optimization", "incompatible-credentials", "incompatible-parameters", "unavailable"); } - auroraUtil.rebootCluster(testInfo.getAuroraClusterName()); - auroraUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName(), "rebooting"); - auroraUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); - auroraUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(10)); + testUtil.rebootCluster(testInfo.getAuroraClusterName()); + testUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName(), "rebooting"); + testUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); + testUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(10)); } public static void rebootAllClusterInstances() throws InterruptedException { final TestEnvironmentInfo testInfo = ContainerEnvironment.getCurrent().getInfo(); - final TestUtility auroraUtil = TestUtility.getUtility(testInfo); + final TestUtility testUtil = TestUtility.getUtility(testInfo); List instanceIDs = testInfo.getDatabaseInfo().getInstances().stream() .map(TestInstanceInfo::getInstanceId) .collect(Collectors.toList()); - auroraUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); + testUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); for (String instanceId : instanceIDs) { - auroraUtil.rebootInstance(instanceId); + testUtil.rebootInstance(instanceId); } - auroraUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); + testUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); for (String instanceId : instanceIDs) { - auroraUtil.waitUntilInstanceHasRightState(instanceId); + testUtil.waitUntilInstanceHasRightState(instanceId); } - auroraUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(10)); + testUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(10)); } } diff --git a/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java b/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java index ff9eb628f..7986da5b0 100644 --- a/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java +++ b/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java @@ -99,7 +99,7 @@ public class AdvancedPerformanceTest { private static final ConcurrentLinkedQueue perfDataList = new ConcurrentLinkedQueue<>(); - protected static final TestUtility auroraUtil = TestUtility.getUtility(); + protected static final TestUtility testUtil = TestUtility.getUtility(); private static void doWritePerfDataToFile( String fileName, ConcurrentLinkedQueue dataList) throws IOException { @@ -645,13 +645,13 @@ private Connection openConnectionWithRetry(String url, Properties props) { private void failoverCluster() throws InterruptedException { String clusterId = ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName(); - String randomNode = auroraUtil.getRandomDBClusterReaderInstanceId(clusterId); - auroraUtil.failoverClusterToTarget(clusterId, randomNode); + String randomNode = testUtil.getRandomDBClusterReaderInstanceId(clusterId); + testUtil.failoverClusterToTarget(clusterId, randomNode); } private void ensureClusterHealthy() throws InterruptedException { - auroraUtil.waitUntilClusterHasRightState( + testUtil.waitUntilClusterHasRightState( ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName()); // Always get the latest topology info with writer as first @@ -662,19 +662,19 @@ private void ensureClusterHealthy() throws InterruptedException { long startTimeNano = System.nanoTime(); while ((latestTopology.size() != ContainerEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances() - || !auroraUtil.isDBInstanceWriter(latestTopology.get(0))) + || !testUtil.isDBInstanceWriter(latestTopology.get(0))) && TimeUnit.NANOSECONDS.toMinutes(System.nanoTime() - startTimeNano) < 5) { Thread.sleep(5000); try { - latestTopology = auroraUtil.getAuroraInstanceIds(); + latestTopology = testUtil.getAuroraInstanceIds(); } catch (SQLException ex) { latestTopology = new ArrayList<>(); } } assertTrue( - auroraUtil.isDBInstanceWriter( + testUtil.isDBInstanceWriter( ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName(), latestTopology.get(0))); String currentWriter = latestTopology.get(0); @@ -683,7 +683,7 @@ private void ensureClusterHealthy() throws InterruptedException { ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().moveInstanceFirst(currentWriter); ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().moveInstanceFirst(currentWriter); - auroraUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(5)); + testUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(5)); TestAuroraHostListProvider.clearCache(); TestPluginServiceImpl.clearHostAvailabilityCache(); diff --git a/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java b/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java index 5c0723040..912d292a8 100644 --- a/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java +++ b/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java @@ -79,7 +79,7 @@ public class AuroraFailoverTest { private static final Logger LOGGER = Logger.getLogger(AuroraFailoverTest.class.getName()); - protected static final TestUtility auroraUtil = TestUtility.getUtility(); + protected static final TestUtility testUtil = TestUtility.getUtility(); protected static final int IS_VALID_TIMEOUT = 5; protected String currentWriter; @@ -116,14 +116,14 @@ public void test_failFromWriterToNewWriter_failOnConnectionInvocation() props)) { // Crash Instance1 and nominate a new writer - auroraUtil.failoverClusterAndWaitUntilWriterChanged(); + testUtil.failoverClusterAndWaitUntilWriterChanged(); // Failure occurs on Connection invocation - auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); // Assert that we are connected to the new writer after failover happens. - final String currentConnectionId = auroraUtil.queryInstanceId(conn); - assertTrue(auroraUtil.isDBInstanceWriter(currentConnectionId)); + final String currentConnectionId = testUtil.queryInstanceId(conn); + assertTrue(testUtil.isDBInstanceWriter(currentConnectionId)); assertNotEquals(currentConnectionId, initialWriterId); } } @@ -155,14 +155,14 @@ public void test_failFromWriterToNewWriter_failOnConnectionBoundObjectInvocation final Statement stmt = conn.createStatement(); // Crash Instance1 and nominate a new writer - auroraUtil.failoverClusterAndWaitUntilWriterChanged(); + testUtil.failoverClusterAndWaitUntilWriterChanged(); // Failure occurs on Statement invocation - auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); // Assert that the driver is connected to the new writer after failover happens. - final String currentConnectionId = auroraUtil.queryInstanceId(conn); - assertTrue(auroraUtil.isDBInstanceWriter(currentConnectionId)); + final String currentConnectionId = testUtil.queryInstanceId(conn); + assertTrue(testUtil.isDBInstanceWriter(currentConnectionId)); assertNotEquals(initialWriterId, currentConnectionId); } @@ -191,13 +191,13 @@ public void test_failFromReaderToWriter() throws SQLException { // Crash the reader instance ProxyHelper.disableConnectivity(instanceId); - auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); // Assert that we are currently connected to the writer instance. final String writerId = this.currentWriter; - String currentConnectionId = auroraUtil.queryInstanceId(conn); + String currentConnectionId = testUtil.queryInstanceId(conn); assertEquals(writerId, currentConnectionId); - assertTrue(auroraUtil.isDBInstanceWriter(currentConnectionId)); + assertTrue(testUtil.isDBInstanceWriter(currentConnectionId)); } } @@ -232,7 +232,7 @@ public void test_writerFailWithinTransaction_setAutoCommitFalse() final Statement testStmt2 = conn.createStatement(); testStmt2.executeUpdate("INSERT INTO test3_2 VALUES (1, 'test field string 1')"); - auroraUtil.failoverClusterAndWaitUntilWriterChanged(); + testUtil.failoverClusterAndWaitUntilWriterChanged(); // If there is an active transaction, roll it back and return an error with SQLState 08007. final SQLException exception = @@ -244,10 +244,10 @@ public void test_writerFailWithinTransaction_setAutoCommitFalse() SqlState.CONNECTION_FAILURE_DURING_TRANSACTION.getState(), exception.getSQLState()); // Attempt to query the instance id. - final String currentConnectionId = auroraUtil.queryInstanceId(conn); + final String currentConnectionId = testUtil.queryInstanceId(conn); // Assert that we are connected to the new writer after failover happens. - assertTrue(auroraUtil.isDBInstanceWriter(currentConnectionId)); - final String nextClusterWriterId = auroraUtil.getDBClusterWriterInstanceId(); + assertTrue(testUtil.isDBInstanceWriter(currentConnectionId)); + final String nextClusterWriterId = testUtil.getDBClusterWriterInstanceId(); assertEquals(currentConnectionId, nextClusterWriterId); assertNotEquals(initialWriterId, nextClusterWriterId); @@ -292,7 +292,7 @@ public void test_writerFailWithinTransaction_startTransaction() final Statement testStmt2 = conn.createStatement(); testStmt2.executeUpdate("INSERT INTO test3_3 VALUES (1, 'test field string 1')"); - auroraUtil.failoverClusterAndWaitUntilWriterChanged(); + testUtil.failoverClusterAndWaitUntilWriterChanged(); // If there is an active transaction, roll it back and return an error with SQLState 08007. final SQLException exception = @@ -304,10 +304,10 @@ public void test_writerFailWithinTransaction_startTransaction() SqlState.CONNECTION_FAILURE_DURING_TRANSACTION.getState(), exception.getSQLState()); // Attempt to query the instance id. - final String currentConnectionId = auroraUtil.queryInstanceId(conn); + final String currentConnectionId = testUtil.queryInstanceId(conn); // Assert that we are connected to the new writer after failover happens. - assertTrue(auroraUtil.isDBInstanceWriter(currentConnectionId)); - final String nextClusterWriterId = auroraUtil.getDBClusterWriterInstanceId(); + assertTrue(testUtil.isDBInstanceWriter(currentConnectionId)); + final String nextClusterWriterId = testUtil.getDBClusterWriterInstanceId(); assertEquals(currentConnectionId, nextClusterWriterId); assertNotEquals(initialWriterId, nextClusterWriterId); @@ -355,7 +355,7 @@ public void testServerFailoverWithIdleConnections() throws SQLException, Interru ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { - final String instanceId = auroraUtil.queryInstanceId( + final String instanceId = testUtil.queryInstanceId( ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), conn); @@ -367,12 +367,12 @@ public void testServerFailoverWithIdleConnections() throws SQLException, Interru } // Crash current writer and nominate a new writer - auroraUtil.failoverClusterAndWaitUntilWriterChanged(); + testUtil.failoverClusterAndWaitUntilWriterChanged(); // Assert failover has occurred. assertThrows( FailoverSQLException.class, - () -> auroraUtil.queryInstanceId( + () -> testUtil.queryInstanceId( ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), conn)); @@ -388,7 +388,7 @@ public void testServerFailoverWithIdleConnections() throws SQLException, Interru ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { - final String instanceId = auroraUtil.queryInstanceId( + final String instanceId = testUtil.queryInstanceId( ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), conn); @@ -424,13 +424,13 @@ public void test_DataSourceWriterConnection_BasicFailover() initialWriterInstanceInfo.getHost())) { // Trigger failover - auroraUtil.failoverClusterToATargetAndWaitUntilWriterChanged( + testUtil.failoverClusterToATargetAndWaitUntilWriterChanged( initialWriterInstanceInfo.getInstanceId(), nominatedWriterId); - auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); // Execute Query again to get the current connection id; - final String currentConnectionId = auroraUtil.queryInstanceId(conn); + final String currentConnectionId = testUtil.queryInstanceId(conn); LOGGER.fine("currentConnectionId: " + currentConnectionId); // Assert that we are connected to the new writer after failover happens. @@ -444,7 +444,7 @@ public void test_DataSourceWriterConnection_BasicFailover() continue; } try { - instanceIDs = auroraUtil.getAuroraInstanceIds( + instanceIDs = testUtil.getAuroraInstanceIds( ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), ConnectionStringHelper.getUrl( @@ -509,9 +509,9 @@ public void test_takeOverConnectionProperties() throws SQLException, Interrupted testStmt1.executeQuery("select 1; select 2; select 3;"); // Crash Instance1 and nominate a new writer - auroraUtil.failoverClusterAndWaitUntilWriterChanged(); + testUtil.failoverClusterAndWaitUntilWriterChanged(); - auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); // Assert that the connection property is maintained. final Statement testStmt2 = conn.createStatement(); @@ -553,7 +553,7 @@ public void test_failFromWriterWhereKeepSessionStateOnFailoverIsTrue() final Statement testStmt2 = conn.createStatement(); testStmt2.executeUpdate("INSERT INTO test3_3 VALUES (1, 'test field string 1')"); - auroraUtil.failoverClusterAndWaitUntilWriterChanged(); + testUtil.failoverClusterAndWaitUntilWriterChanged(); // If there is an active transaction, roll it back and return an error with SQLState 08007. final SQLException exception = @@ -565,10 +565,10 @@ public void test_failFromWriterWhereKeepSessionStateOnFailoverIsTrue() SqlState.CONNECTION_FAILURE_DURING_TRANSACTION.getState(), exception.getSQLState()); // Attempt to query the instance id. - final String currentConnectionId = auroraUtil.queryInstanceId(conn); + final String currentConnectionId = testUtil.queryInstanceId(conn); // Assert that we are connected to the new writer after failover happens. - assertTrue(auroraUtil.isDBInstanceWriter(currentConnectionId)); - final String nextClusterWriterId = auroraUtil.getDBClusterWriterInstanceId(); + assertTrue(testUtil.isDBInstanceWriter(currentConnectionId)); + final String nextClusterWriterId = testUtil.getDBClusterWriterInstanceId(); assertEquals(currentConnectionId, nextClusterWriterId); assertNotEquals(initialWriterId, nextClusterWriterId); @@ -629,11 +629,11 @@ public void test_writerFailover_writerReelected() throws SQLException, Interrupt TimeUnit.MILLISECONDS.sleep(500); // Failure occurs on Connection invocation - auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); // Assert that we are connected to the new writer after failover happens. - final String currentConnectionId = auroraUtil.queryInstanceId(conn); - assertTrue(auroraUtil.isDBInstanceWriter(currentConnectionId)); + final String currentConnectionId = testUtil.queryInstanceId(conn); + assertTrue(testUtil.isDBInstanceWriter(currentConnectionId)); assertEquals(currentConnectionId, initialWriterId); } finally { executor.shutdownNow(); @@ -660,10 +660,10 @@ public void test_readerFailover_readerOrWriter() throws SQLException, Interrupte props)) { // Crash Instance1 and nominate a new writer - auroraUtil.failoverClusterAndWaitUntilWriterChanged(); + testUtil.failoverClusterAndWaitUntilWriterChanged(); // Failure occurs on Connection invocation - auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); } } @@ -686,13 +686,13 @@ public void test_readerFailover_strictReader() throws SQLException, InterruptedE props)) { // Crash Instance1 and nominate a new writer - auroraUtil.failoverClusterAndWaitUntilWriterChanged(); + testUtil.failoverClusterAndWaitUntilWriterChanged(); // Failure occurs on Connection invocation - auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); - String currentConnectionId = auroraUtil.queryInstanceId(conn); - assertFalse(auroraUtil.isDBInstanceWriter(currentConnectionId)); + String currentConnectionId = testUtil.queryInstanceId(conn); + assertFalse(testUtil.isDBInstanceWriter(currentConnectionId)); } } @@ -738,7 +738,7 @@ public void test_readerFailover_writerReelected() throws SQLException, Interrupt TimeUnit.MILLISECONDS.sleep(500); // Failure occurs on Connection invocation - auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); } finally { executor.shutdownNow(); } diff --git a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java index d1773ff05..a75e8ca2e 100644 --- a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java +++ b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java @@ -64,7 +64,7 @@ @MakeSureFirstInstanceWriter @Order(17) public class AutoscalingTests { - protected static final TestUtility auroraUtil = TestUtility.getUtility(); + protected static final TestUtility testUtil = TestUtility.getUtility(); protected static Properties getDefaultPropsNoPlugins() { final Properties props = ConnectionStringHelper.getDefaultProperties(); @@ -129,16 +129,16 @@ public void test_pooledConnectionAutoScaling_setReadOnlyOnOldConnection() final Connection newInstanceConn; final String instanceClass = - auroraUtil.getDbInstanceClass(ContainerEnvironment.getCurrent().getInfo().getRequest()); + testUtil.getDbInstanceClass(ContainerEnvironment.getCurrent().getInfo().getRequest()); final TestInstanceInfo newInstance = - auroraUtil.createInstance(instanceClass, "auto-scaling-instance", instances); + testUtil.createInstance(instanceClass, "auto-scaling-instance", instances); try { newInstanceConn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props); connections.add(newInstanceConn); Thread.sleep(topologyRefreshRateMs); newInstanceConn.setReadOnly(true); - final String readerId = auroraUtil.queryInstanceId(newInstanceConn); + final String readerId = testUtil.queryInstanceId(newInstanceConn); assertEquals(newInstance.getInstanceId(), readerId); // Verify that there is a pool for the new instance @@ -146,23 +146,23 @@ public void test_pooledConnectionAutoScaling_setReadOnlyOnOldConnection() .anyMatch((url) -> url.equals(newInstance.getUrl()))); newInstanceConn.setReadOnly(false); } finally { - auroraUtil.deleteInstance(newInstance, instances); + testUtil.deleteInstance(newInstance, instances); } final long deletionCheckTimeout = System.nanoTime() + TimeUnit.MINUTES.toNanos(5); while (System.nanoTime() < deletionCheckTimeout - && auroraUtil.getAuroraInstanceIds().size() != originalClusterSize) { + && testUtil.getAuroraInstanceIds().size() != originalClusterSize) { TimeUnit.SECONDS.sleep(5); } - if (auroraUtil.getAuroraInstanceIds().size() != originalClusterSize) { + if (testUtil.getAuroraInstanceIds().size() != originalClusterSize) { fail("The deleted instance is still in the cluster topology"); } newInstanceConn.setReadOnly(true); // Connection pool cache should have hit the cleanup threshold and removed the pool for the // deleted instance. - String instanceId = auroraUtil.queryInstanceId(newInstanceConn); + String instanceId = testUtil.queryInstanceId(newInstanceConn); assertNotEquals(instances.get(0).getInstanceId(), instanceId); assertNotEquals(newInstance.getInstanceId(), instanceId); assertFalse(provider.getHosts().stream() @@ -204,25 +204,25 @@ public void test_pooledConnectionAutoScaling_failoverFromDeletedReader() final Connection newInstanceConn; final String instanceClass = - auroraUtil.getDbInstanceClass(ContainerEnvironment.getCurrent().getInfo().getRequest()); + testUtil.getDbInstanceClass(ContainerEnvironment.getCurrent().getInfo().getRequest()); final TestInstanceInfo newInstance = - auroraUtil.createInstance(instanceClass, "auto-scaling-instance", instances); + testUtil.createInstance(instanceClass, "auto-scaling-instance", instances); try { newInstanceConn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(newInstance), props); connections.add(newInstanceConn); newInstanceConn.setReadOnly(true); - final String readerId = auroraUtil.queryInstanceId(newInstanceConn); + final String readerId = testUtil.queryInstanceId(newInstanceConn); assertEquals(newInstance.getInstanceId(), readerId); // Verify that there is a pool for the new instance assertTrue(provider.getHosts().stream() .anyMatch((url) -> url.equals(newInstance.getUrl()))); } finally { - auroraUtil.deleteInstance(newInstance, instances); + testUtil.deleteInstance(newInstance, instances); } - auroraUtil.assertFirstQueryThrows(newInstanceConn, FailoverSuccessSQLException.class); - String newReaderId = auroraUtil.queryInstanceId(newInstanceConn); + testUtil.assertFirstQueryThrows(newInstanceConn, FailoverSuccessSQLException.class); + String newReaderId = testUtil.queryInstanceId(newInstanceConn); assertNotEquals(newInstance.getInstanceId(), newReaderId); } finally { for (Connection connection : connections) { diff --git a/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java b/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java index c85491ca5..eb97c7b36 100644 --- a/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java +++ b/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java @@ -81,7 +81,7 @@ public class CustomEndpointTest { protected static final String endpointId = "test-endpoint-1-" + UUID.randomUUID(); protected static DBClusterEndpoint endpointInfo; - protected static final TestUtility auroraUtil = TestUtility.getUtility(); + protected static final TestUtility testUtil = TestUtility.getUtility(); protected static final boolean reuseExistingEndpoint = false; protected String currentWriter; @@ -239,19 +239,19 @@ public void testCustomEndpointFailover() throws SQLException, InterruptedExcepti ConnectionStringHelper.getWrapperUrl(endpointInfo.endpoint(), port, dbInfo.getDefaultDbName()), props)) { List endpointMembers = endpointInfo.staticMembers(); - String instanceId = auroraUtil.queryInstanceId(conn); + String instanceId = testUtil.queryInstanceId(conn); assertTrue(endpointMembers.contains(instanceId)); // Use failover API to break connection. if (instanceId.equals(this.currentWriter)) { - auroraUtil.failoverClusterAndWaitUntilWriterChanged(); + testUtil.failoverClusterAndWaitUntilWriterChanged(); } else { - auroraUtil.failoverClusterToATargetAndWaitUntilWriterChanged(this.currentWriter, instanceId); + testUtil.failoverClusterToATargetAndWaitUntilWriterChanged(this.currentWriter, instanceId); } - assertThrows(FailoverSuccessSQLException.class, () -> auroraUtil.queryInstanceId(conn)); + assertThrows(FailoverSuccessSQLException.class, () -> testUtil.queryInstanceId(conn)); - String newInstanceId = auroraUtil.queryInstanceId(conn); + String newInstanceId = testUtil.queryInstanceId(conn); assertTrue(endpointMembers.contains(newInstanceId)); } } @@ -272,7 +272,7 @@ public void testCustomEndpointReadWriteSplitting_withCustomEndpointChanges() thr props); final RdsClient client = RdsClient.builder().region(Region.of(envInfo.getRegion())).build()) { List endpointMembers = endpointInfo.staticMembers(); - String instanceId1 = auroraUtil.queryInstanceId(conn); + String instanceId1 = testUtil.queryInstanceId(conn); assertTrue(endpointMembers.contains(instanceId1)); // Attempt to switch to an instance of the opposite role. This should fail since the custom endpoint consists only @@ -283,7 +283,7 @@ public void testCustomEndpointReadWriteSplitting_withCustomEndpointChanges() thr // throw an exception. In this scenario we log a warning and purposefully stick with the writer. LOGGER.fine("Initial connection is to the writer. Attempting to switch to reader..."); conn.setReadOnly(newReadOnlyValue); - String newInstanceId = auroraUtil.queryInstanceId(conn); + String newInstanceId = testUtil.queryInstanceId(conn); assertEquals(instanceId1, newInstanceId); } else { // We are connected to the reader. Attempting to switch to the writer will throw an exception. @@ -307,7 +307,7 @@ public void testCustomEndpointReadWriteSplitting_withCustomEndpointChanges() thr // We should now be able to switch to newMember. assertDoesNotThrow(() -> conn.setReadOnly(newReadOnlyValue)); - String instanceId2 = auroraUtil.queryInstanceId(conn); + String instanceId2 = testUtil.queryInstanceId(conn); assertEquals(instanceId2, newMember); // Switch back to original instance. @@ -324,7 +324,7 @@ public void testCustomEndpointReadWriteSplitting_withCustomEndpointChanges() thr // We are connected to the writer. Attempting to switch to the reader will not work but will intentionally not // throw an exception. In this scenario we log a warning and purposefully stick with the writer. conn.setReadOnly(newReadOnlyValue); - String newInstanceId = auroraUtil.queryInstanceId(conn); + String newInstanceId = testUtil.queryInstanceId(conn); assertEquals(instanceId1, newInstanceId); } else { // We are connected to the reader. Attempting to switch to the writer will throw an exception. diff --git a/wrapper/src/test/java/integration/container/tests/HikariTests.java b/wrapper/src/test/java/integration/container/tests/HikariTests.java index 0608e7946..008de62d4 100644 --- a/wrapper/src/test/java/integration/container/tests/HikariTests.java +++ b/wrapper/src/test/java/integration/container/tests/HikariTests.java @@ -87,6 +87,7 @@ public class HikariTests { private static final Logger LOGGER = Logger.getLogger(HikariTests.class.getName()); + protected static final TestUtility testUtil = TestUtility.getUtility(); @TestTemplate public void testOpenConnectionWithUrl() throws SQLException { @@ -174,8 +175,6 @@ public void testOpenConnectionWithDataSourceClassName() throws SQLException { @EnableOnTestFeature({TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED}) @EnableOnNumOfInstances(min = 3) public void testFailoverLostConnection() throws SQLException { - - final TestUtility auroraUtil = TestUtility.getUtility(); final Properties customProps = new Properties(); PLUGINS.set(customProps, "failover"); FAILOVER_TIMEOUT_MS.set(customProps, Integer.toString(1)); @@ -193,7 +192,7 @@ public void testFailoverLostConnection() throws SQLException { // (since we rely on small socket timeout and small failover timeout). However, // if it takes more time, we'd like to exit by timeout rather than waiting indefinitely. executeWithTimeout( - () -> auroraUtil.queryInstanceId(conn), + () -> testUtil.queryInstanceId(conn), TimeUnit.MINUTES.toMillis(1) ) ); @@ -217,8 +216,6 @@ public void testFailoverLostConnection() throws SQLException { @EnableOnTestFeature({TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED}) @EnableOnNumOfInstances(min = 3) public void testEFMFailover() throws SQLException { - - final TestUtility auroraUtil = TestUtility.getUtility(); ProxyHelper.disableAllConnectivity(); final List instances = ContainerEnvironment.getCurrent() @@ -237,18 +234,18 @@ public void testEFMFailover() throws SQLException { // Get a valid connection, then make it fail over to a different instance try (Connection conn = dataSource.getConnection()) { assertTrue(conn.isValid(5)); - String currentConnectionId = auroraUtil.queryInstanceId(conn); + String currentConnectionId = testUtil.queryInstanceId(conn); assertTrue(currentConnectionId.equalsIgnoreCase(writerIdentifier)); LOGGER.fine("Connected to instance: " + currentConnectionId); ProxyHelper.enableConnectivity(readerIdentifier); ProxyHelper.disableConnectivity(writerIdentifier); - assertThrows(FailoverSuccessSQLException.class, () -> auroraUtil.queryInstanceId(conn)); + assertThrows(FailoverSuccessSQLException.class, () -> testUtil.queryInstanceId(conn)); // Check the connection is valid after connecting to a different instance assertTrue(conn.isValid(5)); - currentConnectionId = auroraUtil.queryInstanceId(conn); + currentConnectionId = testUtil.queryInstanceId(conn); LOGGER.fine("Connected to instance: " + currentConnectionId); assertTrue(currentConnectionId.equalsIgnoreCase(readerIdentifier)); @@ -270,7 +267,6 @@ public void testEFMFailover() throws SQLException { @EnableOnNumOfInstances(min = 2) public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation() throws SQLException, InterruptedException { - final TestUtility auroraUtil = TestUtility.getUtility(); final TestProxyDatabaseInfo proxyInfo = ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); final List instances = proxyInfo.getInstances(); final TestInstanceInfo reader = instances.get(1); @@ -284,7 +280,7 @@ public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation() // Open connection and then return it to the pool Connection conn = ds.getConnection(); - assertEquals(readerId, auroraUtil.queryInstanceId(conn)); + assertEquals(readerId, testUtil.queryInstanceId(conn)); conn.close(); ProxyHelper.disableConnectivity(reader.getInstanceId()); @@ -296,7 +292,7 @@ public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation() // Driver will fail over internally and return a connection to another node. conn = ds.getConnection(); // Assert that we connected to a different node. - assertNotEquals(readerId, auroraUtil.queryInstanceId(conn)); + assertNotEquals(readerId, testUtil.queryInstanceId(conn)); } finally { ConnectionProviderManager.releaseResources(); } @@ -312,7 +308,6 @@ public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation() @EnableOnNumOfInstances(min = 2) public void testInternalPools_driverReaderFailoverOnGetConnectionInvocation() throws SQLException, InterruptedException { - final TestUtility auroraUtil = TestUtility.getUtility(); final TestProxyDatabaseInfo proxyInfo = ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); final List instances = proxyInfo.getInstances(); final TestInstanceInfo writer = instances.get(0); @@ -345,7 +340,7 @@ public void testInternalPools_driverReaderFailoverOnGetConnectionInvocation() // Driver will fail over internally and return a connection to another node. try (Connection conn = ds.getConnection()) { // Assert that we connected to a different node. - assertNotEquals(writerId, auroraUtil.queryInstanceId(conn)); + assertNotEquals(writerId, testUtil.queryInstanceId(conn)); } } finally { ConnectionProviderManager.releaseResources(); @@ -362,7 +357,6 @@ public void testInternalPools_driverReaderFailoverOnGetConnectionInvocation() @EnableOnNumOfInstances(max = 1) public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation_singleInstance() throws SQLException, InterruptedException { - final TestUtility auroraUtil = TestUtility.getUtility(); final TestProxyDatabaseInfo proxyInfo = ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); final List instances = proxyInfo.getInstances(); final TestInstanceInfo writer = instances.get(0); @@ -377,7 +371,7 @@ public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation_sing // Open connection and then return it to the pool Connection conn = ds.getConnection(); - assertEquals(writerId, auroraUtil.queryInstanceId(conn)); + assertEquals(writerId, testUtil.queryInstanceId(conn)); conn.close(); ProxyHelper.disableAllConnectivity(); diff --git a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingPerformanceTest.java b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingPerformanceTest.java index 11b21e9f7..a7496e93e 100644 --- a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingPerformanceTest.java +++ b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingPerformanceTest.java @@ -19,8 +19,8 @@ import com.zaxxer.hikari.HikariConfig; import integration.TestEnvironmentFeatures; import integration.container.ConnectionStringHelper; -import integration.container.TestDriverProvider; import integration.container.ContainerEnvironment; +import integration.container.TestDriverProvider; import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.EnableOnTestFeature; import java.io.File; diff --git a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java index 8018123df..79e05916a 100644 --- a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java +++ b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java @@ -34,10 +34,10 @@ import integration.TestEnvironmentInfo; import integration.TestInstanceInfo; import integration.container.ConnectionStringHelper; +import integration.container.ContainerEnvironment; import integration.container.ProxyHelper; import integration.container.TestDriver; import integration.container.TestDriverProvider; -import integration.container.ContainerEnvironment; import integration.container.aurora.TestPluginServiceImpl; import integration.container.condition.DisableOnTestDriver; import integration.container.condition.DisableOnTestFeature; @@ -89,7 +89,7 @@ @Order(12) public class ReadWriteSplittingTests { - protected static final TestUtility auroraUtil = TestUtility.getUtility(); + protected static final TestUtility testUtil = TestUtility.getUtility(); private static final Logger LOGGER = Logger.getLogger(ReadWriteSplittingTests.class.getName()); protected static Properties getProxiedPropsWithFailover() { @@ -136,26 +136,26 @@ public void test_connectToWriter_switchSetReadOnly() throws SQLException { LOGGER.finest("Connecting to url " + url); try (final Connection conn = DriverManager.getConnection(url, getProps())) { - final String writerConnectionId = auroraUtil.queryInstanceId(conn); + final String writerConnectionId = testUtil.queryInstanceId(conn); conn.setReadOnly(true); - final String readerConnectionId = auroraUtil.queryInstanceId(conn); + final String readerConnectionId = testUtil.queryInstanceId(conn); assertNotEquals(writerConnectionId, readerConnectionId); conn.setReadOnly(true); - String currentConnectionId = auroraUtil.queryInstanceId(conn); + String currentConnectionId = testUtil.queryInstanceId(conn); assertEquals(readerConnectionId, currentConnectionId); conn.setReadOnly(false); - currentConnectionId = auroraUtil.queryInstanceId(conn); + currentConnectionId = testUtil.queryInstanceId(conn); assertEquals(writerConnectionId, currentConnectionId); conn.setReadOnly(false); - currentConnectionId = auroraUtil.queryInstanceId(conn); + currentConnectionId = testUtil.queryInstanceId(conn); assertEquals(writerConnectionId, currentConnectionId); conn.setReadOnly(true); - currentConnectionId = auroraUtil.queryInstanceId(conn); + currentConnectionId = testUtil.queryInstanceId(conn); assertEquals(readerConnectionId, currentConnectionId); } } @@ -166,15 +166,15 @@ public void test_connectToReader_setReadOnlyTrueFalse() throws SQLException { LOGGER.finest("Connecting to url " + url); try (final Connection conn = DriverManager.getConnection(url, getProps())) { - final String readerConnectionId = auroraUtil.queryInstanceId(conn); + final String readerConnectionId = testUtil.queryInstanceId(conn); LOGGER.finest("readerConnectionId: " + readerConnectionId); conn.setReadOnly(true); - final String currentConnectionId = auroraUtil.queryInstanceId(conn); + final String currentConnectionId = testUtil.queryInstanceId(conn); assertEquals(readerConnectionId, currentConnectionId); conn.setReadOnly(false); - final String writerConnectionId = auroraUtil.queryInstanceId(conn); + final String writerConnectionId = testUtil.queryInstanceId(conn); LOGGER.finest("writerConnectionId: " + writerConnectionId); assertNotEquals(readerConnectionId, writerConnectionId); } @@ -192,15 +192,15 @@ public void test_connectToReaderCluster_setReadOnlyTrueFalse() throws SQLExcepti final String url = ConnectionStringHelper.getWrapperReaderClusterUrl(); LOGGER.finest("Connecting to url " + url); try (final Connection conn = DriverManager.getConnection(url, getProps())) { - final String readerConnectionId = auroraUtil.queryInstanceId(conn); + final String readerConnectionId = testUtil.queryInstanceId(conn); LOGGER.finest("readerConnectionId: " + readerConnectionId); conn.setReadOnly(true); - final String currentConnectionId = auroraUtil.queryInstanceId(conn); + final String currentConnectionId = testUtil.queryInstanceId(conn); assertEquals(readerConnectionId, currentConnectionId); conn.setReadOnly(false); - final String writerConnectionId = auroraUtil.queryInstanceId(conn); + final String writerConnectionId = testUtil.queryInstanceId(conn); LOGGER.finest("writerConnectionId: " + writerConnectionId); assertNotEquals(readerConnectionId, writerConnectionId); } @@ -210,10 +210,10 @@ public void test_connectToReaderCluster_setReadOnlyTrueFalse() throws SQLExcepti public void test_setReadOnlyFalseInReadOnlyTransaction() throws SQLException { try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), getProps())) { - final String writerConnectionId = auroraUtil.queryInstanceId(conn); + final String writerConnectionId = testUtil.queryInstanceId(conn); conn.setReadOnly(true); - final String readerConnectionId = auroraUtil.queryInstanceId(conn); + final String readerConnectionId = testUtil.queryInstanceId(conn); assertNotEquals(writerConnectionId, readerConnectionId); final Statement stmt = conn.createStatement(); @@ -222,14 +222,14 @@ public void test_setReadOnlyFalseInReadOnlyTransaction() throws SQLException { final SQLException exception = assertThrows(SQLException.class, () -> conn.setReadOnly(false)); - String currentConnectionId = auroraUtil.queryInstanceId(conn); + String currentConnectionId = testUtil.queryInstanceId(conn); assertEquals(SqlState.ACTIVE_SQL_TRANSACTION.getState(), exception.getSQLState()); assertEquals(readerConnectionId, currentConnectionId); stmt.execute("COMMIT"); conn.setReadOnly(false); - currentConnectionId = auroraUtil.queryInstanceId(conn); + currentConnectionId = testUtil.queryInstanceId(conn); assertEquals(writerConnectionId, currentConnectionId); } } @@ -238,10 +238,10 @@ public void test_setReadOnlyFalseInReadOnlyTransaction() throws SQLException { public void test_setReadOnlyFalseInTransaction_setAutocommitFalse() throws SQLException { try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), getProps())) { - final String writerConnectionId = auroraUtil.queryInstanceId(conn); + final String writerConnectionId = testUtil.queryInstanceId(conn); conn.setReadOnly(true); - final String readerConnectionId = auroraUtil.queryInstanceId(conn); + final String readerConnectionId = testUtil.queryInstanceId(conn); assertNotEquals(writerConnectionId, readerConnectionId); final Statement stmt = conn.createStatement(); @@ -250,14 +250,14 @@ public void test_setReadOnlyFalseInTransaction_setAutocommitFalse() throws SQLEx final SQLException exception = assertThrows(SQLException.class, () -> conn.setReadOnly(false)); - String currentConnectionId = auroraUtil.queryInstanceId(conn); + String currentConnectionId = testUtil.queryInstanceId(conn); assertEquals(SqlState.ACTIVE_SQL_TRANSACTION.getState(), exception.getSQLState()); assertEquals(readerConnectionId, currentConnectionId); stmt.execute("COMMIT"); conn.setReadOnly(false); - currentConnectionId = auroraUtil.queryInstanceId(conn); + currentConnectionId = testUtil.queryInstanceId(conn); assertEquals(writerConnectionId, currentConnectionId); } } @@ -268,7 +268,7 @@ public void test_setReadOnlyFalseInTransaction_setAutocommitFalse() throws SQLEx public void test_setReadOnlyTrueInTransaction() throws SQLException { try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), getProps())) { - final String writerConnectionId = auroraUtil.queryInstanceId(conn); + final String writerConnectionId = testUtil.queryInstanceId(conn); final Statement stmt1 = conn.createStatement(); stmt1.executeUpdate("DROP TABLE IF EXISTS test_readWriteSplitting_readOnlyTrueInTransaction"); @@ -283,7 +283,7 @@ public void test_setReadOnlyTrueInTransaction() throws SQLException { + "VALUES (1, 'test_field value 1')"); assertDoesNotThrow(() -> conn.setReadOnly(true)); - final String currentConnectionId = auroraUtil.queryInstanceId(conn); + final String currentConnectionId = testUtil.queryInstanceId(conn); assertEquals(writerConnectionId, currentConnectionId); stmt2.execute("COMMIT"); @@ -306,7 +306,7 @@ public void test_setReadOnlyTrue_allReadersDown() throws SQLException { try (final Connection conn = DriverManager.getConnection( ConnectionStringHelper.getProxyWrapperUrl(), getProxiedProps())) { - final String writerConnectionId = auroraUtil.queryInstanceId(conn); + final String writerConnectionId = testUtil.queryInstanceId(conn); // Kill all reader instances final List instanceIDs = @@ -317,16 +317,16 @@ public void test_setReadOnlyTrue_allReadersDown() throws SQLException { } assertDoesNotThrow(() -> conn.setReadOnly(true)); - String currentConnectionId = assertDoesNotThrow(() -> auroraUtil.queryInstanceId(conn)); + String currentConnectionId = assertDoesNotThrow(() -> testUtil.queryInstanceId(conn)); assertEquals(writerConnectionId, currentConnectionId); assertDoesNotThrow(() -> conn.setReadOnly(false)); - currentConnectionId = assertDoesNotThrow(() -> auroraUtil.queryInstanceId(conn)); + currentConnectionId = assertDoesNotThrow(() -> testUtil.queryInstanceId(conn)); assertEquals(writerConnectionId, currentConnectionId); ProxyHelper.enableAllConnectivity(); assertDoesNotThrow(() -> conn.setReadOnly(true)); - currentConnectionId = auroraUtil.queryInstanceId(conn); + currentConnectionId = testUtil.queryInstanceId(conn); assertNotEquals(writerConnectionId, currentConnectionId); } } @@ -353,10 +353,10 @@ public void test_setReadOnlyFalse_allInstancesDown() throws SQLException { try (final Connection conn = DriverManager.getConnection( ConnectionStringHelper.getProxyWrapperUrl(), getProxiedProps())) { - final String writerConnectionId = auroraUtil.queryInstanceId(conn); + final String writerConnectionId = testUtil.queryInstanceId(conn); conn.setReadOnly(true); - final String readerConnectionId = auroraUtil.queryInstanceId(conn); + final String readerConnectionId = testUtil.queryInstanceId(conn); assertNotEquals(writerConnectionId, readerConnectionId); // Kill all instances @@ -390,7 +390,7 @@ public void test_setReadOnlyFalse_whenAllInstancesDown() throws SQLException { public void test_executeWithOldConnection() throws SQLException { try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), getProps())) { - final String writerId = auroraUtil.queryInstanceId(conn); + final String writerId = testUtil.queryInstanceId(conn); final Statement oldStmt = conn.createStatement(); final ResultSet oldRs = oldStmt.executeQuery("SELECT 1"); @@ -400,13 +400,13 @@ public void test_executeWithOldConnection() throws SQLException { assertThrows(SQLException.class, () -> oldStmt.execute("SELECT 1")); assertThrows(SQLException.class, () -> oldRs.getInt(1)); - final String readerId = auroraUtil.queryInstanceId(conn); + final String readerId = testUtil.queryInstanceId(conn); assertNotEquals(writerId, readerId); assertDoesNotThrow(oldStmt::close); assertDoesNotThrow(oldRs::close); - final String sameReaderId = auroraUtil.queryInstanceId(conn); + final String sameReaderId = testUtil.queryInstanceId(conn); assertEquals(readerId, sameReaderId); } } @@ -419,7 +419,7 @@ public void test_failoverToNewWriter_setReadOnlyTrueFalse() try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getProxyWrapperUrl(), getProxiedPropsWithFailover())) { - final String originalWriterId = auroraUtil.queryInstanceId(conn); + final String originalWriterId = testUtil.queryInstanceId(conn); // Kill all reader instances final int numOfInstances = @@ -436,29 +436,29 @@ public void test_failoverToNewWriter_setReadOnlyTrueFalse() // Force internal reader connection to the writer instance conn.setReadOnly(true); - String currentConnectionId = auroraUtil.queryInstanceId(conn); + String currentConnectionId = testUtil.queryInstanceId(conn); assertEquals(originalWriterId, currentConnectionId); conn.setReadOnly(false); ProxyHelper.enableAllConnectivity(); // Crash Instance1 and nominate a new writer - auroraUtil.failoverClusterAndWaitUntilWriterChanged(); + testUtil.failoverClusterAndWaitUntilWriterChanged(); // Failure occurs on Connection invocation - auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); // Assert that we are connected to the new writer after failover happens. - String newWriterId = auroraUtil.queryInstanceId(conn); - assertTrue(auroraUtil.isDBInstanceWriter(newWriterId)); + String newWriterId = testUtil.queryInstanceId(conn); + assertTrue(testUtil.isDBInstanceWriter(newWriterId)); assertNotEquals(newWriterId, originalWriterId); conn.setReadOnly(true); - currentConnectionId = auroraUtil.queryInstanceId(conn); + currentConnectionId = testUtil.queryInstanceId(conn); assertNotEquals(newWriterId, currentConnectionId); conn.setReadOnly(false); - currentConnectionId = auroraUtil.queryInstanceId(conn); + currentConnectionId = testUtil.queryInstanceId(conn); assertEquals(newWriterId, currentConnectionId); } } @@ -474,11 +474,11 @@ public void test_failoverToNewReader_setReadOnlyFalseTrue() throws SQLException try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getProxyWrapperUrl(), props)) { - final String writerConnectionId = auroraUtil.queryInstanceId(conn); + final String writerConnectionId = testUtil.queryInstanceId(conn); LOGGER.info("writerConnectionId: " + writerConnectionId); conn.setReadOnly(true); - final String readerConnectionId = auroraUtil.queryInstanceId(conn); + final String readerConnectionId = testUtil.queryInstanceId(conn); assertNotEquals(writerConnectionId, readerConnectionId); String otherReaderId = ""; @@ -490,7 +490,7 @@ public void test_failoverToNewReader_setReadOnlyFalseTrue() throws SQLException break; } } - if (otherReaderId.equals("")) { + if (otherReaderId.isEmpty()) { fail("could not acquire new reader ID"); } @@ -503,20 +503,20 @@ public void test_failoverToNewReader_setReadOnlyFalseTrue() throws SQLException ProxyHelper.disableConnectivity(instanceId); } - auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); assertFalse(conn.isClosed()); - String currentConnectionId = auroraUtil.queryInstanceId(conn); + String currentConnectionId = testUtil.queryInstanceId(conn); assertEquals(otherReaderId, currentConnectionId); assertNotEquals(readerConnectionId, currentConnectionId); ProxyHelper.enableAllConnectivity(); conn.setReadOnly(false); - currentConnectionId = auroraUtil.queryInstanceId(conn); + currentConnectionId = testUtil.queryInstanceId(conn); assertEquals(writerConnectionId, currentConnectionId); conn.setReadOnly(true); - currentConnectionId = auroraUtil.queryInstanceId(conn); + currentConnectionId = testUtil.queryInstanceId(conn); assertEquals(otherReaderId, currentConnectionId); } } @@ -530,11 +530,11 @@ public void test_failoverReaderToWriter_setReadOnlyTrueFalse() try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getProxyWrapperUrl(), getProxiedPropsWithFailover())) { - final String writerConnectionId = auroraUtil.queryInstanceId(conn); + final String writerConnectionId = testUtil.queryInstanceId(conn); LOGGER.finest("writerConnectionId=" + writerConnectionId); conn.setReadOnly(true); - final String readerConnectionId = auroraUtil.queryInstanceId(conn); + final String readerConnectionId = testUtil.queryInstanceId(conn); LOGGER.finest("readerConnectionId=" + readerConnectionId); assertNotEquals(writerConnectionId, readerConnectionId); @@ -550,28 +550,28 @@ public void test_failoverReaderToWriter_setReadOnlyTrueFalse() ProxyHelper.disableConnectivity(instanceId); } - auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); assertFalse(conn.isClosed()); - String currentConnectionId = auroraUtil.queryInstanceId(conn); + String currentConnectionId = testUtil.queryInstanceId(conn); LOGGER.finest("currentConnectionId=" + currentConnectionId); assertEquals(writerConnectionId, currentConnectionId); ProxyHelper.enableAllConnectivity(); - // During failover above some of readers have been tried to connect to and failed since they were not - // available. We should expect that some of readers in topology are marked as UNAVAILABLE. + // During failover above some of the readers have been tried to connect to and failed since they were not + // available. We should expect that some of the readers in topology are marked as UNAVAILABLE. // The following code reset node availability and make them AVAILABLE. // That is important for further steps. TestPluginServiceImpl.clearHostAvailabilityCache(); conn.unwrap(PluginService.class).forceRefreshHostList(); conn.setReadOnly(true); - currentConnectionId = auroraUtil.queryInstanceId(conn); + currentConnectionId = testUtil.queryInstanceId(conn); LOGGER.finest("currentConnectionId=" + currentConnectionId); assertNotEquals(writerConnectionId, currentConnectionId); conn.setReadOnly(false); - currentConnectionId = auroraUtil.queryInstanceId(conn); + currentConnectionId = testUtil.queryInstanceId(conn); LOGGER.finest("currentConnectionId=" + currentConnectionId); assertEquals(writerConnectionId, currentConnectionId); } @@ -643,14 +643,14 @@ public void test_pooledConnectionFailover() throws SQLException, InterruptedExce try { try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props)) { initialWriterConn1 = conn.unwrap(Connection.class); - initialWriterId = auroraUtil.queryInstanceId(conn); + initialWriterId = testUtil.queryInstanceId(conn); LOGGER.finest("initialWriterId: " + initialWriterId); provider.logConnections(); - auroraUtil.failoverClusterAndWaitUntilWriterChanged(); + testUtil.failoverClusterAndWaitUntilWriterChanged(); - assertThrows(FailoverSuccessSQLException.class, () -> auroraUtil.queryInstanceId(conn)); - nextWriterId = auroraUtil.queryInstanceId(conn); + assertThrows(FailoverSuccessSQLException.class, () -> testUtil.queryInstanceId(conn)); + nextWriterId = testUtil.queryInstanceId(conn); LOGGER.finest("nextWriterId: " + nextWriterId); assertNotEquals(initialWriterId, nextWriterId); newWriterConn = conn.unwrap(Connection.class); @@ -660,7 +660,7 @@ public void test_pooledConnectionFailover() throws SQLException, InterruptedExce try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props)) { // This should be a new connection to the initial writer instance (now a reader). - final String oldWriterConnectionId = auroraUtil.queryInstanceId(conn); + final String oldWriterConnectionId = testUtil.queryInstanceId(conn); LOGGER.finest("oldWriterConnectionId: " + oldWriterConnectionId); assertEquals(initialWriterId, oldWriterConnectionId); initialWriterConn2 = conn.unwrap(Connection.class); @@ -693,10 +693,10 @@ public void test_pooledConnectionFailoverWithClusterURL() throws SQLException, I initialWriterConn = conn.unwrap(Connection.class); // The internal connection pool should not be used if the connection is established via a cluster URL. assertEquals(0, provider.getHostCount(), "Internal connection pool should be empty."); - final String writerConnectionId = auroraUtil.queryInstanceId(conn); - auroraUtil.failoverClusterAndWaitUntilWriterChanged(); - assertThrows(FailoverSuccessSQLException.class, () -> auroraUtil.queryInstanceId(conn)); - final String nextWriterId = auroraUtil.queryInstanceId(conn); + final String writerConnectionId = testUtil.queryInstanceId(conn); + testUtil.failoverClusterAndWaitUntilWriterChanged(); + assertThrows(FailoverSuccessSQLException.class, () -> testUtil.queryInstanceId(conn)); + final String nextWriterId = testUtil.queryInstanceId(conn); assertNotEquals(writerConnectionId, nextWriterId); assertEquals(0, provider.getHostCount(), "Internal connection pool should be empty."); newWriterConn = conn.unwrap(Connection.class); @@ -725,14 +725,14 @@ public void test_pooledConnection_failoverFailed() throws SQLException { final String initialWriterId; try (Connection conn = DriverManager.getConnection(ConnectionStringHelper.getProxyWrapperUrl(), props)) { initialWriterConn1 = conn.unwrap(Connection.class); - initialWriterId = auroraUtil.queryInstanceId(conn); + initialWriterId = testUtil.queryInstanceId(conn); ProxyHelper.disableAllConnectivity(); - assertThrows(FailoverFailedSQLException.class, () -> auroraUtil.queryInstanceId(conn)); + assertThrows(FailoverFailedSQLException.class, () -> testUtil.queryInstanceId(conn)); } ProxyHelper.enableAllConnectivity(); try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getProxyWrapperUrl(), props)) { - final String writerConnectionId = auroraUtil.queryInstanceId(conn); + final String writerConnectionId = testUtil.queryInstanceId(conn); assertEquals(initialWriterId, writerConnectionId); initialWriterConn2 = conn.unwrap(Connection.class); // The initial connection should have been evicted from the pool when failover occurred, so @@ -766,13 +766,13 @@ public void test_pooledConnection_failoverInTransaction() try (Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props)) { initialWriterConn1 = conn.unwrap(Connection.class); conn.setAutoCommit(false); - initialWriterId = auroraUtil.queryInstanceId(conn); + initialWriterId = testUtil.queryInstanceId(conn); LOGGER.finest("initialWriterId: " + initialWriterId + ", " + initialWriterConn1); - auroraUtil.failoverClusterAndWaitUntilWriterChanged(); + testUtil.failoverClusterAndWaitUntilWriterChanged(); assertThrows(TransactionStateUnknownSQLException.class, - () -> auroraUtil.queryInstanceId(conn)); + () -> testUtil.queryInstanceId(conn)); conn.setAutoCommit(true); - nextWriterId = auroraUtil.queryInstanceId(conn); + nextWriterId = testUtil.queryInstanceId(conn); newWriterConn = conn.unwrap(Connection.class); LOGGER.finest("nextWriterId: " + nextWriterId + ", " + newWriterConn); assertNotEquals(initialWriterId, nextWriterId); @@ -781,12 +781,12 @@ public void test_pooledConnection_failoverInTransaction() // Make sure all instances up after failover. // Old writer in RDS MultiAz clusters may be unavailable for quite long time. - auroraUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(15)); + testUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(15)); // It makes sense to run the following step when initial writer is up. try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props)) { // This should be a new connection to the initial writer instance (now a reader). - final String writerConnectionId = auroraUtil.queryInstanceId(conn); + final String writerConnectionId = testUtil.queryInstanceId(conn); assertEquals(initialWriterId, writerConnectionId); initialWriterConn2 = conn.unwrap(Connection.class); // The initial connection should have been evicted from the pool when failover occurred, so @@ -824,7 +824,7 @@ public void test_pooledConnection_differentUsers() throws SQLException { try (Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), privilegedUserProps); Statement stmt = conn.createStatement()) { stmt.execute("DROP USER IF EXISTS " + limitedUserName); - auroraUtil.createUser(conn, limitedUserName, limitedUserPassword); + testUtil.createUser(conn, limitedUserName, limitedUserPassword); TestEnvironmentInfo info = ContainerEnvironment.getCurrent().getInfo(); DatabaseEngine engine = info.getRequest().getDatabaseEngine(); if (DatabaseEngine.MYSQL.equals(engine)) { @@ -843,7 +843,7 @@ public void test_pooledConnection_differentUsers() throws SQLException { assertThrows( HikariPool.PoolInitializationException.class, () -> { - try (final Connection conn = DriverManager.getConnection( + try (final Connection ignored = DriverManager.getConnection( ConnectionStringHelper.getWrapperUrl(), wrongUserRightPasswordProps)) { // Do nothing (close connection automatically) } @@ -882,7 +882,7 @@ public void test_pooledConnection_leastConnectionsStrategy() throws SQLException DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props); connections.add(conn); conn.setReadOnly(true); - final String readerId = auroraUtil.queryInstanceId(conn); + final String readerId = testUtil.queryInstanceId(conn); assertFalse(connectedReaderIDs.contains(readerId)); connectedReaderIDs.add(readerId); @@ -950,7 +950,7 @@ public void test_pooledConnection_leastConnectionsWithPoolMapping() throws SQLEx DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), defaultProps); connections.add(conn); conn.setReadOnly(true); - final String readerId = auroraUtil.queryInstanceId(conn); + final String readerId = testUtil.queryInstanceId(conn); assertNotEquals(overloadedReaderId, readerId); } } finally { diff --git a/wrapper/src/test/java/integration/host/HostEnvironment.java b/wrapper/src/test/java/integration/host/HostEnvironment.java index 6b14eb72d..420cadff2 100644 --- a/wrapper/src/test/java/integration/host/HostEnvironment.java +++ b/wrapper/src/test/java/integration/host/HostEnvironment.java @@ -104,7 +104,7 @@ public class HostEnvironment implements AutoCloseable { private final Network network = Network.newNetwork(); - private TestUtility auroraUtil; + private TestUtility testUtil; private HostEnvironment(TestEnvironmentRequest request) { this.info.setRequest(request); @@ -363,7 +363,7 @@ private static void createDbCluster(HostEnvironment env, int numOfInstances) { env.rdsEndpoint = config.rdsEndpoint; // "XYZ.us-west-2.rds.amazonaws.com" env.info.setRdsEndpoint(env.rdsEndpoint); - env.auroraUtil = + env.testUtil = new TestUtility( env.info.getRegion(), env.rdsEndpoint, @@ -378,7 +378,7 @@ private static void createDbCluster(HostEnvironment env, int numOfInstances) { throw new RuntimeException("Environment variable RDS_CLUSTER_DOMAIN is required."); } - if (!env.auroraUtil.doesClusterExist(env.auroraClusterName)) { + if (!env.testUtil.doesClusterExist(env.auroraClusterName)) { throw new RuntimeException( "It's requested to reuse existing DB cluster but it doesn't exist: " + env.auroraClusterName @@ -388,9 +388,9 @@ private static void createDbCluster(HostEnvironment env, int numOfInstances) { LOGGER.finer( "Reuse existing cluster " + env.auroraClusterName + ".cluster-" + env.auroraClusterDomain); - DBCluster clusterInfo = env.auroraUtil.getClusterInfo(env.auroraClusterName); + DBCluster clusterInfo = env.testUtil.getClusterInfo(env.auroraClusterName); - DatabaseEngine existingClusterDatabaseEngine = env.auroraUtil.getClusterEngine(clusterInfo); + DatabaseEngine existingClusterDatabaseEngine = env.testUtil.getClusterEngine(clusterInfo); if (existingClusterDatabaseEngine != env.info.getRequest().getDatabaseEngine()) { throw new RuntimeException( "Existing cluster is " @@ -402,7 +402,7 @@ private static void createDbCluster(HostEnvironment env, int numOfInstances) { env.info.setDatabaseEngine(clusterInfo.engine()); env.info.setDatabaseEngineVersion(clusterInfo.engineVersion()); - instances.addAll(env.auroraUtil.getClusterInstanceIds(env.auroraClusterName)); + instances.addAll(env.testUtil.getClusterInstanceIds(env.auroraClusterName)); } else { if (StringUtils.isNullOrEmpty(env.auroraClusterName)) { @@ -410,7 +410,7 @@ private static void createDbCluster(HostEnvironment env, int numOfInstances) { boolean clusterExists = false; while (remainingTries-- > 0) { env.auroraClusterName = getRandomName(env.info.getRequest()); - if (env.auroraUtil.doesClusterExist(env.auroraClusterName)) { + if (env.testUtil.doesClusterExist(env.auroraClusterName)) { clusterExists = true; LOGGER.finest("Cluster " + env.auroraClusterName + " already exists. Pick up another name."); } else { @@ -430,13 +430,13 @@ private static void createDbCluster(HostEnvironment env, int numOfInstances) { if (StringUtils.isNullOrEmpty(engineVersion)) { throw new RuntimeException("Failed to get engine version."); } - String instanceClass = env.auroraUtil.getDbInstanceClass(env.info.getRequest()); + String instanceClass = env.testUtil.getDbInstanceClass(env.info.getRequest()); LOGGER.finer( "Using " + engine + " " + engineVersion); env.auroraClusterDomain = - env.auroraUtil.createCluster( + env.testUtil.createCluster( env.info.getDatabaseInfo().getUsername(), env.info.getDatabaseInfo().getPassword(), env.info.getDatabaseInfo().getDefaultDbName(), @@ -458,7 +458,7 @@ private static void createDbCluster(HostEnvironment env, int numOfInstances) { // remove cluster and instances LOGGER.finer("Deleting cluster " + env.auroraClusterName); - env.auroraUtil.deleteCluster(env.auroraClusterName, env.info.getRequest().getDatabaseEngineDeployment()); + env.testUtil.deleteCluster(env.auroraClusterName, env.info.getRequest().getDatabaseEngineDeployment()); LOGGER.finer("Deleted cluster " + env.auroraClusterName); throw new RuntimeException(e); @@ -499,12 +499,12 @@ private static void createDbCluster(HostEnvironment env, int numOfInstances) { private static void authorizeIP(HostEnvironment env) { try { - env.runnerIP = env.auroraUtil.getPublicIPAddress(); + env.runnerIP = env.testUtil.getPublicIPAddress(); LOGGER.finest("Test runner IP: " + env.runnerIP); } catch (UnknownHostException e) { throw new RuntimeException(e); } - env.auroraUtil.ec2AuthorizeIP(env.runnerIP); + env.testUtil.ec2AuthorizeIP(env.runnerIP); } private static String getRandomName(TestEnvironmentRequest request) { @@ -600,13 +600,13 @@ private static String findAuroraDbEngineVersion( String systemPropertyVersion) { if (StringUtils.isNullOrEmpty(systemPropertyVersion)) { - return env.auroraUtil.getDefaultVersion(engineName); + return env.testUtil.getDefaultVersion(engineName); } switch (systemPropertyVersion.toLowerCase()) { case "default": - return env.auroraUtil.getDefaultVersion(engineName); + return env.testUtil.getDefaultVersion(engineName); case "latest": - return env.auroraUtil.getLatestVersion(engineName); + return env.testUtil.getLatestVersion(engineName); default: return systemPropertyVersion; } @@ -907,7 +907,7 @@ private static void configureIamAccess(HostEnvironment env) { env.info.getDatabaseInfo().getDefaultDbName()); try { - env.auroraUtil.addAuroraAwsIamUser( + env.testUtil.addAuroraAwsIamUser( env.info.getRequest().getDatabaseEngine(), url, env.info.getDatabaseInfo().getUsername(), @@ -1041,13 +1041,13 @@ private void deleteDbCluster() { if (ipAddressUsageRefCount.decrementAndGet() == 0) { // Another test environments are still in use of test task runner IP address. // The last execute tst environment will do the cleanup. - auroraUtil.ec2DeauthorizesIP(runnerIP); + testUtil.ec2DeauthorizesIP(runnerIP); } } if (!this.reuseAuroraDbCluster) { LOGGER.finest("Deleting cluster " + this.auroraClusterName + ".cluster-" + this.auroraClusterDomain); - auroraUtil.deleteCluster(this.auroraClusterName, this.info.getRequest().getDatabaseEngineDeployment()); + testUtil.deleteCluster(this.auroraClusterName, this.info.getRequest().getDatabaseEngineDeployment()); LOGGER.finest("Deleted cluster " + this.auroraClusterName + ".cluster-" + this.auroraClusterDomain); } } diff --git a/wrapper/src/test/java/integration/util/TestUtility.java b/wrapper/src/test/java/integration/util/TestUtility.java index abdbfbfa7..69822298b 100644 --- a/wrapper/src/test/java/integration/util/TestUtility.java +++ b/wrapper/src/test/java/integration/util/TestUtility.java @@ -118,7 +118,7 @@ public class TestUtility { private final RdsClient rdsClient; private final Ec2Client ec2Client; - public TestUtility(String region, String endpoint) throws URISyntaxException { + public TestUtility(String region, String endpoint) { this(getRegionInternal(region), endpoint, DefaultCredentialsProvider.create()); } @@ -162,6 +162,18 @@ public TestUtility(Region region, String rdsEndpoint, AwsCredentialsProvider cre .build(); } + public static TestUtility getUtility() { + return getUtility(null); + } + + public static TestUtility getUtility(@Nullable TestEnvironmentInfo info) { + if (info == null) { + info = ContainerEnvironment.getCurrent().getInfo(); + } + + return new TestUtility(info.getRegion(), info.getRdsEndpoint()); + } + protected static Region getRegionInternal(String rdsRegion) { Optional regionOptional = Region.regions().stream().filter(r -> r.id().equalsIgnoreCase(rdsRegion)).findFirst(); @@ -1417,22 +1429,6 @@ public String getDefaultVersion(String engine) { throw new RuntimeException("Failed to find default version"); } - public static TestUtility getUtility() { - return getUtility(null); - } - - public static TestUtility getUtility(TestEnvironmentInfo info) { - if (info == null) { - info = ContainerEnvironment.getCurrent().getInfo(); - } - - try { - return new TestUtility(info.getRegion(), info.getRdsEndpoint()); - } catch (URISyntaxException e) { - throw new RuntimeException(e); - } - } - public static T executeWithTimeout(final Callable callable, long timeoutMs) throws Throwable { final ExecutorService executorService = Executors.newSingleThreadExecutor(); Future future = executorService.submit(callable); From 2ed579ede1fa57b0eb495a4a09a0b8a92bc405b6 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Mon, 20 Jan 2025 15:36:54 -0800 Subject: [PATCH 12/21] wip javadocs --- .../java/integration/util/TestUtility.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/wrapper/src/test/java/integration/util/TestUtility.java b/wrapper/src/test/java/integration/util/TestUtility.java index 69822298b..b956bfc4a 100644 --- a/wrapper/src/test/java/integration/util/TestUtility.java +++ b/wrapper/src/test/java/integration/util/TestUtility.java @@ -105,7 +105,7 @@ import software.amazon.jdbc.util.StringUtils; /** - * Creates and destroys AWS RDS Clusters and Instances. To use this functionality the following environment variables + * Provides useful functions for RDS integration testing. To use this functionality the following environment variables * must be defined: - AWS_ACCESS_KEY_ID - AWS_SECRET_ACCESS_KEY */ public class TestUtility { @@ -134,13 +134,14 @@ public TestUtility( } /** - * Initializes an AmazonRDS & AmazonEC2 client. + * Creates a TestUtility instance. As part of the creation, an RdsClient and Ec2Client are initialized. * - * @param region define AWS Regions, refer to + * @param region The AWS region for the cluster(s) the tests will be running against, refer to * Regions, - * Availability Zones, and Local Zones - * @param credentialsProvider Specific AWS credential provider + * href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts + * .RegionsAndAvailabilityZones.html"> + * Regions, Availability Zones, and Local Zones + * @param credentialsProvider The AWS credential provider to use to initialize the RdsClient and Ec2Client. */ public TestUtility(Region region, String rdsEndpoint, AwsCredentialsProvider credentialsProvider) { final RdsClientBuilder rdsClientBuilder = RdsClient.builder() @@ -185,10 +186,14 @@ protected static Region getRegionInternal(String rdsRegion) { } /** - * Creates RDS Cluster/Instances and waits until they are up, and proper IP whitelisting for databases. + * Performs the following: + * - creates an RDS cluster based on the passed in details + * - waits until it is available + * - adds the current IP address as an inbound rule to the security group so that the cluster can be accessed + * - creates a database with the given name within the cluster * - * @param username Master username for access to database - * @param password Master password for access to database + * @param username the master username for access to the database + * @param password the master password for access to the database * @param dbName Database name * @param identifier Database cluster identifier * @param engine Database engine to use, refer to From 92a2a2b75e717d7e78b4f5b328976565819c0013 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Mon, 20 Jan 2025 16:47:23 -0800 Subject: [PATCH 13/21] Remove instances parameter from createCluster functions --- .../container/tests/AutoscalingTests.java | 12 +- .../integration/host/HostEnvironment.java | 41 +++-- .../java/integration/util/TestUtility.java | 165 +++++++++--------- 3 files changed, 109 insertions(+), 109 deletions(-) diff --git a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java index a75e8ca2e..d2dad8332 100644 --- a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java +++ b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java @@ -131,7 +131,8 @@ public void test_pooledConnectionAutoScaling_setReadOnlyOnOldConnection() final String instanceClass = testUtil.getDbInstanceClass(ContainerEnvironment.getCurrent().getInfo().getRequest()); final TestInstanceInfo newInstance = - testUtil.createInstance(instanceClass, "auto-scaling-instance", instances); + testUtil.createInstance(instanceClass, "auto-scaling-instance"); + instances.add(newInstance); try { newInstanceConn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props); @@ -146,7 +147,8 @@ public void test_pooledConnectionAutoScaling_setReadOnlyOnOldConnection() .anyMatch((url) -> url.equals(newInstance.getUrl()))); newInstanceConn.setReadOnly(false); } finally { - testUtil.deleteInstance(newInstance, instances); + testUtil.deleteInstance(newInstance); + instances.remove(newInstance); } final long deletionCheckTimeout = System.nanoTime() + TimeUnit.MINUTES.toNanos(5); @@ -206,7 +208,8 @@ public void test_pooledConnectionAutoScaling_failoverFromDeletedReader() final String instanceClass = testUtil.getDbInstanceClass(ContainerEnvironment.getCurrent().getInfo().getRequest()); final TestInstanceInfo newInstance = - testUtil.createInstance(instanceClass, "auto-scaling-instance", instances); + testUtil.createInstance(instanceClass, "auto-scaling-instance"); + instances.add(newInstance); try { newInstanceConn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(newInstance), props); @@ -218,7 +221,8 @@ public void test_pooledConnectionAutoScaling_failoverFromDeletedReader() assertTrue(provider.getHosts().stream() .anyMatch((url) -> url.equals(newInstance.getUrl()))); } finally { - testUtil.deleteInstance(newInstance, instances); + testUtil.deleteInstance(newInstance); + instances.remove(newInstance); } testUtil.assertFirstQueryThrows(newInstanceConn, FailoverSuccessSQLException.class); diff --git a/wrapper/src/test/java/integration/host/HostEnvironment.java b/wrapper/src/test/java/integration/host/HostEnvironment.java index 420cadff2..f1b18a4f0 100644 --- a/wrapper/src/test/java/integration/host/HostEnvironment.java +++ b/wrapper/src/test/java/integration/host/HostEnvironment.java @@ -32,8 +32,8 @@ import integration.TestProxyDatabaseInfo; import integration.TestTelemetryInfo; import integration.host.TestEnvironmentProvider.EnvPreCreateInfo; -import integration.util.TestUtility; import integration.util.ContainerHelper; +import integration.util.TestUtility; import java.io.IOException; import java.net.URISyntaxException; import java.net.UnknownHostException; @@ -55,6 +55,7 @@ import org.testcontainers.shaded.org.apache.commons.lang3.NotImplementedException; import org.testcontainers.utility.MountableFile; import software.amazon.awssdk.services.rds.model.DBCluster; +import software.amazon.awssdk.services.rds.model.DBInstance; import software.amazon.jdbc.util.StringUtils; public class HostEnvironment implements AutoCloseable { @@ -370,9 +371,6 @@ private static void createDbCluster(HostEnvironment env, int numOfInstances) { env.awsAccessKeyId, env.awsSecretAccessKey, env.awsSessionToken); - - ArrayList instances = new ArrayList<>(); - if (env.reuseAuroraDbCluster) { if (StringUtils.isNullOrEmpty(env.auroraClusterDomain)) { throw new RuntimeException("Environment variable RDS_CLUSTER_DOMAIN is required."); @@ -402,8 +400,6 @@ private static void createDbCluster(HostEnvironment env, int numOfInstances) { env.info.setDatabaseEngine(clusterInfo.engine()); env.info.setDatabaseEngineVersion(clusterInfo.engineVersion()); - instances.addAll(env.testUtil.getClusterInstanceIds(env.auroraClusterName)); - } else { if (StringUtils.isNullOrEmpty(env.auroraClusterName)) { int remainingTries = 5; @@ -435,19 +431,25 @@ private static void createDbCluster(HostEnvironment env, int numOfInstances) { LOGGER.finer( "Using " + engine + " " + engineVersion); - env.auroraClusterDomain = - env.testUtil.createCluster( - env.info.getDatabaseInfo().getUsername(), - env.info.getDatabaseInfo().getPassword(), - env.info.getDatabaseInfo().getDefaultDbName(), - env.auroraClusterName, - env.info.getRequest().getDatabaseEngineDeployment(), - env.info.getRegion(), - engine, - instanceClass, - engineVersion, - numOfInstances, - instances); + env.testUtil.createCluster( + env.info.getDatabaseInfo().getUsername(), + env.info.getDatabaseInfo().getPassword(), + env.info.getDatabaseInfo().getDefaultDbName(), + env.auroraClusterName, + env.info.getRequest().getDatabaseEngineDeployment(), + env.info.getRegion(), + engine, + instanceClass, + engineVersion, + numOfInstances); + + List dbInstances = env.testUtil.getDBInstances(env.auroraClusterName); + if (dbInstances.isEmpty()) { + throw new RuntimeException("Failed to get instance information for cluster " + env.auroraClusterName); + } + + final String instanceEndpoint = dbInstances.get(0).endpoint().address(); + env.auroraClusterDomain = instanceEndpoint.substring(instanceEndpoint.indexOf(".")); env.info.setDatabaseEngine(engine); env.info.setDatabaseEngineVersion(engineVersion); LOGGER.finer( @@ -478,6 +480,7 @@ private static void createDbCluster(HostEnvironment env, int numOfInstances) { env.auroraClusterName + ".cluster-ro-" + env.auroraClusterDomain, port); env.info.getDatabaseInfo().setInstanceEndpointSuffix(env.auroraClusterDomain, port); + List instances = env.testUtil.generateTestInstancesInfo(env.auroraClusterName); env.info.getDatabaseInfo().getInstances().clear(); env.info.getDatabaseInfo().getInstances().addAll(instances); diff --git a/wrapper/src/test/java/integration/util/TestUtility.java b/wrapper/src/test/java/integration/util/TestUtility.java index b956bfc4a..8c10e3051 100644 --- a/wrapper/src/test/java/integration/util/TestUtility.java +++ b/wrapper/src/test/java/integration/util/TestUtility.java @@ -113,6 +113,7 @@ public class TestUtility { private static final Logger LOGGER = Logger.getLogger(TestUtility.class.getName()); private static final String DEFAULT_SECURITY_GROUP = "default"; private static final String DUPLICATE_IP_ERROR_CODE = "InvalidPermission.Duplicate"; + private static final int MULTI_AZ_SIZE = 3; private static final Random rand = new Random(); private final RdsClient rdsClient; @@ -194,17 +195,19 @@ protected static Region getRegionInternal(String rdsRegion) { * * @param username the master username for access to the database * @param password the master password for access to the database - * @param dbName Database name - * @param identifier Database cluster identifier - * @param engine Database engine to use, refer to - * ... - * @param instanceClass instance class, refer to - * ... + * @param dbName the database to create within the cluster + * @param identifier the cluster identifier + * @param deployment the engine deployment to use + * @param region the region that the cluster should be created in + * @param engine the engine to use, refer to + * CreateDbClusterRequest.engine + * @param instanceClass the instance class, refer to + * Supported instance classes * @param version the database engine's version - * @return An endpoint for one of the instances + * @param numInstances the number of instances to create for the cluster * @throws InterruptedException when clusters have not started after 30 minutes */ - public String createCluster( + public void createCluster( String username, String password, String dbName, @@ -214,29 +217,48 @@ public String createCluster( String engine, String instanceClass, String version, - int numInstances, - ArrayList instances) + int numInstances) throws InterruptedException { switch (deployment) { case AURORA: - return createAuroraCluster( - username, password, dbName, identifier, region, engine, instanceClass, version, numInstances, instances); + createAuroraCluster( + username, password, dbName, identifier, region, engine, instanceClass, version, numInstances); case RDS_MULTI_AZ_CLUSTER: - return createMultiAzCluster( - username, password, dbName, identifier, region, engine, instanceClass, version, instances); + if (numInstances != MULTI_AZ_SIZE) { + throw new RuntimeException( + "A multi-az cluster with " + numInstances + " instances was requested, but multi-az clusters must have " + + MULTI_AZ_SIZE + " instances."); + } + + createMultiAzCluster( + username, password, dbName, identifier, region, engine, instanceClass, version); default: throw new UnsupportedOperationException(deployment.toString()); } } /** - * Creates RDS Cluster/Instances and waits until they are up, and proper IP whitelisting for databases. + * Performs the following: + * - creates an RDS Aurora cluster based on the passed in details + * - waits until it is available + * - adds the current IP address as an inbound rule to the security group so that the cluster can be accessed + * - creates a database with the given name within the cluster * - * @return An endpoint for one of the instances + * @param username the master username for access to the database + * @param password the master password for access to the database + * @param dbName the database to create within the cluster + * @param identifier the cluster identifier + * @param region the region that the cluster should be created in + * @param engine the engine to use, refer to + * CreateDbClusterRequest.engine + * @param instanceClass the instance class, refer to + * Supported instance classes + * @param version the database engine's version + * @param numInstances the number of instances to create for the cluster * @throws InterruptedException when clusters have not started after 30 minutes */ - public String createAuroraCluster( + public void createAuroraCluster( String username, String password, String dbName, @@ -245,12 +267,9 @@ public String createAuroraCluster( String engine, String instanceClass, String version, - int numInstances, - ArrayList instances) + int numInstances) throws InterruptedException { - // Create Cluster final Tag testRunnerTag = Tag.builder().key("env").value("test-runner").build(); - final CreateDbClusterRequest dbClusterRequest = CreateDbClusterRequest.builder() .dbClusterIdentifier(identifier) @@ -296,43 +315,36 @@ public String createAuroraCluster( throw new InterruptedException( "Unable to start AWS RDS Cluster & Instances after waiting for 30 minutes"); } - - final DescribeDbInstancesResponse dbInstancesResult = - rdsClient.describeDBInstances( - (builder) -> - builder.filters( - Filter.builder().name("db-cluster-id").values(identifier).build())); - final String endpoint = dbInstancesResult.dbInstances().get(0).endpoint().address(); - final String clusterDomainPrefix = endpoint.substring(endpoint.indexOf('.') + 1); - - for (DBInstance instance : dbInstancesResult.dbInstances()) { - instances.add( - new TestInstanceInfo( - instance.dbInstanceIdentifier(), - instance.endpoint().address(), - instance.endpoint().port())); - } - - return clusterDomainPrefix; } /** - * Creates RDS Cluster/Instances and waits until they are up, and proper IP whitelisting for databases. + * Performs the following: + * - creates an RDS multi-az cluster based on the passed in details + * - waits until it is available + * - adds the current IP address as an inbound rule to the security group so that the cluster can be accessed + * - creates a database with the given name within the cluster * - * @return An endpoint for one of the instances + * @param username the master username for access to the database + * @param password the master password for access to the database + * @param dbName the database to create within the cluster + * @param identifier the cluster identifier + * @param region the region that the cluster should be created in + * @param engine the engine to use, refer to + * CreateDbClusterRequest.engine + * @param instanceClass the instance class, refer to + * Supported instance classes + * @param version the database engine's version * @throws InterruptedException when clusters have not started after 30 minutes */ - public String createMultiAzCluster(String username, + public void createMultiAzCluster(String username, String password, String dbName, String identifier, String region, String engine, String instanceClass, - String version, - ArrayList instances) + String version) throws InterruptedException { - // Create Cluster final Tag testRunnerTag = Tag.builder().key("env").value("test-runner").build(); CreateDbClusterRequest.Builder clusterBuilder = CreateDbClusterRequest.builder() @@ -357,9 +369,7 @@ public String createMultiAzCluster(String username, rdsClient.createDBCluster(clusterBuilder.build()); - // For multi-AZ deployments, the cluster instances are created automatically. - - // Wait for all instances to be up + // For multi-AZ deployments, the cluster instances are created automatically. Wait for all instances to be up. final RdsWaiter waiter = rdsClient.waiter(); WaiterResponse waiterResponse = waiter.waitUntilDBInstanceAvailable( @@ -373,24 +383,6 @@ public String createMultiAzCluster(String username, throw new InterruptedException( "Unable to start AWS RDS Cluster & Instances after waiting for 30 minutes"); } - - final DescribeDbInstancesResponse dbInstancesResult = - rdsClient.describeDBInstances( - (builder) -> - builder.filters( - Filter.builder().name("db-cluster-id").values(identifier).build())); - final String endpoint = dbInstancesResult.dbInstances().get(0).endpoint().address(); - final String clusterDomainPrefix = endpoint.substring(endpoint.indexOf('.') + 1); - - for (DBInstance instance : dbInstancesResult.dbInstances()) { - instances.add( - new TestInstanceInfo( - instance.dbInstanceIdentifier(), - instance.endpoint().address(), - instance.endpoint().port())); - } - - return clusterDomainPrefix; } /** @@ -400,7 +392,7 @@ public String createMultiAzCluster(String username, * @return the instance info of the new instance * @throws InterruptedException if the new instance is not available within 5 minutes */ - public TestInstanceInfo createInstance(String instanceClass, String instanceId, List instances) + public TestInstanceInfo createInstance(String instanceClass, String instanceId) throws InterruptedException { final Tag testRunnerTag = Tag.builder().key("env").value("test-runner").build(); final TestEnvironmentInfo info = ContainerEnvironment.getCurrent().getInfo(); @@ -445,12 +437,18 @@ public TestInstanceInfo createInstance(String instanceClass, String instanceId, } DBInstance instance = dbInstancesResult.dbInstances().get(0); - TestInstanceInfo instanceInfo = new TestInstanceInfo( + return new TestInstanceInfo( instance.dbInstanceIdentifier(), instance.endpoint().address(), instance.endpoint().port()); - instances.add(instanceInfo); - return instanceInfo; + } + + public List getDBInstances(String clusterId) { + final DescribeDbInstancesResponse dbInstancesResult = + rdsClient.describeDBInstances( + (builder) -> + builder.filters(Filter.builder().name("db-cluster-id").values(clusterId).build())); + return dbInstancesResult.dbInstances(); } /** @@ -459,15 +457,13 @@ public TestInstanceInfo createInstance(String instanceClass, String instanceId, * @param instanceToDelete the info for the instance to delete * @throws InterruptedException if the instance has not been deleted within 5 minutes */ - public void deleteInstance(TestInstanceInfo instanceToDelete, List instances) + public void deleteInstance(TestInstanceInfo instanceToDelete) throws InterruptedException { rdsClient.deleteDBInstance( DeleteDbInstanceRequest.builder() .dbInstanceIdentifier(instanceToDelete.getInstanceId()) .skipFinalSnapshot(true) .build()); - instances.remove(instanceToDelete); - final RdsWaiter waiter = rdsClient.waiter(); WaiterResponse waiterResponse = waiter.waitUntilDBInstanceDeleted( (requestBuilder) -> requestBuilder.filters( @@ -696,21 +692,18 @@ public String getDbInstanceClass(TestEnvironmentRequest request) { } } - public List getClusterInstanceIds(final String clusterId) { - final DescribeDbInstancesResponse dbInstancesResult = - rdsClient.describeDBInstances( - (builder) -> - builder.filters(Filter.builder().name("db-cluster-id").values(clusterId).build())); - - List result = new ArrayList<>(); - for (DBInstance instance : dbInstancesResult.dbInstances()) { - result.add( + public List generateTestInstancesInfo(final String clusterId) { + List dbInstances = getDBInstances(clusterId); + List instancesInfo = new ArrayList<>(); + for (DBInstance dbInstance : dbInstances) { + instancesInfo.add( new TestInstanceInfo( - instance.dbInstanceIdentifier(), - instance.endpoint().address(), - instance.endpoint().port())); + dbInstance.dbInstanceIdentifier(), + dbInstance.endpoint().address(), + dbInstance.endpoint().port())); } - return result; + + return instancesInfo; } public void waitUntilClusterHasRightState(String clusterId) throws InterruptedException { From b0f623690e4d7cb120665f7ab28254bc3fe85290 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Tue, 21 Jan 2025 15:03:16 -0800 Subject: [PATCH 14/21] Finish javadocs --- .../java/integration/util/TestUtility.java | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/wrapper/src/test/java/integration/util/TestUtility.java b/wrapper/src/test/java/integration/util/TestUtility.java index 8c10e3051..c2f9361ad 100644 --- a/wrapper/src/test/java/integration/util/TestUtility.java +++ b/wrapper/src/test/java/integration/util/TestUtility.java @@ -111,8 +111,10 @@ public class TestUtility { private static final Logger LOGGER = Logger.getLogger(TestUtility.class.getName()); - private static final String DEFAULT_SECURITY_GROUP = "default"; private static final String DUPLICATE_IP_ERROR_CODE = "InvalidPermission.Duplicate"; + private static final String DEFAULT_SECURITY_GROUP = "default"; + private static final String DEFAULT_STORAGE_TYPE = "io1"; + private static final int DEFAULT_IOPS = 1000; private static final int MULTI_AZ_SIZE = 3; private static final Random rand = new Random(); @@ -364,8 +366,8 @@ public void createMultiAzCluster(String username, clusterBuilder = clusterBuilder.allocatedStorage(100) .dbClusterInstanceClass(instanceClass) - .storageType("io1") - .iops(1000); + .storageType(DEFAULT_STORAGE_TYPE) + .iops(DEFAULT_IOPS); rdsClient.createDBCluster(clusterBuilder.build()); @@ -388,8 +390,9 @@ public void createMultiAzCluster(String username, /** * Creates an RDS instance under the current cluster and waits until it is up. * + * @param instanceClass the desired instance class of the new instance * @param instanceId the desired instance ID of the new instance - * @return the instance info of the new instance + * @return the instance info for the new instance * @throws InterruptedException if the new instance is not available within 5 minutes */ public TestInstanceInfo createInstance(String instanceClass, String instanceId) @@ -479,10 +482,10 @@ public void deleteInstance(TestInstanceInfo instanceToDelete) } /** - * Gets public IP. + * Gets the public IP address for the current machine. * - * @return public IP of user - * @throws UnknownHostException when checkip host isn't available + * @return the public IP address for the current machine + * @throws UnknownHostException when checkip.amazonaws.com isn't available */ public String getPublicIPAddress() throws UnknownHostException { String ip; @@ -497,7 +500,9 @@ public String getPublicIPAddress() throws UnknownHostException { } /** - * Authorizes IP to EC2 Security groups for RDS access. + * Adds the given IP address to the default security group for RDS access. + * + * @param ipAddress the IP address to add to the default security group */ public void ec2AuthorizeIP(String ipAddress) { if (StringUtils.isNullOrEmpty(ipAddress)) { @@ -544,7 +549,9 @@ private boolean ipExists(String ipAddress) { } /** - * De-authorizes IP from EC2 Security groups. + * Removes the given IP address from the default security group. + * + * @param ipAddress the IP address to remove from the default security group. */ public void ec2DeauthorizesIP(String ipAddress) { if (StringUtils.isNullOrEmpty(ipAddress)) { @@ -565,9 +572,10 @@ public void ec2DeauthorizesIP(String ipAddress) { } /** - * Deletes the specified cluster. Removes IP from EC2 whitelist. + * Deletes the specified cluster and removes the current IP address from the default security group. * - * @param identifier database identifier to delete + * @param identifier the cluster identifier for the cluster to delete + * @param deployment the engine deployment for the cluster to delete */ public void deleteCluster(String identifier, DatabaseEngineDeployment deployment) { switch (deployment) { @@ -583,7 +591,9 @@ public void deleteCluster(String identifier, DatabaseEngineDeployment deployment } /** - * Destroys all instances and clusters. Removes IP from EC2 whitelist. + * Deletes the specified Aurora cluster and removes the current IP address from the default security group. + * + * @param identifier the cluster identifier for the cluster to delete */ public void deleteAuroraCluster(String identifier) { List members = getDBCluster(identifier).dbClusterMembers(); @@ -622,7 +632,9 @@ public void deleteAuroraCluster(String identifier) { } /** - * Destroys all instances and clusters. + * Deletes the specified multi-az cluster and removes the current IP address from the default security group. + * + * @param identifier the cluster identifier for the cluster to delete */ public void deleteMultiAzCluster(String identifier) { // deleteDBinstance requests are not necessary to delete a multi-az cluster. From ce05deff4177904776da2347295f6453f0265888 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Tue, 21 Jan 2025 16:45:12 -0800 Subject: [PATCH 15/21] cleanup --- wrapper/src/test/java/integration/util/TestUtility.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrapper/src/test/java/integration/util/TestUtility.java b/wrapper/src/test/java/integration/util/TestUtility.java index c2f9361ad..ac53d0f25 100644 --- a/wrapper/src/test/java/integration/util/TestUtility.java +++ b/wrapper/src/test/java/integration/util/TestUtility.java @@ -992,7 +992,6 @@ public void makeSureInstancesUp(List instances, long timeoutSe throw new RuntimeException(e); } - stop.set(true); executorService.shutdownNow(); @@ -1203,6 +1202,7 @@ public boolean waitDnsEqual( TimeUnit.SECONDS.sleep(5); hostIpAddress = this.hostToIP(hostToCheck, false); } + if (hostIpAddress == null) { fail("Can't get IP address for " + hostToCheck); } From d0af9fd4ffb3c8618690da642686be259c08cee7 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Tue, 21 Jan 2025 17:19:00 -0800 Subject: [PATCH 16/21] Rename HostEnvironment and ContainerEnvironment back to TestEnvironment --- .../test/java/integration/DriverHelper.java | 36 +++--- .../container/ConnectionStringHelper.java | 72 ++++++------ .../integration/container/ProxyHelper.java | 8 +- .../container/TestDriverProvider.java | 30 ++--- ...rEnvironment.java => TestEnvironment.java} | 16 +-- .../DisableOnTestFeatureCondition.java | 4 +- ...bleBasedOnEnvironmentFeatureExtension.java | 4 +- .../EnableOnDatabaseEngineCondition.java | 4 +- ...leOnDatabaseEngineDeploymentCondition.java | 4 +- .../EnableOnNumOfInstancesCondition.java | 4 +- .../EnableOnTestFeatureCondition.java | 4 +- .../tests/AdvancedPerformanceTest.java | 60 +++++----- .../tests/AuroraConnectivityTests.java | 6 +- .../container/tests/AuroraFailoverTest.java | 110 +++++++++--------- .../container/tests/AutoscalingTests.java | 10 +- .../tests/AwsIamIntegrationTest.java | 40 +++---- .../tests/BasicConnectivityTests.java | 68 +++++------ .../container/tests/CustomEndpointTest.java | 12 +- .../container/tests/DataSourceTests.java | 26 ++--- .../container/tests/HikariTests.java | 44 +++---- .../container/tests/PerformanceTest.java | 32 ++--- .../ReadWriteSplittingPerformanceTest.java | 10 +- .../tests/ReadWriteSplittingTests.java | 28 ++--- .../container/tests/SpringTests.java | 6 +- ...tEnvironment.java => TestEnvironment.java} | 56 ++++----- .../java/integration/host/TestRunner.java | 4 +- .../java/integration/util/TestUtility.java | 42 +++---- .../test/resources/logging-test.properties | 2 +- 28 files changed, 371 insertions(+), 371 deletions(-) rename wrapper/src/test/java/integration/container/{ContainerEnvironment.java => TestEnvironment.java} (95%) rename wrapper/src/test/java/integration/host/{HostEnvironment.java => TestEnvironment.java} (96%) diff --git a/wrapper/src/test/java/integration/DriverHelper.java b/wrapper/src/test/java/integration/DriverHelper.java index 0781c4f64..4175b6cc9 100644 --- a/wrapper/src/test/java/integration/DriverHelper.java +++ b/wrapper/src/test/java/integration/DriverHelper.java @@ -18,7 +18,7 @@ import com.mysql.cj.conf.PropertyKey; import integration.container.TestDriver; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManager; @@ -38,8 +38,8 @@ public class DriverHelper { public static String getDriverProtocol() { return getDriverProtocol( - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - ContainerEnvironment.getCurrent().getCurrentDriver()); + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + TestEnvironment.getCurrent().getCurrentDriver()); } public static String getDriverProtocol(DatabaseEngine databaseEngine) { @@ -75,13 +75,13 @@ public static String getDriverProtocol(DatabaseEngine databaseEngine, TestDriver public static String getWrapperDriverProtocol() { return getWrapperDriverProtocol( - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - ContainerEnvironment.getCurrent().getCurrentDriver()); + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + TestEnvironment.getCurrent().getCurrentDriver()); } public static String getWrapperDriverProtocol(TestDriver testDriver) { return getWrapperDriverProtocol( - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), testDriver); + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), testDriver); } public static String getWrapperDriverProtocol( @@ -117,7 +117,7 @@ public static String getDriverClassname(DatabaseEngine databaseEngine) { } public static String getDriverClassname() { - return getDriverClassname(ContainerEnvironment.getCurrent().getCurrentDriver()); + return getDriverClassname(TestEnvironment.getCurrent().getCurrentDriver()); } public static String getDriverClassname(TestDriver testDriver) { @@ -134,7 +134,7 @@ public static String getDriverClassname(TestDriver testDriver) { } public static String getDataSourceClassname() { - return getDataSourceClassname(ContainerEnvironment.getCurrent().getCurrentDriver()); + return getDataSourceClassname(TestEnvironment.getCurrent().getCurrentDriver()); } public static String getDataSourceClassname(TestDriver testDriver) { @@ -151,7 +151,7 @@ public static String getDataSourceClassname(TestDriver testDriver) { } public static Class getConnectionClass() { - return getConnectionClass(ContainerEnvironment.getCurrent().getCurrentDriver()); + return getConnectionClass(TestEnvironment.getCurrent().getCurrentDriver()); } public static Class getConnectionClass(TestDriver testDriver) { @@ -169,13 +169,13 @@ public static Class getConnectionClass(TestDriver testDriver) { public static String getDriverRequiredParameters() { return getDriverRequiredParameters( - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - ContainerEnvironment.getCurrent().getCurrentDriver()); + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + TestEnvironment.getCurrent().getCurrentDriver()); } public static String getDriverRequiredParameters(TestDriver testDriver) { return getDriverRequiredParameters( - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), testDriver); + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), testDriver); } public static String getDriverRequiredParameters( @@ -187,7 +187,7 @@ public static String getDriverRequiredParameters( } public static String getHostnameSql() { - return getHostnameSql(ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine()); + return getHostnameSql(TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine()); } public static String getHostnameSql(DatabaseEngine databaseEngine) { @@ -204,7 +204,7 @@ public static String getHostnameSql(DatabaseEngine databaseEngine) { // This method should be used on connections with a target driver ONLY! public static void setConnectTimeout(Properties props, long timeout, TimeUnit timeUnit) { - setConnectTimeout(ContainerEnvironment.getCurrent().getCurrentDriver(), props, timeout, timeUnit); + setConnectTimeout(TestEnvironment.getCurrent().getCurrentDriver(), props, timeout, timeUnit); } // This method should be used on connections with a target driver ONLY! @@ -229,7 +229,7 @@ public static void setConnectTimeout( // This method should be used on connections with a target driver ONLY! public static void setSocketTimeout(Properties props, long timeout, TimeUnit timeUnit) { - setSocketTimeout(ContainerEnvironment.getCurrent().getCurrentDriver(), props, timeout, timeUnit); + setSocketTimeout(TestEnvironment.getCurrent().getCurrentDriver(), props, timeout, timeUnit); } // This method should be used on connections with a target driver ONLY! @@ -254,7 +254,7 @@ public static void setSocketTimeout( // This method should be used on connections with a target driver ONLY! public static void setTcpKeepAlive(Properties props, boolean enabled) { - setTcpKeepAlive(ContainerEnvironment.getCurrent().getCurrentDriver(), props, enabled); + setTcpKeepAlive(TestEnvironment.getCurrent().getCurrentDriver(), props, enabled); } // This method should be used on connections with a target driver ONLY! @@ -278,7 +278,7 @@ public static void setTcpKeepAlive(TestDriver testDriver, Properties props, bool public static void setMonitoringConnectTimeout( Properties props, long timeout, TimeUnit timeUnit) { setMonitoringConnectTimeout( - ContainerEnvironment.getCurrent().getCurrentDriver(), props, timeout, timeUnit); + TestEnvironment.getCurrent().getCurrentDriver(), props, timeout, timeUnit); } // This method should be used on connections with a target driver ONLY! @@ -306,7 +306,7 @@ public static void setMonitoringConnectTimeout( // This method should be used on connections with a target driver ONLY! public static void setMonitoringSocketTimeout(Properties props, long timeout, TimeUnit timeUnit) { setMonitoringSocketTimeout( - ContainerEnvironment.getCurrent().getCurrentDriver(), props, timeout, timeUnit); + TestEnvironment.getCurrent().getCurrentDriver(), props, timeout, timeUnit); } // This method should be used on connections with a target driver ONLY! diff --git a/wrapper/src/test/java/integration/container/ConnectionStringHelper.java b/wrapper/src/test/java/integration/container/ConnectionStringHelper.java index 35e35ad04..5867270a9 100644 --- a/wrapper/src/test/java/integration/container/ConnectionStringHelper.java +++ b/wrapper/src/test/java/integration/container/ConnectionStringHelper.java @@ -29,24 +29,24 @@ public class ConnectionStringHelper { public static String getUrl() { return getUrl( - ContainerEnvironment.getCurrent().getCurrentDriver(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent().getCurrentDriver(), + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); } public static String getUrl(String host, int port, String databaseName) { - return getUrl(ContainerEnvironment.getCurrent().getCurrentDriver(), host, port, databaseName); + return getUrl(TestEnvironment.getCurrent().getCurrentDriver(), host, port, databaseName); } public static String getUrl( @@ -54,7 +54,7 @@ public static String getUrl( String host, int port, String databaseName) { - final DatabaseEngine databaseEngine = ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(); + final DatabaseEngine databaseEngine = TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(); final String requiredParameters = DriverHelper.getDriverRequiredParameters(databaseEngine, testDriver); final String url = DriverHelper.getDriverProtocol(databaseEngine, testDriver) + host @@ -67,7 +67,7 @@ public static String getUrl( } public static String getUrlWithPlugins(String host, int port, String databaseName, String wrapperPlugins) { - final String url = getUrl(ContainerEnvironment.getCurrent().getCurrentDriver(), host, port, databaseName); + final String url = getUrl(TestEnvironment.getCurrent().getCurrentDriver(), host, port, databaseName); return url + (url.contains("?") ? "&" : "?") + "wrapperPlugins=" @@ -94,125 +94,125 @@ public static String getUrlWithPlugins( */ public static String getWrapperUrl() { return getWrapperUrl( - ContainerEnvironment.getCurrent().getCurrentDriver(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent().getCurrentDriver(), + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); } public static String getWrapperUrl(TestInstanceInfo instance) { return getWrapperUrl( - ContainerEnvironment.getCurrent().getCurrentDriver(), + TestEnvironment.getCurrent().getCurrentDriver(), instance.getHost(), instance.getPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); } public static String getWrapperUrl(String host, int port, String databaseName) { - return getWrapperUrl(ContainerEnvironment.getCurrent().getCurrentDriver(), host, port, databaseName); + return getWrapperUrl(TestEnvironment.getCurrent().getCurrentDriver(), host, port, databaseName); } public static String getWrapperUrl( TestDriver testDriver, String host, int port, String databaseName) { return DriverHelper.getWrapperDriverProtocol( - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), testDriver) + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), testDriver) + host + ":" + port + "/" + databaseName + DriverHelper.getDriverRequiredParameters( - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), testDriver); + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), testDriver); } public static String getWrapperReaderClusterUrl() { return ConnectionStringHelper.getWrapperUrl( - ContainerEnvironment.getCurrent().getCurrentDriver(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent().getCurrentDriver(), + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterReadOnlyEndpoint(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterReadOnlyEndpointPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); } public static String getProxyWrapperUrl() { return getWrapperUrl( - ContainerEnvironment.getCurrent().getCurrentDriver(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent().getCurrentDriver(), + TestEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances() .get(0) .getHost(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances() .get(0) .getPort(), - ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()); + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()); } public static String getProxyUrl() { return getUrl( - ContainerEnvironment.getCurrent().getCurrentDriver(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent().getCurrentDriver(), + TestEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances() .get(0) .getHost(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances() .get(0) .getPort(), - ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()); + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()); } public static String getWrapperClusterEndpointUrl() { - if (StringUtils.isNullOrEmpty(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint())) { + if (StringUtils.isNullOrEmpty(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint())) { throw new RuntimeException("Cluster Endpoint is not available in this test environment."); } return getWrapperUrl( - ContainerEnvironment.getCurrent().getCurrentDriver(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent().getCurrentDriver(), + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpoint(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpointPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); } public static Properties getDefaultProperties() { final Properties props = new Properties(); props.setProperty( PropertyDefinition.USER.name, - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); props.setProperty( PropertyDefinition.PASSWORD.name, - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); final Set features = - ContainerEnvironment.getCurrent().getInfo().getRequest().getFeatures(); + TestEnvironment.getCurrent().getInfo().getRequest().getFeatures(); props.setProperty(PropertyDefinition.ENABLE_TELEMETRY.name, "true"); props.setProperty(PropertyDefinition.TELEMETRY_SUBMIT_TOPLEVEL.name, "true"); props.setProperty( diff --git a/wrapper/src/test/java/integration/container/ProxyHelper.java b/wrapper/src/test/java/integration/container/ProxyHelper.java index eae726321..76fbd3e68 100644 --- a/wrapper/src/test/java/integration/container/ProxyHelper.java +++ b/wrapper/src/test/java/integration/container/ProxyHelper.java @@ -27,14 +27,14 @@ public class ProxyHelper { /** Stops all traffic to and from server. */ public static void disableAllConnectivity() { - for (Proxy proxy : ContainerEnvironment.getCurrent().getProxies()) { + for (Proxy proxy : TestEnvironment.getCurrent().getProxies()) { disableConnectivity(proxy); } } /** Stops all traffic to and from server. */ public static void disableConnectivity(String instanceName) { - Proxy proxy = ContainerEnvironment.getCurrent().getProxy(instanceName); + Proxy proxy = TestEnvironment.getCurrent().getProxy(instanceName); if (proxy == null) { throw new RuntimeException("Proxy for instance " + instanceName + " not found."); } @@ -65,14 +65,14 @@ private static void disableConnectivity(Proxy proxy) { /** Allow traffic to and from server. */ public static void enableAllConnectivity() { - for (Proxy proxy : ContainerEnvironment.getCurrent().getProxies()) { + for (Proxy proxy : TestEnvironment.getCurrent().getProxies()) { enableConnectivity(proxy); } } /** Allow traffic to and from server. */ public static void enableConnectivity(String instanceName) { - Proxy proxy = ContainerEnvironment.getCurrent().getProxy(instanceName); + Proxy proxy = TestEnvironment.getCurrent().getProxy(instanceName); if (proxy == null) { throw new RuntimeException("Proxy for instance " + instanceName + " not found."); } diff --git a/wrapper/src/test/java/integration/container/TestDriverProvider.java b/wrapper/src/test/java/integration/container/TestDriverProvider.java index dfa0cdf3b..e3d9fcfa1 100644 --- a/wrapper/src/test/java/integration/container/TestDriverProvider.java +++ b/wrapper/src/test/java/integration/container/TestDriverProvider.java @@ -71,7 +71,7 @@ public Stream provideTestTemplateInvocationContex ExtensionContext context) { ArrayList resultContextList = new ArrayList<>(); - for (TestDriver testDriver : ContainerEnvironment.getCurrent().getAllowedTestDrivers()) { + for (TestDriver testDriver : TestEnvironment.getCurrent().getAllowedTestDrivers()) { TestTemplateInvocationContext testTemplateInvocationContext = getEnvironment(context, testDriver); resultContextList.add(testTemplateInvocationContext); @@ -89,7 +89,7 @@ public String getDisplayName(int invocationIndex) { invocationIndex, context.getDisplayName(), testDriver, - ContainerEnvironment.getCurrent().getInfo().getRequest().getDisplayName()); + TestEnvironment.getCurrent().getInfo().getRequest().getDisplayName()); } @Override @@ -101,7 +101,7 @@ public List getAdditionalExtensions() { new BeforeEachCallback() { @Override public void beforeEach(ExtensionContext context) throws Exception { - boolean tracesEnabled = ContainerEnvironment.getCurrent() + boolean tracesEnabled = TestEnvironment.getCurrent() .getInfo() .getRequest() .getFeatures() @@ -116,11 +116,11 @@ public void beforeEach(ExtensionContext context) throws Exception { Segment segment = AWSXRay.beginSegment("test: setup"); segment.putAnnotation("engine", - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine().toString()); + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine().toString()); segment.putAnnotation("deployment", - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment().toString()); + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment().toString()); segment.putAnnotation("targetJVM", - ContainerEnvironment.getCurrent().getInfo().getRequest().getTargetJvm().toString()); + TestEnvironment.getCurrent().getInfo().getRequest().getTargetJvm().toString()); if (testName != null) { segment.putAnnotation("testName", testName); } @@ -129,7 +129,7 @@ public void beforeEach(ExtensionContext context) throws Exception { registerDrivers(testDriver); - if (ContainerEnvironment.getCurrent().getInfo().getRequest().getFeatures() + if (TestEnvironment.getCurrent().getInfo().getRequest().getFeatures() .contains(TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED)) { // Enable all proxies ProxyHelper.enableAllConnectivity(); @@ -140,7 +140,7 @@ public void beforeEach(ExtensionContext context) throws Exception { || isAnnotated(context.getTestClass(), MakeSureFirstInstanceWriter.class); final DatabaseEngineDeployment deployment = - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(); + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(); if (deployment == DatabaseEngineDeployment.AURORA || deployment == DatabaseEngineDeployment.RDS_MULTI_AZ_CLUSTER) { @@ -168,11 +168,11 @@ public void beforeEach(ExtensionContext context) throws Exception { } if (!success) { fail("Cluster " - + ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName() + + TestEnvironment.getCurrent().getInfo().getAuroraClusterName() + " is not healthy."); } LOGGER.finest("Cluster " - + ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName() + + TestEnvironment.getCurrent().getInfo().getAuroraClusterName() + " is healthy."); } @@ -188,7 +188,7 @@ public void beforeEach(ExtensionContext context) throws Exception { @Override public void afterEach(ExtensionContext context) throws Exception { - Set features = ContainerEnvironment.getCurrent() + Set features = TestEnvironment.getCurrent() .getInfo() .getRequest() .getFeatures(); @@ -209,7 +209,7 @@ public void afterEach(ExtensionContext context) throws Exception { private static void registerDrivers(final TestDriver testDriver) throws SQLException { DriverHelper.unregisterAllDrivers(); DriverHelper.registerDriver(testDriver); - ContainerEnvironment.getCurrent().setCurrentDriver(testDriver); + TestEnvironment.getCurrent().setCurrentDriver(testDriver); LOGGER.finest("Registered " + testDriver + " driver."); } @@ -223,7 +223,7 @@ private static void clearCaches() { private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter) throws InterruptedException, SQLException { - final TestEnvironmentInfo testInfo = ContainerEnvironment.getCurrent().getInfo(); + final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); final TestEnvironmentRequest testRequest = testInfo.getRequest(); final TestUtility testUtil = TestUtility.getUtility(testInfo); @@ -294,7 +294,7 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter public static void rebootCluster() throws InterruptedException { - final TestEnvironmentInfo testInfo = ContainerEnvironment.getCurrent().getInfo(); + final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); final TestUtility testUtil = TestUtility.getUtility(testInfo); List instanceIDs = testInfo.getDatabaseInfo().getInstances().stream() @@ -317,7 +317,7 @@ public static void rebootCluster() throws InterruptedException { public static void rebootAllClusterInstances() throws InterruptedException { - final TestEnvironmentInfo testInfo = ContainerEnvironment.getCurrent().getInfo(); + final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); final TestUtility testUtil = TestUtility.getUtility(testInfo); List instanceIDs = testInfo.getDatabaseInfo().getInstances().stream() diff --git a/wrapper/src/test/java/integration/container/ContainerEnvironment.java b/wrapper/src/test/java/integration/container/TestEnvironment.java similarity index 95% rename from wrapper/src/test/java/integration/container/ContainerEnvironment.java rename to wrapper/src/test/java/integration/container/TestEnvironment.java index 7bdbf3b2c..55054c9d7 100644 --- a/wrapper/src/test/java/integration/container/ContainerEnvironment.java +++ b/wrapper/src/test/java/integration/container/TestEnvironment.java @@ -45,27 +45,27 @@ import software.amazon.jdbc.Driver; import software.amazon.jdbc.util.StringUtils; -public class ContainerEnvironment { +public class TestEnvironment { - private static final Logger LOGGER = Logger.getLogger(ContainerEnvironment.class.getName()); + private static final Logger LOGGER = Logger.getLogger(TestEnvironment.class.getName()); - private static ContainerEnvironment env; + private static TestEnvironment env; private TestEnvironmentInfo info; private HashMap proxies; private TestDriver currentDriver; - private ContainerEnvironment() {} + private TestEnvironment() {} - public static synchronized ContainerEnvironment getCurrent() { + public static synchronized TestEnvironment getCurrent() { if (env == null) { env = create(); } return env; } - private static ContainerEnvironment create() { - ContainerEnvironment environment = new ContainerEnvironment(); + private static TestEnvironment create() { + TestEnvironment environment = new TestEnvironment(); String infoJson = System.getenv("TEST_ENV_INFO_JSON"); @@ -154,7 +154,7 @@ private static ContainerEnvironment create() { return environment; } - private static void initProxies(ContainerEnvironment environment) { + private static void initProxies(TestEnvironment environment) { environment.proxies = new HashMap<>(); int proxyControlPort = environment.info.getProxyDatabaseInfo().getControlPort(); diff --git a/wrapper/src/test/java/integration/container/condition/DisableOnTestFeatureCondition.java b/wrapper/src/test/java/integration/container/condition/DisableOnTestFeatureCondition.java index 0f2b27da3..841383cae 100644 --- a/wrapper/src/test/java/integration/container/condition/DisableOnTestFeatureCondition.java +++ b/wrapper/src/test/java/integration/container/condition/DisableOnTestFeatureCondition.java @@ -19,7 +19,7 @@ import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation; import integration.TestEnvironmentFeatures; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import java.util.Arrays; import java.util.Set; import org.junit.jupiter.api.extension.ConditionEvaluationResult; @@ -34,7 +34,7 @@ public DisableOnTestFeatureCondition() {} public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { Set features = - ContainerEnvironment.getCurrent().getInfo().getRequest().getFeatures(); + TestEnvironment.getCurrent().getInfo().getRequest().getFeatures(); boolean disabled = findAnnotation(context.getElement(), DisableOnTestFeature.class) diff --git a/wrapper/src/test/java/integration/container/condition/EnableBasedOnEnvironmentFeatureExtension.java b/wrapper/src/test/java/integration/container/condition/EnableBasedOnEnvironmentFeatureExtension.java index 2d725b08d..ff8c07e67 100644 --- a/wrapper/src/test/java/integration/container/condition/EnableBasedOnEnvironmentFeatureExtension.java +++ b/wrapper/src/test/java/integration/container/condition/EnableBasedOnEnvironmentFeatureExtension.java @@ -17,7 +17,7 @@ package integration.container.condition; import integration.container.TestDriver; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import java.util.logging.Logger; import org.junit.jupiter.api.extension.ConditionEvaluationResult; import org.junit.jupiter.api.extension.ExecutionCondition; @@ -36,7 +36,7 @@ public EnableBasedOnEnvironmentFeatureExtension(TestDriver testDriver) { @Override public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { - if (!ContainerEnvironment.getCurrent().isTestDriverAllowed(this.testDriver)) { + if (!TestEnvironment.getCurrent().isTestDriverAllowed(this.testDriver)) { return ConditionEvaluationResult.disabled("Disabled by test environment features."); } return ConditionEvaluationResult.enabled("Test enabled"); diff --git a/wrapper/src/test/java/integration/container/condition/EnableOnDatabaseEngineCondition.java b/wrapper/src/test/java/integration/container/condition/EnableOnDatabaseEngineCondition.java index a5b6fb9dd..9cca39f2b 100644 --- a/wrapper/src/test/java/integration/container/condition/EnableOnDatabaseEngineCondition.java +++ b/wrapper/src/test/java/integration/container/condition/EnableOnDatabaseEngineCondition.java @@ -19,7 +19,7 @@ import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation; import integration.DatabaseEngine; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import java.util.Arrays; import java.util.logging.Logger; import org.junit.jupiter.api.extension.ConditionEvaluationResult; @@ -37,7 +37,7 @@ public EnableOnDatabaseEngineCondition() {} public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { final DatabaseEngine databaseEngine = - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(); + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(); boolean enabled = findAnnotation(context.getElement(), EnableOnDatabaseEngine.class) diff --git a/wrapper/src/test/java/integration/container/condition/EnableOnDatabaseEngineDeploymentCondition.java b/wrapper/src/test/java/integration/container/condition/EnableOnDatabaseEngineDeploymentCondition.java index b13cfa45f..c927ec02f 100644 --- a/wrapper/src/test/java/integration/container/condition/EnableOnDatabaseEngineDeploymentCondition.java +++ b/wrapper/src/test/java/integration/container/condition/EnableOnDatabaseEngineDeploymentCondition.java @@ -19,7 +19,7 @@ import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation; import integration.DatabaseEngineDeployment; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import java.util.Arrays; import java.util.logging.Logger; import org.junit.jupiter.api.extension.ConditionEvaluationResult; @@ -37,7 +37,7 @@ public EnableOnDatabaseEngineDeploymentCondition() {} public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { final DatabaseEngineDeployment databaseEngineDeployment = - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(); + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(); boolean enabled = findAnnotation(context.getElement(), EnableOnDatabaseEngineDeployment.class) diff --git a/wrapper/src/test/java/integration/container/condition/EnableOnNumOfInstancesCondition.java b/wrapper/src/test/java/integration/container/condition/EnableOnNumOfInstancesCondition.java index 7f783f9ee..c33a3359d 100644 --- a/wrapper/src/test/java/integration/container/condition/EnableOnNumOfInstancesCondition.java +++ b/wrapper/src/test/java/integration/container/condition/EnableOnNumOfInstancesCondition.java @@ -18,7 +18,7 @@ import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import java.util.logging.Logger; import org.junit.jupiter.api.extension.ConditionEvaluationResult; import org.junit.jupiter.api.extension.ExecutionCondition; @@ -35,7 +35,7 @@ public EnableOnNumOfInstancesCondition() {} public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { final int actualNumOfInstances = - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().size(); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().size(); boolean enabled = findAnnotation(context.getElement(), EnableOnNumOfInstances.class) diff --git a/wrapper/src/test/java/integration/container/condition/EnableOnTestFeatureCondition.java b/wrapper/src/test/java/integration/container/condition/EnableOnTestFeatureCondition.java index db6373051..673a3379e 100644 --- a/wrapper/src/test/java/integration/container/condition/EnableOnTestFeatureCondition.java +++ b/wrapper/src/test/java/integration/container/condition/EnableOnTestFeatureCondition.java @@ -19,7 +19,7 @@ import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation; import integration.TestEnvironmentFeatures; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import java.util.Arrays; import java.util.Set; import java.util.logging.Logger; @@ -38,7 +38,7 @@ public EnableOnTestFeatureCondition() {} public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { final Set features = - ContainerEnvironment.getCurrent().getInfo().getRequest().getFeatures(); + TestEnvironment.getCurrent().getInfo().getRequest().getFeatures(); boolean enabled = findAnnotation(context.getElement(), EnableOnTestFeature.class) diff --git a/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java b/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java index 7986da5b0..591787481 100644 --- a/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java +++ b/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java @@ -28,7 +28,7 @@ import integration.TestEnvironmentFeatures; import integration.container.ConnectionStringHelper; import integration.container.TestDriverProvider; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import integration.container.aurora.TestAuroraHostListProvider; import integration.container.aurora.TestPluginServiceImpl; import integration.container.condition.EnableOnTestFeature; @@ -188,9 +188,9 @@ public void test_AdvancedPerformance() throws IOException { String.format( "./build/reports/tests/AdvancedPerformanceResults_" + "Db_%s_Driver_%s_Instances_%d.xlsx", - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - ContainerEnvironment.getCurrent().getCurrentDriver(), - ContainerEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances()), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + TestEnvironment.getCurrent().getCurrentDriver(), + TestEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances()), perfDataList); perfDataList.clear(); } @@ -238,7 +238,7 @@ private void doMeasurePerformance(int sleepDelayMillis) throws InterruptedExcept private void ensureDnsHealthy() throws UnknownHostException, InterruptedException { LOGGER.finest( "Writer is " - + ContainerEnvironment.getCurrent() + + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() @@ -246,7 +246,7 @@ private void ensureDnsHealthy() throws UnknownHostException, InterruptedExceptio .getInstanceId()); final String writerIpAddress = InetAddress.getByName( - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() @@ -256,10 +256,10 @@ private void ensureDnsHealthy() throws UnknownHostException, InterruptedExceptio LOGGER.finest("Writer resolves to " + writerIpAddress); LOGGER.finest( "Cluster Endpoint is " - + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint()); + + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint()); String clusterIpAddress = InetAddress.getByName( - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint()) + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint()) .getHostAddress(); LOGGER.finest("Cluster Endpoint resolves to " + clusterIpAddress); @@ -269,7 +269,7 @@ private void ensureDnsHealthy() throws UnknownHostException, InterruptedExceptio Thread.sleep(1000); clusterIpAddress = InetAddress.getByName( - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint()) + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint()) .getHostAddress(); LOGGER.finest("Cluster Endpoint resolves to " + clusterIpAddress); } @@ -328,15 +328,15 @@ private Thread getThread_DirectDriver( final Connection conn = openConnectionWithRetry( ConnectionStringHelper.getUrlWithPlugins( - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpoint(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpointPort(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getDefaultDbName(), @@ -369,7 +369,7 @@ private Thread getThread_DirectDriver( PerfStat data = new PerfStat(); data.paramFailoverDelayMillis = sleepDelayMillis; data.paramDriverName = - "DirectDriver - " + ContainerEnvironment.getCurrent().getCurrentDriver(); + "DirectDriver - " + TestEnvironment.getCurrent().getCurrentDriver(); data.failureDetectionTimeMillis = TimeUnit.NANOSECONDS.toMillis(failureTimeNano); LOGGER.finest("DirectDriver Collected data: " + data); perfDataList.add(data); @@ -410,15 +410,15 @@ private Thread getThread_WrapperEfm( final Connection conn = openConnectionWithRetry( ConnectionStringHelper.getWrapperUrl( - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpoint(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpointPort(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getDefaultDbName()), @@ -452,7 +452,7 @@ private Thread getThread_WrapperEfm( data.paramFailoverDelayMillis = sleepDelayMillis; data.paramDriverName = String.format( - "AWS Wrapper (%s, EFM)", ContainerEnvironment.getCurrent().getCurrentDriver()); + "AWS Wrapper (%s, EFM)", TestEnvironment.getCurrent().getCurrentDriver()); data.failureDetectionTimeMillis = TimeUnit.NANOSECONDS.toMillis(failureTimeNano); LOGGER.finest("WrapperEfm Collected data: " + data); perfDataList.add(data); @@ -494,15 +494,15 @@ private Thread getThread_WrapperEfmFailover( final Connection conn = openConnectionWithRetry( ConnectionStringHelper.getWrapperUrl( - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpoint(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpointPort(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getDefaultDbName()), @@ -538,7 +538,7 @@ private Thread getThread_WrapperEfmFailover( data.paramDriverName = String.format( "AWS Wrapper (%s, EFM, Failover)", - ContainerEnvironment.getCurrent().getCurrentDriver()); + TestEnvironment.getCurrent().getCurrentDriver()); data.reconnectTimeMillis = TimeUnit.NANOSECONDS.toMillis(failureTimeNano); LOGGER.finest("WrapperEfmFailover Collected data: " + data); perfDataList.add(data); @@ -565,7 +565,7 @@ private Thread getThread_DNS( try { currentClusterIpAddress = InetAddress.getByName( - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpoint()) @@ -579,7 +579,7 @@ private Thread getThread_DNS( String clusterIpAddress = InetAddress.getByName( - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpoint()) @@ -591,7 +591,7 @@ private Thread getThread_DNS( Thread.sleep(1000); clusterIpAddress = InetAddress.getByName( - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getClusterEndpoint()) @@ -644,7 +644,7 @@ private Connection openConnectionWithRetry(String url, Properties props) { } private void failoverCluster() throws InterruptedException { - String clusterId = ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName(); + String clusterId = TestEnvironment.getCurrent().getInfo().getAuroraClusterName(); String randomNode = testUtil.getRandomDBClusterReaderInstanceId(clusterId); testUtil.failoverClusterToTarget(clusterId, randomNode); } @@ -652,7 +652,7 @@ private void failoverCluster() throws InterruptedException { private void ensureClusterHealthy() throws InterruptedException { testUtil.waitUntilClusterHasRightState( - ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName()); + TestEnvironment.getCurrent().getInfo().getAuroraClusterName()); // Always get the latest topology info with writer as first List latestTopology = new ArrayList<>(); @@ -661,7 +661,7 @@ private void ensureClusterHealthy() throws InterruptedException { // Wait up to 5min long startTimeNano = System.nanoTime(); while ((latestTopology.size() - != ContainerEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances() + != TestEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances() || !testUtil.isDBInstanceWriter(latestTopology.get(0))) && TimeUnit.NANOSECONDS.toMinutes(System.nanoTime() - startTimeNano) < 5) { @@ -675,13 +675,13 @@ private void ensureClusterHealthy() throws InterruptedException { } assertTrue( testUtil.isDBInstanceWriter( - ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName(), latestTopology.get(0))); + TestEnvironment.getCurrent().getInfo().getAuroraClusterName(), latestTopology.get(0))); String currentWriter = latestTopology.get(0); // Adjust database info to reflect a current writer and to move corresponding instance to // position 0. - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().moveInstanceFirst(currentWriter); - ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().moveInstanceFirst(currentWriter); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().moveInstanceFirst(currentWriter); + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().moveInstanceFirst(currentWriter); testUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(5)); diff --git a/wrapper/src/test/java/integration/container/tests/AuroraConnectivityTests.java b/wrapper/src/test/java/integration/container/tests/AuroraConnectivityTests.java index 473697cd9..2d450b32f 100644 --- a/wrapper/src/test/java/integration/container/tests/AuroraConnectivityTests.java +++ b/wrapper/src/test/java/integration/container/tests/AuroraConnectivityTests.java @@ -24,7 +24,7 @@ import integration.container.ConnectionStringHelper; import integration.container.TestDriver; import integration.container.TestDriverProvider; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import integration.container.condition.DisableOnTestFeature; import integration.container.condition.EnableOnDatabaseEngineDeployment; import integration.container.condition.EnableOnNumOfInstances; @@ -63,10 +63,10 @@ public void test_WrapperConnectionReaderClusterWithEfmEnabled(TestDriver testDri final Properties props = new Properties(); props.setProperty( PropertyDefinition.USER.name, - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); props.setProperty( PropertyDefinition.PASSWORD.name, - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); props.setProperty(PropertyDefinition.CONNECT_TIMEOUT.name, "10000"); props.setProperty(PropertyDefinition.SOCKET_TIMEOUT.name, "10000"); props.setProperty(PropertyDefinition.PLUGINS.name, "efm"); diff --git a/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java b/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java index 912d292a8..04322da2d 100644 --- a/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java +++ b/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java @@ -33,7 +33,7 @@ import integration.container.ProxyHelper; import integration.container.TestDriver; import integration.container.TestDriverProvider; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import integration.container.condition.DisableOnTestFeature; import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.EnableOnTestDriver; @@ -88,7 +88,7 @@ public class AuroraFailoverTest { @BeforeEach public void setUpEach() { this.currentWriter = - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(0) + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(0) .getInstanceId(); } @@ -103,7 +103,7 @@ public void test_failFromWriterToNewWriter_failOnConnectionInvocation() final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProps(); @@ -112,7 +112,7 @@ public void test_failFromWriterToNewWriter_failOnConnectionInvocation() ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { // Crash Instance1 and nominate a new writer @@ -140,7 +140,7 @@ public void test_failFromWriterToNewWriter_failOnConnectionBoundObjectInvocation final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProps(); @@ -149,7 +149,7 @@ public void test_failFromWriterToNewWriter_failOnConnectionBoundObjectInvocation ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { final Statement stmt = conn.createStatement(); @@ -176,7 +176,7 @@ public void test_failFromWriterToNewWriter_failOnConnectionBoundObjectInvocation public void test_failFromReaderToWriter() throws SQLException { // Connect to the only available reader instance final TestInstanceInfo instanceInfo = - ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstances().get(1); + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstances().get(1); final String instanceId = instanceInfo.getInstanceId(); final Properties props = initDefaultProxiedProps(); @@ -185,7 +185,7 @@ public void test_failFromReaderToWriter() throws SQLException { ConnectionStringHelper.getWrapperUrl( instanceInfo.getHost(), instanceInfo.getPort(), - ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()), + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()), props)) { // Crash the reader instance @@ -211,7 +211,7 @@ public void test_writerFailWithinTransaction_setAutoCommitFalse() final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProps(); @@ -220,7 +220,7 @@ public void test_writerFailWithinTransaction_setAutoCommitFalse() ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { final Statement testStmt1 = conn.createStatement(); @@ -271,7 +271,7 @@ public void test_writerFailWithinTransaction_startTransaction() final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProps(); @@ -280,7 +280,7 @@ public void test_writerFailWithinTransaction_startTransaction() ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { final Statement testStmt1 = conn.createStatement(); @@ -331,8 +331,8 @@ public void test_writerFailWithinTransaction_startTransaction() @EnableOnTestFeature(TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED) public void testServerFailoverWithIdleConnections() throws SQLException, InterruptedException { final List idleConnections = new ArrayList<>(); - final String clusterEndpoint = ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint(); - final int clusterEndpointPort = ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpointPort(); + final String clusterEndpoint = TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint(); + final int clusterEndpointPort = TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpointPort(); final Properties props = initDefaultProps(); props.setProperty(PropertyDefinition.PLUGINS.name, "auroraConnectionTracker,failover"); @@ -343,7 +343,7 @@ public void testServerFailoverWithIdleConnections() throws SQLException, Interru ConnectionStringHelper.getWrapperUrl( clusterEndpoint, clusterEndpointPort, - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)); } @@ -352,12 +352,12 @@ public void testServerFailoverWithIdleConnections() throws SQLException, Interru ConnectionStringHelper.getWrapperUrl( clusterEndpoint, clusterEndpointPort, - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { final String instanceId = testUtil.queryInstanceId( - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), conn); assertEquals(this.currentWriter, instanceId); @@ -373,8 +373,8 @@ public void testServerFailoverWithIdleConnections() throws SQLException, Interru assertThrows( FailoverSQLException.class, () -> testUtil.queryInstanceId( - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), conn)); } @@ -385,12 +385,12 @@ public void testServerFailoverWithIdleConnections() throws SQLException, Interru ConnectionStringHelper.getWrapperUrl( clusterEndpoint, clusterEndpointPort, - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { final String instanceId = testUtil.queryInstanceId( - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), conn); if (this.currentWriter.equals(instanceId)) { @@ -414,9 +414,9 @@ public void test_DataSourceWriterConnection_BasicFailover() throws SQLException, InterruptedException { TestInstanceInfo initialWriterInstanceInfo = - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(0); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(0); TestInstanceInfo nominatedWriterInstanceInfo = - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(1); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(1); final String nominatedWriterId = nominatedWriterInstanceInfo.getInstanceId(); try (final Connection conn = @@ -435,9 +435,9 @@ public void test_DataSourceWriterConnection_BasicFailover() // Assert that we are connected to the new writer after failover happens. List instanceIDs = null; - for (TestInstanceInfo instanceInfo : ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances()) { + for (TestInstanceInfo instanceInfo : TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances()) { if (instanceInfo == initialWriterInstanceInfo - && ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment() + && TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment() == DatabaseEngineDeployment.RDS_MULTI_AZ_CLUSTER) { // Old writer node for RDS MultiAz clusters (usually) isn't available for a long time after failover. // Let's skip this node and fetch topology from another node. @@ -445,13 +445,13 @@ public void test_DataSourceWriterConnection_BasicFailover() } try { instanceIDs = testUtil.getAuroraInstanceIds( - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), ConnectionStringHelper.getUrl( instanceInfo.getHost(), instanceInfo.getPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); if (!instanceIDs.isEmpty()) { break; } @@ -488,9 +488,9 @@ public void test_takeOverConnectionProperties() throws SQLException, Interrupted final Connection establishCacheConnection = DriverManager.getConnection( ConnectionStringHelper.getWrapperUrl( - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpointPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint(), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpointPort(), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props); establishCacheConnection.close(); @@ -499,9 +499,9 @@ public void test_takeOverConnectionProperties() throws SQLException, Interrupted try (final Connection conn = DriverManager.getConnection( ConnectionStringHelper.getWrapperUrl( - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpointPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint(), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpointPort(), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { // Verify that connection accepts multi-statement sql @@ -530,7 +530,7 @@ public void test_failFromWriterWhereKeepSessionStateOnFailoverIsTrue() final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProps(); @@ -539,7 +539,7 @@ public void test_failFromWriterWhereKeepSessionStateOnFailoverIsTrue() ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { conn.setAutoCommit(false); @@ -593,7 +593,7 @@ public void test_failFromWriterWhereKeepSessionStateOnFailoverIsTrue() public void test_writerFailover_writerReelected() throws SQLException, InterruptedException { final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstance(initialWriterId); + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProxiedProps(); PropertyDefinition.SOCKET_TIMEOUT.set(props, "2000"); @@ -603,7 +603,7 @@ public void test_writerFailover_writerReelected() throws SQLException, Interrupt ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { ExecutorService executor = Executors.newFixedThreadPool(1, r -> { @@ -646,7 +646,7 @@ public void test_writerFailover_writerReelected() throws SQLException, Interrupt public void test_readerFailover_readerOrWriter() throws SQLException, InterruptedException { final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProps(); props.setProperty("failoverMode", "reader-or-writer"); @@ -656,7 +656,7 @@ public void test_readerFailover_readerOrWriter() throws SQLException, Interrupte ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { // Crash Instance1 and nominate a new writer @@ -672,7 +672,7 @@ public void test_readerFailover_readerOrWriter() throws SQLException, Interrupte public void test_readerFailover_strictReader() throws SQLException, InterruptedException { final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProps(); props.setProperty("failoverMode", "strict-reader"); @@ -682,7 +682,7 @@ public void test_readerFailover_strictReader() throws SQLException, InterruptedE ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { // Crash Instance1 and nominate a new writer @@ -701,7 +701,7 @@ public void test_readerFailover_strictReader() throws SQLException, InterruptedE public void test_readerFailover_writerReelected() throws SQLException, InterruptedException { final String initialWriterId = this.currentWriter; TestInstanceInfo initialWriterInstanceInfo = - ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstance(initialWriterId); + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstance(initialWriterId); final Properties props = initDefaultProxiedProps(); PropertyDefinition.SOCKET_TIMEOUT.set(props, "2000"); @@ -712,7 +712,7 @@ public void test_readerFailover_writerReelected() throws SQLException, Interrupt ConnectionStringHelper.getWrapperUrl( initialWriterInstanceInfo.getHost(), initialWriterInstanceInfo.getPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { ExecutorService executor = Executors.newFixedThreadPool(1, r -> { @@ -766,8 +766,8 @@ protected Properties initDefaultProxiedProps() { PropertyDefinition.SOCKET_TIMEOUT.set(props, "10000"); AuroraHostListProvider.CLUSTER_INSTANCE_HOST_PATTERN.set( props, - "?." + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointSuffix() - + ":" + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointPort()); + "?." + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointSuffix() + + ":" + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointPort()); return props; } @@ -779,7 +779,7 @@ protected Connection createDataSourceConnectionWithFailoverUsingInstanceId( // Configure the property names for the underlying driver-specific data source: ds.setJdbcProtocol(DriverHelper.getDriverProtocol()); ds.setServerName(instanceEndpoint); - ds.setDatabase(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + ds.setDatabase(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); // Specify the driver-specific data source: ds.setTargetDataSourceClassName(DriverHelper.getDataSourceClassname()); @@ -788,8 +788,8 @@ protected Connection createDataSourceConnectionWithFailoverUsingInstanceId( Properties targetDataSourceProps = ConnectionStringHelper.getDefaultProperties(); targetDataSourceProps.setProperty("wrapperPlugins", this.getFailoverPlugin()); - if (ContainerEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB - && ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() + if (TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB + && TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() == DatabaseEngine.MYSQL) { // Connecting to Mysql database with MariaDb driver requires a configuration parameter // "permitMysqlScheme" @@ -802,7 +802,7 @@ protected Connection createDataSourceConnectionWithFailoverUsingInstanceId( ds.setTargetDataSourceProperties(targetDataSourceProps); return ds.getConnection( - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); } } diff --git a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java index d2dad8332..6e04a1d09 100644 --- a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java +++ b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java @@ -28,7 +28,7 @@ import integration.TestEnvironmentInfo; import integration.TestInstanceInfo; import integration.container.ConnectionStringHelper; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import integration.container.TestDriverProvider; import integration.container.condition.EnableOnDatabaseEngineDeployment; import integration.container.condition.EnableOnNumOfInstances; @@ -107,7 +107,7 @@ public void test_pooledConnectionAutoScaling_setReadOnlyOnOldConnection() AuroraHostListProvider.CLUSTER_TOPOLOGY_REFRESH_RATE_MS.set(props, Long.toString(topologyRefreshRateMs)); - final TestEnvironmentInfo testInfo = ContainerEnvironment.getCurrent().getInfo(); + final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); final List instances = testInfo.getDatabaseInfo().getInstances(); final int originalClusterSize = instances.size(); final long poolExpirationNanos = TimeUnit.MINUTES.toNanos(3); @@ -129,7 +129,7 @@ public void test_pooledConnectionAutoScaling_setReadOnlyOnOldConnection() final Connection newInstanceConn; final String instanceClass = - testUtil.getDbInstanceClass(ContainerEnvironment.getCurrent().getInfo().getRequest()); + testUtil.getDbInstanceClass(TestEnvironment.getCurrent().getInfo().getRequest()); final TestInstanceInfo newInstance = testUtil.createInstance(instanceClass, "auto-scaling-instance"); instances.add(newInstance); @@ -189,7 +189,7 @@ public void test_pooledConnectionAutoScaling_failoverFromDeletedReader() AuroraHostListProvider.CLUSTER_TOPOLOGY_REFRESH_RATE_MS.set(props, Long.toString(topologyRefreshRateMs)); - final TestEnvironmentInfo testInfo = ContainerEnvironment.getCurrent().getInfo(); + final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); final List instances = testInfo.getDatabaseInfo().getInstances(); final HikariPooledConnectionProvider provider = new HikariPooledConnectionProvider(getHikariConfig(instances.size() * 5)); @@ -206,7 +206,7 @@ public void test_pooledConnectionAutoScaling_failoverFromDeletedReader() final Connection newInstanceConn; final String instanceClass = - testUtil.getDbInstanceClass(ContainerEnvironment.getCurrent().getInfo().getRequest()); + testUtil.getDbInstanceClass(TestEnvironment.getCurrent().getInfo().getRequest()); final TestInstanceInfo newInstance = testUtil.createInstance(instanceClass, "auto-scaling-instance"); instances.add(newInstance); diff --git a/wrapper/src/test/java/integration/container/tests/AwsIamIntegrationTest.java b/wrapper/src/test/java/integration/container/tests/AwsIamIntegrationTest.java index d49ba3dfb..9f3d56d2e 100644 --- a/wrapper/src/test/java/integration/container/tests/AwsIamIntegrationTest.java +++ b/wrapper/src/test/java/integration/container/tests/AwsIamIntegrationTest.java @@ -24,7 +24,7 @@ import integration.container.ConnectionStringHelper; import integration.container.TestDriver; import integration.container.TestDriverProvider; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import integration.container.condition.DisableOnTestDriver; import integration.container.condition.DisableOnTestFeature; import integration.container.condition.EnableOnTestFeature; @@ -88,9 +88,9 @@ public void test_AwsIam_WrongDatabaseUsername() { final Properties props = initAwsIamProps( "WRONG_" - + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername() + + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername() + "_USER", - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); Assertions.assertThrows( SQLException.class, @@ -102,7 +102,7 @@ public void test_AwsIam_WrongDatabaseUsername() { @DisableOnTestDriver(TestDriver.MARIADB) public void test_AwsIam_NoDatabaseUsername() { final Properties props = - initAwsIamProps("", ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + initAwsIamProps("", TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); Assertions.assertThrows( SQLException.class, @@ -114,11 +114,11 @@ public void test_AwsIam_NoDatabaseUsername() { @DisableOnTestDriver(TestDriver.MARIADB) public void test_AwsIam_UsingIPAddress() throws UnknownHostException, SQLException { final Properties props = - initAwsIamProps(ContainerEnvironment.getCurrent().getInfo().getIamUsername(), ""); + initAwsIamProps(TestEnvironment.getCurrent().getInfo().getIamUsername(), ""); final String hostIp = hostToIP( - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() @@ -126,7 +126,7 @@ public void test_AwsIam_UsingIPAddress() throws UnknownHostException, SQLExcepti .getHost()); props.setProperty( "iamHost", - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() @@ -137,13 +137,13 @@ public void test_AwsIam_UsingIPAddress() throws UnknownHostException, SQLExcepti DriverManager.getConnection( ConnectionStringHelper.getWrapperUrl( hostIp, - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props); Assertions.assertDoesNotThrow(conn::close); } @@ -153,7 +153,7 @@ public void test_AwsIam_UsingIPAddress() throws UnknownHostException, SQLExcepti @DisableOnTestDriver(TestDriver.MARIADB) public void test_AwsIam_ValidConnectionProperties() throws SQLException { final Properties props = - initAwsIamProps(ContainerEnvironment.getCurrent().getInfo().getIamUsername(), ""); + initAwsIamProps(TestEnvironment.getCurrent().getInfo().getIamUsername(), ""); final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props); @@ -167,7 +167,7 @@ public void test_AwsIam_ValidConnectionProperties() throws SQLException { @DisableOnTestDriver(TestDriver.MARIADB) public void test_AwsIam_ValidConnectionPropertiesNoPassword() throws SQLException { final Properties props = - initAwsIamProps(ContainerEnvironment.getCurrent().getInfo().getIamUsername(), ""); + initAwsIamProps(TestEnvironment.getCurrent().getInfo().getIamUsername(), ""); final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props); conn.close(); @@ -182,14 +182,14 @@ public void test_AwsIam_ValidConnectionPropertiesNoPassword() throws SQLExceptio void test_AwsIam_NoAwsProtocolConnection() throws SQLException { final String dbConn = ConnectionStringHelper.getWrapperUrl(); final Properties validProp = - initAwsIamProps(ContainerEnvironment.getCurrent().getInfo().getIamUsername(), ""); + initAwsIamProps(TestEnvironment.getCurrent().getInfo().getIamUsername(), ""); final Connection conn = DriverManager.getConnection(dbConn, validProp); conn.close(); final Properties invalidProp = initAwsIamProps( - "WRONG_" + ContainerEnvironment.getCurrent().getInfo().getIamUsername() + "_USER", + "WRONG_" + TestEnvironment.getCurrent().getInfo().getIamUsername() + "_USER", ""); Assertions.assertThrows( @@ -204,7 +204,7 @@ void test_AwsIam_NoAwsProtocolConnection() throws SQLException { void test_AwsIam_UserInConnStr() throws SQLException { final String dbConn = ConnectionStringHelper.getWrapperUrl(); final Properties awsIamProp = - initAwsIamProps(ContainerEnvironment.getCurrent().getInfo().getIamUsername(), ""); + initAwsIamProps(TestEnvironment.getCurrent().getInfo().getIamUsername(), ""); awsIamProp.remove(PropertyDefinition.USER.name); final Connection validConn = @@ -213,7 +213,7 @@ void test_AwsIam_UserInConnStr() throws SQLException { + (dbConn.contains("?") ? "&" : "?") + PropertyDefinition.USER.name + "=" - + ContainerEnvironment.getCurrent().getInfo().getIamUsername(), + + TestEnvironment.getCurrent().getInfo().getIamUsername(), awsIamProp); Assertions.assertNotNull(validConn); Assertions.assertThrows( @@ -225,7 +225,7 @@ void test_AwsIam_UserInConnStr() throws SQLException { + PropertyDefinition.USER.name + "=" + "WRONG_" - + ContainerEnvironment.getCurrent().getInfo().getIamUsername(), + + TestEnvironment.getCurrent().getInfo().getIamUsername(), awsIamProp)); } @@ -238,12 +238,12 @@ void test_AwsIam_UserInConnStr() throws SQLException { void test_AwsIam_UserAndPasswordPropertiesArePreserved() throws SQLException { final AwsWrapperDataSource ds = new AwsWrapperDataSource(); ds.setJdbcProtocol(DriverHelper.getDriverProtocol()); - ds.setServerName(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint()); - ds.setDatabase(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + ds.setServerName(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getClusterEndpoint()); + ds.setDatabase(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); ds.setTargetDataSourceClassName(DriverHelper.getDataSourceClassname()); final Properties props = - initAwsIamProps(ContainerEnvironment.getCurrent().getInfo().getIamUsername(), ""); + initAwsIamProps(TestEnvironment.getCurrent().getInfo().getIamUsername(), ""); ds.setTargetDataSourceProperties(props); try (final Connection conn = ds.getConnection()) { @@ -303,7 +303,7 @@ protected Properties initAwsIamProps(String user, String password) { props.setProperty(PropertyDefinition.PLUGINS.name, "iam"); props.setProperty( IamAuthConnectionPlugin.IAM_REGION.name, - ContainerEnvironment.getCurrent().getInfo().getRegion()); + TestEnvironment.getCurrent().getInfo().getRegion()); props.setProperty(PropertyDefinition.USER.name, user); props.setProperty(PropertyDefinition.PASSWORD.name, password); props.setProperty(PropertyDefinition.TCP_KEEP_ALIVE.name, "false"); diff --git a/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java b/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java index 949ede922..c29cd2cce 100644 --- a/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java +++ b/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java @@ -30,7 +30,7 @@ import integration.container.ProxyHelper; import integration.container.TestDriver; import integration.container.TestDriverProvider; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import integration.container.condition.DisableOnTestFeature; import integration.container.condition.EnableOnTestFeature; import java.sql.Connection; @@ -77,19 +77,19 @@ public void test_DirectConnection(TestDriver testDriver) throws SQLException { String url = ConnectionStringHelper.getUrlWithPlugins( testDriver, - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(), ""); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(), ""); LOGGER.finest("Connecting to " + url); final Connection conn = DriverManager.getConnection(url, props); @@ -116,19 +116,19 @@ public void test_WrapperConnection(TestDriver testDriver) throws SQLException { String url = ConnectionStringHelper.getWrapperUrl( testDriver, - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost(), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getPort(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); LOGGER.finest("Connecting to " + url); final Connection conn = DriverManager.getConnection(url, props); @@ -154,14 +154,14 @@ public void test_ProxiedDirectConnection(TestDriver testDriver) throws SQLExcept DriverHelper.setSocketTimeout(testDriver, props, 10, TimeUnit.SECONDS); TestInstanceInfo instanceInfo = - ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstances().get(0); + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstances().get(0); String url = ConnectionStringHelper.getUrlWithPlugins( testDriver, instanceInfo.getHost(), instanceInfo.getPort(), - ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName(), ""); + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName(), ""); LOGGER.finest("Connecting to " + url); final Connection conn = DriverManager.getConnection(url, props); @@ -186,20 +186,20 @@ public void test_ProxiedDirectConnection(TestDriver testDriver) throws SQLExcept @ExtendWith(TestDriverProvider.class) @EnableOnTestFeature(TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED) public void test_ProxiedWrapperConnection() throws SQLException { - LOGGER.info(ContainerEnvironment.getCurrent().getCurrentDriver().toString()); + LOGGER.info(TestEnvironment.getCurrent().getCurrentDriver().toString()); final Properties props = ConnectionStringHelper.getDefaultPropertiesWithNoPlugins(); PropertyDefinition.CONNECT_TIMEOUT.set(props, "10000"); PropertyDefinition.SOCKET_TIMEOUT.set(props, "10000"); TestInstanceInfo instanceInfo = - ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstances().get(0); + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstances().get(0); String url = ConnectionStringHelper.getWrapperUrl( instanceInfo.getHost(), instanceInfo.getPort(), - ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()); + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()); LOGGER.finest("Connecting to " + url); final Connection conn = DriverManager.getConnection(url, props); @@ -225,14 +225,14 @@ public void test_ProxiedWrapperConnection() throws SQLException { public void testSuccessOpenConnectionNoPort() throws SQLException { String url = DriverHelper.getWrapperDriverProtocol() - + ContainerEnvironment.getCurrent() + + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost() + "/" - + ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName() + + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName() + DriverHelper.getDriverRequiredParameters(); LOGGER.finest("Connecting to " + url); @@ -250,7 +250,7 @@ public void testSuccessOpenConnectionNoPort() throws SQLException { public void testFailedConnection(TestDriver testDriver, String url) throws SQLException { DriverHelper.unregisterAllDrivers(); DriverHelper.registerDriver(testDriver); - ContainerEnvironment.getCurrent().setCurrentDriver(testDriver); + TestEnvironment.getCurrent().setCurrentDriver(testDriver); LOGGER.finest("Connecting to " + url); @@ -269,12 +269,12 @@ public void testFailedProperties( TestDriver testDriver, String url, String username, String password) throws SQLException { DriverHelper.unregisterAllDrivers(); DriverHelper.registerDriver(testDriver); - ContainerEnvironment.getCurrent().setCurrentDriver(testDriver); + TestEnvironment.getCurrent().setCurrentDriver(testDriver); - if (ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() + if (TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() == DatabaseEngine.MARIADB - && ContainerEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB - && ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment() + && TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB + && TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment() == DatabaseEngineDeployment.DOCKER && StringUtils.isNullOrEmpty(username)) { // MariaDb driver uses "root" username if no username is provided. Since MariaDb database in @@ -310,7 +310,7 @@ protected static String buildConnectionString( private static Stream testConnectionParameters() { ArrayList results = new ArrayList<>(); - for (TestDriver testDriver : ContainerEnvironment.getCurrent().getAllowedTestDrivers()) { + for (TestDriver testDriver : TestEnvironment.getCurrent().getAllowedTestDrivers()) { // missing connection prefix results.add( @@ -318,20 +318,20 @@ private static Stream testConnectionParameters() { testDriver, buildConnectionString( "", - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost(), String.valueOf( - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getPort()), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(), DriverHelper.getDriverRequiredParameters(testDriver)))); // incorrect database name @@ -340,14 +340,14 @@ private static Stream testConnectionParameters() { testDriver, buildConnectionString( DriverHelper.getWrapperDriverProtocol(testDriver), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost(), String.valueOf( - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() @@ -361,7 +361,7 @@ private static Stream testConnectionParameters() { private static Stream testPropertiesParameters() { ArrayList results = new ArrayList<>(); - for (TestDriver testDriver : ContainerEnvironment.getCurrent().getAllowedTestDrivers()) { + for (TestDriver testDriver : TestEnvironment.getCurrent().getAllowedTestDrivers()) { // missing username results.add( @@ -369,23 +369,23 @@ private static Stream testPropertiesParameters() { testDriver, buildConnectionString( DriverHelper.getWrapperDriverProtocol(testDriver), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost(), String.valueOf( - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getPort()), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(), DriverHelper.getDriverRequiredParameters(testDriver)), "", - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword())); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword())); // missing password results.add( @@ -393,22 +393,22 @@ private static Stream testPropertiesParameters() { testDriver, buildConnectionString( DriverHelper.getWrapperDriverProtocol(testDriver), - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost(), String.valueOf( - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getPort()), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(), DriverHelper.getDriverRequiredParameters(testDriver)), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), "")); } return results.stream(); diff --git a/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java b/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java index eb97c7b36..a3ec5639d 100644 --- a/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java +++ b/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java @@ -29,7 +29,7 @@ import integration.TestInstanceInfo; import integration.container.ConnectionStringHelper; import integration.container.TestDriverProvider; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import integration.container.condition.DisableOnTestFeature; import integration.container.condition.EnableOnDatabaseEngineDeployment; import integration.container.condition.EnableOnNumOfInstances; @@ -88,7 +88,7 @@ public class CustomEndpointTest { @BeforeAll public static void setupEndpoint() { - TestEnvironmentInfo envInfo = ContainerEnvironment.getCurrent().getInfo(); + TestEnvironmentInfo envInfo = TestEnvironment.getCurrent().getInfo(); String clusterId = envInfo.getAuroraClusterName(); String region = envInfo.getRegion(); @@ -196,7 +196,7 @@ public static void waitUntilEndpointHasMembers(RdsClient client, String endpoint @BeforeEach public void identifyWriter() { this.currentWriter = - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(0) + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(0) .getInstanceId(); } @@ -206,7 +206,7 @@ public static void cleanup() { return; } - String region = ContainerEnvironment.getCurrent().getInfo().getRegion(); + String region = TestEnvironment.getCurrent().getInfo().getRegion(); try (RdsClient client = RdsClient.builder().region(Region.of(region)).build()) { deleteEndpoint(client); } @@ -230,7 +230,7 @@ protected Properties initDefaultProps() { @TestTemplate public void testCustomEndpointFailover() throws SQLException, InterruptedException { - final TestDatabaseInfo dbInfo = ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo(); + final TestDatabaseInfo dbInfo = TestEnvironment.getCurrent().getInfo().getDatabaseInfo(); final int port = dbInfo.getClusterEndpointPort(); final Properties props = initDefaultProps(); props.setProperty("failoverMode", "reader-or-writer"); @@ -258,7 +258,7 @@ public void testCustomEndpointFailover() throws SQLException, InterruptedExcepti @TestTemplate public void testCustomEndpointReadWriteSplitting_withCustomEndpointChanges() throws SQLException { - TestEnvironmentInfo envInfo = ContainerEnvironment.getCurrent().getInfo(); + TestEnvironmentInfo envInfo = TestEnvironment.getCurrent().getInfo(); final TestDatabaseInfo dbInfo = envInfo.getDatabaseInfo(); final int port = dbInfo.getClusterEndpointPort(); final Properties props = initDefaultProps(); diff --git a/wrapper/src/test/java/integration/container/tests/DataSourceTests.java b/wrapper/src/test/java/integration/container/tests/DataSourceTests.java index 62fc4404e..8f547e639 100644 --- a/wrapper/src/test/java/integration/container/tests/DataSourceTests.java +++ b/wrapper/src/test/java/integration/container/tests/DataSourceTests.java @@ -26,7 +26,7 @@ import integration.container.ConnectionStringHelper; import integration.container.TestDriver; import integration.container.TestDriverProvider; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import integration.container.condition.DisableOnTestDriver; import integration.container.condition.DisableOnTestFeature; import integration.util.SimpleJndiContextFactory; @@ -65,15 +65,15 @@ public void testConnectionWithDataSourceClassNameAndServerNameFromJndiLookup() throws SQLException, NamingException, IllegalAccessException { final AwsWrapperDataSource ds = new AwsWrapperDataSource(); ds.setJdbcProtocol(DriverHelper.getDriverProtocol()); - ds.setServerName(ContainerEnvironment.getCurrent() + ds.setServerName(TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost()); - ds.setDatabase(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); - ds.setUser(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); - ds.setPassword(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + ds.setDatabase(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + ds.setUser(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); + ds.setPassword(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); ds.setTargetDataSourceClassName(DriverHelper.getDataSourceClassname()); final Properties targetDataSourceProps = ConnectionStringHelper.getDefaultPropertiesWithNoPlugins(); @@ -105,13 +105,13 @@ public void testConnectionWithDataSourceClassNameAndServerNameFromJndiLookup() try (final Connection conn = dsFromJndiLookup.getConnection( - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword())) { + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword())) { assertTrue(conn.isWrapperFor(DriverHelper.getConnectionClass())); assertEquals( conn.getCatalog(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); assertTrue(conn.isValid(10)); } @@ -125,8 +125,8 @@ public void testConnectionWithDataSourceClassNameAndUrlFromJndiLookup() ds.setTargetDataSourceClassName(DriverHelper.getDataSourceClassname()); ds.setJdbcProtocol(DriverHelper.getDriverProtocol()); ds.setJdbcUrl(ConnectionStringHelper.getUrl()); - ds.setUser(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); - ds.setPassword(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + ds.setUser(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); + ds.setPassword(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); final Properties targetDataSourceProps = new Properties(); targetDataSourceProps.setProperty(PropertyDefinition.PLUGINS.name, ""); @@ -158,14 +158,14 @@ public void testConnectionWithDataSourceClassNameAndUrlFromJndiLookup() try (final Connection conn = dsFromJndiLookup.getConnection( - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword())) { + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword())) { assertTrue(conn instanceof ConnectionWrapper); assertTrue(conn.isWrapperFor(DriverHelper.getConnectionClass())); assertEquals( conn.getCatalog(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); assertTrue(conn.isValid(10)); } diff --git a/wrapper/src/test/java/integration/container/tests/HikariTests.java b/wrapper/src/test/java/integration/container/tests/HikariTests.java index 008de62d4..f70cec232 100644 --- a/wrapper/src/test/java/integration/container/tests/HikariTests.java +++ b/wrapper/src/test/java/integration/container/tests/HikariTests.java @@ -39,7 +39,7 @@ import integration.container.ProxyHelper; import integration.container.TestDriver; import integration.container.TestDriverProvider; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import integration.container.condition.DisableOnTestFeature; import integration.container.condition.EnableOnDatabaseEngineDeployment; import integration.container.condition.EnableOnNumOfInstances; @@ -94,8 +94,8 @@ public void testOpenConnectionWithUrl() throws SQLException { try (final HikariDataSource dataSource = new HikariDataSource()) { final String url = ConnectionStringHelper.getWrapperUrl(); dataSource.setJdbcUrl(url); - dataSource.setUsername(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); - dataSource.setPassword(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + dataSource.setUsername(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); + dataSource.setPassword(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); dataSource.addDataSourceProperty(PLUGINS.name, ""); final Connection conn = dataSource.getConnection(); @@ -120,20 +120,20 @@ public void testOpenConnectionWithDataSourceClassName() throws SQLException { dataSource.setDataSourceClassName(AwsWrapperDataSource.class.getName()); // Configure the connection pool: - dataSource.setUsername(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); - dataSource.setPassword(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + dataSource.setUsername(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); + dataSource.setPassword(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); // Configure AwsWrapperDataSource: dataSource.addDataSourceProperty("jdbcProtocol", DriverHelper.getDriverProtocol()); dataSource.addDataSourceProperty("serverName", - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() .get(0) .getHost()); dataSource.addDataSourceProperty(PropertyDefinition.DATABASE.name, - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()); // Specify the driver-specific DataSource for AwsWrapperDataSource: dataSource.addDataSourceProperty("targetDataSourceClassName", @@ -143,8 +143,8 @@ public void testOpenConnectionWithDataSourceClassName() throws SQLException { final Properties targetDataSourceProps = new Properties(); targetDataSourceProps.setProperty(PLUGINS.name, ""); - if (ContainerEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB - && ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() + if (TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB + && TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() == DatabaseEngine.MYSQL) { // Connecting to Mysql database with MariaDb driver requires a configuration parameter // "permitMysqlScheme" @@ -218,7 +218,7 @@ public void testFailoverLostConnection() throws SQLException { public void testEFMFailover() throws SQLException { ProxyHelper.disableAllConnectivity(); - final List instances = ContainerEnvironment.getCurrent() + final List instances = TestEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances(); @@ -267,7 +267,7 @@ public void testEFMFailover() throws SQLException { @EnableOnNumOfInstances(min = 2) public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation() throws SQLException, InterruptedException { - final TestProxyDatabaseInfo proxyInfo = ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); + final TestProxyDatabaseInfo proxyInfo = TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); final List instances = proxyInfo.getInstances(); final TestInstanceInfo reader = instances.get(1); final String readerId = reader.getInstanceId(); @@ -308,7 +308,7 @@ public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation() @EnableOnNumOfInstances(min = 2) public void testInternalPools_driverReaderFailoverOnGetConnectionInvocation() throws SQLException, InterruptedException { - final TestProxyDatabaseInfo proxyInfo = ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); + final TestProxyDatabaseInfo proxyInfo = TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); final List instances = proxyInfo.getInstances(); final TestInstanceInfo writer = instances.get(0); final String writerId = writer.getInstanceId(); @@ -357,7 +357,7 @@ public void testInternalPools_driverReaderFailoverOnGetConnectionInvocation() @EnableOnNumOfInstances(max = 1) public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation_singleInstance() throws SQLException, InterruptedException { - final TestProxyDatabaseInfo proxyInfo = ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); + final TestProxyDatabaseInfo proxyInfo = TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); final List instances = proxyInfo.getInstances(); final TestInstanceInfo writer = instances.get(0); final String writerId = writer.getInstanceId(); @@ -407,8 +407,8 @@ private AwsWrapperDataSource createWrapperDataSource(TestInstanceInfo instanceIn "?." + proxyInfo.getInstanceEndpointSuffix()); targetDataSourceProps.setProperty(RdsHostListProvider.CLUSTER_ID.name, "HikariTestsCluster"); - if (ContainerEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB - && ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() == DatabaseEngine.MYSQL) { + if (TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB + && TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() == DatabaseEngine.MYSQL) { targetDataSourceProps.setProperty("permitMysqlScheme", "1"); } @@ -468,7 +468,7 @@ private HikariDataSource createHikariDataSource(final Properties customProps) { private HikariConfig getConfig(final Properties customProps) { final HikariConfig config = new HikariConfig(); final TestProxyDatabaseInfo proxyDatabaseInfo = - ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo(); config.setUsername(proxyDatabaseInfo.getUsername()); config.setPassword(proxyDatabaseInfo.getPassword()); @@ -489,16 +489,16 @@ configured host (provider with "serverName" property), these attempts may fail. DriverHelper.getDataSourceClassname()); config.addDataSourceProperty("jdbcProtocol", DriverHelper.getDriverProtocol()); config.addDataSourceProperty("serverName", - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances() .get(0) .getHost()); config.addDataSourceProperty("database", - ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()); + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getDefaultDbName()); config.addDataSourceProperty("serverPort", - Integer.toString(ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo() + Integer.toString(TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo() .getClusterEndpointPort())); final Properties targetDataSourceProps = ConnectionStringHelper.getDefaultProperties(); @@ -507,7 +507,7 @@ configured host (provider with "serverName" property), these attempts may fail. targetDataSourceProps.setProperty( "clusterInstanceHostPattern", "?." - + ContainerEnvironment.getCurrent() + + TestEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstanceEndpointSuffix()); @@ -521,8 +521,8 @@ configured host (provider with "serverName" property), these attempts may fail. targetDataSourceProps.setProperty( HostMonitoringConnectionPlugin.FAILURE_DETECTION_COUNT.name, "1"); - if (ContainerEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB - && ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() == DatabaseEngine.MYSQL) { + if (TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB + && TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() == DatabaseEngine.MYSQL) { // Connecting to Mysql database with MariaDb driver requires a configuration parameter // "permitMysqlScheme" targetDataSourceProps.setProperty("permitMysqlScheme", "1"); diff --git a/wrapper/src/test/java/integration/container/tests/PerformanceTest.java b/wrapper/src/test/java/integration/container/tests/PerformanceTest.java index 7feef4d3d..8df6c1669 100644 --- a/wrapper/src/test/java/integration/container/tests/PerformanceTest.java +++ b/wrapper/src/test/java/integration/container/tests/PerformanceTest.java @@ -30,7 +30,7 @@ import integration.container.ConnectionStringHelper; import integration.container.ProxyHelper; import integration.container.TestDriverProvider; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import integration.container.condition.EnableOnTestFeature; import java.io.File; import java.io.FileOutputStream; @@ -172,9 +172,9 @@ public void test_FailureDetectionTime_EnhancedMonitoringEnabled(final String efm String.format( "./build/reports/tests/EnhancedMonitoringOnly_" + "Db_%s_Driver_%s_Instances_%d_Plugin_%s.xlsx", - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - ContainerEnvironment.getCurrent().getCurrentDriver(), - ContainerEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances(), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + TestEnvironment.getCurrent().getCurrentDriver(), + TestEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances(), efmPlugin), enhancedFailureMonitoringPerfDataList); enhancedFailureMonitoringPerfDataList.clear(); @@ -254,9 +254,9 @@ public void test_FailureDetectionTime_FailoverAndEnhancedMonitoringEnabled(final String.format( "./build/reports/tests/FailoverWithEnhancedMonitoring_" + "Db_%s_Driver_%s_Instances_%d_Plugin_%s.xlsx", - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - ContainerEnvironment.getCurrent().getCurrentDriver(), - ContainerEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances(), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + TestEnvironment.getCurrent().getCurrentDriver(), + TestEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances(), plugins.replace(",", "_")), failoverWithEfmPerfDataList); failoverWithEfmPerfDataList.clear(); @@ -290,7 +290,7 @@ private void execute_FailureDetectionTime_FailoverAndEnhancedMonitoringEnabled( props.setProperty( "clusterInstanceHostPattern", "?." - + ContainerEnvironment.getCurrent() + + TestEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstanceEndpointSuffix()); @@ -341,9 +341,9 @@ private void test_FailoverTime_SocketTimeout(final String plugins) throws IOExce String.format( "./build/reports/tests/FailoverWithSocketTimeout_" + "Db_%s_Driver_%s_Instances_%d_Plugins_%s.xlsx", - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - ContainerEnvironment.getCurrent().getCurrentDriver(), - ContainerEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances(), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + TestEnvironment.getCurrent().getCurrentDriver(), + TestEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances(), plugins.replace(",", "_")), failoverWithSocketTimeoutPerfDataList); failoverWithSocketTimeoutPerfDataList.clear(); @@ -363,7 +363,7 @@ private void execute_FailoverTime_SocketTimeout(final String plugins, int socket props.setProperty( "clusterInstanceHostPattern", "?." - + ContainerEnvironment.getCurrent() + + TestEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstanceEndpointSuffix()); @@ -409,7 +409,7 @@ private void doMeasurePerformance( Thread.sleep(sleepDelayMillis); // Kill network ProxyHelper.disableConnectivity( - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances() @@ -447,7 +447,7 @@ private void doMeasurePerformance( } finally { thread.interrupt(); // Ensure thread has stopped running ProxyHelper.enableConnectivity( - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances() @@ -480,7 +480,7 @@ private Connection openConnectionWithRetry(Properties props) { if (conn == null) { fail( "Can't connect to " - + ContainerEnvironment.getCurrent() + + TestEnvironment.getCurrent() .getInfo() .getProxyDatabaseInfo() .getInstances() @@ -497,7 +497,7 @@ private Connection connectToInstance(Properties props) throws SQLException { private String getQuerySql(final int seconds) { final DatabaseEngine databaseEngine = - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(); + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(); switch (databaseEngine) { case PG: return String.format("SELECT pg_sleep(%d)", seconds); diff --git a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingPerformanceTest.java b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingPerformanceTest.java index a7496e93e..4d78c5a5e 100644 --- a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingPerformanceTest.java +++ b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingPerformanceTest.java @@ -19,7 +19,7 @@ import com.zaxxer.hikari.HikariConfig; import integration.TestEnvironmentFeatures; import integration.container.ConnectionStringHelper; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import integration.container.TestDriverProvider; import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.EnableOnTestFeature; @@ -124,8 +124,8 @@ public void test_switchReaderWriterConnection() "./build/reports/tests/" + "DbEngine_%s_Driver_%s_ReadWriteSplittingPerformanceResults_" + "SwitchReaderWriterConnection.xlsx", - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - ContainerEnvironment.getCurrent().getCurrentDriver()) + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + TestEnvironment.getCurrent().getCurrentDriver()) ); setReadOnlyPerfDataList.clear(); @@ -164,8 +164,8 @@ public void test_switchReaderWriterConnection() "./build/reports/tests/" + "DbEngine_%s_Driver_%s_ReadWriteSplittingPerformanceResults_" + "InternalConnectionPools_SwitchReaderWriterConnection.xlsx", - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - ContainerEnvironment.getCurrent().getCurrentDriver()) + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + TestEnvironment.getCurrent().getCurrentDriver()) ); } diff --git a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java index 79e05916a..ec4e88405 100644 --- a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java +++ b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java @@ -34,7 +34,7 @@ import integration.TestEnvironmentInfo; import integration.TestInstanceInfo; import integration.container.ConnectionStringHelper; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import integration.container.ProxyHelper; import integration.container.TestDriver; import integration.container.TestDriverProvider; @@ -95,16 +95,16 @@ public class ReadWriteSplittingTests { protected static Properties getProxiedPropsWithFailover() { final Properties props = getPropsWithFailover(); AuroraHostListProvider.CLUSTER_INSTANCE_HOST_PATTERN.set(props, - "?." + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointSuffix() - + ":" + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointPort()); + "?." + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointSuffix() + + ":" + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointPort()); return props; } protected static Properties getProxiedProps() { final Properties props = getProps(); AuroraHostListProvider.CLUSTER_INSTANCE_HOST_PATTERN.set(props, - "?." + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointSuffix() - + ":" + ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointPort()); + "?." + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointSuffix() + + ":" + TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().getInstanceEndpointPort()); return props; } @@ -183,7 +183,7 @@ public void test_connectToReader_setReadOnlyTrueFalse() throws SQLException { // Assumes the writer is stored as the first instance and all other instances are readers. protected String getWrapperReaderInstanceUrl() { TestInstanceInfo readerInstance = - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(1); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().get(1); return ConnectionStringHelper.getWrapperUrl(readerInstance); } @@ -310,7 +310,7 @@ public void test_setReadOnlyTrue_allReadersDown() throws SQLException { // Kill all reader instances final List instanceIDs = - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().stream() + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().stream() .map(TestInstanceInfo::getInstanceId).collect(Collectors.toList()); for (int i = 1; i < instanceIDs.size(); i++) { ProxyHelper.disableConnectivity(instanceIDs.get(i)); @@ -423,10 +423,10 @@ public void test_failoverToNewWriter_setReadOnlyTrueFalse() // Kill all reader instances final int numOfInstances = - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().size(); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances().size(); for (int i = 1; i < numOfInstances; i++) { ProxyHelper.disableConnectivity( - ContainerEnvironment.getCurrent() + TestEnvironment.getCurrent() .getInfo() .getDatabaseInfo() .getInstances() @@ -482,7 +482,7 @@ public void test_failoverToNewReader_setReadOnlyFalseTrue() throws SQLException assertNotEquals(writerConnectionId, readerConnectionId); String otherReaderId = ""; - final List instances = ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances(); + final List instances = TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances(); for (int i = 1; i < instances.size(); i++) { if (!instances.get(i).getInstanceId().equals(readerConnectionId)) { @@ -538,7 +538,7 @@ public void test_failoverReaderToWriter_setReadOnlyTrueFalse() LOGGER.finest("readerConnectionId=" + readerConnectionId); assertNotEquals(writerConnectionId, readerConnectionId); - final List instances = ContainerEnvironment.getCurrent().getInfo().getProxyDatabaseInfo() + final List instances = TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo() .getInstances(); // Kill all instances except the writer @@ -825,7 +825,7 @@ public void test_pooledConnection_differentUsers() throws SQLException { privilegedUserProps); Statement stmt = conn.createStatement()) { stmt.execute("DROP USER IF EXISTS " + limitedUserName); testUtil.createUser(conn, limitedUserName, limitedUserPassword); - TestEnvironmentInfo info = ContainerEnvironment.getCurrent().getInfo(); + TestEnvironmentInfo info = TestEnvironment.getCurrent().getInfo(); DatabaseEngine engine = info.getRequest().getDatabaseEngine(); if (DatabaseEngine.MYSQL.equals(engine)) { String db = info.getDatabaseInfo().getDefaultDbName(); @@ -868,7 +868,7 @@ public void test_pooledConnection_leastConnectionsStrategy() throws SQLException ReadWriteSplittingPlugin.READER_HOST_SELECTOR_STRATEGY.set(props, "leastConnections"); final List instances = - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances(); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances(); final HikariPooledConnectionProvider provider = new HikariPooledConnectionProvider(getHikariConfig(instances.size())); ConnectionProviderManager.setConnectionProvider(provider); @@ -917,7 +917,7 @@ public void test_pooledConnection_leastConnectionsWithPoolMapping() throws SQLEx } final List instances = - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances(); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances(); // We will be testing all instances excluding the writer and overloaded reader. Each instance // should be tested numOverloadedReaderConnections times to increase the pool connection count // until it equals the connection count of the overloaded reader. diff --git a/wrapper/src/test/java/integration/container/tests/SpringTests.java b/wrapper/src/test/java/integration/container/tests/SpringTests.java index 74a1f4011..3a1cb9e3a 100644 --- a/wrapper/src/test/java/integration/container/tests/SpringTests.java +++ b/wrapper/src/test/java/integration/container/tests/SpringTests.java @@ -21,7 +21,7 @@ import integration.TestEnvironmentFeatures; import integration.container.ConnectionStringHelper; import integration.container.TestDriverProvider; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import integration.container.condition.DisableOnTestFeature; import java.util.Properties; import java.util.Random; @@ -58,8 +58,8 @@ private DataSource getDataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("software.amazon.jdbc.Driver"); dataSource.setUrl(ConnectionStringHelper.getWrapperUrl()); - dataSource.setUsername(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); - dataSource.setPassword(ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + dataSource.setUsername(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername()); + dataSource.setPassword(TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); Properties props = ConnectionStringHelper.getDefaultPropertiesWithNoPlugins(); props.setProperty(PropertyDefinition.LOGGER_LEVEL.name, "ALL"); diff --git a/wrapper/src/test/java/integration/host/HostEnvironment.java b/wrapper/src/test/java/integration/host/TestEnvironment.java similarity index 96% rename from wrapper/src/test/java/integration/host/HostEnvironment.java rename to wrapper/src/test/java/integration/host/TestEnvironment.java index f1b18a4f0..6641d8c98 100644 --- a/wrapper/src/test/java/integration/host/HostEnvironment.java +++ b/wrapper/src/test/java/integration/host/TestEnvironment.java @@ -58,9 +58,9 @@ import software.amazon.awssdk.services.rds.model.DBInstance; import software.amazon.jdbc.util.StringUtils; -public class HostEnvironment implements AutoCloseable { +public class TestEnvironment implements AutoCloseable { - private static final Logger LOGGER = Logger.getLogger(HostEnvironment.class.getName()); + private static final Logger LOGGER = Logger.getLogger(TestEnvironment.class.getName()); private static final int NUM_OR_ENV_PRE_CREATE = 1; // create this number of environments in advance private static final ExecutorService envPreCreateExecutor = Executors.newCachedThreadPool(); @@ -107,11 +107,11 @@ public class HostEnvironment implements AutoCloseable { private TestUtility testUtil; - private HostEnvironment(TestEnvironmentRequest request) { + private TestEnvironment(TestEnvironmentRequest request) { this.info.setRequest(request); } - public static HostEnvironment build(TestEnvironmentRequest request) throws IOException, URISyntaxException { + public static TestEnvironment build(TestEnvironmentRequest request) throws IOException, URISyntaxException { DatabaseEngineDeployment deployment = request.getDatabaseEngineDeployment(); if (deployment == DatabaseEngineDeployment.AURORA @@ -126,11 +126,11 @@ public static HostEnvironment build(TestEnvironmentRequest request) throws IOExc LOGGER.finest("Building test env: " + request.getEnvPreCreateIndex()); preCreateEnvironment(request.getEnvPreCreateIndex()); - HostEnvironment env; + TestEnvironment env; switch (deployment) { case DOCKER: - env = new HostEnvironment(request); + env = new TestEnvironment(request); initDatabaseParams(env); createDatabaseContainers(env); @@ -175,7 +175,7 @@ public static HostEnvironment build(TestEnvironmentRequest request) throws IOExc return env; } - private static HostEnvironment createAuroraOrMultiAzEnvironment(TestEnvironmentRequest request) { + private static TestEnvironment createAuroraOrMultiAzEnvironment(TestEnvironmentRequest request) { EnvPreCreateInfo preCreateInfo = TestEnvironmentProvider.preCreateInfos.get(request.getEnvPreCreateIndex()); @@ -206,18 +206,18 @@ private static HostEnvironment createAuroraOrMultiAzEnvironment(TestEnvironmentR if (result instanceof Exception) { throw new RuntimeException((Exception) result); } - if (result instanceof HostEnvironment) { - HostEnvironment resultHostEnvironment = (HostEnvironment) result; + if (result instanceof TestEnvironment) { + TestEnvironment resultTestEnvironment = (TestEnvironment) result; LOGGER.finer(() -> String.format("Use pre-created DB cluster: %s.cluster-%s", - resultHostEnvironment.auroraClusterName, resultHostEnvironment.auroraClusterDomain)); + resultTestEnvironment.auroraClusterName, resultTestEnvironment.auroraClusterDomain)); - return resultHostEnvironment; + return resultTestEnvironment; } throw new RuntimeException( "Test environment create error. Unrecognized result type: " + result.getClass().getName()); } else { - HostEnvironment env = new HostEnvironment(request); + TestEnvironment env = new TestEnvironment(request); initDatabaseParams(env); createDbCluster(env); @@ -233,7 +233,7 @@ private static HostEnvironment createAuroraOrMultiAzEnvironment(TestEnvironmentR } - private static void createDatabaseContainers(HostEnvironment env) { + private static void createDatabaseContainers(TestEnvironment env) { ContainerHelper containerHelper = new ContainerHelper(); switch (env.info.getRequest().getDatabaseInstances()) { @@ -325,7 +325,7 @@ private static void createDatabaseContainers(HostEnvironment env) { } } - private static void createDbCluster(HostEnvironment env) { + private static void createDbCluster(TestEnvironment env) { switch (env.info.getRequest().getDatabaseInstances()) { case SINGLE_INSTANCE: @@ -351,7 +351,7 @@ private static void createDbCluster(HostEnvironment env) { } } - private static void createDbCluster(HostEnvironment env, int numOfInstances) { + private static void createDbCluster(TestEnvironment env, int numOfInstances) { env.info.setRegion( !StringUtils.isNullOrEmpty(config.rdsDbRegion) @@ -500,7 +500,7 @@ private static void createDbCluster(HostEnvironment env, int numOfInstances) { } } - private static void authorizeIP(HostEnvironment env) { + private static void authorizeIP(TestEnvironment env) { try { env.runnerIP = env.testUtil.getPublicIPAddress(); LOGGER.finest("Test runner IP: " + env.runnerIP); @@ -555,7 +555,7 @@ private static String getRdsEngine(TestEnvironmentRequest request) { } } - private static String getDbEngineVersion(HostEnvironment env) { + private static String getDbEngineVersion(TestEnvironment env) { switch (env.info.getRequest().getDatabaseEngineDeployment()) { case AURORA: return getAuroraDbEngineVersion(env); @@ -567,7 +567,7 @@ private static String getDbEngineVersion(HostEnvironment env) { } } - private static String getAuroraDbEngineVersion(HostEnvironment env) { + private static String getAuroraDbEngineVersion(TestEnvironment env) { String engineName; String systemPropertyVersion; TestEnvironmentRequest request = env.info.getRequest(); @@ -598,7 +598,7 @@ private static String getRdsEngineVersion(TestEnvironmentRequest request) { } private static String findAuroraDbEngineVersion( - HostEnvironment env, + TestEnvironment env, String engineName, String systemPropertyVersion) { @@ -627,7 +627,7 @@ private static int getPort(TestEnvironmentRequest request) { } } - private static void initDatabaseParams(HostEnvironment env) { + private static void initDatabaseParams(TestEnvironment env) { final String dbName = !StringUtils.isNullOrEmpty(config.dbName) ? config.dbName @@ -647,7 +647,7 @@ private static void initDatabaseParams(HostEnvironment env) { env.info.getDatabaseInfo().setDefaultDbName(dbName); } - private static void initAwsCredentials(HostEnvironment env) { + private static void initAwsCredentials(TestEnvironment env) { env.awsAccessKeyId = config.awsAccessKeyId; env.awsSecretAccessKey = config.awsSecretAccessKey; env.awsSessionToken = config.awsSessionToken; @@ -671,7 +671,7 @@ private static void initAwsCredentials(HostEnvironment env) { } } - private static void createProxyContainers(HostEnvironment env) throws IOException { + private static void createProxyContainers(TestEnvironment env) throws IOException { ContainerHelper containerHelper = new ContainerHelper(); int port = getPort(env.info.getRequest()); @@ -750,7 +750,7 @@ private static void createProxyContainers(HostEnvironment env) throws IOExceptio } } - private static void createTestContainer(HostEnvironment env) { + private static void createTestContainer(TestEnvironment env) { final ContainerHelper containerHelper = new ContainerHelper(); if (env.info.getRequest().getFeatures().contains(TestEnvironmentFeatures.RUN_HIBERNATE_TESTS_ONLY)) { @@ -800,7 +800,7 @@ private static void createTestContainer(HostEnvironment env) { env.testContainer.start(); } - private static void createTelemetryXRayContainer(HostEnvironment env) { + private static void createTelemetryXRayContainer(TestEnvironment env) { String xrayAwsRegion = !StringUtils.isNullOrEmpty(System.getenv("XRAY_AWS_REGION")) ? System.getenv("XRAY_AWS_REGION") @@ -831,7 +831,7 @@ private static void createTelemetryXRayContainer(HostEnvironment env) { env.telemetryXRayContainer.start(); } - private static void createTelemetryOtlpContainer(HostEnvironment env) { + private static void createTelemetryOtlpContainer(TestEnvironment env) { LOGGER.finest("Creating OTLP telemetry container"); final ContainerHelper containerHelper = new ContainerHelper(); @@ -879,7 +879,7 @@ private static String getContainerBaseImageName(TestEnvironmentRequest request) } } - private static void configureIamAccess(HostEnvironment env) { + private static void configureIamAccess(TestEnvironment env) { if (env.info.getRequest().getDatabaseEngineDeployment() != DatabaseEngineDeployment.AURORA) { throw new UnsupportedOperationException( @@ -924,7 +924,7 @@ private static void configureIamAccess(HostEnvironment env) { } } - private static String getEnvironmentInfoAsString(HostEnvironment env) { + private static String getEnvironmentInfoAsString(TestEnvironment env) { try { final ObjectMapper mapper = new ObjectMapper(); return mapper.writeValueAsString(env.info); @@ -1075,7 +1075,7 @@ private static void preCreateEnvironment(int currentEnvIndex) { LOGGER.finest(() -> String.format("Pre-create environment for [%d] - %s", finalIndex, preCreateInfo.request.getDisplayName())); - final HostEnvironment env = new HostEnvironment(preCreateInfo.request); + final TestEnvironment env = new TestEnvironment(preCreateInfo.request); preCreateInfo.envPreCreateFuture = envPreCreateExecutor.submit(() -> { final long startTime = System.nanoTime(); diff --git a/wrapper/src/test/java/integration/host/TestRunner.java b/wrapper/src/test/java/integration/host/TestRunner.java index 1337ac66d..718304873 100644 --- a/wrapper/src/test/java/integration/host/TestRunner.java +++ b/wrapper/src/test/java/integration/host/TestRunner.java @@ -26,7 +26,7 @@ public class TestRunner { @TestTemplate public void runTests(TestEnvironmentRequest testEnvironmentRequest) throws Exception { - try (final HostEnvironment env = HostEnvironment.build(testEnvironmentRequest)) { + try (final TestEnvironment env = TestEnvironment.build(testEnvironmentRequest)) { env.runTests("in-container"); } } @@ -34,7 +34,7 @@ public void runTests(TestEnvironmentRequest testEnvironmentRequest) throws Excep @TestTemplate public void debugTests(TestEnvironmentRequest testEnvironmentRequest) throws Exception { - try (final HostEnvironment env = HostEnvironment.build(testEnvironmentRequest)) { + try (final TestEnvironment env = TestEnvironment.build(testEnvironmentRequest)) { env.debugTests("in-container"); } } diff --git a/wrapper/src/test/java/integration/util/TestUtility.java b/wrapper/src/test/java/integration/util/TestUtility.java index ac53d0f25..1b674cbed 100644 --- a/wrapper/src/test/java/integration/util/TestUtility.java +++ b/wrapper/src/test/java/integration/util/TestUtility.java @@ -28,7 +28,7 @@ import integration.TestEnvironmentRequest; import integration.TestInstanceInfo; import integration.container.ConnectionStringHelper; -import integration.container.ContainerEnvironment; +import integration.container.TestEnvironment; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.InetAddress; @@ -172,7 +172,7 @@ public static TestUtility getUtility() { public static TestUtility getUtility(@Nullable TestEnvironmentInfo info) { if (info == null) { - info = ContainerEnvironment.getCurrent().getInfo(); + info = TestEnvironment.getCurrent().getInfo(); } return new TestUtility(info.getRegion(), info.getRdsEndpoint()); @@ -398,7 +398,7 @@ public void createMultiAzCluster(String username, public TestInstanceInfo createInstance(String instanceClass, String instanceId) throws InterruptedException { final Tag testRunnerTag = Tag.builder().key("env").value("test-runner").build(); - final TestEnvironmentInfo info = ContainerEnvironment.getCurrent().getInfo(); + final TestEnvironmentInfo info = TestEnvironment.getCurrent().getInfo(); rdsClient.createDBInstance( CreateDbInstanceRequest.builder() @@ -807,11 +807,11 @@ public void waitUntilInstanceHasRightState(String instanceId, String... allowedS public List getAuroraInstanceIds() throws SQLException { return getAuroraInstanceIds( - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), ConnectionStringHelper.getUrl(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), - ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getUsername(), + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getPassword()); } // The first instance in topology should be a writer! @@ -903,7 +903,7 @@ private String getMultiAzMysqlReplicaWriterInstanceId( public Boolean isDBInstanceWriter(String instanceId) { return isDBInstanceWriter( - ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName(), instanceId); + TestEnvironment.getCurrent().getInfo().getAuroraClusterName(), instanceId); } public Boolean isDBInstanceWriter(String clusterId, String instanceId) { @@ -929,7 +929,7 @@ public List getDBClusterMemberList(String clusterId) { public void makeSureInstancesUp(long timeoutSec) { List instances = new ArrayList<>(); - TestEnvironmentInfo envInfo = ContainerEnvironment.getCurrent().getInfo(); + TestEnvironmentInfo envInfo = TestEnvironment.getCurrent().getInfo(); instances.addAll(envInfo.getDatabaseInfo().getInstances()); instances.addAll(envInfo.getProxyDatabaseInfo().getInstances()); makeSureInstancesUp(instances, timeoutSec); @@ -937,7 +937,7 @@ public void makeSureInstancesUp(long timeoutSec) { public void makeSureInstancesUp(List instances, long timeoutSec) { final ConcurrentHashMap remainingInstances = new ConcurrentHashMap<>(); - final String dbName = ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(); + final String dbName = TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName(); instances.forEach((i) -> remainingInstances.put(i.getHost(), true)); @@ -1008,15 +1008,15 @@ public void assertFirstQueryThrows(Connection connection, Class { String instanceId = queryInstanceId( - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), connection); LOGGER.finest(() -> "Instance ID: " + instanceId); }); } public void failoverClusterAndWaitUntilWriterChanged() throws InterruptedException { - String clusterId = ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName(); + String clusterId = TestEnvironment.getCurrent().getInfo().getAuroraClusterName(); failoverClusterToATargetAndWaitUntilWriterChanged( clusterId, getDBClusterWriterInstanceId(clusterId), @@ -1026,7 +1026,7 @@ public void failoverClusterAndWaitUntilWriterChanged() throws InterruptedExcepti public void failoverClusterToATargetAndWaitUntilWriterChanged( String initialWriterId, String targetWriterId) throws InterruptedException { failoverClusterToATargetAndWaitUntilWriterChanged( - ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName(), + TestEnvironment.getCurrent().getInfo().getAuroraClusterName(), initialWriterId, targetWriterId); } @@ -1036,13 +1036,13 @@ public void failoverClusterToATargetAndWaitUntilWriterChanged( throws InterruptedException { DatabaseEngineDeployment deployment = - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(); + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(); if (deployment == DatabaseEngineDeployment.RDS_MULTI_AZ_CLUSTER) { LOGGER.finest(String.format("failover from: %s", initialWriterId)); } else { LOGGER.finest(String.format("failover from %s to target: %s", initialWriterId, targetWriterId)); } - final TestDatabaseInfo dbInfo = ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo(); + final TestDatabaseInfo dbInfo = TestEnvironment.getCurrent().getInfo().getDatabaseInfo(); final String clusterEndpoint = dbInfo.getClusterEndpoint(); failoverClusterToTarget( @@ -1087,7 +1087,7 @@ public void failoverClusterToATargetAndWaitUntilWriterChanged( LOGGER.finest("Cluster endpoint resolves to (after wait): " + newClusterEndpointIp); // wait until all instances except initial writer instance to be available - List instances = ContainerEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances() + List instances = TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getInstances() .stream() .filter(x -> !x.getInstanceId().equalsIgnoreCase(initialWriterId)) .collect(Collectors.toList()); @@ -1293,7 +1293,7 @@ public String getRandomDBClusterReaderInstanceId(String clusterId) { public String getDBClusterWriterInstanceId() { return getDBClusterWriterInstanceId( - ContainerEnvironment.getCurrent().getInfo().getAuroraClusterName()); + TestEnvironment.getCurrent().getInfo().getAuroraClusterName()); } public String getDBClusterWriterInstanceId(String clusterId) { @@ -1337,8 +1337,8 @@ protected String getInstanceIdSql(DatabaseEngine databaseEngine, DatabaseEngineD public String queryInstanceId(Connection connection) throws SQLException { return queryInstanceId( - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), - ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), + TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), connection); } @@ -1362,7 +1362,7 @@ protected String executeInstanceIdQuery( } public void createUser(Connection conn, String username, String password) throws SQLException { - DatabaseEngine engine = ContainerEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(); + DatabaseEngine engine = TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(); String dropUserSql = getCreateUserSql(engine, username, password); try (Statement stmt = conn.createStatement()) { stmt.execute(dropUserSql); diff --git a/wrapper/src/test/resources/logging-test.properties b/wrapper/src/test/resources/logging-test.properties index c736e12fb..02aab1b46 100644 --- a/wrapper/src/test/resources/logging-test.properties +++ b/wrapper/src/test/resources/logging-test.properties @@ -26,6 +26,6 @@ software.amazon.jdbc.states.level=INFO integration.level=FINEST integration.container.level=FINEST -integration.host.HostEnvironment.level=FINEST +integration.host.TestEnvironment.level=FINEST io.opentelemetry.sdk.level=SEVERE From 1adaa8daffa459b3fd5a9d8bd827eec705106469 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Tue, 21 Jan 2025 17:19:59 -0800 Subject: [PATCH 17/21] Rename TestUtility back to AuroraTestUtility --- .../container/TestDriverProvider.java | 8 ++++---- .../container/tests/AdvancedPerformanceTest.java | 4 ++-- .../container/tests/AuroraFailoverTest.java | 4 ++-- .../container/tests/AutoscalingTests.java | 4 ++-- .../container/tests/CustomEndpointTest.java | 4 ++-- .../integration/container/tests/HikariTests.java | 6 +++--- .../container/tests/ReadWriteSplittingTests.java | 4 ++-- .../java/integration/host/TestEnvironment.java | 6 +++--- .../{TestUtility.java => AuroraTestUtility.java} | 16 ++++++++-------- 9 files changed, 28 insertions(+), 28 deletions(-) rename wrapper/src/test/java/integration/util/{TestUtility.java => AuroraTestUtility.java} (99%) diff --git a/wrapper/src/test/java/integration/container/TestDriverProvider.java b/wrapper/src/test/java/integration/container/TestDriverProvider.java index e3d9fcfa1..beb10aff2 100644 --- a/wrapper/src/test/java/integration/container/TestDriverProvider.java +++ b/wrapper/src/test/java/integration/container/TestDriverProvider.java @@ -34,7 +34,7 @@ import integration.container.condition.EnableBasedOnEnvironmentFeatureExtension; import integration.container.condition.EnableBasedOnTestDriverExtension; import integration.container.condition.MakeSureFirstInstanceWriter; -import integration.util.TestUtility; +import integration.util.AuroraTestUtility; import java.lang.reflect.Method; import java.sql.SQLException; import java.util.ArrayList; @@ -226,7 +226,7 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); final TestEnvironmentRequest testRequest = testInfo.getRequest(); - final TestUtility testUtil = TestUtility.getUtility(testInfo); + final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(testInfo); testUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); testUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(3)); @@ -295,7 +295,7 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter public static void rebootCluster() throws InterruptedException { final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); - final TestUtility testUtil = TestUtility.getUtility(testInfo); + final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(testInfo); List instanceIDs = testInfo.getDatabaseInfo().getInstances().stream() .map(TestInstanceInfo::getInstanceId) @@ -318,7 +318,7 @@ public static void rebootCluster() throws InterruptedException { public static void rebootAllClusterInstances() throws InterruptedException { final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); - final TestUtility testUtil = TestUtility.getUtility(testInfo); + final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(testInfo); List instanceIDs = testInfo.getDatabaseInfo().getInstances().stream() .map(TestInstanceInfo::getInstanceId) diff --git a/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java b/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java index 591787481..7bc65d62d 100644 --- a/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java +++ b/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java @@ -32,7 +32,7 @@ import integration.container.aurora.TestAuroraHostListProvider; import integration.container.aurora.TestPluginServiceImpl; import integration.container.condition.EnableOnTestFeature; -import integration.util.TestUtility; +import integration.util.AuroraTestUtility; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -99,7 +99,7 @@ public class AdvancedPerformanceTest { private static final ConcurrentLinkedQueue perfDataList = new ConcurrentLinkedQueue<>(); - protected static final TestUtility testUtil = TestUtility.getUtility(); + protected static final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(); private static void doWritePerfDataToFile( String fileName, ConcurrentLinkedQueue dataList) throws IOException { diff --git a/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java b/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java index 04322da2d..27b2f823c 100644 --- a/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java +++ b/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java @@ -39,7 +39,7 @@ import integration.container.condition.EnableOnTestDriver; import integration.container.condition.EnableOnTestFeature; import integration.container.condition.MakeSureFirstInstanceWriter; -import integration.util.TestUtility; +import integration.util.AuroraTestUtility; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; @@ -79,7 +79,7 @@ public class AuroraFailoverTest { private static final Logger LOGGER = Logger.getLogger(AuroraFailoverTest.class.getName()); - protected static final TestUtility testUtil = TestUtility.getUtility(); + protected static final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(); protected static final int IS_VALID_TIMEOUT = 5; protected String currentWriter; diff --git a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java index 6e04a1d09..4a475c629 100644 --- a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java +++ b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java @@ -34,7 +34,7 @@ import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.EnableOnTestFeature; import integration.container.condition.MakeSureFirstInstanceWriter; -import integration.util.TestUtility; +import integration.util.AuroraTestUtility; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -64,7 +64,7 @@ @MakeSureFirstInstanceWriter @Order(17) public class AutoscalingTests { - protected static final TestUtility testUtil = TestUtility.getUtility(); + protected static final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(); protected static Properties getDefaultPropsNoPlugins() { final Properties props = ConnectionStringHelper.getDefaultProperties(); diff --git a/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java b/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java index a3ec5639d..aa165344f 100644 --- a/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java +++ b/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java @@ -34,7 +34,7 @@ import integration.container.condition.EnableOnDatabaseEngineDeployment; import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.MakeSureFirstInstanceWriter; -import integration.util.TestUtility; +import integration.util.AuroraTestUtility; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -81,7 +81,7 @@ public class CustomEndpointTest { protected static final String endpointId = "test-endpoint-1-" + UUID.randomUUID(); protected static DBClusterEndpoint endpointInfo; - protected static final TestUtility testUtil = TestUtility.getUtility(); + protected static final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(); protected static final boolean reuseExistingEndpoint = false; protected String currentWriter; diff --git a/wrapper/src/test/java/integration/container/tests/HikariTests.java b/wrapper/src/test/java/integration/container/tests/HikariTests.java index f70cec232..1c15192a7 100644 --- a/wrapper/src/test/java/integration/container/tests/HikariTests.java +++ b/wrapper/src/test/java/integration/container/tests/HikariTests.java @@ -16,7 +16,7 @@ package integration.container.tests; -import static integration.util.TestUtility.executeWithTimeout; +import static integration.util.AuroraTestUtility.executeWithTimeout; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -45,7 +45,7 @@ import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.EnableOnTestFeature; import integration.container.condition.MakeSureFirstInstanceWriter; -import integration.util.TestUtility; +import integration.util.AuroraTestUtility; import java.sql.Connection; import java.sql.SQLException; import java.sql.SQLTransientConnectionException; @@ -87,7 +87,7 @@ public class HikariTests { private static final Logger LOGGER = Logger.getLogger(HikariTests.class.getName()); - protected static final TestUtility testUtil = TestUtility.getUtility(); + protected static final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(); @TestTemplate public void testOpenConnectionWithUrl() throws SQLException { diff --git a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java index ec4e88405..374ddf1b8 100644 --- a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java +++ b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java @@ -46,7 +46,7 @@ import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.EnableOnTestFeature; import integration.container.condition.MakeSureFirstInstanceWriter; -import integration.util.TestUtility; +import integration.util.AuroraTestUtility; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; @@ -89,7 +89,7 @@ @Order(12) public class ReadWriteSplittingTests { - protected static final TestUtility testUtil = TestUtility.getUtility(); + protected static final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(); private static final Logger LOGGER = Logger.getLogger(ReadWriteSplittingTests.class.getName()); protected static Properties getProxiedPropsWithFailover() { diff --git a/wrapper/src/test/java/integration/host/TestEnvironment.java b/wrapper/src/test/java/integration/host/TestEnvironment.java index 6641d8c98..1fe6b7779 100644 --- a/wrapper/src/test/java/integration/host/TestEnvironment.java +++ b/wrapper/src/test/java/integration/host/TestEnvironment.java @@ -33,7 +33,7 @@ import integration.TestTelemetryInfo; import integration.host.TestEnvironmentProvider.EnvPreCreateInfo; import integration.util.ContainerHelper; -import integration.util.TestUtility; +import integration.util.AuroraTestUtility; import java.io.IOException; import java.net.URISyntaxException; import java.net.UnknownHostException; @@ -105,7 +105,7 @@ public class TestEnvironment implements AutoCloseable { private final Network network = Network.newNetwork(); - private TestUtility testUtil; + private AuroraTestUtility testUtil; private TestEnvironment(TestEnvironmentRequest request) { this.info.setRequest(request); @@ -365,7 +365,7 @@ private static void createDbCluster(TestEnvironment env, int numOfInstances) { env.info.setRdsEndpoint(env.rdsEndpoint); env.testUtil = - new TestUtility( + new AuroraTestUtility( env.info.getRegion(), env.rdsEndpoint, env.awsAccessKeyId, diff --git a/wrapper/src/test/java/integration/util/TestUtility.java b/wrapper/src/test/java/integration/util/AuroraTestUtility.java similarity index 99% rename from wrapper/src/test/java/integration/util/TestUtility.java rename to wrapper/src/test/java/integration/util/AuroraTestUtility.java index 1b674cbed..86fb0ed2b 100644 --- a/wrapper/src/test/java/integration/util/TestUtility.java +++ b/wrapper/src/test/java/integration/util/AuroraTestUtility.java @@ -108,9 +108,9 @@ * Provides useful functions for RDS integration testing. To use this functionality the following environment variables * must be defined: - AWS_ACCESS_KEY_ID - AWS_SECRET_ACCESS_KEY */ -public class TestUtility { +public class AuroraTestUtility { - private static final Logger LOGGER = Logger.getLogger(TestUtility.class.getName()); + private static final Logger LOGGER = Logger.getLogger(AuroraTestUtility.class.getName()); private static final String DUPLICATE_IP_ERROR_CODE = "InvalidPermission.Duplicate"; private static final String DEFAULT_SECURITY_GROUP = "default"; private static final String DEFAULT_STORAGE_TYPE = "io1"; @@ -121,11 +121,11 @@ public class TestUtility { private final RdsClient rdsClient; private final Ec2Client ec2Client; - public TestUtility(String region, String endpoint) { + public AuroraTestUtility(String region, String endpoint) { this(getRegionInternal(region), endpoint, DefaultCredentialsProvider.create()); } - public TestUtility( + public AuroraTestUtility( String region, String rdsEndpoint, String awsAccessKeyId, String awsSecretAccessKey, String awsSessionToken) { this( getRegionInternal(region), @@ -146,7 +146,7 @@ public TestUtility( * Regions, Availability Zones, and Local Zones * @param credentialsProvider The AWS credential provider to use to initialize the RdsClient and Ec2Client. */ - public TestUtility(Region region, String rdsEndpoint, AwsCredentialsProvider credentialsProvider) { + public AuroraTestUtility(Region region, String rdsEndpoint, AwsCredentialsProvider credentialsProvider) { final RdsClientBuilder rdsClientBuilder = RdsClient.builder() .region(region) .credentialsProvider(credentialsProvider); @@ -166,16 +166,16 @@ public TestUtility(Region region, String rdsEndpoint, AwsCredentialsProvider cre .build(); } - public static TestUtility getUtility() { + public static AuroraTestUtility getUtility() { return getUtility(null); } - public static TestUtility getUtility(@Nullable TestEnvironmentInfo info) { + public static AuroraTestUtility getUtility(@Nullable TestEnvironmentInfo info) { if (info == null) { info = TestEnvironment.getCurrent().getInfo(); } - return new TestUtility(info.getRegion(), info.getRdsEndpoint()); + return new AuroraTestUtility(info.getRegion(), info.getRdsEndpoint()); } protected static Region getRegionInternal(String rdsRegion) { From 9990eab5feace70a40daf2ccda7d5e8e048ceb53 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Tue, 21 Jan 2025 17:20:45 -0800 Subject: [PATCH 18/21] Rename testUtil variable back to auroraUtil --- .../container/TestDriverProvider.java | 42 ++--- .../tests/AdvancedPerformanceTest.java | 16 +- .../container/tests/AuroraFailoverTest.java | 88 +++++------ .../container/tests/AutoscalingTests.java | 28 ++-- .../container/tests/CustomEndpointTest.java | 20 +-- .../container/tests/HikariTests.java | 18 +-- .../tests/ReadWriteSplittingTests.java | 146 +++++++++--------- .../integration/host/TestEnvironment.java | 38 ++--- 8 files changed, 198 insertions(+), 198 deletions(-) diff --git a/wrapper/src/test/java/integration/container/TestDriverProvider.java b/wrapper/src/test/java/integration/container/TestDriverProvider.java index beb10aff2..491d35447 100644 --- a/wrapper/src/test/java/integration/container/TestDriverProvider.java +++ b/wrapper/src/test/java/integration/container/TestDriverProvider.java @@ -226,10 +226,10 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); final TestEnvironmentRequest testRequest = testInfo.getRequest(); - final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(testInfo); - testUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); + final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(testInfo); + auroraUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); - testUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(3)); + auroraUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(3)); if (makeSureFirstInstanceWriter) { @@ -240,13 +240,13 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter long startTimeNano = System.nanoTime(); while ((instanceIDs.size() != testRequest.getNumOfInstances() || instanceIDs.isEmpty() - || !testUtil.isDBInstanceWriter(instanceIDs.get(0))) + || !auroraUtil.isDBInstanceWriter(instanceIDs.get(0))) && TimeUnit.NANOSECONDS.toMinutes(System.nanoTime() - startTimeNano) < 10) { Thread.sleep(5000); try { - instanceIDs = testUtil.getAuroraInstanceIds(); + instanceIDs = auroraUtil.getAuroraInstanceIds(); } catch (SQLException ex) { if (POSTGRES_AUTH_ERROR_CODE.equals(ex.getSQLState())) { // This authentication error for PG is caused by test environment configuration. @@ -257,7 +257,7 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter } assertTrue(instanceIDs.size() > 0); assertTrue( - testUtil.isDBInstanceWriter( + auroraUtil.isDBInstanceWriter( testInfo.getAuroraClusterName(), instanceIDs.get(0))); String currentWriter = instanceIDs.get(0); @@ -269,7 +269,7 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter testInfo.getProxyDatabaseInfo().moveInstanceFirst(currentWriter); // Wait for cluster endpoint to resolve to the writer - final boolean dnsOk = testUtil.waitDnsEqual( + final boolean dnsOk = auroraUtil.waitDnsEqual( dbInfo.getClusterEndpoint(), dbInfo.getInstances().get(0).getHost(), TimeUnit.MINUTES.toSeconds(5), @@ -280,7 +280,7 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter if (instanceIDs.size() > 1) { // Wait for cluster RO endpoint to resolve NOT to the writer - final boolean dnsROOk = testUtil.waitDnsNotEqual( + final boolean dnsROOk = auroraUtil.waitDnsNotEqual( dbInfo.getClusterReadOnlyEndpoint(), dbInfo.getInstances().get(0).getHost(), TimeUnit.MINUTES.toSeconds(5), @@ -295,47 +295,47 @@ private static void checkClusterHealth(final boolean makeSureFirstInstanceWriter public static void rebootCluster() throws InterruptedException { final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); - final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(testInfo); + final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(testInfo); List instanceIDs = testInfo.getDatabaseInfo().getInstances().stream() .map(TestInstanceInfo::getInstanceId) .collect(Collectors.toList()); - testUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); + auroraUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); // Instances should have one of the following statuses to allow reboot a cluster. for (String instanceId : instanceIDs) { - testUtil.waitUntilInstanceHasRightState(instanceId, + auroraUtil.waitUntilInstanceHasRightState(instanceId, "available", "storage-optimization", "incompatible-credentials", "incompatible-parameters", "unavailable"); } - testUtil.rebootCluster(testInfo.getAuroraClusterName()); - testUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName(), "rebooting"); - testUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); - testUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(10)); + auroraUtil.rebootCluster(testInfo.getAuroraClusterName()); + auroraUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName(), "rebooting"); + auroraUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); + auroraUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(10)); } public static void rebootAllClusterInstances() throws InterruptedException { final TestEnvironmentInfo testInfo = TestEnvironment.getCurrent().getInfo(); - final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(testInfo); + final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(testInfo); List instanceIDs = testInfo.getDatabaseInfo().getInstances().stream() .map(TestInstanceInfo::getInstanceId) .collect(Collectors.toList()); - testUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); + auroraUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); for (String instanceId : instanceIDs) { - testUtil.rebootInstance(instanceId); + auroraUtil.rebootInstance(instanceId); } - testUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); + auroraUtil.waitUntilClusterHasRightState(testInfo.getAuroraClusterName()); for (String instanceId : instanceIDs) { - testUtil.waitUntilInstanceHasRightState(instanceId); + auroraUtil.waitUntilInstanceHasRightState(instanceId); } - testUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(10)); + auroraUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(10)); } } diff --git a/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java b/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java index 7bc65d62d..22db0293d 100644 --- a/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java +++ b/wrapper/src/test/java/integration/container/tests/AdvancedPerformanceTest.java @@ -99,7 +99,7 @@ public class AdvancedPerformanceTest { private static final ConcurrentLinkedQueue perfDataList = new ConcurrentLinkedQueue<>(); - protected static final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(); + protected static final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(); private static void doWritePerfDataToFile( String fileName, ConcurrentLinkedQueue dataList) throws IOException { @@ -645,13 +645,13 @@ private Connection openConnectionWithRetry(String url, Properties props) { private void failoverCluster() throws InterruptedException { String clusterId = TestEnvironment.getCurrent().getInfo().getAuroraClusterName(); - String randomNode = testUtil.getRandomDBClusterReaderInstanceId(clusterId); - testUtil.failoverClusterToTarget(clusterId, randomNode); + String randomNode = auroraUtil.getRandomDBClusterReaderInstanceId(clusterId); + auroraUtil.failoverClusterToTarget(clusterId, randomNode); } private void ensureClusterHealthy() throws InterruptedException { - testUtil.waitUntilClusterHasRightState( + auroraUtil.waitUntilClusterHasRightState( TestEnvironment.getCurrent().getInfo().getAuroraClusterName()); // Always get the latest topology info with writer as first @@ -662,19 +662,19 @@ private void ensureClusterHealthy() throws InterruptedException { long startTimeNano = System.nanoTime(); while ((latestTopology.size() != TestEnvironment.getCurrent().getInfo().getRequest().getNumOfInstances() - || !testUtil.isDBInstanceWriter(latestTopology.get(0))) + || !auroraUtil.isDBInstanceWriter(latestTopology.get(0))) && TimeUnit.NANOSECONDS.toMinutes(System.nanoTime() - startTimeNano) < 5) { Thread.sleep(5000); try { - latestTopology = testUtil.getAuroraInstanceIds(); + latestTopology = auroraUtil.getAuroraInstanceIds(); } catch (SQLException ex) { latestTopology = new ArrayList<>(); } } assertTrue( - testUtil.isDBInstanceWriter( + auroraUtil.isDBInstanceWriter( TestEnvironment.getCurrent().getInfo().getAuroraClusterName(), latestTopology.get(0))); String currentWriter = latestTopology.get(0); @@ -683,7 +683,7 @@ private void ensureClusterHealthy() throws InterruptedException { TestEnvironment.getCurrent().getInfo().getDatabaseInfo().moveInstanceFirst(currentWriter); TestEnvironment.getCurrent().getInfo().getProxyDatabaseInfo().moveInstanceFirst(currentWriter); - testUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(5)); + auroraUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(5)); TestAuroraHostListProvider.clearCache(); TestPluginServiceImpl.clearHostAvailabilityCache(); diff --git a/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java b/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java index 27b2f823c..8bccdc86d 100644 --- a/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java +++ b/wrapper/src/test/java/integration/container/tests/AuroraFailoverTest.java @@ -79,7 +79,7 @@ public class AuroraFailoverTest { private static final Logger LOGGER = Logger.getLogger(AuroraFailoverTest.class.getName()); - protected static final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(); + protected static final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(); protected static final int IS_VALID_TIMEOUT = 5; protected String currentWriter; @@ -116,14 +116,14 @@ public void test_failFromWriterToNewWriter_failOnConnectionInvocation() props)) { // Crash Instance1 and nominate a new writer - testUtil.failoverClusterAndWaitUntilWriterChanged(); + auroraUtil.failoverClusterAndWaitUntilWriterChanged(); // Failure occurs on Connection invocation - testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); // Assert that we are connected to the new writer after failover happens. - final String currentConnectionId = testUtil.queryInstanceId(conn); - assertTrue(testUtil.isDBInstanceWriter(currentConnectionId)); + final String currentConnectionId = auroraUtil.queryInstanceId(conn); + assertTrue(auroraUtil.isDBInstanceWriter(currentConnectionId)); assertNotEquals(currentConnectionId, initialWriterId); } } @@ -155,14 +155,14 @@ public void test_failFromWriterToNewWriter_failOnConnectionBoundObjectInvocation final Statement stmt = conn.createStatement(); // Crash Instance1 and nominate a new writer - testUtil.failoverClusterAndWaitUntilWriterChanged(); + auroraUtil.failoverClusterAndWaitUntilWriterChanged(); // Failure occurs on Statement invocation - testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); // Assert that the driver is connected to the new writer after failover happens. - final String currentConnectionId = testUtil.queryInstanceId(conn); - assertTrue(testUtil.isDBInstanceWriter(currentConnectionId)); + final String currentConnectionId = auroraUtil.queryInstanceId(conn); + assertTrue(auroraUtil.isDBInstanceWriter(currentConnectionId)); assertNotEquals(initialWriterId, currentConnectionId); } @@ -191,13 +191,13 @@ public void test_failFromReaderToWriter() throws SQLException { // Crash the reader instance ProxyHelper.disableConnectivity(instanceId); - testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); // Assert that we are currently connected to the writer instance. final String writerId = this.currentWriter; - String currentConnectionId = testUtil.queryInstanceId(conn); + String currentConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(writerId, currentConnectionId); - assertTrue(testUtil.isDBInstanceWriter(currentConnectionId)); + assertTrue(auroraUtil.isDBInstanceWriter(currentConnectionId)); } } @@ -232,7 +232,7 @@ public void test_writerFailWithinTransaction_setAutoCommitFalse() final Statement testStmt2 = conn.createStatement(); testStmt2.executeUpdate("INSERT INTO test3_2 VALUES (1, 'test field string 1')"); - testUtil.failoverClusterAndWaitUntilWriterChanged(); + auroraUtil.failoverClusterAndWaitUntilWriterChanged(); // If there is an active transaction, roll it back and return an error with SQLState 08007. final SQLException exception = @@ -244,10 +244,10 @@ public void test_writerFailWithinTransaction_setAutoCommitFalse() SqlState.CONNECTION_FAILURE_DURING_TRANSACTION.getState(), exception.getSQLState()); // Attempt to query the instance id. - final String currentConnectionId = testUtil.queryInstanceId(conn); + final String currentConnectionId = auroraUtil.queryInstanceId(conn); // Assert that we are connected to the new writer after failover happens. - assertTrue(testUtil.isDBInstanceWriter(currentConnectionId)); - final String nextClusterWriterId = testUtil.getDBClusterWriterInstanceId(); + assertTrue(auroraUtil.isDBInstanceWriter(currentConnectionId)); + final String nextClusterWriterId = auroraUtil.getDBClusterWriterInstanceId(); assertEquals(currentConnectionId, nextClusterWriterId); assertNotEquals(initialWriterId, nextClusterWriterId); @@ -292,7 +292,7 @@ public void test_writerFailWithinTransaction_startTransaction() final Statement testStmt2 = conn.createStatement(); testStmt2.executeUpdate("INSERT INTO test3_3 VALUES (1, 'test field string 1')"); - testUtil.failoverClusterAndWaitUntilWriterChanged(); + auroraUtil.failoverClusterAndWaitUntilWriterChanged(); // If there is an active transaction, roll it back and return an error with SQLState 08007. final SQLException exception = @@ -304,10 +304,10 @@ public void test_writerFailWithinTransaction_startTransaction() SqlState.CONNECTION_FAILURE_DURING_TRANSACTION.getState(), exception.getSQLState()); // Attempt to query the instance id. - final String currentConnectionId = testUtil.queryInstanceId(conn); + final String currentConnectionId = auroraUtil.queryInstanceId(conn); // Assert that we are connected to the new writer after failover happens. - assertTrue(testUtil.isDBInstanceWriter(currentConnectionId)); - final String nextClusterWriterId = testUtil.getDBClusterWriterInstanceId(); + assertTrue(auroraUtil.isDBInstanceWriter(currentConnectionId)); + final String nextClusterWriterId = auroraUtil.getDBClusterWriterInstanceId(); assertEquals(currentConnectionId, nextClusterWriterId); assertNotEquals(initialWriterId, nextClusterWriterId); @@ -355,7 +355,7 @@ public void testServerFailoverWithIdleConnections() throws SQLException, Interru TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { - final String instanceId = testUtil.queryInstanceId( + final String instanceId = auroraUtil.queryInstanceId( TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), conn); @@ -367,12 +367,12 @@ public void testServerFailoverWithIdleConnections() throws SQLException, Interru } // Crash current writer and nominate a new writer - testUtil.failoverClusterAndWaitUntilWriterChanged(); + auroraUtil.failoverClusterAndWaitUntilWriterChanged(); // Assert failover has occurred. assertThrows( FailoverSQLException.class, - () -> testUtil.queryInstanceId( + () -> auroraUtil.queryInstanceId( TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), conn)); @@ -388,7 +388,7 @@ public void testServerFailoverWithIdleConnections() throws SQLException, Interru TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()), props)) { - final String instanceId = testUtil.queryInstanceId( + final String instanceId = auroraUtil.queryInstanceId( TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), conn); @@ -424,13 +424,13 @@ public void test_DataSourceWriterConnection_BasicFailover() initialWriterInstanceInfo.getHost())) { // Trigger failover - testUtil.failoverClusterToATargetAndWaitUntilWriterChanged( + auroraUtil.failoverClusterToATargetAndWaitUntilWriterChanged( initialWriterInstanceInfo.getInstanceId(), nominatedWriterId); - testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); // Execute Query again to get the current connection id; - final String currentConnectionId = testUtil.queryInstanceId(conn); + final String currentConnectionId = auroraUtil.queryInstanceId(conn); LOGGER.fine("currentConnectionId: " + currentConnectionId); // Assert that we are connected to the new writer after failover happens. @@ -444,7 +444,7 @@ public void test_DataSourceWriterConnection_BasicFailover() continue; } try { - instanceIDs = testUtil.getAuroraInstanceIds( + instanceIDs = auroraUtil.getAuroraInstanceIds( TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine(), TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment(), ConnectionStringHelper.getUrl( @@ -509,9 +509,9 @@ public void test_takeOverConnectionProperties() throws SQLException, Interrupted testStmt1.executeQuery("select 1; select 2; select 3;"); // Crash Instance1 and nominate a new writer - testUtil.failoverClusterAndWaitUntilWriterChanged(); + auroraUtil.failoverClusterAndWaitUntilWriterChanged(); - testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); // Assert that the connection property is maintained. final Statement testStmt2 = conn.createStatement(); @@ -553,7 +553,7 @@ public void test_failFromWriterWhereKeepSessionStateOnFailoverIsTrue() final Statement testStmt2 = conn.createStatement(); testStmt2.executeUpdate("INSERT INTO test3_3 VALUES (1, 'test field string 1')"); - testUtil.failoverClusterAndWaitUntilWriterChanged(); + auroraUtil.failoverClusterAndWaitUntilWriterChanged(); // If there is an active transaction, roll it back and return an error with SQLState 08007. final SQLException exception = @@ -565,10 +565,10 @@ public void test_failFromWriterWhereKeepSessionStateOnFailoverIsTrue() SqlState.CONNECTION_FAILURE_DURING_TRANSACTION.getState(), exception.getSQLState()); // Attempt to query the instance id. - final String currentConnectionId = testUtil.queryInstanceId(conn); + final String currentConnectionId = auroraUtil.queryInstanceId(conn); // Assert that we are connected to the new writer after failover happens. - assertTrue(testUtil.isDBInstanceWriter(currentConnectionId)); - final String nextClusterWriterId = testUtil.getDBClusterWriterInstanceId(); + assertTrue(auroraUtil.isDBInstanceWriter(currentConnectionId)); + final String nextClusterWriterId = auroraUtil.getDBClusterWriterInstanceId(); assertEquals(currentConnectionId, nextClusterWriterId); assertNotEquals(initialWriterId, nextClusterWriterId); @@ -629,11 +629,11 @@ public void test_writerFailover_writerReelected() throws SQLException, Interrupt TimeUnit.MILLISECONDS.sleep(500); // Failure occurs on Connection invocation - testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); // Assert that we are connected to the new writer after failover happens. - final String currentConnectionId = testUtil.queryInstanceId(conn); - assertTrue(testUtil.isDBInstanceWriter(currentConnectionId)); + final String currentConnectionId = auroraUtil.queryInstanceId(conn); + assertTrue(auroraUtil.isDBInstanceWriter(currentConnectionId)); assertEquals(currentConnectionId, initialWriterId); } finally { executor.shutdownNow(); @@ -660,10 +660,10 @@ public void test_readerFailover_readerOrWriter() throws SQLException, Interrupte props)) { // Crash Instance1 and nominate a new writer - testUtil.failoverClusterAndWaitUntilWriterChanged(); + auroraUtil.failoverClusterAndWaitUntilWriterChanged(); // Failure occurs on Connection invocation - testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); } } @@ -686,13 +686,13 @@ public void test_readerFailover_strictReader() throws SQLException, InterruptedE props)) { // Crash Instance1 and nominate a new writer - testUtil.failoverClusterAndWaitUntilWriterChanged(); + auroraUtil.failoverClusterAndWaitUntilWriterChanged(); // Failure occurs on Connection invocation - testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); - String currentConnectionId = testUtil.queryInstanceId(conn); - assertFalse(testUtil.isDBInstanceWriter(currentConnectionId)); + String currentConnectionId = auroraUtil.queryInstanceId(conn); + assertFalse(auroraUtil.isDBInstanceWriter(currentConnectionId)); } } @@ -738,7 +738,7 @@ public void test_readerFailover_writerReelected() throws SQLException, Interrupt TimeUnit.MILLISECONDS.sleep(500); // Failure occurs on Connection invocation - testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); } finally { executor.shutdownNow(); } diff --git a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java index 4a475c629..b2642d06d 100644 --- a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java +++ b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java @@ -64,7 +64,7 @@ @MakeSureFirstInstanceWriter @Order(17) public class AutoscalingTests { - protected static final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(); + protected static final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(); protected static Properties getDefaultPropsNoPlugins() { final Properties props = ConnectionStringHelper.getDefaultProperties(); @@ -129,9 +129,9 @@ public void test_pooledConnectionAutoScaling_setReadOnlyOnOldConnection() final Connection newInstanceConn; final String instanceClass = - testUtil.getDbInstanceClass(TestEnvironment.getCurrent().getInfo().getRequest()); + auroraUtil.getDbInstanceClass(TestEnvironment.getCurrent().getInfo().getRequest()); final TestInstanceInfo newInstance = - testUtil.createInstance(instanceClass, "auto-scaling-instance"); + auroraUtil.createInstance(instanceClass, "auto-scaling-instance"); instances.add(newInstance); try { newInstanceConn = @@ -139,7 +139,7 @@ public void test_pooledConnectionAutoScaling_setReadOnlyOnOldConnection() connections.add(newInstanceConn); Thread.sleep(topologyRefreshRateMs); newInstanceConn.setReadOnly(true); - final String readerId = testUtil.queryInstanceId(newInstanceConn); + final String readerId = auroraUtil.queryInstanceId(newInstanceConn); assertEquals(newInstance.getInstanceId(), readerId); // Verify that there is a pool for the new instance @@ -147,24 +147,24 @@ public void test_pooledConnectionAutoScaling_setReadOnlyOnOldConnection() .anyMatch((url) -> url.equals(newInstance.getUrl()))); newInstanceConn.setReadOnly(false); } finally { - testUtil.deleteInstance(newInstance); + auroraUtil.deleteInstance(newInstance); instances.remove(newInstance); } final long deletionCheckTimeout = System.nanoTime() + TimeUnit.MINUTES.toNanos(5); while (System.nanoTime() < deletionCheckTimeout - && testUtil.getAuroraInstanceIds().size() != originalClusterSize) { + && auroraUtil.getAuroraInstanceIds().size() != originalClusterSize) { TimeUnit.SECONDS.sleep(5); } - if (testUtil.getAuroraInstanceIds().size() != originalClusterSize) { + if (auroraUtil.getAuroraInstanceIds().size() != originalClusterSize) { fail("The deleted instance is still in the cluster topology"); } newInstanceConn.setReadOnly(true); // Connection pool cache should have hit the cleanup threshold and removed the pool for the // deleted instance. - String instanceId = testUtil.queryInstanceId(newInstanceConn); + String instanceId = auroraUtil.queryInstanceId(newInstanceConn); assertNotEquals(instances.get(0).getInstanceId(), instanceId); assertNotEquals(newInstance.getInstanceId(), instanceId); assertFalse(provider.getHosts().stream() @@ -206,27 +206,27 @@ public void test_pooledConnectionAutoScaling_failoverFromDeletedReader() final Connection newInstanceConn; final String instanceClass = - testUtil.getDbInstanceClass(TestEnvironment.getCurrent().getInfo().getRequest()); + auroraUtil.getDbInstanceClass(TestEnvironment.getCurrent().getInfo().getRequest()); final TestInstanceInfo newInstance = - testUtil.createInstance(instanceClass, "auto-scaling-instance"); + auroraUtil.createInstance(instanceClass, "auto-scaling-instance"); instances.add(newInstance); try { newInstanceConn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(newInstance), props); connections.add(newInstanceConn); newInstanceConn.setReadOnly(true); - final String readerId = testUtil.queryInstanceId(newInstanceConn); + final String readerId = auroraUtil.queryInstanceId(newInstanceConn); assertEquals(newInstance.getInstanceId(), readerId); // Verify that there is a pool for the new instance assertTrue(provider.getHosts().stream() .anyMatch((url) -> url.equals(newInstance.getUrl()))); } finally { - testUtil.deleteInstance(newInstance); + auroraUtil.deleteInstance(newInstance); instances.remove(newInstance); } - testUtil.assertFirstQueryThrows(newInstanceConn, FailoverSuccessSQLException.class); - String newReaderId = testUtil.queryInstanceId(newInstanceConn); + auroraUtil.assertFirstQueryThrows(newInstanceConn, FailoverSuccessSQLException.class); + String newReaderId = auroraUtil.queryInstanceId(newInstanceConn); assertNotEquals(newInstance.getInstanceId(), newReaderId); } finally { for (Connection connection : connections) { diff --git a/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java b/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java index aa165344f..9c0fdaab4 100644 --- a/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java +++ b/wrapper/src/test/java/integration/container/tests/CustomEndpointTest.java @@ -81,7 +81,7 @@ public class CustomEndpointTest { protected static final String endpointId = "test-endpoint-1-" + UUID.randomUUID(); protected static DBClusterEndpoint endpointInfo; - protected static final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(); + protected static final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(); protected static final boolean reuseExistingEndpoint = false; protected String currentWriter; @@ -239,19 +239,19 @@ public void testCustomEndpointFailover() throws SQLException, InterruptedExcepti ConnectionStringHelper.getWrapperUrl(endpointInfo.endpoint(), port, dbInfo.getDefaultDbName()), props)) { List endpointMembers = endpointInfo.staticMembers(); - String instanceId = testUtil.queryInstanceId(conn); + String instanceId = auroraUtil.queryInstanceId(conn); assertTrue(endpointMembers.contains(instanceId)); // Use failover API to break connection. if (instanceId.equals(this.currentWriter)) { - testUtil.failoverClusterAndWaitUntilWriterChanged(); + auroraUtil.failoverClusterAndWaitUntilWriterChanged(); } else { - testUtil.failoverClusterToATargetAndWaitUntilWriterChanged(this.currentWriter, instanceId); + auroraUtil.failoverClusterToATargetAndWaitUntilWriterChanged(this.currentWriter, instanceId); } - assertThrows(FailoverSuccessSQLException.class, () -> testUtil.queryInstanceId(conn)); + assertThrows(FailoverSuccessSQLException.class, () -> auroraUtil.queryInstanceId(conn)); - String newInstanceId = testUtil.queryInstanceId(conn); + String newInstanceId = auroraUtil.queryInstanceId(conn); assertTrue(endpointMembers.contains(newInstanceId)); } } @@ -272,7 +272,7 @@ public void testCustomEndpointReadWriteSplitting_withCustomEndpointChanges() thr props); final RdsClient client = RdsClient.builder().region(Region.of(envInfo.getRegion())).build()) { List endpointMembers = endpointInfo.staticMembers(); - String instanceId1 = testUtil.queryInstanceId(conn); + String instanceId1 = auroraUtil.queryInstanceId(conn); assertTrue(endpointMembers.contains(instanceId1)); // Attempt to switch to an instance of the opposite role. This should fail since the custom endpoint consists only @@ -283,7 +283,7 @@ public void testCustomEndpointReadWriteSplitting_withCustomEndpointChanges() thr // throw an exception. In this scenario we log a warning and purposefully stick with the writer. LOGGER.fine("Initial connection is to the writer. Attempting to switch to reader..."); conn.setReadOnly(newReadOnlyValue); - String newInstanceId = testUtil.queryInstanceId(conn); + String newInstanceId = auroraUtil.queryInstanceId(conn); assertEquals(instanceId1, newInstanceId); } else { // We are connected to the reader. Attempting to switch to the writer will throw an exception. @@ -307,7 +307,7 @@ public void testCustomEndpointReadWriteSplitting_withCustomEndpointChanges() thr // We should now be able to switch to newMember. assertDoesNotThrow(() -> conn.setReadOnly(newReadOnlyValue)); - String instanceId2 = testUtil.queryInstanceId(conn); + String instanceId2 = auroraUtil.queryInstanceId(conn); assertEquals(instanceId2, newMember); // Switch back to original instance. @@ -324,7 +324,7 @@ public void testCustomEndpointReadWriteSplitting_withCustomEndpointChanges() thr // We are connected to the writer. Attempting to switch to the reader will not work but will intentionally not // throw an exception. In this scenario we log a warning and purposefully stick with the writer. conn.setReadOnly(newReadOnlyValue); - String newInstanceId = testUtil.queryInstanceId(conn); + String newInstanceId = auroraUtil.queryInstanceId(conn); assertEquals(instanceId1, newInstanceId); } else { // We are connected to the reader. Attempting to switch to the writer will throw an exception. diff --git a/wrapper/src/test/java/integration/container/tests/HikariTests.java b/wrapper/src/test/java/integration/container/tests/HikariTests.java index 1c15192a7..f1e74464e 100644 --- a/wrapper/src/test/java/integration/container/tests/HikariTests.java +++ b/wrapper/src/test/java/integration/container/tests/HikariTests.java @@ -87,7 +87,7 @@ public class HikariTests { private static final Logger LOGGER = Logger.getLogger(HikariTests.class.getName()); - protected static final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(); + protected static final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(); @TestTemplate public void testOpenConnectionWithUrl() throws SQLException { @@ -192,7 +192,7 @@ public void testFailoverLostConnection() throws SQLException { // (since we rely on small socket timeout and small failover timeout). However, // if it takes more time, we'd like to exit by timeout rather than waiting indefinitely. executeWithTimeout( - () -> testUtil.queryInstanceId(conn), + () -> auroraUtil.queryInstanceId(conn), TimeUnit.MINUTES.toMillis(1) ) ); @@ -234,18 +234,18 @@ public void testEFMFailover() throws SQLException { // Get a valid connection, then make it fail over to a different instance try (Connection conn = dataSource.getConnection()) { assertTrue(conn.isValid(5)); - String currentConnectionId = testUtil.queryInstanceId(conn); + String currentConnectionId = auroraUtil.queryInstanceId(conn); assertTrue(currentConnectionId.equalsIgnoreCase(writerIdentifier)); LOGGER.fine("Connected to instance: " + currentConnectionId); ProxyHelper.enableConnectivity(readerIdentifier); ProxyHelper.disableConnectivity(writerIdentifier); - assertThrows(FailoverSuccessSQLException.class, () -> testUtil.queryInstanceId(conn)); + assertThrows(FailoverSuccessSQLException.class, () -> auroraUtil.queryInstanceId(conn)); // Check the connection is valid after connecting to a different instance assertTrue(conn.isValid(5)); - currentConnectionId = testUtil.queryInstanceId(conn); + currentConnectionId = auroraUtil.queryInstanceId(conn); LOGGER.fine("Connected to instance: " + currentConnectionId); assertTrue(currentConnectionId.equalsIgnoreCase(readerIdentifier)); @@ -280,7 +280,7 @@ public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation() // Open connection and then return it to the pool Connection conn = ds.getConnection(); - assertEquals(readerId, testUtil.queryInstanceId(conn)); + assertEquals(readerId, auroraUtil.queryInstanceId(conn)); conn.close(); ProxyHelper.disableConnectivity(reader.getInstanceId()); @@ -292,7 +292,7 @@ public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation() // Driver will fail over internally and return a connection to another node. conn = ds.getConnection(); // Assert that we connected to a different node. - assertNotEquals(readerId, testUtil.queryInstanceId(conn)); + assertNotEquals(readerId, auroraUtil.queryInstanceId(conn)); } finally { ConnectionProviderManager.releaseResources(); } @@ -340,7 +340,7 @@ public void testInternalPools_driverReaderFailoverOnGetConnectionInvocation() // Driver will fail over internally and return a connection to another node. try (Connection conn = ds.getConnection()) { // Assert that we connected to a different node. - assertNotEquals(writerId, testUtil.queryInstanceId(conn)); + assertNotEquals(writerId, auroraUtil.queryInstanceId(conn)); } } finally { ConnectionProviderManager.releaseResources(); @@ -371,7 +371,7 @@ public void testInternalPools_driverWriterFailoverOnGetConnectionInvocation_sing // Open connection and then return it to the pool Connection conn = ds.getConnection(); - assertEquals(writerId, testUtil.queryInstanceId(conn)); + assertEquals(writerId, auroraUtil.queryInstanceId(conn)); conn.close(); ProxyHelper.disableAllConnectivity(); diff --git a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java index 374ddf1b8..51459729d 100644 --- a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java +++ b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java @@ -89,7 +89,7 @@ @Order(12) public class ReadWriteSplittingTests { - protected static final AuroraTestUtility testUtil = AuroraTestUtility.getUtility(); + protected static final AuroraTestUtility auroraUtil = AuroraTestUtility.getUtility(); private static final Logger LOGGER = Logger.getLogger(ReadWriteSplittingTests.class.getName()); protected static Properties getProxiedPropsWithFailover() { @@ -136,26 +136,26 @@ public void test_connectToWriter_switchSetReadOnly() throws SQLException { LOGGER.finest("Connecting to url " + url); try (final Connection conn = DriverManager.getConnection(url, getProps())) { - final String writerConnectionId = testUtil.queryInstanceId(conn); + final String writerConnectionId = auroraUtil.queryInstanceId(conn); conn.setReadOnly(true); - final String readerConnectionId = testUtil.queryInstanceId(conn); + final String readerConnectionId = auroraUtil.queryInstanceId(conn); assertNotEquals(writerConnectionId, readerConnectionId); conn.setReadOnly(true); - String currentConnectionId = testUtil.queryInstanceId(conn); + String currentConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(readerConnectionId, currentConnectionId); conn.setReadOnly(false); - currentConnectionId = testUtil.queryInstanceId(conn); + currentConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(writerConnectionId, currentConnectionId); conn.setReadOnly(false); - currentConnectionId = testUtil.queryInstanceId(conn); + currentConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(writerConnectionId, currentConnectionId); conn.setReadOnly(true); - currentConnectionId = testUtil.queryInstanceId(conn); + currentConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(readerConnectionId, currentConnectionId); } } @@ -166,15 +166,15 @@ public void test_connectToReader_setReadOnlyTrueFalse() throws SQLException { LOGGER.finest("Connecting to url " + url); try (final Connection conn = DriverManager.getConnection(url, getProps())) { - final String readerConnectionId = testUtil.queryInstanceId(conn); + final String readerConnectionId = auroraUtil.queryInstanceId(conn); LOGGER.finest("readerConnectionId: " + readerConnectionId); conn.setReadOnly(true); - final String currentConnectionId = testUtil.queryInstanceId(conn); + final String currentConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(readerConnectionId, currentConnectionId); conn.setReadOnly(false); - final String writerConnectionId = testUtil.queryInstanceId(conn); + final String writerConnectionId = auroraUtil.queryInstanceId(conn); LOGGER.finest("writerConnectionId: " + writerConnectionId); assertNotEquals(readerConnectionId, writerConnectionId); } @@ -192,15 +192,15 @@ public void test_connectToReaderCluster_setReadOnlyTrueFalse() throws SQLExcepti final String url = ConnectionStringHelper.getWrapperReaderClusterUrl(); LOGGER.finest("Connecting to url " + url); try (final Connection conn = DriverManager.getConnection(url, getProps())) { - final String readerConnectionId = testUtil.queryInstanceId(conn); + final String readerConnectionId = auroraUtil.queryInstanceId(conn); LOGGER.finest("readerConnectionId: " + readerConnectionId); conn.setReadOnly(true); - final String currentConnectionId = testUtil.queryInstanceId(conn); + final String currentConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(readerConnectionId, currentConnectionId); conn.setReadOnly(false); - final String writerConnectionId = testUtil.queryInstanceId(conn); + final String writerConnectionId = auroraUtil.queryInstanceId(conn); LOGGER.finest("writerConnectionId: " + writerConnectionId); assertNotEquals(readerConnectionId, writerConnectionId); } @@ -210,10 +210,10 @@ public void test_connectToReaderCluster_setReadOnlyTrueFalse() throws SQLExcepti public void test_setReadOnlyFalseInReadOnlyTransaction() throws SQLException { try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), getProps())) { - final String writerConnectionId = testUtil.queryInstanceId(conn); + final String writerConnectionId = auroraUtil.queryInstanceId(conn); conn.setReadOnly(true); - final String readerConnectionId = testUtil.queryInstanceId(conn); + final String readerConnectionId = auroraUtil.queryInstanceId(conn); assertNotEquals(writerConnectionId, readerConnectionId); final Statement stmt = conn.createStatement(); @@ -222,14 +222,14 @@ public void test_setReadOnlyFalseInReadOnlyTransaction() throws SQLException { final SQLException exception = assertThrows(SQLException.class, () -> conn.setReadOnly(false)); - String currentConnectionId = testUtil.queryInstanceId(conn); + String currentConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(SqlState.ACTIVE_SQL_TRANSACTION.getState(), exception.getSQLState()); assertEquals(readerConnectionId, currentConnectionId); stmt.execute("COMMIT"); conn.setReadOnly(false); - currentConnectionId = testUtil.queryInstanceId(conn); + currentConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(writerConnectionId, currentConnectionId); } } @@ -238,10 +238,10 @@ public void test_setReadOnlyFalseInReadOnlyTransaction() throws SQLException { public void test_setReadOnlyFalseInTransaction_setAutocommitFalse() throws SQLException { try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), getProps())) { - final String writerConnectionId = testUtil.queryInstanceId(conn); + final String writerConnectionId = auroraUtil.queryInstanceId(conn); conn.setReadOnly(true); - final String readerConnectionId = testUtil.queryInstanceId(conn); + final String readerConnectionId = auroraUtil.queryInstanceId(conn); assertNotEquals(writerConnectionId, readerConnectionId); final Statement stmt = conn.createStatement(); @@ -250,14 +250,14 @@ public void test_setReadOnlyFalseInTransaction_setAutocommitFalse() throws SQLEx final SQLException exception = assertThrows(SQLException.class, () -> conn.setReadOnly(false)); - String currentConnectionId = testUtil.queryInstanceId(conn); + String currentConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(SqlState.ACTIVE_SQL_TRANSACTION.getState(), exception.getSQLState()); assertEquals(readerConnectionId, currentConnectionId); stmt.execute("COMMIT"); conn.setReadOnly(false); - currentConnectionId = testUtil.queryInstanceId(conn); + currentConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(writerConnectionId, currentConnectionId); } } @@ -268,7 +268,7 @@ public void test_setReadOnlyFalseInTransaction_setAutocommitFalse() throws SQLEx public void test_setReadOnlyTrueInTransaction() throws SQLException { try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), getProps())) { - final String writerConnectionId = testUtil.queryInstanceId(conn); + final String writerConnectionId = auroraUtil.queryInstanceId(conn); final Statement stmt1 = conn.createStatement(); stmt1.executeUpdate("DROP TABLE IF EXISTS test_readWriteSplitting_readOnlyTrueInTransaction"); @@ -283,7 +283,7 @@ public void test_setReadOnlyTrueInTransaction() throws SQLException { + "VALUES (1, 'test_field value 1')"); assertDoesNotThrow(() -> conn.setReadOnly(true)); - final String currentConnectionId = testUtil.queryInstanceId(conn); + final String currentConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(writerConnectionId, currentConnectionId); stmt2.execute("COMMIT"); @@ -306,7 +306,7 @@ public void test_setReadOnlyTrue_allReadersDown() throws SQLException { try (final Connection conn = DriverManager.getConnection( ConnectionStringHelper.getProxyWrapperUrl(), getProxiedProps())) { - final String writerConnectionId = testUtil.queryInstanceId(conn); + final String writerConnectionId = auroraUtil.queryInstanceId(conn); // Kill all reader instances final List instanceIDs = @@ -317,16 +317,16 @@ public void test_setReadOnlyTrue_allReadersDown() throws SQLException { } assertDoesNotThrow(() -> conn.setReadOnly(true)); - String currentConnectionId = assertDoesNotThrow(() -> testUtil.queryInstanceId(conn)); + String currentConnectionId = assertDoesNotThrow(() -> auroraUtil.queryInstanceId(conn)); assertEquals(writerConnectionId, currentConnectionId); assertDoesNotThrow(() -> conn.setReadOnly(false)); - currentConnectionId = assertDoesNotThrow(() -> testUtil.queryInstanceId(conn)); + currentConnectionId = assertDoesNotThrow(() -> auroraUtil.queryInstanceId(conn)); assertEquals(writerConnectionId, currentConnectionId); ProxyHelper.enableAllConnectivity(); assertDoesNotThrow(() -> conn.setReadOnly(true)); - currentConnectionId = testUtil.queryInstanceId(conn); + currentConnectionId = auroraUtil.queryInstanceId(conn); assertNotEquals(writerConnectionId, currentConnectionId); } } @@ -353,10 +353,10 @@ public void test_setReadOnlyFalse_allInstancesDown() throws SQLException { try (final Connection conn = DriverManager.getConnection( ConnectionStringHelper.getProxyWrapperUrl(), getProxiedProps())) { - final String writerConnectionId = testUtil.queryInstanceId(conn); + final String writerConnectionId = auroraUtil.queryInstanceId(conn); conn.setReadOnly(true); - final String readerConnectionId = testUtil.queryInstanceId(conn); + final String readerConnectionId = auroraUtil.queryInstanceId(conn); assertNotEquals(writerConnectionId, readerConnectionId); // Kill all instances @@ -390,7 +390,7 @@ public void test_setReadOnlyFalse_whenAllInstancesDown() throws SQLException { public void test_executeWithOldConnection() throws SQLException { try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), getProps())) { - final String writerId = testUtil.queryInstanceId(conn); + final String writerId = auroraUtil.queryInstanceId(conn); final Statement oldStmt = conn.createStatement(); final ResultSet oldRs = oldStmt.executeQuery("SELECT 1"); @@ -400,13 +400,13 @@ public void test_executeWithOldConnection() throws SQLException { assertThrows(SQLException.class, () -> oldStmt.execute("SELECT 1")); assertThrows(SQLException.class, () -> oldRs.getInt(1)); - final String readerId = testUtil.queryInstanceId(conn); + final String readerId = auroraUtil.queryInstanceId(conn); assertNotEquals(writerId, readerId); assertDoesNotThrow(oldStmt::close); assertDoesNotThrow(oldRs::close); - final String sameReaderId = testUtil.queryInstanceId(conn); + final String sameReaderId = auroraUtil.queryInstanceId(conn); assertEquals(readerId, sameReaderId); } } @@ -419,7 +419,7 @@ public void test_failoverToNewWriter_setReadOnlyTrueFalse() try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getProxyWrapperUrl(), getProxiedPropsWithFailover())) { - final String originalWriterId = testUtil.queryInstanceId(conn); + final String originalWriterId = auroraUtil.queryInstanceId(conn); // Kill all reader instances final int numOfInstances = @@ -436,29 +436,29 @@ public void test_failoverToNewWriter_setReadOnlyTrueFalse() // Force internal reader connection to the writer instance conn.setReadOnly(true); - String currentConnectionId = testUtil.queryInstanceId(conn); + String currentConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(originalWriterId, currentConnectionId); conn.setReadOnly(false); ProxyHelper.enableAllConnectivity(); // Crash Instance1 and nominate a new writer - testUtil.failoverClusterAndWaitUntilWriterChanged(); + auroraUtil.failoverClusterAndWaitUntilWriterChanged(); // Failure occurs on Connection invocation - testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); // Assert that we are connected to the new writer after failover happens. - String newWriterId = testUtil.queryInstanceId(conn); - assertTrue(testUtil.isDBInstanceWriter(newWriterId)); + String newWriterId = auroraUtil.queryInstanceId(conn); + assertTrue(auroraUtil.isDBInstanceWriter(newWriterId)); assertNotEquals(newWriterId, originalWriterId); conn.setReadOnly(true); - currentConnectionId = testUtil.queryInstanceId(conn); + currentConnectionId = auroraUtil.queryInstanceId(conn); assertNotEquals(newWriterId, currentConnectionId); conn.setReadOnly(false); - currentConnectionId = testUtil.queryInstanceId(conn); + currentConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(newWriterId, currentConnectionId); } } @@ -474,11 +474,11 @@ public void test_failoverToNewReader_setReadOnlyFalseTrue() throws SQLException try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getProxyWrapperUrl(), props)) { - final String writerConnectionId = testUtil.queryInstanceId(conn); + final String writerConnectionId = auroraUtil.queryInstanceId(conn); LOGGER.info("writerConnectionId: " + writerConnectionId); conn.setReadOnly(true); - final String readerConnectionId = testUtil.queryInstanceId(conn); + final String readerConnectionId = auroraUtil.queryInstanceId(conn); assertNotEquals(writerConnectionId, readerConnectionId); String otherReaderId = ""; @@ -503,20 +503,20 @@ public void test_failoverToNewReader_setReadOnlyFalseTrue() throws SQLException ProxyHelper.disableConnectivity(instanceId); } - testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); assertFalse(conn.isClosed()); - String currentConnectionId = testUtil.queryInstanceId(conn); + String currentConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(otherReaderId, currentConnectionId); assertNotEquals(readerConnectionId, currentConnectionId); ProxyHelper.enableAllConnectivity(); conn.setReadOnly(false); - currentConnectionId = testUtil.queryInstanceId(conn); + currentConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(writerConnectionId, currentConnectionId); conn.setReadOnly(true); - currentConnectionId = testUtil.queryInstanceId(conn); + currentConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(otherReaderId, currentConnectionId); } } @@ -530,11 +530,11 @@ public void test_failoverReaderToWriter_setReadOnlyTrueFalse() try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getProxyWrapperUrl(), getProxiedPropsWithFailover())) { - final String writerConnectionId = testUtil.queryInstanceId(conn); + final String writerConnectionId = auroraUtil.queryInstanceId(conn); LOGGER.finest("writerConnectionId=" + writerConnectionId); conn.setReadOnly(true); - final String readerConnectionId = testUtil.queryInstanceId(conn); + final String readerConnectionId = auroraUtil.queryInstanceId(conn); LOGGER.finest("readerConnectionId=" + readerConnectionId); assertNotEquals(writerConnectionId, readerConnectionId); @@ -550,9 +550,9 @@ public void test_failoverReaderToWriter_setReadOnlyTrueFalse() ProxyHelper.disableConnectivity(instanceId); } - testUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); + auroraUtil.assertFirstQueryThrows(conn, FailoverSuccessSQLException.class); assertFalse(conn.isClosed()); - String currentConnectionId = testUtil.queryInstanceId(conn); + String currentConnectionId = auroraUtil.queryInstanceId(conn); LOGGER.finest("currentConnectionId=" + currentConnectionId); assertEquals(writerConnectionId, currentConnectionId); @@ -566,12 +566,12 @@ public void test_failoverReaderToWriter_setReadOnlyTrueFalse() conn.unwrap(PluginService.class).forceRefreshHostList(); conn.setReadOnly(true); - currentConnectionId = testUtil.queryInstanceId(conn); + currentConnectionId = auroraUtil.queryInstanceId(conn); LOGGER.finest("currentConnectionId=" + currentConnectionId); assertNotEquals(writerConnectionId, currentConnectionId); conn.setReadOnly(false); - currentConnectionId = testUtil.queryInstanceId(conn); + currentConnectionId = auroraUtil.queryInstanceId(conn); LOGGER.finest("currentConnectionId=" + currentConnectionId); assertEquals(writerConnectionId, currentConnectionId); } @@ -643,14 +643,14 @@ public void test_pooledConnectionFailover() throws SQLException, InterruptedExce try { try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props)) { initialWriterConn1 = conn.unwrap(Connection.class); - initialWriterId = testUtil.queryInstanceId(conn); + initialWriterId = auroraUtil.queryInstanceId(conn); LOGGER.finest("initialWriterId: " + initialWriterId); provider.logConnections(); - testUtil.failoverClusterAndWaitUntilWriterChanged(); + auroraUtil.failoverClusterAndWaitUntilWriterChanged(); - assertThrows(FailoverSuccessSQLException.class, () -> testUtil.queryInstanceId(conn)); - nextWriterId = testUtil.queryInstanceId(conn); + assertThrows(FailoverSuccessSQLException.class, () -> auroraUtil.queryInstanceId(conn)); + nextWriterId = auroraUtil.queryInstanceId(conn); LOGGER.finest("nextWriterId: " + nextWriterId); assertNotEquals(initialWriterId, nextWriterId); newWriterConn = conn.unwrap(Connection.class); @@ -660,7 +660,7 @@ public void test_pooledConnectionFailover() throws SQLException, InterruptedExce try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props)) { // This should be a new connection to the initial writer instance (now a reader). - final String oldWriterConnectionId = testUtil.queryInstanceId(conn); + final String oldWriterConnectionId = auroraUtil.queryInstanceId(conn); LOGGER.finest("oldWriterConnectionId: " + oldWriterConnectionId); assertEquals(initialWriterId, oldWriterConnectionId); initialWriterConn2 = conn.unwrap(Connection.class); @@ -693,10 +693,10 @@ public void test_pooledConnectionFailoverWithClusterURL() throws SQLException, I initialWriterConn = conn.unwrap(Connection.class); // The internal connection pool should not be used if the connection is established via a cluster URL. assertEquals(0, provider.getHostCount(), "Internal connection pool should be empty."); - final String writerConnectionId = testUtil.queryInstanceId(conn); - testUtil.failoverClusterAndWaitUntilWriterChanged(); - assertThrows(FailoverSuccessSQLException.class, () -> testUtil.queryInstanceId(conn)); - final String nextWriterId = testUtil.queryInstanceId(conn); + final String writerConnectionId = auroraUtil.queryInstanceId(conn); + auroraUtil.failoverClusterAndWaitUntilWriterChanged(); + assertThrows(FailoverSuccessSQLException.class, () -> auroraUtil.queryInstanceId(conn)); + final String nextWriterId = auroraUtil.queryInstanceId(conn); assertNotEquals(writerConnectionId, nextWriterId); assertEquals(0, provider.getHostCount(), "Internal connection pool should be empty."); newWriterConn = conn.unwrap(Connection.class); @@ -725,14 +725,14 @@ public void test_pooledConnection_failoverFailed() throws SQLException { final String initialWriterId; try (Connection conn = DriverManager.getConnection(ConnectionStringHelper.getProxyWrapperUrl(), props)) { initialWriterConn1 = conn.unwrap(Connection.class); - initialWriterId = testUtil.queryInstanceId(conn); + initialWriterId = auroraUtil.queryInstanceId(conn); ProxyHelper.disableAllConnectivity(); - assertThrows(FailoverFailedSQLException.class, () -> testUtil.queryInstanceId(conn)); + assertThrows(FailoverFailedSQLException.class, () -> auroraUtil.queryInstanceId(conn)); } ProxyHelper.enableAllConnectivity(); try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getProxyWrapperUrl(), props)) { - final String writerConnectionId = testUtil.queryInstanceId(conn); + final String writerConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(initialWriterId, writerConnectionId); initialWriterConn2 = conn.unwrap(Connection.class); // The initial connection should have been evicted from the pool when failover occurred, so @@ -766,13 +766,13 @@ public void test_pooledConnection_failoverInTransaction() try (Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props)) { initialWriterConn1 = conn.unwrap(Connection.class); conn.setAutoCommit(false); - initialWriterId = testUtil.queryInstanceId(conn); + initialWriterId = auroraUtil.queryInstanceId(conn); LOGGER.finest("initialWriterId: " + initialWriterId + ", " + initialWriterConn1); - testUtil.failoverClusterAndWaitUntilWriterChanged(); + auroraUtil.failoverClusterAndWaitUntilWriterChanged(); assertThrows(TransactionStateUnknownSQLException.class, - () -> testUtil.queryInstanceId(conn)); + () -> auroraUtil.queryInstanceId(conn)); conn.setAutoCommit(true); - nextWriterId = testUtil.queryInstanceId(conn); + nextWriterId = auroraUtil.queryInstanceId(conn); newWriterConn = conn.unwrap(Connection.class); LOGGER.finest("nextWriterId: " + nextWriterId + ", " + newWriterConn); assertNotEquals(initialWriterId, nextWriterId); @@ -781,12 +781,12 @@ public void test_pooledConnection_failoverInTransaction() // Make sure all instances up after failover. // Old writer in RDS MultiAz clusters may be unavailable for quite long time. - testUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(15)); + auroraUtil.makeSureInstancesUp(TimeUnit.MINUTES.toSeconds(15)); // It makes sense to run the following step when initial writer is up. try (final Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props)) { // This should be a new connection to the initial writer instance (now a reader). - final String writerConnectionId = testUtil.queryInstanceId(conn); + final String writerConnectionId = auroraUtil.queryInstanceId(conn); assertEquals(initialWriterId, writerConnectionId); initialWriterConn2 = conn.unwrap(Connection.class); // The initial connection should have been evicted from the pool when failover occurred, so @@ -824,7 +824,7 @@ public void test_pooledConnection_differentUsers() throws SQLException { try (Connection conn = DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), privilegedUserProps); Statement stmt = conn.createStatement()) { stmt.execute("DROP USER IF EXISTS " + limitedUserName); - testUtil.createUser(conn, limitedUserName, limitedUserPassword); + auroraUtil.createUser(conn, limitedUserName, limitedUserPassword); TestEnvironmentInfo info = TestEnvironment.getCurrent().getInfo(); DatabaseEngine engine = info.getRequest().getDatabaseEngine(); if (DatabaseEngine.MYSQL.equals(engine)) { @@ -882,7 +882,7 @@ public void test_pooledConnection_leastConnectionsStrategy() throws SQLException DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), props); connections.add(conn); conn.setReadOnly(true); - final String readerId = testUtil.queryInstanceId(conn); + final String readerId = auroraUtil.queryInstanceId(conn); assertFalse(connectedReaderIDs.contains(readerId)); connectedReaderIDs.add(readerId); @@ -950,7 +950,7 @@ public void test_pooledConnection_leastConnectionsWithPoolMapping() throws SQLEx DriverManager.getConnection(ConnectionStringHelper.getWrapperUrl(), defaultProps); connections.add(conn); conn.setReadOnly(true); - final String readerId = testUtil.queryInstanceId(conn); + final String readerId = auroraUtil.queryInstanceId(conn); assertNotEquals(overloadedReaderId, readerId); } } finally { diff --git a/wrapper/src/test/java/integration/host/TestEnvironment.java b/wrapper/src/test/java/integration/host/TestEnvironment.java index 1fe6b7779..33c072280 100644 --- a/wrapper/src/test/java/integration/host/TestEnvironment.java +++ b/wrapper/src/test/java/integration/host/TestEnvironment.java @@ -105,7 +105,7 @@ public class TestEnvironment implements AutoCloseable { private final Network network = Network.newNetwork(); - private AuroraTestUtility testUtil; + private AuroraTestUtility auroraUtil; private TestEnvironment(TestEnvironmentRequest request) { this.info.setRequest(request); @@ -364,7 +364,7 @@ private static void createDbCluster(TestEnvironment env, int numOfInstances) { env.rdsEndpoint = config.rdsEndpoint; // "XYZ.us-west-2.rds.amazonaws.com" env.info.setRdsEndpoint(env.rdsEndpoint); - env.testUtil = + env.auroraUtil = new AuroraTestUtility( env.info.getRegion(), env.rdsEndpoint, @@ -376,7 +376,7 @@ private static void createDbCluster(TestEnvironment env, int numOfInstances) { throw new RuntimeException("Environment variable RDS_CLUSTER_DOMAIN is required."); } - if (!env.testUtil.doesClusterExist(env.auroraClusterName)) { + if (!env.auroraUtil.doesClusterExist(env.auroraClusterName)) { throw new RuntimeException( "It's requested to reuse existing DB cluster but it doesn't exist: " + env.auroraClusterName @@ -386,9 +386,9 @@ private static void createDbCluster(TestEnvironment env, int numOfInstances) { LOGGER.finer( "Reuse existing cluster " + env.auroraClusterName + ".cluster-" + env.auroraClusterDomain); - DBCluster clusterInfo = env.testUtil.getClusterInfo(env.auroraClusterName); + DBCluster clusterInfo = env.auroraUtil.getClusterInfo(env.auroraClusterName); - DatabaseEngine existingClusterDatabaseEngine = env.testUtil.getClusterEngine(clusterInfo); + DatabaseEngine existingClusterDatabaseEngine = env.auroraUtil.getClusterEngine(clusterInfo); if (existingClusterDatabaseEngine != env.info.getRequest().getDatabaseEngine()) { throw new RuntimeException( "Existing cluster is " @@ -406,7 +406,7 @@ private static void createDbCluster(TestEnvironment env, int numOfInstances) { boolean clusterExists = false; while (remainingTries-- > 0) { env.auroraClusterName = getRandomName(env.info.getRequest()); - if (env.testUtil.doesClusterExist(env.auroraClusterName)) { + if (env.auroraUtil.doesClusterExist(env.auroraClusterName)) { clusterExists = true; LOGGER.finest("Cluster " + env.auroraClusterName + " already exists. Pick up another name."); } else { @@ -426,12 +426,12 @@ private static void createDbCluster(TestEnvironment env, int numOfInstances) { if (StringUtils.isNullOrEmpty(engineVersion)) { throw new RuntimeException("Failed to get engine version."); } - String instanceClass = env.testUtil.getDbInstanceClass(env.info.getRequest()); + String instanceClass = env.auroraUtil.getDbInstanceClass(env.info.getRequest()); LOGGER.finer( "Using " + engine + " " + engineVersion); - env.testUtil.createCluster( + env.auroraUtil.createCluster( env.info.getDatabaseInfo().getUsername(), env.info.getDatabaseInfo().getPassword(), env.info.getDatabaseInfo().getDefaultDbName(), @@ -443,7 +443,7 @@ private static void createDbCluster(TestEnvironment env, int numOfInstances) { engineVersion, numOfInstances); - List dbInstances = env.testUtil.getDBInstances(env.auroraClusterName); + List dbInstances = env.auroraUtil.getDBInstances(env.auroraClusterName); if (dbInstances.isEmpty()) { throw new RuntimeException("Failed to get instance information for cluster " + env.auroraClusterName); } @@ -460,7 +460,7 @@ private static void createDbCluster(TestEnvironment env, int numOfInstances) { // remove cluster and instances LOGGER.finer("Deleting cluster " + env.auroraClusterName); - env.testUtil.deleteCluster(env.auroraClusterName, env.info.getRequest().getDatabaseEngineDeployment()); + env.auroraUtil.deleteCluster(env.auroraClusterName, env.info.getRequest().getDatabaseEngineDeployment()); LOGGER.finer("Deleted cluster " + env.auroraClusterName); throw new RuntimeException(e); @@ -480,7 +480,7 @@ private static void createDbCluster(TestEnvironment env, int numOfInstances) { env.auroraClusterName + ".cluster-ro-" + env.auroraClusterDomain, port); env.info.getDatabaseInfo().setInstanceEndpointSuffix(env.auroraClusterDomain, port); - List instances = env.testUtil.generateTestInstancesInfo(env.auroraClusterName); + List instances = env.auroraUtil.generateTestInstancesInfo(env.auroraClusterName); env.info.getDatabaseInfo().getInstances().clear(); env.info.getDatabaseInfo().getInstances().addAll(instances); @@ -502,12 +502,12 @@ private static void createDbCluster(TestEnvironment env, int numOfInstances) { private static void authorizeIP(TestEnvironment env) { try { - env.runnerIP = env.testUtil.getPublicIPAddress(); + env.runnerIP = env.auroraUtil.getPublicIPAddress(); LOGGER.finest("Test runner IP: " + env.runnerIP); } catch (UnknownHostException e) { throw new RuntimeException(e); } - env.testUtil.ec2AuthorizeIP(env.runnerIP); + env.auroraUtil.ec2AuthorizeIP(env.runnerIP); } private static String getRandomName(TestEnvironmentRequest request) { @@ -603,13 +603,13 @@ private static String findAuroraDbEngineVersion( String systemPropertyVersion) { if (StringUtils.isNullOrEmpty(systemPropertyVersion)) { - return env.testUtil.getDefaultVersion(engineName); + return env.auroraUtil.getDefaultVersion(engineName); } switch (systemPropertyVersion.toLowerCase()) { case "default": - return env.testUtil.getDefaultVersion(engineName); + return env.auroraUtil.getDefaultVersion(engineName); case "latest": - return env.testUtil.getLatestVersion(engineName); + return env.auroraUtil.getLatestVersion(engineName); default: return systemPropertyVersion; } @@ -910,7 +910,7 @@ private static void configureIamAccess(TestEnvironment env) { env.info.getDatabaseInfo().getDefaultDbName()); try { - env.testUtil.addAuroraAwsIamUser( + env.auroraUtil.addAuroraAwsIamUser( env.info.getRequest().getDatabaseEngine(), url, env.info.getDatabaseInfo().getUsername(), @@ -1044,13 +1044,13 @@ private void deleteDbCluster() { if (ipAddressUsageRefCount.decrementAndGet() == 0) { // Another test environments are still in use of test task runner IP address. // The last execute tst environment will do the cleanup. - testUtil.ec2DeauthorizesIP(runnerIP); + auroraUtil.ec2DeauthorizesIP(runnerIP); } } if (!this.reuseAuroraDbCluster) { LOGGER.finest("Deleting cluster " + this.auroraClusterName + ".cluster-" + this.auroraClusterDomain); - testUtil.deleteCluster(this.auroraClusterName, this.info.getRequest().getDatabaseEngineDeployment()); + auroraUtil.deleteCluster(this.auroraClusterName, this.info.getRequest().getDatabaseEngineDeployment()); LOGGER.finest("Deleted cluster " + this.auroraClusterName + ".cluster-" + this.auroraClusterDomain); } } From 435626bef183cb0fbd05e78aa7534c9576d4fea7 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Wed, 22 Jan 2025 10:56:18 -0800 Subject: [PATCH 19/21] Fix checkstyle --- .../container/tests/AutoscalingTests.java | 2 +- .../ReadWriteSplittingPerformanceTest.java | 2 +- .../tests/ReadWriteSplittingTests.java | 2 +- .../integration/host/TestEnvironment.java | 2 +- .../integration/util/AuroraTestUtility.java | 26 ++++++++----------- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java index b2642d06d..80c50cfd9 100644 --- a/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java +++ b/wrapper/src/test/java/integration/container/tests/AutoscalingTests.java @@ -28,8 +28,8 @@ import integration.TestEnvironmentInfo; import integration.TestInstanceInfo; import integration.container.ConnectionStringHelper; -import integration.container.TestEnvironment; import integration.container.TestDriverProvider; +import integration.container.TestEnvironment; import integration.container.condition.EnableOnDatabaseEngineDeployment; import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.EnableOnTestFeature; diff --git a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingPerformanceTest.java b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingPerformanceTest.java index 4d78c5a5e..1bf956de2 100644 --- a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingPerformanceTest.java +++ b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingPerformanceTest.java @@ -19,8 +19,8 @@ import com.zaxxer.hikari.HikariConfig; import integration.TestEnvironmentFeatures; import integration.container.ConnectionStringHelper; -import integration.container.TestEnvironment; import integration.container.TestDriverProvider; +import integration.container.TestEnvironment; import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.EnableOnTestFeature; import java.io.File; diff --git a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java index 72f3252e6..138090bd7 100644 --- a/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java +++ b/wrapper/src/test/java/integration/container/tests/ReadWriteSplittingTests.java @@ -34,10 +34,10 @@ import integration.TestEnvironmentInfo; import integration.TestInstanceInfo; import integration.container.ConnectionStringHelper; -import integration.container.TestEnvironment; import integration.container.ProxyHelper; import integration.container.TestDriver; import integration.container.TestDriverProvider; +import integration.container.TestEnvironment; import integration.container.aurora.TestPluginServiceImpl; import integration.container.condition.DisableOnTestDriver; import integration.container.condition.DisableOnTestFeature; diff --git a/wrapper/src/test/java/integration/host/TestEnvironment.java b/wrapper/src/test/java/integration/host/TestEnvironment.java index e5b0e1566..35d18af0c 100644 --- a/wrapper/src/test/java/integration/host/TestEnvironment.java +++ b/wrapper/src/test/java/integration/host/TestEnvironment.java @@ -32,8 +32,8 @@ import integration.TestProxyDatabaseInfo; import integration.TestTelemetryInfo; import integration.host.TestEnvironmentProvider.EnvPreCreateInfo; -import integration.util.ContainerHelper; import integration.util.AuroraTestUtility; +import integration.util.ContainerHelper; import java.io.IOException; import java.net.URISyntaxException; import java.net.UnknownHostException; diff --git a/wrapper/src/test/java/integration/util/AuroraTestUtility.java b/wrapper/src/test/java/integration/util/AuroraTestUtility.java index e944bd3c7..fe64fe3b0 100644 --- a/wrapper/src/test/java/integration/util/AuroraTestUtility.java +++ b/wrapper/src/test/java/integration/util/AuroraTestUtility.java @@ -190,11 +190,9 @@ protected static Region getRegionInternal(String rdsRegion) { } /** - * Performs the following: - * - creates an RDS cluster based on the passed in details - * - waits until it is available - * - adds the current IP address as an inbound rule to the security group so that the cluster can be accessed - * - creates a database with the given name within the cluster + * Creates an RDS cluster based on the passed in details. After the cluster is created, this method will wait + * until it is available, adds the current IP address to the default security group, and create a database with the + * given name within the cluster. * * @param username the master username for access to the database * @param password the master password for access to the database @@ -227,6 +225,7 @@ public void createCluster( case AURORA: createAuroraCluster( username, password, dbName, identifier, region, engine, instanceClass, version, numInstances); + break; case RDS_MULTI_AZ_CLUSTER: if (numInstances != MULTI_AZ_SIZE) { throw new RuntimeException( @@ -236,17 +235,16 @@ public void createCluster( createMultiAzCluster( username, password, dbName, identifier, region, engine, instanceClass, version); + break; default: throw new UnsupportedOperationException(deployment.toString()); } } /** - * Performs the following: - * - creates an RDS Aurora cluster based on the passed in details - * - waits until it is available - * - adds the current IP address as an inbound rule to the security group so that the cluster can be accessed - * - creates a database with the given name within the cluster + * Creates an RDS Aurora cluster based on the passed in details. After the cluster is created, this method will wait + * until it is available, adds the current IP address to the default security group, and create a database with the + * given name within the cluster. * * @param username the master username for access to the database * @param password the master password for access to the database @@ -321,11 +319,9 @@ public void createAuroraCluster( } /** - * Performs the following: - * - creates an RDS multi-az cluster based on the passed in details - * - waits until it is available - * - adds the current IP address as an inbound rule to the security group so that the cluster can be accessed - * - creates a database with the given name within the cluster + * Creates an RDS multi-az cluster based on the passed in details. After the cluster is created, this method will wait + * until it is available, adds the current IP address to the default security group, and create a database with the + * given name within the cluster. * * @param username the master username for access to the database * @param password the master password for access to the database From 1bbe5eedd1dda2a3f63dc17228b87a09884433a5 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Wed, 22 Jan 2025 11:38:58 -0800 Subject: [PATCH 20/21] cleanup --- .../java/integration/host/TestEnvironment.java | 2 +- .../integration/util/AuroraTestUtility.java | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/wrapper/src/test/java/integration/host/TestEnvironment.java b/wrapper/src/test/java/integration/host/TestEnvironment.java index 35d18af0c..67f4b2472 100644 --- a/wrapper/src/test/java/integration/host/TestEnvironment.java +++ b/wrapper/src/test/java/integration/host/TestEnvironment.java @@ -480,7 +480,7 @@ private static void createDbCluster(TestEnvironment env, int numOfInstances) { env.auroraClusterName + ".cluster-ro-" + env.auroraClusterDomain, port); env.info.getDatabaseInfo().setInstanceEndpointSuffix(env.auroraClusterDomain, port); - List instances = env.auroraUtil.generateTestInstancesInfo(env.auroraClusterName); + List instances = env.auroraUtil.getTestInstancesInfo(env.auroraClusterName); env.info.getDatabaseInfo().getInstances().clear(); env.info.getDatabaseInfo().getInstances().addAll(instances); diff --git a/wrapper/src/test/java/integration/util/AuroraTestUtility.java b/wrapper/src/test/java/integration/util/AuroraTestUtility.java index fe64fe3b0..fe70eace4 100644 --- a/wrapper/src/test/java/integration/util/AuroraTestUtility.java +++ b/wrapper/src/test/java/integration/util/AuroraTestUtility.java @@ -392,8 +392,7 @@ public void createMultiAzCluster(String username, * @return the instance info for the new instance * @throws InterruptedException if the new instance is not available within 5 minutes */ - public TestInstanceInfo createInstance(String instanceClass, String instanceId) - throws InterruptedException { + public TestInstanceInfo createInstance(String instanceClass, String instanceId) throws InterruptedException { final Tag testRunnerTag = Tag.builder().key("env").value("test-runner").build(); final TestEnvironmentInfo info = TestEnvironment.getCurrent().getInfo(); @@ -457,8 +456,7 @@ public List getDBInstances(String clusterId) { * @param instanceToDelete the info for the instance to delete * @throws InterruptedException if the instance has not been deleted within 5 minutes */ - public void deleteInstance(TestInstanceInfo instanceToDelete) - throws InterruptedException { + public void deleteInstance(TestInstanceInfo instanceToDelete) throws InterruptedException { rdsClient.deleteDBInstance( DeleteDbInstanceRequest.builder() .dbInstanceIdentifier(instanceToDelete.getInstanceId()) @@ -701,7 +699,7 @@ public String getDbInstanceClass(TestEnvironmentRequest request) { } } - public List generateTestInstancesInfo(final String clusterId) { + public List getTestInstancesInfo(final String clusterId) { List dbInstances = getDBInstances(clusterId); List instancesInfo = new ArrayList<>(); for (DBInstance dbInstance : dbInstances) { @@ -781,8 +779,7 @@ public DBInstance getDBInstance(String instanceId) { return dbClusterList.get(0); } - public void waitUntilInstanceHasRightState(String instanceId, String... allowedStatuses) - throws InterruptedException { + public void waitUntilInstanceHasRightState(String instanceId, String... allowedStatuses) throws InterruptedException { String status = getDBInstance(instanceId).dbInstanceStatus(); LOGGER.finest("Instance " + instanceId + " status: " + status @@ -1067,8 +1064,8 @@ public void failoverClusterAndWaitUntilWriterChanged() throws InterruptedExcepti getRandomDBClusterReaderInstanceId(clusterId)); } - public void failoverClusterToATargetAndWaitUntilWriterChanged( - String initialWriterId, String targetWriterId) throws InterruptedException { + public void failoverClusterToATargetAndWaitUntilWriterChanged(String initialWriterId, String targetWriterId) + throws InterruptedException { failoverClusterToATargetAndWaitUntilWriterChanged( TestEnvironment.getCurrent().getInfo().getAuroraClusterName(), initialWriterId, @@ -1140,8 +1137,7 @@ public void failoverClusterToATargetAndWaitUntilWriterChanged( LOGGER.finest(String.format("finished failover from %s to target: %s", initialWriterId, targetWriterId)); } - public void failoverClusterToTarget(String clusterId, @Nullable String targetInstanceId) - throws InterruptedException { + public void failoverClusterToTarget(String clusterId, @Nullable String targetInstanceId) throws InterruptedException { waitUntilClusterHasRightState(clusterId); int remainingAttempts = 10; From c486682220cbc744243b639110fa386fe653b993 Mon Sep 17 00:00:00 2001 From: aaron-congo Date: Wed, 22 Jan 2025 14:21:51 -0800 Subject: [PATCH 21/21] Fix mistake in formation of test host suffix --- wrapper/src/test/java/integration/host/TestEnvironment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wrapper/src/test/java/integration/host/TestEnvironment.java b/wrapper/src/test/java/integration/host/TestEnvironment.java index 67f4b2472..a2deab855 100644 --- a/wrapper/src/test/java/integration/host/TestEnvironment.java +++ b/wrapper/src/test/java/integration/host/TestEnvironment.java @@ -449,7 +449,7 @@ private static void createDbCluster(TestEnvironment env, int numOfInstances) { } final String instanceEndpoint = dbInstances.get(0).endpoint().address(); - env.auroraClusterDomain = instanceEndpoint.substring(instanceEndpoint.indexOf(".")); + env.auroraClusterDomain = instanceEndpoint.substring(instanceEndpoint.indexOf(".") + 1); env.info.setDatabaseEngine(engine); env.info.setDatabaseEngineVersion(engineVersion); LOGGER.finer(