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 29
29
*/
30
30
public interface Cluster extends Closeable {
31
31
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
+
32
40
/**
33
41
* Get the description of this cluster. This method will not return normally until the cluster type is known.
34
42
*
Original file line number Diff line number Diff line change @@ -49,6 +49,19 @@ class BaseClusterSpecification extends Specification {
49
49
private final List<ServerAddress > allServers = [firstServer, secondServer, thirdServer]
50
50
private final TestClusterableServerFactory factory = new TestClusterableServerFactory ()
51
51
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
+
52
65
def ' should compose server selector passed to selectServer with server selector in cluster settings' () {
53
66
given :
54
67
def cluster = new MultiServerCluster (new ClusterId (),
Original file line number Diff line number Diff line change @@ -390,8 +390,7 @@ public ReadPreference getReadPreference() {
390
390
* @throws MongoException if there's a failure
391
391
*/
392
392
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 ();
395
394
}
396
395
397
396
/**
Original file line number Diff line number Diff line change 22
22
import java .net .UnknownHostException ;
23
23
import java .util .Arrays ;
24
24
import java .util .Collections ;
25
+ import java .util .List ;
25
26
26
27
import static org .junit .Assert .assertEquals ;
27
28
import static org .junit .Assert .assertNotNull ;
28
29
import static org .junit .Assert .assertSame ;
30
+ import static org .junit .Assert .fail ;
29
31
30
32
public class MongoConstructorsTest {
31
33
@@ -52,11 +54,18 @@ public void shouldUseGivenHost() throws UnknownHostException {
52
54
}
53
55
54
56
@ 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 );
58
60
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
+
60
69
} finally {
61
70
mongo .close ();
62
71
}
You can’t perform that action at this time.
0 commit comments