Permalink
Browse files

JAVA-744: Added MongoClient.getMongoClientOptions

  • Loading branch information...
1 parent 0d3b964 commit 461c9b8f2956a060ba889234aa78259fdeb62156 @jyemin jyemin committed Feb 27, 2013
Showing with 24 additions and 2 deletions.
  1. +9 −0 src/main/com/mongodb/MongoClient.java
  2. +15 −2 src/test/com/mongodb/MongoClientTest.java
View
9 src/main/com/mongodb/MongoClient.java
@@ -70,6 +70,8 @@
*/
public class MongoClient extends Mongo {
+ private final MongoClientOptions options;
+
/**
* Creates an instance based on a (single) mongodb node (localhost, default port).
*
@@ -163,6 +165,7 @@ public MongoClient(ServerAddress addr, MongoClientOptions options) {
*/
public MongoClient(ServerAddress addr, List<MongoCredential> credentialsList, MongoClientOptions options) {
super(MongoAuthority.direct(addr, new MongoCredentialsStore(credentialsList)), new MongoOptions(options));
+ this.options = options;
}
/**
@@ -246,6 +249,7 @@ public MongoClient(List<ServerAddress> seeds, MongoClientOptions options) {
*/
public MongoClient(List<ServerAddress> seeds, List<MongoCredential> credentialsList, MongoClientOptions options) {
super(MongoAuthority.dynamicSet(seeds, new MongoCredentialsStore(credentialsList)), new MongoOptions(options));
+ this.options = options;
}
@@ -260,6 +264,7 @@ public MongoClient(List<ServerAddress> seeds, List<MongoCredential> credentialsL
*/
public MongoClient(MongoClientURI uri) throws UnknownHostException {
super(new MongoURI(uri));
+ this.options = uri.getOptions();
}
/**
@@ -271,4 +276,8 @@ public MongoClient(MongoClientURI uri) throws UnknownHostException {
public List<MongoCredential> getCredentialsList() {
return getAuthority().getCredentialsStore().asList();
}
+
+ public MongoClientOptions getMongoClientOptions() {
+ return options;
+ }
}
View
17 src/test/com/mongodb/MongoClientTest.java
@@ -37,30 +37,35 @@ public void testConstructors() throws UnknownHostException {
Assert.assertEquals(new ServerAddress(), mc.getAddress());
Assert.assertEquals(defaultOptions, mc.getMongoOptions());
Assert.assertEquals(emptyCredentials, mc.getCredentialsList());
+ Assert.assertEquals(MongoClientOptions.builder().build(), mc.getMongoClientOptions());
mc.close();
mc = new MongoClient("127.0.0.1");
Assert.assertEquals(new ServerAddress("127.0.0.1"), mc.getAddress());
Assert.assertEquals(defaultOptions, mc.getMongoOptions());
Assert.assertEquals(emptyCredentials, mc.getCredentialsList());
+ Assert.assertEquals(MongoClientOptions.builder().build(), mc.getMongoClientOptions());
mc.close();
mc = new MongoClient("127.0.0.1", customClientOptions);
Assert.assertEquals(new ServerAddress("127.0.0.1"), mc.getAddress());
Assert.assertEquals(customOptions, mc.getMongoOptions());
Assert.assertEquals(emptyCredentials, mc.getCredentialsList());
+ Assert.assertEquals(customClientOptions, mc.getMongoClientOptions());
mc.close();
mc = new MongoClient("127.0.0.1", 27018);
Assert.assertEquals(new ServerAddress("127.0.0.1", 27018), mc.getAddress());
Assert.assertEquals(defaultOptions, mc.getMongoOptions());
Assert.assertEquals(emptyCredentials, mc.getCredentialsList());
+ Assert.assertEquals(MongoClientOptions.builder().build(), mc.getMongoClientOptions());
mc.close();
mc = new MongoClient(new ServerAddress("127.0.0.1"));
Assert.assertEquals(new ServerAddress("127.0.0.1"), mc.getAddress());
Assert.assertEquals(defaultOptions, mc.getMongoOptions());
Assert.assertEquals(emptyCredentials, mc.getCredentialsList());
+ Assert.assertEquals(MongoClientOptions.builder().build(), mc.getMongoClientOptions());
mc.close();
final List<MongoCredential> credentialsList = Arrays.asList(
@@ -69,48 +74,56 @@ public void testConstructors() throws UnknownHostException {
Assert.assertEquals(new ServerAddress("127.0.0.1"), mc.getAddress());
Assert.assertEquals(defaultOptions, mc.getMongoOptions());
Assert.assertEquals(credentialsList, mc.getCredentialsList());
+ Assert.assertEquals(MongoClientOptions.builder().build(), mc.getMongoClientOptions());
mc.close();
mc = new MongoClient(new ServerAddress("127.0.0.1"), customClientOptions);
Assert.assertEquals(new ServerAddress("127.0.0.1"), mc.getAddress());
Assert.assertEquals(customOptions, mc.getMongoOptions());
Assert.assertEquals(emptyCredentials, mc.getCredentialsList());
+ Assert.assertEquals(customClientOptions, mc.getMongoClientOptions());
mc.close();
mc = new MongoClient(new ServerAddress("127.0.0.1"), credentialsList, customClientOptions);
Assert.assertEquals(new ServerAddress("127.0.0.1"), mc.getAddress());
Assert.assertEquals(customOptions, mc.getMongoOptions());
Assert.assertEquals(credentialsList, mc.getCredentialsList());
+ Assert.assertEquals(customClientOptions, mc.getMongoClientOptions());
mc.close();
mc = new MongoClient(Arrays.asList(new ServerAddress("localhost", 27017), new ServerAddress("127.0.0.1", 27018)));
Assert.assertEquals(Arrays.asList(new ServerAddress("localhost", 27017), new ServerAddress("127.0.0.1", 27018)), mc.getAllAddress());
Assert.assertEquals(defaultOptions, mc.getMongoOptions());
Assert.assertEquals(emptyCredentials, mc.getCredentialsList());
+ Assert.assertEquals(MongoClientOptions.builder().build(), mc.getMongoClientOptions());
mc.close();
mc = new MongoClient(Arrays.asList(new ServerAddress("localhost", 27017), new ServerAddress("127.0.0.1", 27018)), customClientOptions);
Assert.assertEquals(Arrays.asList(new ServerAddress("localhost", 27017), new ServerAddress("127.0.0.1", 27018)), mc.getAllAddress());
Assert.assertEquals(customOptions, mc.getMongoOptions());
Assert.assertEquals(emptyCredentials, mc.getCredentialsList());
+ Assert.assertEquals(customClientOptions, mc.getMongoClientOptions());
mc.close();
mc = new MongoClient(Arrays.asList(new ServerAddress("localhost", 27017), new ServerAddress("127.0.0.1", 27018)), credentialsList, customClientOptions);
Assert.assertEquals(Arrays.asList(new ServerAddress("localhost", 27017), new ServerAddress("127.0.0.1", 27018)), mc.getAllAddress());
Assert.assertEquals(customOptions, mc.getMongoOptions());
Assert.assertEquals(credentialsList, mc.getCredentialsList());
+ Assert.assertEquals(customClientOptions, mc.getMongoClientOptions());
mc.close();
mc = new MongoClient(new MongoClientURI("mongodb://127.0.0.1"));
Assert.assertEquals(new ServerAddress("127.0.0.1"), mc.getAddress());
Assert.assertEquals(defaultOptions, mc.getMongoOptions());
Assert.assertEquals(emptyCredentials, mc.getCredentialsList());
+ Assert.assertEquals(MongoClientOptions.builder().build(), mc.getMongoClientOptions());
mc.close();
- mc = new MongoClient(new MongoClientURI("mongodb://user1:pwd@127.0.0.1/test"));
+ mc = new MongoClient(new MongoClientURI("mongodb://user1:pwd@127.0.0.1/test?maxPoolSize=500"));
Assert.assertEquals(new ServerAddress("127.0.0.1"), mc.getAddress());
- Assert.assertEquals(defaultOptions, mc.getMongoOptions());
+ Assert.assertEquals(customOptions, mc.getMongoOptions());
Assert.assertEquals(credentialsList, mc.getCredentialsList());
+ Assert.assertEquals(customClientOptions, mc.getMongoClientOptions());
mc.close();
}
}

0 comments on commit 461c9b8

Please sign in to comment.