|
16 | 16 |
|
17 | 17 | package integration.container.tests; |
18 | 18 |
|
| 19 | +import static integration.container.ConnectionStringHelper.getDefaultProperties; |
19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; |
20 | 21 | import static org.junit.jupiter.api.Assertions.assertFalse; |
21 | 22 | import static org.junit.jupiter.api.Assertions.assertThrows; |
|
39 | 40 | import java.sql.SQLException; |
40 | 41 | import java.sql.Statement; |
41 | 42 | import java.util.ArrayList; |
| 43 | +import java.util.Arrays; |
| 44 | +import java.util.List; |
42 | 45 | import java.util.Properties; |
43 | 46 | import java.util.concurrent.TimeUnit; |
44 | 47 | import java.util.logging.Logger; |
|
52 | 55 | import org.junit.jupiter.params.provider.Arguments; |
53 | 56 | import org.junit.jupiter.params.provider.MethodSource; |
54 | 57 | import software.amazon.jdbc.PropertyDefinition; |
| 58 | +import software.amazon.jdbc.plugin.AuroraConnectionTrackerPluginFactory; |
| 59 | +import software.amazon.jdbc.plugin.AuroraInitialConnectionStrategyPluginFactory; |
| 60 | +import software.amazon.jdbc.plugin.AwsSecretsManagerConnectionPluginFactory; |
| 61 | +import software.amazon.jdbc.plugin.ConnectTimeConnectionPluginFactory; |
| 62 | +import software.amazon.jdbc.plugin.DataCacheConnectionPluginFactory; |
| 63 | +import software.amazon.jdbc.plugin.DriverMetaDataConnectionPluginFactory; |
| 64 | +import software.amazon.jdbc.plugin.ExecutionTimeConnectionPluginFactory; |
| 65 | +import software.amazon.jdbc.plugin.LogQueryConnectionPluginFactory; |
| 66 | +import software.amazon.jdbc.plugin.customendpoint.CustomEndpointPluginFactory; |
| 67 | +import software.amazon.jdbc.plugin.dev.DeveloperConnectionPluginFactory; |
| 68 | +import software.amazon.jdbc.plugin.efm.HostMonitoringConnectionPluginFactory; |
| 69 | +import software.amazon.jdbc.plugin.failover.FailoverConnectionPluginFactory; |
| 70 | +import software.amazon.jdbc.plugin.federatedauth.FederatedAuthPluginFactory; |
| 71 | +import software.amazon.jdbc.plugin.federatedauth.OktaAuthPluginFactory; |
| 72 | +import software.amazon.jdbc.plugin.iam.IamAuthConnectionPluginFactory; |
| 73 | +import software.amazon.jdbc.plugin.limitless.LimitlessConnectionPluginFactory; |
| 74 | +import software.amazon.jdbc.plugin.readwritesplitting.ReadWriteSplittingPluginFactory; |
| 75 | +import software.amazon.jdbc.plugin.staledns.AuroraStaleDnsPluginFactory; |
| 76 | +import software.amazon.jdbc.plugin.strategy.fastestresponse.FastestResponseStrategyPluginFactory; |
55 | 77 | import software.amazon.jdbc.util.StringUtils; |
56 | 78 | import software.amazon.jdbc.wrapper.ConnectionWrapper; |
57 | 79 |
|
58 | 80 | @TestMethodOrder(MethodOrderer.MethodName.class) |
| 81 | +@ExtendWith(TestDriverProvider.class) |
59 | 82 | @DisableOnTestFeature({ |
60 | 83 | TestEnvironmentFeatures.PERFORMANCE, |
61 | 84 | TestEnvironmentFeatures.RUN_HIBERNATE_TESTS_ONLY, |
|
64 | 87 | public class BasicConnectivityTests { |
65 | 88 |
|
66 | 89 | private static final Logger LOGGER = Logger.getLogger(BasicConnectivityTests.class.getName()); |
| 90 | + private static final List<String> PLUGINS = Arrays.asList( |
| 91 | + "executionTime", |
| 92 | + "logQuery", |
| 93 | + "dataCache", |
| 94 | + "customEndpoint", |
| 95 | + "efm", |
| 96 | + "efm2", |
| 97 | + "failover", |
| 98 | + "failover2", |
| 99 | + "auroraStaleDns", |
| 100 | + "readWriteSplitting", |
| 101 | + "auroraConnectionTracker", |
| 102 | + "driverMetaData", |
| 103 | + "connectTime", |
| 104 | + "dev", |
| 105 | + "fastestResponseStrategy", |
| 106 | + "initialConnection", |
| 107 | + "limitless" |
| 108 | + ); |
67 | 109 |
|
68 | 110 | @TestTemplate |
69 | | - @ExtendWith(TestDriverProvider.class) |
70 | 111 | public void test_DirectConnection(TestDriver testDriver) throws SQLException { |
71 | 112 | LOGGER.info(testDriver.toString()); |
72 | 113 |
|
@@ -105,7 +146,6 @@ public void test_DirectConnection(TestDriver testDriver) throws SQLException { |
105 | 146 | } |
106 | 147 |
|
107 | 148 | @TestTemplate |
108 | | - @ExtendWith(TestDriverProvider.class) |
109 | 149 | public void test_WrapperConnection(TestDriver testDriver) throws SQLException { |
110 | 150 | LOGGER.info(testDriver.toString()); |
111 | 151 |
|
@@ -144,7 +184,6 @@ public void test_WrapperConnection(TestDriver testDriver) throws SQLException { |
144 | 184 | } |
145 | 185 |
|
146 | 186 | @TestTemplate |
147 | | - @ExtendWith(TestDriverProvider.class) |
148 | 187 | @EnableOnTestFeature(TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED) |
149 | 188 | public void test_ProxiedDirectConnection(TestDriver testDriver) throws SQLException { |
150 | 189 | LOGGER.info(testDriver.toString()); |
@@ -182,8 +221,23 @@ public void test_ProxiedDirectConnection(TestDriver testDriver) throws SQLExcept |
182 | 221 | conn.close(); |
183 | 222 | } |
184 | 223 |
|
| 224 | + @ParameterizedTest |
| 225 | + @MethodSource("testPluginParameters") |
| 226 | + public void testBasicConnectivityTestWithPlugins(String plugin, String url) throws SQLException { |
| 227 | + final Properties props = getDefaultProperties(); |
| 228 | + props.setProperty(PropertyDefinition.PLUGINS.name, plugin); |
| 229 | + LOGGER.finest("Connecting to " + url); |
| 230 | + |
| 231 | + try (Connection conn = DriverManager.getConnection(url, props); |
| 232 | + Statement stmt = conn.createStatement(); |
| 233 | + ResultSet rs = stmt.executeQuery("SELECT 1"); |
| 234 | + ) { |
| 235 | + assertTrue(rs.next()); |
| 236 | + assertEquals(1, rs.getInt(1)); |
| 237 | + } |
| 238 | + } |
| 239 | + |
185 | 240 | @TestTemplate |
186 | | - @ExtendWith(TestDriverProvider.class) |
187 | 241 | @EnableOnTestFeature(TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED) |
188 | 242 | public void test_ProxiedWrapperConnection() throws SQLException { |
189 | 243 | LOGGER.info(TestEnvironment.getCurrent().getCurrentDriver().toString()); |
@@ -221,16 +275,15 @@ public void test_ProxiedWrapperConnection() throws SQLException { |
221 | 275 | } |
222 | 276 |
|
223 | 277 | @TestTemplate |
224 | | - @ExtendWith(TestDriverProvider.class) |
225 | 278 | public void testSuccessOpenConnectionNoPort() throws SQLException { |
226 | 279 | String url = |
227 | 280 | DriverHelper.getWrapperDriverProtocol() |
228 | 281 | + TestEnvironment.getCurrent() |
229 | | - .getInfo() |
230 | | - .getDatabaseInfo() |
231 | | - .getInstances() |
232 | | - .get(0) |
233 | | - .getHost() |
| 282 | + .getInfo() |
| 283 | + .getDatabaseInfo() |
| 284 | + .getInstances() |
| 285 | + .get(0) |
| 286 | + .getHost() |
234 | 287 | + "/" |
235 | 288 | + TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName() |
236 | 289 | + DriverHelper.getDriverRequiredParameters(); |
@@ -272,10 +325,10 @@ public void testFailedProperties( |
272 | 325 | TestEnvironment.getCurrent().setCurrentDriver(testDriver); |
273 | 326 |
|
274 | 327 | if (TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine() |
275 | | - == DatabaseEngine.MARIADB |
| 328 | + == DatabaseEngine.MARIADB |
276 | 329 | && TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB |
277 | 330 | && TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment() |
278 | | - == DatabaseEngineDeployment.DOCKER |
| 331 | + == DatabaseEngineDeployment.DOCKER |
279 | 332 | && StringUtils.isNullOrEmpty(username)) { |
280 | 333 | // MariaDb driver uses "root" username if no username is provided. Since MariaDb database in |
281 | 334 | // docker container |
@@ -314,7 +367,7 @@ protected static String buildConnectionString( |
314 | 367 | } |
315 | 368 |
|
316 | 369 | private static Stream<Arguments> testConnectionParameters() { |
317 | | - ArrayList<Arguments> results = new ArrayList<>(); |
| 370 | + final List<Arguments> results = new ArrayList<>(); |
318 | 371 | for (TestDriver testDriver : TestEnvironment.getCurrent().getAllowedTestDrivers()) { |
319 | 372 |
|
320 | 373 | // missing connection prefix |
@@ -365,9 +418,8 @@ private static Stream<Arguments> testConnectionParameters() { |
365 | 418 | } |
366 | 419 |
|
367 | 420 | private static Stream<Arguments> testPropertiesParameters() { |
368 | | - ArrayList<Arguments> results = new ArrayList<>(); |
| 421 | + final List<Arguments> results = new ArrayList<>(); |
369 | 422 | for (TestDriver testDriver : TestEnvironment.getCurrent().getAllowedTestDrivers()) { |
370 | | - |
371 | 423 | // missing username |
372 | 424 | results.add( |
373 | 425 | Arguments.of( |
@@ -418,4 +470,29 @@ private static Stream<Arguments> testPropertiesParameters() { |
418 | 470 | } |
419 | 471 | return results.stream(); |
420 | 472 | } |
| 473 | + |
| 474 | + private static Stream<Arguments> testPluginParameters() { |
| 475 | + final List<Arguments> results = new ArrayList<>(); |
| 476 | + final TestInstanceInfo readerInstance = TestEnvironment.getCurrent() |
| 477 | + .getInfo() |
| 478 | + .getDatabaseInfo() |
| 479 | + .getInstances() |
| 480 | + .get(1); |
| 481 | + final String writerInstanceUrl = ConnectionStringHelper.getWrapperUrl(); |
| 482 | + final String readerInstanceUrl = ConnectionStringHelper.getWrapperUrl(readerInstance); |
| 483 | + final String writerClusterUrl = ConnectionStringHelper.getWrapperClusterEndpointUrl(); |
| 484 | + final String readerClusterUrl = ConnectionStringHelper.getWrapperReaderClusterUrl(); |
| 485 | + |
| 486 | + for (String plugin : PLUGINS) { |
| 487 | + // Connect via writer instance endpoint. |
| 488 | + results.add(Arguments.of(plugin, writerInstanceUrl)); |
| 489 | + // Connect via reader instance endpoint. |
| 490 | + results.add(Arguments.of(plugin, readerInstanceUrl)); |
| 491 | + // Connect via writer cluster endpoint. |
| 492 | + results.add(Arguments.of(plugin, writerClusterUrl)); |
| 493 | + // Connect via reader cluster endpoint. |
| 494 | + results.add(Arguments.of(plugin, readerClusterUrl)); |
| 495 | + } |
| 496 | + return results.stream(); |
| 497 | + } |
421 | 498 | } |
0 commit comments