71
71
// See https://github.com/mongodb/specifications/tree/master/source/initial-dns-seedlist-discovery/tests
72
72
@ RunWith (Parameterized .class )
73
73
public abstract class InitialDnsSeedlistDiscoveryTest {
74
- private final String filename ;
75
74
private final Path parentDirectory ;
76
75
private final String uri ;
77
76
@ Nullable
@@ -85,11 +84,10 @@ public abstract class InitialDnsSeedlistDiscoveryTest {
85
84
private final boolean isError ;
86
85
private final BsonDocument options ;
87
86
88
- public InitialDnsSeedlistDiscoveryTest (final String filename , final Path parentDirectory , final String uri ,
87
+ public InitialDnsSeedlistDiscoveryTest (@ SuppressWarnings ( "unused" ) final String filename , final Path parentDirectory , final String uri ,
89
88
@ Nullable final List <String > seeds , @ Nullable final Integer numSeeds ,
90
89
@ Nullable final List <String > hosts , @ Nullable final Integer numHosts ,
91
90
final boolean isError , final BsonDocument options ) {
92
- this .filename = filename ;
93
91
this .parentDirectory = parentDirectory ;
94
92
this .uri = uri ;
95
93
this .seeds = seeds ;
@@ -121,7 +119,7 @@ public void shouldResolveTxtRecord() throws InterruptedException {
121
119
if (isError ) {
122
120
MongoClient client = null ;
123
121
try {
124
- final AtomicReference <MongoException > exceptionReference = new AtomicReference <MongoException >();
122
+ final AtomicReference <MongoException > exceptionReference = new AtomicReference <>();
125
123
final CountDownLatch latch = new CountDownLatch (1 );
126
124
127
125
ConnectionString connectionString ;
@@ -131,27 +129,21 @@ public void shouldResolveTxtRecord() throws InterruptedException {
131
129
final SslSettings sslSettings = getSslSettings (connectionString );
132
130
assumeTrue ("SSL settings don't match" , getSslSettings ().isEnabled () == sslSettings .isEnabled ());
133
131
settings = MongoClientSettings .builder ().applyConnectionString (connectionString )
134
- .applyToSslSettings (new Block <SslSettings .Builder >() {
135
- @ Override
136
- public void apply (final SslSettings .Builder builder ) {
137
- builder .applySettings (sslSettings );
138
- builder .invalidHostNameAllowed (true );
139
- }
132
+ .applyToSslSettings (builder -> {
133
+ builder .applySettings (sslSettings );
134
+ builder .invalidHostNameAllowed (true );
140
135
})
141
- .applyToClusterSettings (new Block <ClusterSettings .Builder >() {
142
- @ Override
143
- public void apply (final ClusterSettings .Builder builder ) {
144
- builder .serverSelectionTimeout (5 , TimeUnit .SECONDS );
145
- builder .addClusterListener (new ClusterListener () {
146
- @ Override
147
- public void clusterDescriptionChanged (final ClusterDescriptionChangedEvent event ) {
148
- if (event .getNewDescription ().getSrvResolutionException () != null ) {
149
- exceptionReference .set (event .getNewDescription ().getSrvResolutionException ());
150
- latch .countDown ();
151
- }
136
+ .applyToClusterSettings (builder -> {
137
+ builder .serverSelectionTimeout (5 , TimeUnit .SECONDS );
138
+ builder .addClusterListener (new ClusterListener () {
139
+ @ Override
140
+ public void clusterDescriptionChanged (final ClusterDescriptionChangedEvent event ) {
141
+ if (event .getNewDescription ().getSrvResolutionException () != null ) {
142
+ exceptionReference .set (event .getNewDescription ().getSrvResolutionException ());
143
+ latch .countDown ();
152
144
}
153
- });
154
- }
145
+ }
146
+ });
155
147
})
156
148
.build ();
157
149
} catch (MongoClientException | IllegalArgumentException e ) {
@@ -160,7 +152,7 @@ public void clusterDescriptionChanged(final ClusterDescriptionChangedEvent event
160
152
}
161
153
client = createMongoClient (settings );
162
154
// Load balancing mode has special rules regarding cluster event publishing, so we can't rely on those here.
163
- // Instead we just try to execute an operation and assert that it throws
155
+ // Instead, we just try to execute an operation and assert that it throws
164
156
if (settings .getClusterSettings ().getMode () == ClusterConnectionMode .LOAD_BALANCED ) {
165
157
try {
166
158
client .getDatabase ("admin" ).runCommand (new Document ("ping" , 1 ));
@@ -186,25 +178,33 @@ public void clusterDescriptionChanged(final ClusterDescriptionChangedEvent event
186
178
ConnectionString connectionString = new ConnectionString (this .uri );
187
179
188
180
for (Map .Entry <String , BsonValue > entry : options .entrySet ()) {
189
- if (entry .getKey ().equals ("replicaSet" )) {
190
- assertEquals (entry .getValue ().asString ().getValue (), connectionString .getRequiredReplicaSetName ());
191
- } else if (entry .getKey ().equals ("ssl" )) {
192
- assertEquals (entry .getValue ().asBoolean ().getValue (), connectionString .getSslEnabled ());
193
- } else if (entry .getKey ().equals ("authSource" )) {
194
- // ignoring authSource for now, because without at least a userName also in the connection string,
195
- // the authSource is ignored. If the test gets this far, at least we know that a TXT record
196
- // containing in authSource doesn't blow up. We just don't test that it's actually used.
197
- assertTrue (true );
198
- } else if (entry .getKey ().equals ("directConnection" )) {
199
- assertEquals (entry .getValue ().asBoolean ().getValue (), connectionString .isDirectConnection ());
200
- } else if (entry .getKey ().equals ("loadBalanced" )) {
201
- assertEquals (entry .getValue ().asBoolean ().getValue (), connectionString .isLoadBalanced ());
202
- } else if (entry .getKey ().equals ("srvMaxHosts" )) {
203
- assertEquals (Integer .valueOf (entry .getValue ().asInt32 ().getValue ()), connectionString .getSrvMaxHosts ());
204
- } else if (entry .getKey ().equals ("srvServiceName" )) {
205
- assertEquals (entry .getValue ().asString ().getValue (), connectionString .getSrvServiceName ());
206
- } else {
207
- throw new UnsupportedOperationException ("No support configured yet for " + entry .getKey ());
181
+ switch (entry .getKey ()) {
182
+ case "replicaSet" :
183
+ assertEquals (entry .getValue ().asString ().getValue (), connectionString .getRequiredReplicaSetName ());
184
+ break ;
185
+ case "ssl" :
186
+ assertEquals (entry .getValue ().asBoolean ().getValue (), connectionString .getSslEnabled ());
187
+ break ;
188
+ case "authSource" :
189
+ // ignoring authSource for now, because without at least a userName also in the connection string,
190
+ // the authSource is ignored. If the test gets this far, at least we know that a TXT record
191
+ // containing in authSource doesn't blow up. We just don't test that it's actually used.
192
+ assertTrue (true );
193
+ break ;
194
+ case "directConnection" :
195
+ assertEquals (entry .getValue ().asBoolean ().getValue (), connectionString .isDirectConnection ());
196
+ break ;
197
+ case "loadBalanced" :
198
+ assertEquals (entry .getValue ().asBoolean ().getValue (), connectionString .isLoadBalanced ());
199
+ break ;
200
+ case "srvMaxHosts" :
201
+ assertEquals (Integer .valueOf (entry .getValue ().asInt32 ().getValue ()), connectionString .getSrvMaxHosts ());
202
+ break ;
203
+ case "srvServiceName" :
204
+ assertEquals (entry .getValue ().asString ().getValue (), connectionString .getSrvServiceName ());
205
+ break ;
206
+ default :
207
+ throw new UnsupportedOperationException ("No support configured yet for " + entry .getKey ());
208
208
}
209
209
}
210
210
}
@@ -266,12 +266,9 @@ private void hostsCheck(final List<String> actual, @Nullable final List<String>
266
266
}
267
267
}
268
268
})
269
- .applyToSslSettings (new Block <SslSettings .Builder >() {
270
- @ Override
271
- public void apply (final SslSettings .Builder builder ) {
272
- builder .applySettings (sslSettings );
273
- builder .invalidHostNameAllowed (true );
274
- }
269
+ .applyToSslSettings (builder -> {
270
+ builder .applySettings (sslSettings );
271
+ builder .invalidHostNameAllowed (true );
275
272
})
276
273
.build ();
277
274
@@ -284,7 +281,7 @@ public void apply(final SslSettings.Builder builder) {
284
281
285
282
@ Parameterized .Parameters (name = "{0}" )
286
283
public static Collection <Object []> data () throws URISyntaxException , IOException {
287
- List <Object []> data = new ArrayList <Object [] >();
284
+ List <Object []> data = new ArrayList <>();
288
285
for (File file : JsonPoweredTestHelper .getTestFiles ("/initial-dns-seedlist-discovery" )) {
289
286
BsonDocument testDocument = JsonPoweredTestHelper .getTestDocument (file );
290
287
data .add (new Object []{
@@ -316,7 +313,7 @@ private static List<String> toStringList(@Nullable final BsonArray bsonArray) {
316
313
if (bsonArray == null ) {
317
314
return null ;
318
315
}
319
- List <String > retVal = new ArrayList <String >(bsonArray .size ());
316
+ List <String > retVal = new ArrayList <>(bsonArray .size ());
320
317
for (BsonValue cur : bsonArray ) {
321
318
retVal .add (cur .asString ().getValue ());
322
319
}
0 commit comments