Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…ions.Builder public
  • Loading branch information...
commit 0cd926a386b83de5fe475c73e0fbff3064526998 1 parent fb03f36
@jyemin jyemin authored
View
11 src/main/com/mongodb/MongoClientURI.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))
View
13 src/test/com/mongodb/MongoClientURITest.java
@@ -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");
Please sign in to comment.
Something went wrong with that request. Please try again.