Skip to content

Commit 0cd926a

Browse files
committed
JAVA-780: Made MongoClientURI constructor that takes a MongoClientOptions.Builder public
1 parent fb03f36 commit 0cd926a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/main/com/mongodb/MongoClientURI.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,16 @@ public MongoClientURI(final String uri) {
159159
this(uri, new MongoClientOptions.Builder());
160160
}
161161

162-
MongoClientURI(String uri, MongoClientOptions.Builder builder) {
162+
/**
163+
* Creates a MongoURI from the given URI string, and MongoClientOptions.Builder. The builder can be configured
164+
* with default options, which may be overridden by options specified in the URI string.
165+
*
166+
* @param uri the URI
167+
* @param builder a Builder
168+
* @see com.mongodb.MongoClientURI#getOptions()
169+
* @since 2.11.0
170+
*/
171+
public MongoClientURI(String uri, MongoClientOptions.Builder builder) {
163172
try {
164173
this.uri = uri;
165174
if (!uri.startsWith(PREFIX))

src/test/com/mongodb/MongoClientURITest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public void testUnsupportedOption() {
3131
new MongoClientURI("mongodb://localhost/?unknownOption=true");
3232
}
3333

34+
@Test
35+
public void testURIGetter() {
36+
assertEquals("mongodb://localhost", new MongoClientURI("mongodb://localhost").getURI());
37+
}
38+
3439
@Test
3540
public void testOptionsWithoutTrailingSlash() {
3641
try {
@@ -197,6 +202,14 @@ public void testOptions() {
197202
assertOnOptions(uMixed.getOptions());
198203
}
199204

205+
@Test
206+
public void testBuilderOverrides() {
207+
MongoClientURI uri = new MongoClientURI("mongodb://localhost/?maxPoolSize=150",
208+
MongoClientOptions.builder().autoConnectRetry(true).connectionsPerHost(200));
209+
assertTrue(uri.getOptions().isAutoConnectRetry());
210+
assertEquals(150, uri.getOptions().getConnectionsPerHost());
211+
}
212+
200213
@Test()
201214
public void testURIDefaults() throws UnknownHostException {
202215
MongoClientURI uri = new MongoClientURI("mongodb://localhost");

0 commit comments

Comments
 (0)