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..5d024bbc1 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,10 @@ 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() || 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..f5fbcb21f 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; @@ -32,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; @@ -39,6 +42,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 +57,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 +89,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 +148,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 +186,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()); @@ -183,7 +224,41 @@ public void test_ProxiedDirectConnection(TestDriver testDriver) throws SQLExcept } @TestTemplate - @ExtendWith(TestDriverProvider.class) + @EnableOnNumOfInstances(min = 2) + @EnableOnDatabaseEngineDeployment({DatabaseEngineDeployment.AURORA, DatabaseEngineDeployment.RDS_MULTI_AZ_CLUSTER}) + public void testBasicConnectivityTestWithPlugins() throws SQLException { + final TestInstanceInfo readerInstance = TestEnvironment.getCurrent() + .getInfo() + .getDatabaseInfo() + .getInstances() + .get(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 @EnableOnTestFeature(TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED) public void test_ProxiedWrapperConnection() throws SQLException { LOGGER.info(TestEnvironment.getCurrent().getCurrentDriver().toString()); @@ -221,16 +296,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 +346,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 +388,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 +439,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(