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 ;
56
59
import software .amazon .jdbc .wrapper .ConnectionWrapper ;
57
60
58
61
@ TestMethodOrder (MethodOrderer .MethodName .class )
62
+ @ ExtendWith (TestDriverProvider .class )
59
63
@ DisableOnTestFeature ({
60
64
TestEnvironmentFeatures .PERFORMANCE ,
61
65
TestEnvironmentFeatures .RUN_HIBERNATE_TESTS_ONLY ,
@@ -66,7 +70,6 @@ public class BasicConnectivityTests {
66
70
private static final Logger LOGGER = Logger .getLogger (BasicConnectivityTests .class .getName ());
67
71
68
72
@ TestTemplate
69
- @ ExtendWith (TestDriverProvider .class )
70
73
public void test_DirectConnection (TestDriver testDriver ) throws SQLException {
71
74
LOGGER .info (testDriver .toString ());
72
75
@@ -105,7 +108,6 @@ public void test_DirectConnection(TestDriver testDriver) throws SQLException {
105
108
}
106
109
107
110
@ TestTemplate
108
- @ ExtendWith (TestDriverProvider .class )
109
111
public void test_WrapperConnection (TestDriver testDriver ) throws SQLException {
110
112
LOGGER .info (testDriver .toString ());
111
113
@@ -144,7 +146,6 @@ public void test_WrapperConnection(TestDriver testDriver) throws SQLException {
144
146
}
145
147
146
148
@ TestTemplate
147
- @ ExtendWith (TestDriverProvider .class )
148
149
@ EnableOnTestFeature (TestEnvironmentFeatures .NETWORK_OUTAGES_ENABLED )
149
150
public void test_ProxiedDirectConnection (TestDriver testDriver ) throws SQLException {
150
151
LOGGER .info (testDriver .toString ());
@@ -182,8 +183,23 @@ public void test_ProxiedDirectConnection(TestDriver testDriver) throws SQLExcept
182
183
conn .close ();
183
184
}
184
185
186
+ @ ParameterizedTest
187
+ @ MethodSource ("testPluginParameters" )
188
+ public void testBasicConnectivityTestWithPlugins (String plugin , String url ) throws SQLException {
189
+ final Properties props = getDefaultProperties ();
190
+ props .setProperty (PropertyDefinition .PLUGINS .name , plugin );
191
+ LOGGER .finest ("Connecting to " + url );
192
+
193
+ try (Connection conn = DriverManager .getConnection (url , props );
194
+ Statement stmt = conn .createStatement ();
195
+ ResultSet rs = stmt .executeQuery ("SELECT 1" );
196
+ ) {
197
+ assertTrue (rs .next ());
198
+ assertEquals (1 , rs .getInt (1 ));
199
+ }
200
+ }
201
+
185
202
@ TestTemplate
186
- @ ExtendWith (TestDriverProvider .class )
187
203
@ EnableOnTestFeature (TestEnvironmentFeatures .NETWORK_OUTAGES_ENABLED )
188
204
public void test_ProxiedWrapperConnection () throws SQLException {
189
205
LOGGER .info (TestEnvironment .getCurrent ().getCurrentDriver ().toString ());
@@ -221,16 +237,15 @@ public void test_ProxiedWrapperConnection() throws SQLException {
221
237
}
222
238
223
239
@ TestTemplate
224
- @ ExtendWith (TestDriverProvider .class )
225
240
public void testSuccessOpenConnectionNoPort () throws SQLException {
226
241
String url =
227
242
DriverHelper .getWrapperDriverProtocol ()
228
243
+ TestEnvironment .getCurrent ()
229
- .getInfo ()
230
- .getDatabaseInfo ()
231
- .getInstances ()
232
- .get (0 )
233
- .getHost ()
244
+ .getInfo ()
245
+ .getDatabaseInfo ()
246
+ .getInstances ()
247
+ .get (0 )
248
+ .getHost ()
234
249
+ "/"
235
250
+ TestEnvironment .getCurrent ().getInfo ().getDatabaseInfo ().getDefaultDbName ()
236
251
+ DriverHelper .getDriverRequiredParameters ();
@@ -272,10 +287,10 @@ public void testFailedProperties(
272
287
TestEnvironment .getCurrent ().setCurrentDriver (testDriver );
273
288
274
289
if (TestEnvironment .getCurrent ().getInfo ().getRequest ().getDatabaseEngine ()
275
- == DatabaseEngine .MARIADB
290
+ == DatabaseEngine .MARIADB
276
291
&& TestEnvironment .getCurrent ().getCurrentDriver () == TestDriver .MARIADB
277
292
&& TestEnvironment .getCurrent ().getInfo ().getRequest ().getDatabaseEngineDeployment ()
278
- == DatabaseEngineDeployment .DOCKER
293
+ == DatabaseEngineDeployment .DOCKER
279
294
&& StringUtils .isNullOrEmpty (username )) {
280
295
// MariaDb driver uses "root" username if no username is provided. Since MariaDb database in
281
296
// docker container
@@ -314,7 +329,7 @@ protected static String buildConnectionString(
314
329
}
315
330
316
331
private static Stream <Arguments > testConnectionParameters () {
317
- ArrayList <Arguments > results = new ArrayList <>();
332
+ final List <Arguments > results = new ArrayList <>();
318
333
for (TestDriver testDriver : TestEnvironment .getCurrent ().getAllowedTestDrivers ()) {
319
334
320
335
// missing connection prefix
@@ -365,9 +380,8 @@ private static Stream<Arguments> testConnectionParameters() {
365
380
}
366
381
367
382
private static Stream <Arguments > testPropertiesParameters () {
368
- ArrayList <Arguments > results = new ArrayList <>();
383
+ final List <Arguments > results = new ArrayList <>();
369
384
for (TestDriver testDriver : TestEnvironment .getCurrent ().getAllowedTestDrivers ()) {
370
-
371
385
// missing username
372
386
results .add (
373
387
Arguments .of (
@@ -418,4 +432,33 @@ private static Stream<Arguments> testPropertiesParameters() {
418
432
}
419
433
return results .stream ();
420
434
}
435
+
436
+ private static Stream <Arguments > testPluginParameters () {
437
+ final List <String > plugins = Arrays .asList (
438
+ "executeTime" ,
439
+ "connectTime"
440
+ );
441
+ final List <Arguments > results = new ArrayList <>();
442
+ final TestInstanceInfo readerInstance = TestEnvironment .getCurrent ()
443
+ .getInfo ()
444
+ .getDatabaseInfo ()
445
+ .getInstances ()
446
+ .get (1 );
447
+ final String writerInstanceUrl = ConnectionStringHelper .getWrapperUrl ();
448
+ final String readerInstanceUrl = ConnectionStringHelper .getWrapperUrl (readerInstance );
449
+ final String writerClusterUrl = ConnectionStringHelper .getWrapperClusterEndpointUrl ();
450
+ final String readerClusterUrl = ConnectionStringHelper .getWrapperReaderClusterUrl ();
451
+
452
+ for (String plugin : plugins ) {
453
+ // Connect via writer instance endpoint.
454
+ results .add (Arguments .of (plugin , writerInstanceUrl ));
455
+ // Connect via reader instance endpoint.
456
+ results .add (Arguments .of (plugin , readerInstanceUrl ));
457
+ // Connect via writer cluster endpoint.
458
+ results .add (Arguments .of (plugin , writerClusterUrl ));
459
+ // Connect via reader cluster endpoint.
460
+ results .add (Arguments .of (plugin , readerClusterUrl ));
461
+ }
462
+ return results .stream ();
463
+ }
421
464
}
0 commit comments