From 590a6e3e96593cea4c10b4e18c28f682776a9f85 Mon Sep 17 00:00:00 2001 From: Karen Chen Date: Mon, 3 Feb 2025 18:01:09 -0800 Subject: [PATCH 1/4] fix: skip host list provider check if url is not a cluster endpoint --- .../jdbc/plugin/AuroraInitialConnectionStrategyPlugin.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/AuroraInitialConnectionStrategyPlugin.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/AuroraInitialConnectionStrategyPlugin.java index 7b1eedbad..1f9ebd52a 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/AuroraInitialConnectionStrategyPlugin.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/AuroraInitialConnectionStrategyPlugin.java @@ -124,8 +124,9 @@ public void initHostProvider( final HostListProviderService hostListProviderService, final JdbcCallable initHostProviderFunc) throws SQLException { + final RdsUrlType type = this.rdsUtils.identifyRdsType(initialUrl); this.hostListProviderService = hostListProviderService; - if (hostListProviderService.isStaticHostListProvider()) { + if (type.isRdsCluster() && hostListProviderService.isStaticHostListProvider()) { throw new SQLException(Messages.get("AuroraInitialConnectionStrategyPlugin.requireDynamicProvider")); } initHostProviderFunc.call(); From 77a01edd104ed4f7f06b2e7b9733613db52d01a3 Mon Sep 17 00:00:00 2001 From: Karen Chen Date: Thu, 6 Feb 2025 12:44:56 -0800 Subject: [PATCH 2/4] test: add integration tests --- ...AuroraInitialConnectionStrategyPlugin.java | 3 +- .../tests/BasicConnectivityTests.java | 107 +++++++++++++++--- 2 files changed, 94 insertions(+), 16 deletions(-) diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/AuroraInitialConnectionStrategyPlugin.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/AuroraInitialConnectionStrategyPlugin.java index 1f9ebd52a..5d024bbc1 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/AuroraInitialConnectionStrategyPlugin.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/AuroraInitialConnectionStrategyPlugin.java @@ -126,7 +126,8 @@ public void initHostProvider( final RdsUrlType type = this.rdsUtils.identifyRdsType(initialUrl); this.hostListProviderService = hostListProviderService; - if (type.isRdsCluster() && hostListProviderService.isStaticHostListProvider()) { + if ((type.isRdsCluster() || this.verifyOpenedConnectionType != null) + && hostListProviderService.isStaticHostListProvider()) { throw new SQLException(Messages.get("AuroraInitialConnectionStrategyPlugin.requireDynamicProvider")); } initHostProviderFunc.call(); diff --git a/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java b/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java index 22097a75c..8c33f369f 100644 --- a/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java +++ b/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java @@ -16,6 +16,7 @@ package integration.container.tests; +import static integration.container.ConnectionStringHelper.getDefaultProperties; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -39,6 +40,8 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Properties; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; @@ -52,10 +55,30 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import software.amazon.jdbc.PropertyDefinition; +import software.amazon.jdbc.plugin.AuroraConnectionTrackerPluginFactory; +import software.amazon.jdbc.plugin.AuroraInitialConnectionStrategyPluginFactory; +import software.amazon.jdbc.plugin.AwsSecretsManagerConnectionPluginFactory; +import software.amazon.jdbc.plugin.ConnectTimeConnectionPluginFactory; +import software.amazon.jdbc.plugin.DataCacheConnectionPluginFactory; +import software.amazon.jdbc.plugin.DriverMetaDataConnectionPluginFactory; +import software.amazon.jdbc.plugin.ExecutionTimeConnectionPluginFactory; +import software.amazon.jdbc.plugin.LogQueryConnectionPluginFactory; +import software.amazon.jdbc.plugin.customendpoint.CustomEndpointPluginFactory; +import software.amazon.jdbc.plugin.dev.DeveloperConnectionPluginFactory; +import software.amazon.jdbc.plugin.efm.HostMonitoringConnectionPluginFactory; +import software.amazon.jdbc.plugin.failover.FailoverConnectionPluginFactory; +import software.amazon.jdbc.plugin.federatedauth.FederatedAuthPluginFactory; +import software.amazon.jdbc.plugin.federatedauth.OktaAuthPluginFactory; +import software.amazon.jdbc.plugin.iam.IamAuthConnectionPluginFactory; +import software.amazon.jdbc.plugin.limitless.LimitlessConnectionPluginFactory; +import software.amazon.jdbc.plugin.readwritesplitting.ReadWriteSplittingPluginFactory; +import software.amazon.jdbc.plugin.staledns.AuroraStaleDnsPluginFactory; +import software.amazon.jdbc.plugin.strategy.fastestresponse.FastestResponseStrategyPluginFactory; import software.amazon.jdbc.util.StringUtils; import software.amazon.jdbc.wrapper.ConnectionWrapper; @TestMethodOrder(MethodOrderer.MethodName.class) +@ExtendWith(TestDriverProvider.class) @DisableOnTestFeature({ TestEnvironmentFeatures.PERFORMANCE, TestEnvironmentFeatures.RUN_HIBERNATE_TESTS_ONLY, @@ -64,9 +87,27 @@ public class BasicConnectivityTests { private static final Logger LOGGER = Logger.getLogger(BasicConnectivityTests.class.getName()); + private static final List PLUGINS = Arrays.asList( + "executionTime", + "logQuery", + "dataCache", + "customEndpoint", + "efm", + "efm2", + "failover", + "failover2", + "auroraStaleDns", + "readWriteSplitting", + "auroraConnectionTracker", + "driverMetaData", + "connectTime", + "dev", + "fastestResponseStrategy", + "initialConnection", + "limitless" + ); @TestTemplate - @ExtendWith(TestDriverProvider.class) public void test_DirectConnection(TestDriver testDriver) throws SQLException { LOGGER.info(testDriver.toString()); @@ -105,7 +146,6 @@ public void test_DirectConnection(TestDriver testDriver) throws SQLException { } @TestTemplate - @ExtendWith(TestDriverProvider.class) public void test_WrapperConnection(TestDriver testDriver) throws SQLException { LOGGER.info(testDriver.toString()); @@ -144,7 +184,6 @@ public void test_WrapperConnection(TestDriver testDriver) throws SQLException { } @TestTemplate - @ExtendWith(TestDriverProvider.class) @EnableOnTestFeature(TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED) public void test_ProxiedDirectConnection(TestDriver testDriver) throws SQLException { LOGGER.info(testDriver.toString()); @@ -182,8 +221,23 @@ public void test_ProxiedDirectConnection(TestDriver testDriver) throws SQLExcept conn.close(); } + @ParameterizedTest + @MethodSource("testPluginParameters") + public void testBasicConnectivityTestWithPlugins(String plugin, String url) throws SQLException { + final Properties props = getDefaultProperties(); + props.setProperty(PropertyDefinition.PLUGINS.name, plugin); + LOGGER.finest("Connecting to " + url); + + try (Connection conn = DriverManager.getConnection(url, props); + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT 1"); + ) { + assertTrue(rs.next()); + assertEquals(1, rs.getInt(1)); + } + } + @TestTemplate - @ExtendWith(TestDriverProvider.class) @EnableOnTestFeature(TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED) public void test_ProxiedWrapperConnection() throws SQLException { LOGGER.info(TestEnvironment.getCurrent().getCurrentDriver().toString()); @@ -221,16 +275,15 @@ public void test_ProxiedWrapperConnection() throws SQLException { } @TestTemplate - @ExtendWith(TestDriverProvider.class) public void testSuccessOpenConnectionNoPort() throws SQLException { String url = DriverHelper.getWrapperDriverProtocol() + TestEnvironment.getCurrent() - .getInfo() - .getDatabaseInfo() - .getInstances() - .get(0) - .getHost() + .getInfo() + .getDatabaseInfo() + .getInstances() + .get(0) + .getHost() + "/" + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName() + DriverHelper.getDriverRequiredParameters(); @@ -272,10 +325,10 @@ public void testFailedProperties( TestEnvironment.getCurrent().setCurrentDriver(testDriver); if (TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() - == DatabaseEngine.MARIADB + == DatabaseEngine.MARIADB && TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB && TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment() - == DatabaseEngineDeployment.DOCKER + == DatabaseEngineDeployment.DOCKER && StringUtils.isNullOrEmpty(username)) { // MariaDb driver uses "root" username if no username is provided. Since MariaDb database in // docker container @@ -314,7 +367,7 @@ protected static String buildConnectionString( } private static Stream testConnectionParameters() { - ArrayList results = new ArrayList<>(); + final List results = new ArrayList<>(); for (TestDriver testDriver : TestEnvironment.getCurrent().getAllowedTestDrivers()) { // missing connection prefix @@ -365,9 +418,8 @@ private static Stream testConnectionParameters() { } private static Stream testPropertiesParameters() { - ArrayList results = new ArrayList<>(); + final List results = new ArrayList<>(); for (TestDriver testDriver : TestEnvironment.getCurrent().getAllowedTestDrivers()) { - // missing username results.add( Arguments.of( @@ -418,4 +470,29 @@ private static Stream testPropertiesParameters() { } return results.stream(); } + + private static Stream testPluginParameters() { + final List results = new ArrayList<>(); + final TestInstanceInfo readerInstance = TestEnvironment.getCurrent() + .getInfo() + .getDatabaseInfo() + .getInstances() + .get(1); + final String writerInstanceUrl = ConnectionStringHelper.getWrapperUrl(); + final String readerInstanceUrl = ConnectionStringHelper.getWrapperUrl(readerInstance); + final String writerClusterUrl = ConnectionStringHelper.getWrapperClusterEndpointUrl(); + final String readerClusterUrl = ConnectionStringHelper.getWrapperReaderClusterUrl(); + + for (String plugin : PLUGINS) { + // Connect via writer instance endpoint. + results.add(Arguments.of(plugin, writerInstanceUrl)); + // Connect via reader instance endpoint. + results.add(Arguments.of(plugin, readerInstanceUrl)); + // Connect via writer cluster endpoint. + results.add(Arguments.of(plugin, writerClusterUrl)); + // Connect via reader cluster endpoint. + results.add(Arguments.of(plugin, readerClusterUrl)); + } + return results.stream(); + } } From 60b7c897d242f012d0e61c675c8accee4afb0fc9 Mon Sep 17 00:00:00 2001 From: Karen Chen Date: Tue, 11 Feb 2025 14:52:54 -0800 Subject: [PATCH 3/4] test: disable plugins connectivity tests for single instance clusters --- .../integration/container/tests/BasicConnectivityTests.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java b/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java index 8c33f369f..de3aeac17 100644 --- a/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java +++ b/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java @@ -33,6 +33,8 @@ import integration.container.TestDriverProvider; import integration.container.TestEnvironment; import integration.container.condition.DisableOnTestFeature; +import integration.container.condition.EnableOnDatabaseEngineDeployment; +import integration.container.condition.EnableOnNumOfInstances; import integration.container.condition.EnableOnTestFeature; import java.sql.Connection; import java.sql.DriverManager; @@ -222,6 +224,8 @@ public void test_ProxiedDirectConnection(TestDriver testDriver) throws SQLExcept } @ParameterizedTest + @EnableOnNumOfInstances(min = 2) + @EnableOnDatabaseEngineDeployment({DatabaseEngineDeployment.AURORA, DatabaseEngineDeployment.RDS_MULTI_AZ_CLUSTER}) @MethodSource("testPluginParameters") public void testBasicConnectivityTestWithPlugins(String plugin, String url) throws SQLException { final Properties props = getDefaultProperties(); From cbb32c8f9d69e0dba4ce59a6508159d8b1483563 Mon Sep 17 00:00:00 2001 From: Karen Chen <64801825+karenc-bq@users.noreply.github.com> Date: Fri, 13 Jun 2025 13:21:07 -0700 Subject: [PATCH 4/4] fix: simple connectivity test for each plugin --- .../tests/BasicConnectivityTests.java | 66 ++++++++----------- 1 file changed, 29 insertions(+), 37 deletions(-) diff --git a/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java b/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java index de3aeac17..f5fbcb21f 100644 --- a/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java +++ b/wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java @@ -223,22 +223,39 @@ public void test_ProxiedDirectConnection(TestDriver testDriver) throws SQLExcept conn.close(); } - @ParameterizedTest + @TestTemplate @EnableOnNumOfInstances(min = 2) @EnableOnDatabaseEngineDeployment({DatabaseEngineDeployment.AURORA, DatabaseEngineDeployment.RDS_MULTI_AZ_CLUSTER}) - @MethodSource("testPluginParameters") - public void testBasicConnectivityTestWithPlugins(String plugin, String url) throws SQLException { - final Properties props = getDefaultProperties(); - props.setProperty(PropertyDefinition.PLUGINS.name, plugin); - LOGGER.finest("Connecting to " + url); + public void testBasicConnectivityTestWithPlugins() throws SQLException { + final TestInstanceInfo readerInstance = TestEnvironment.getCurrent() + .getInfo() + .getDatabaseInfo() + .getInstances() + .get(1); - try (Connection conn = DriverManager.getConnection(url, props); - Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT 1"); - ) { - assertTrue(rs.next()); - assertEquals(1, rs.getInt(1)); + final List urls = Arrays.asList( + ConnectionStringHelper.getWrapperUrl(), + ConnectionStringHelper.getWrapperUrl(readerInstance), + ConnectionStringHelper.getWrapperClusterEndpointUrl(), + ConnectionStringHelper.getWrapperReaderClusterUrl() + ); + + for (String url : urls) { + for (String plugin : PLUGINS) { + final Properties props = getDefaultProperties(); + props.setProperty(PropertyDefinition.PLUGINS.name, plugin); + LOGGER.finest("Connecting to " + url); + + try (Connection conn = DriverManager.getConnection(url, props); + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT 1"); + ) { + assertTrue(rs.next()); + assertEquals(1, rs.getInt(1)); + } + } } + } @TestTemplate @@ -474,29 +491,4 @@ private static Stream testPropertiesParameters() { } return results.stream(); } - - private static Stream testPluginParameters() { - final List results = new ArrayList<>(); - final TestInstanceInfo readerInstance = TestEnvironment.getCurrent() - .getInfo() - .getDatabaseInfo() - .getInstances() - .get(1); - final String writerInstanceUrl = ConnectionStringHelper.getWrapperUrl(); - final String readerInstanceUrl = ConnectionStringHelper.getWrapperUrl(readerInstance); - final String writerClusterUrl = ConnectionStringHelper.getWrapperClusterEndpointUrl(); - final String readerClusterUrl = ConnectionStringHelper.getWrapperReaderClusterUrl(); - - for (String plugin : PLUGINS) { - // Connect via writer instance endpoint. - results.add(Arguments.of(plugin, writerInstanceUrl)); - // Connect via reader instance endpoint. - results.add(Arguments.of(plugin, readerInstanceUrl)); - // Connect via writer cluster endpoint. - results.add(Arguments.of(plugin, writerClusterUrl)); - // Connect via reader cluster endpoint. - results.add(Arguments.of(plugin, readerClusterUrl)); - } - return results.stream(); - } }