Permalink
Browse files

JAVA-780: Made MongoClientURI constructor that takes a MongoClientOpt…

…ions.Builder public
  • Loading branch information...
1 parent fb03f36 commit 0cd926a386b83de5fe475c73e0fbff3064526998 @jyemin jyemin committed Mar 9, 2013
Showing with 23 additions and 1 deletion.
  1. +10 −1 src/main/com/mongodb/MongoClientURI.java
  2. +13 −0 src/test/com/mongodb/MongoClientURITest.java
@@ -159,7 +159,16 @@ public MongoClientURI(final String uri) {
this(uri, new MongoClientOptions.Builder());
}
- MongoClientURI(String uri, MongoClientOptions.Builder builder) {
+ /**
+ * Creates a MongoURI from the given URI string, and MongoClientOptions.Builder. The builder can be configured
+ * with default options, which may be overridden by options specified in the URI string.
+ *
+ * @param uri the URI
+ * @param builder a Builder
+ * @see com.mongodb.MongoClientURI#getOptions()
+ * @since 2.11.0
+ */
+ public MongoClientURI(String uri, MongoClientOptions.Builder builder) {
try {
this.uri = uri;
if (!uri.startsWith(PREFIX))
@@ -32,6 +32,11 @@ public void testUnsupportedOption() {
}
@Test
+ public void testURIGetter() {
+ assertEquals("mongodb://localhost", new MongoClientURI("mongodb://localhost").getURI());
+ }
+
+ @Test
public void testOptionsWithoutTrailingSlash() {
try {
new MongoClientURI("mongodb://localhost?wTimeout=5");
@@ -197,6 +202,14 @@ public void testOptions() {
assertOnOptions(uMixed.getOptions());
}
+ @Test
+ public void testBuilderOverrides() {
+ MongoClientURI uri = new MongoClientURI("mongodb://localhost/?maxPoolSize=150",
+ MongoClientOptions.builder().autoConnectRetry(true).connectionsPerHost(200));
+ assertTrue(uri.getOptions().isAutoConnectRetry());
+ assertEquals(150, uri.getOptions().getConnectionsPerHost());
+ }
+
@Test()
public void testURIDefaults() throws UnknownHostException {
MongoClientURI uri = new MongoClientURI("mongodb://localhost");

0 comments on commit 0cd926a

Please sign in to comment.