File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
main/com/mongodb/connection
test/unit/com/mongodb/connection Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 25
25
import java .util .Collections ;
26
26
import java .util .LinkedHashSet ;
27
27
import java .util .List ;
28
+ import java .util .Set ;
28
29
import java .util .concurrent .TimeUnit ;
29
30
30
31
import static com .mongodb .assertions .Assertions .isTrueArgument ;
@@ -94,7 +95,11 @@ public Builder hosts(final List<ServerAddress> hosts) {
94
95
if (hosts .isEmpty ()) {
95
96
throw new IllegalArgumentException ("hosts list may not be empty" );
96
97
}
97
- this .hosts = Collections .unmodifiableList (new ArrayList <ServerAddress >(new LinkedHashSet <ServerAddress >(hosts )));
98
+ Set <ServerAddress > hostsSet = new LinkedHashSet <ServerAddress >(hosts .size ());
99
+ for (ServerAddress host : hosts ) {
100
+ hostsSet .add (new ServerAddress (host .getHost (), host .getPort ()));
101
+ }
102
+ this .hosts = Collections .unmodifiableList (new ArrayList <ServerAddress >(hostsSet ));
98
103
return this ;
99
104
}
100
105
Original file line number Diff line number Diff line change @@ -278,4 +278,19 @@ class ClusterSettingsSpecification extends Specification {
278
278
.maxWaitQueueSize(100 )
279
279
.build(). hashCode() != ClusterSettings . builder(). hosts(hosts). build(). hashCode()
280
280
}
281
+
282
+ def ' should replace ServerAddress subclass instances with ServerAddress' () {
283
+ when :
284
+ def settings = ClusterSettings . builder(). hosts([new ServerAddressSubclass (' server1' ),
285
+ new ServerAddressSubclass (' server2' )]). build();
286
+
287
+ then :
288
+ settings. getHosts() == [new ServerAddress (' server1' ), new ServerAddress (' server2' )]
289
+ }
290
+
291
+ static class ServerAddressSubclass extends ServerAddress {
292
+ ServerAddressSubclass (final String host ) {
293
+ super (host)
294
+ }
295
+ }
281
296
}
You can’t perform that action at this time.
0 commit comments