Skip to content

Commit 1644da6

Browse files
committed
test: add integration tests
1 parent 3111c13 commit 1644da6

File tree

2 files changed

+94
-16
lines changed

2 files changed

+94
-16
lines changed

wrapper/src/main/java/software/amazon/jdbc/plugin/AuroraInitialConnectionStrategyPlugin.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ public void initHostProvider(
126126

127127
final RdsUrlType type = this.rdsUtils.identifyRdsType(initialUrl);
128128
this.hostListProviderService = hostListProviderService;
129-
if (type.isRdsCluster() && hostListProviderService.isStaticHostListProvider()) {
129+
if ((type.isRdsCluster() || this.verifyOpenedConnectionType != null)
130+
&& hostListProviderService.isStaticHostListProvider()) {
130131
throw new SQLException(Messages.get("AuroraInitialConnectionStrategyPlugin.requireDynamicProvider"));
131132
}
132133
initHostProviderFunc.call();

wrapper/src/test/java/integration/container/tests/BasicConnectivityTests.java

+92-15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package integration.container.tests;
1818

19+
import static integration.container.ConnectionStringHelper.getDefaultProperties;
1920
import static org.junit.jupiter.api.Assertions.assertEquals;
2021
import static org.junit.jupiter.api.Assertions.assertFalse;
2122
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -39,6 +40,8 @@
3940
import java.sql.SQLException;
4041
import java.sql.Statement;
4142
import java.util.ArrayList;
43+
import java.util.Arrays;
44+
import java.util.List;
4245
import java.util.Properties;
4346
import java.util.concurrent.TimeUnit;
4447
import java.util.logging.Logger;
@@ -52,10 +55,30 @@
5255
import org.junit.jupiter.params.provider.Arguments;
5356
import org.junit.jupiter.params.provider.MethodSource;
5457
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;
5577
import software.amazon.jdbc.util.StringUtils;
5678
import software.amazon.jdbc.wrapper.ConnectionWrapper;
5779

5880
@TestMethodOrder(MethodOrderer.MethodName.class)
81+
@ExtendWith(TestDriverProvider.class)
5982
@DisableOnTestFeature({
6083
TestEnvironmentFeatures.PERFORMANCE,
6184
TestEnvironmentFeatures.RUN_HIBERNATE_TESTS_ONLY,
@@ -64,9 +87,27 @@
6487
public class BasicConnectivityTests {
6588

6689
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+
);
67109

68110
@TestTemplate
69-
@ExtendWith(TestDriverProvider.class)
70111
public void test_DirectConnection(TestDriver testDriver) throws SQLException {
71112
LOGGER.info(testDriver.toString());
72113

@@ -105,7 +146,6 @@ public void test_DirectConnection(TestDriver testDriver) throws SQLException {
105146
}
106147

107148
@TestTemplate
108-
@ExtendWith(TestDriverProvider.class)
109149
public void test_WrapperConnection(TestDriver testDriver) throws SQLException {
110150
LOGGER.info(testDriver.toString());
111151

@@ -144,7 +184,6 @@ public void test_WrapperConnection(TestDriver testDriver) throws SQLException {
144184
}
145185

146186
@TestTemplate
147-
@ExtendWith(TestDriverProvider.class)
148187
@EnableOnTestFeature(TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED)
149188
public void test_ProxiedDirectConnection(TestDriver testDriver) throws SQLException {
150189
LOGGER.info(testDriver.toString());
@@ -182,8 +221,23 @@ public void test_ProxiedDirectConnection(TestDriver testDriver) throws SQLExcept
182221
conn.close();
183222
}
184223

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+
185240
@TestTemplate
186-
@ExtendWith(TestDriverProvider.class)
187241
@EnableOnTestFeature(TestEnvironmentFeatures.NETWORK_OUTAGES_ENABLED)
188242
public void test_ProxiedWrapperConnection() throws SQLException {
189243
LOGGER.info(TestEnvironment.getCurrent().getCurrentDriver().toString());
@@ -221,16 +275,15 @@ public void test_ProxiedWrapperConnection() throws SQLException {
221275
}
222276

223277
@TestTemplate
224-
@ExtendWith(TestDriverProvider.class)
225278
public void testSuccessOpenConnectionNoPort() throws SQLException {
226279
String url =
227280
DriverHelper.getWrapperDriverProtocol()
228281
+ TestEnvironment.getCurrent()
229-
.getInfo()
230-
.getDatabaseInfo()
231-
.getInstances()
232-
.get(0)
233-
.getHost()
282+
.getInfo()
283+
.getDatabaseInfo()
284+
.getInstances()
285+
.get(0)
286+
.getHost()
234287
+ "/"
235288
+ TestEnvironment.getCurrent().getInfo().getDatabaseInfo().getDefaultDbName()
236289
+ DriverHelper.getDriverRequiredParameters();
@@ -272,10 +325,10 @@ public void testFailedProperties(
272325
TestEnvironment.getCurrent().setCurrentDriver(testDriver);
273326

274327
if (TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngine()
275-
== DatabaseEngine.MARIADB
328+
== DatabaseEngine.MARIADB
276329
&& TestEnvironment.getCurrent().getCurrentDriver() == TestDriver.MARIADB
277330
&& TestEnvironment.getCurrent().getInfo().getRequest().getDatabaseEngineDeployment()
278-
== DatabaseEngineDeployment.DOCKER
331+
== DatabaseEngineDeployment.DOCKER
279332
&& StringUtils.isNullOrEmpty(username)) {
280333
// MariaDb driver uses "root" username if no username is provided. Since MariaDb database in
281334
// docker container
@@ -314,7 +367,7 @@ protected static String buildConnectionString(
314367
}
315368

316369
private static Stream<Arguments> testConnectionParameters() {
317-
ArrayList<Arguments> results = new ArrayList<>();
370+
final List<Arguments> results = new ArrayList<>();
318371
for (TestDriver testDriver : TestEnvironment.getCurrent().getAllowedTestDrivers()) {
319372

320373
// missing connection prefix
@@ -365,9 +418,8 @@ private static Stream<Arguments> testConnectionParameters() {
365418
}
366419

367420
private static Stream<Arguments> testPropertiesParameters() {
368-
ArrayList<Arguments> results = new ArrayList<>();
421+
final List<Arguments> results = new ArrayList<>();
369422
for (TestDriver testDriver : TestEnvironment.getCurrent().getAllowedTestDrivers()) {
370-
371423
// missing username
372424
results.add(
373425
Arguments.of(
@@ -418,4 +470,29 @@ private static Stream<Arguments> testPropertiesParameters() {
418470
}
419471
return results.stream();
420472
}
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+
}
421498
}

0 commit comments

Comments
 (0)