|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2015 the original author or authors.
|
|
|
|
* Copyright 2012-2016 the original author or authors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@ -20,6 +20,7 @@ import java.net.UnknownHostException;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
import com.mongodb.MongoClient;
|
|
|
|
import com.mongodb.MongoClient;
|
|
|
|
|
|
|
|
import com.mongodb.MongoClientOptions;
|
|
|
|
import com.mongodb.MongoCredential;
|
|
|
|
import com.mongodb.MongoCredential;
|
|
|
|
import com.mongodb.ServerAddress;
|
|
|
|
import com.mongodb.ServerAddress;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
@ -120,6 +121,54 @@ public class MongoPropertiesTests {
|
|
|
|
assertMongoCredential(credentialsList.get(0), "user", "secret", "test");
|
|
|
|
assertMongoCredential(credentialsList.get(0), "user", "secret", "test");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void allMongoClientOptionsCanBeSet() throws UnknownHostException {
|
|
|
|
|
|
|
|
MongoClientOptions mco = MongoClientOptions.builder()
|
|
|
|
|
|
|
|
.alwaysUseMBeans(true)
|
|
|
|
|
|
|
|
.connectionsPerHost(101)
|
|
|
|
|
|
|
|
.connectTimeout(10001)
|
|
|
|
|
|
|
|
.cursorFinalizerEnabled(false)
|
|
|
|
|
|
|
|
.description("test")
|
|
|
|
|
|
|
|
.maxWaitTime(120001)
|
|
|
|
|
|
|
|
.socketKeepAlive(true)
|
|
|
|
|
|
|
|
.socketTimeout(1000)
|
|
|
|
|
|
|
|
.threadsAllowedToBlockForConnectionMultiplier(6)
|
|
|
|
|
|
|
|
.minConnectionsPerHost(0)
|
|
|
|
|
|
|
|
.maxConnectionIdleTime(60000)
|
|
|
|
|
|
|
|
.maxConnectionLifeTime(60000)
|
|
|
|
|
|
|
|
.heartbeatFrequency(10001)
|
|
|
|
|
|
|
|
.minHeartbeatFrequency(501)
|
|
|
|
|
|
|
|
.heartbeatConnectTimeout(20001)
|
|
|
|
|
|
|
|
.heartbeatSocketTimeout(20001)
|
|
|
|
|
|
|
|
.localThreshold(20)
|
|
|
|
|
|
|
|
.requiredReplicaSetName("testReplicaSetName")
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MongoProperties properties = new MongoProperties();
|
|
|
|
|
|
|
|
MongoClient client = properties.createMongoClient(mco, null);
|
|
|
|
|
|
|
|
MongoClientOptions wrappedMco = client.getMongoClientOptions();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(wrappedMco.isAlwaysUseMBeans(), equalTo(mco.isAlwaysUseMBeans()));
|
|
|
|
|
|
|
|
assertThat(wrappedMco.getConnectionsPerHost(), equalTo(mco.getConnectionsPerHost()));
|
|
|
|
|
|
|
|
assertThat(wrappedMco.getConnectTimeout(), equalTo(mco.getConnectTimeout()));
|
|
|
|
|
|
|
|
assertThat(wrappedMco.isCursorFinalizerEnabled(), equalTo(mco.isCursorFinalizerEnabled()));
|
|
|
|
|
|
|
|
assertThat(wrappedMco.getDescription(), equalTo(mco.getDescription()));
|
|
|
|
|
|
|
|
assertThat(wrappedMco.getMaxWaitTime(), equalTo(mco.getMaxWaitTime()));
|
|
|
|
|
|
|
|
assertThat(wrappedMco.getSocketTimeout(), equalTo(mco.getSocketTimeout()));
|
|
|
|
|
|
|
|
assertThat(wrappedMco.isSocketKeepAlive(), equalTo(mco.isSocketKeepAlive()));
|
|
|
|
|
|
|
|
assertThat(wrappedMco.getThreadsAllowedToBlockForConnectionMultiplier(), equalTo(
|
|
|
|
|
|
|
|
mco.getThreadsAllowedToBlockForConnectionMultiplier()));
|
|
|
|
|
|
|
|
assertThat(wrappedMco.getMinConnectionsPerHost(), equalTo(mco.getMinConnectionsPerHost()));
|
|
|
|
|
|
|
|
assertThat(wrappedMco.getMaxConnectionIdleTime(), equalTo(mco.getMaxConnectionIdleTime()));
|
|
|
|
|
|
|
|
assertThat(wrappedMco.getMaxConnectionLifeTime(), equalTo(mco.getMaxConnectionLifeTime()));
|
|
|
|
|
|
|
|
assertThat(wrappedMco.getHeartbeatFrequency(), equalTo(mco.getHeartbeatFrequency()));
|
|
|
|
|
|
|
|
assertThat(wrappedMco.getMinHeartbeatFrequency(), equalTo(mco.getMinHeartbeatFrequency()));
|
|
|
|
|
|
|
|
assertThat(wrappedMco.getHeartbeatConnectTimeout(), equalTo(mco.getHeartbeatConnectTimeout()));
|
|
|
|
|
|
|
|
assertThat(wrappedMco.getHeartbeatSocketTimeout(), equalTo(mco.getHeartbeatSocketTimeout()));
|
|
|
|
|
|
|
|
assertThat(wrappedMco.getLocalThreshold(), equalTo(mco.getLocalThreshold()));
|
|
|
|
|
|
|
|
assertThat(wrappedMco.getRequiredReplicaSetName(), equalTo(mco.getRequiredReplicaSetName()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void assertServerAddress(ServerAddress serverAddress, String expectedHost,
|
|
|
|
private void assertServerAddress(ServerAddress serverAddress, String expectedHost,
|
|
|
|
int expectedPort) {
|
|
|
|
int expectedPort) {
|
|
|
|
assertThat(serverAddress.getHost(), equalTo(expectedHost));
|
|
|
|
assertThat(serverAddress.getHost(), equalTo(expectedHost));
|
|
|
|