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 2525import java .util .Collections ;
2626import java .util .LinkedHashSet ;
2727import java .util .List ;
28+ import java .util .Set ;
2829import java .util .concurrent .TimeUnit ;
2930
3031import static com .mongodb .assertions .Assertions .isTrueArgument ;
@@ -94,7 +95,11 @@ public Builder hosts(final List<ServerAddress> hosts) {
9495 if (hosts .isEmpty ()) {
9596 throw new IllegalArgumentException ("hosts list may not be empty" );
9697 }
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 ));
98103 return this ;
99104 }
100105
Original file line number Diff line number Diff line change @@ -278,4 +278,19 @@ class ClusterSettingsSpecification extends Specification {
278278 .maxWaitQueueSize(100 )
279279 .build(). hashCode() != ClusterSettings . builder(). hosts(hosts). build(). hashCode()
280280 }
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+ }
281296}
You can’t perform that action at this time.
0 commit comments