File tree Expand file tree Collapse file tree 4 files changed +35
-6
lines changed
main/com/mongodb/connection
test/unit/com/mongodb/connection Expand file tree Collapse file tree 4 files changed +35
-6
lines changed Original file line number Diff line number Diff line change 2929 */
3030public interface Cluster extends Closeable {
3131
32+ /**
33+ * Gets the cluster settings with which this cluster was created.
34+ *
35+ * @return the cluster settings
36+ * @since 3.4
37+ */
38+ ClusterSettings getSettings ();
39+
3240 /**
3341 * Get the description of this cluster. This method will not return normally until the cluster type is known.
3442 *
Original file line number Diff line number Diff line change @@ -49,6 +49,19 @@ class BaseClusterSpecification extends Specification {
4949 private final List<ServerAddress > allServers = [firstServer, secondServer, thirdServer]
5050 private final TestClusterableServerFactory factory = new TestClusterableServerFactory ()
5151
52+ def ' should get cluster settings' () {
53+ given :
54+ def clusterSettings = builder(). mode(MULTIPLE )
55+ .hosts([firstServer, secondServer, thirdServer])
56+ .serverSelectionTimeout(1 , SECONDS )
57+ .serverSelector(new ServerAddressSelector (firstServer))
58+ .build()
59+ def cluster = new MultiServerCluster (new ClusterId (), clusterSettings, factory)
60+
61+ expect :
62+ cluster. getSettings() == clusterSettings
63+ }
64+
5265 def ' should compose server selector passed to selectServer with server selector in cluster settings' () {
5366 given :
5467 def cluster = new MultiServerCluster (new ClusterId (),
Original file line number Diff line number Diff line change @@ -390,8 +390,7 @@ public ReadPreference getReadPreference() {
390390 * @throws MongoException if there's a failure
391391 */
392392 public List <ServerAddress > getAllAddress () {
393- //TODO It should return the address list without auto-discovered nodes. Not sure if it's required. Maybe users confused with name.
394- return getServerAddressList ();
393+ return cluster .getSettings ().getHosts ();
395394 }
396395
397396 /**
Original file line number Diff line number Diff line change 2222import java .net .UnknownHostException ;
2323import java .util .Arrays ;
2424import java .util .Collections ;
25+ import java .util .List ;
2526
2627import static org .junit .Assert .assertEquals ;
2728import static org .junit .Assert .assertNotNull ;
2829import static org .junit .Assert .assertSame ;
30+ import static org .junit .Assert .fail ;
2931
3032public class MongoConstructorsTest {
3133
@@ -52,11 +54,18 @@ public void shouldUseGivenHost() throws UnknownHostException {
5254 }
5355
5456 @ Test
55- @ Ignore
56- public void shouldUseGivenServerAddress () throws UnknownHostException {
57- Mongo mongo = new MongoClient (new ServerAddress ( "localhost" ) );
57+ public void shouldGetSeedList () throws UnknownHostException {
58+ List < ServerAddress > seedList = Arrays . asList ( new ServerAddress ( "localhost" ), new ServerAddress ( "localhost:27018" ));
59+ Mongo mongo = new MongoClient (seedList );
5860 try {
59- assertEquals (Arrays .asList (new ServerAddress ("localhost" )), mongo .getServerAddressList ());
61+ assertEquals (seedList , mongo .getAllAddress ());
62+ try {
63+ mongo .getAllAddress ().add (new ServerAddress ("localhost:27019" ));
64+ fail ("Address list modification should be unsupported" );
65+ } catch (UnsupportedOperationException e ) {
66+ // all good
67+ }
68+
6069 } finally {
6170 mongo .close ();
6271 }
You can’t perform that action at this time.
0 commit comments