Merge branch '1.3.x'

pull/6018/merge
Stephane Nicoll 9 years ago
commit 958a0a45f1

@ -40,6 +40,7 @@ import org.springframework.core.env.Environment;
* @author Andy Wilkinson
* @author Eddú Meléndez
* @author Stephane Nicoll
* @author Nasko Vasilev
*/
@ConfigurationProperties(prefix = "spring.data.mongodb")
public class MongoProperties {
@ -257,8 +258,17 @@ public class MongoProperties {
builder.dbDecoderFactory(options.getDbDecoderFactory());
builder.dbEncoderFactory(options.getDbEncoderFactory());
builder.description(options.getDescription());
builder.heartbeatConnectTimeout(options.getHeartbeatConnectTimeout());
builder.heartbeatFrequency(options.getHeartbeatFrequency());
builder.heartbeatSocketTimeout(options.getHeartbeatSocketTimeout());
builder.localThreshold(options.getLocalThreshold());
builder.minConnectionsPerHost(options.getMinConnectionsPerHost());
builder.minHeartbeatFrequency(options.getMinHeartbeatFrequency());
builder.maxConnectionIdleTime(options.getMaxConnectionIdleTime());
builder.maxConnectionLifeTime(options.getMaxConnectionLifeTime());
builder.maxWaitTime(options.getMaxWaitTime());
builder.readPreference(options.getReadPreference());
builder.requiredReplicaSetName(options.getRequiredReplicaSetName());
builder.sslEnabled(options.isSslEnabled());
builder.socketFactory(options.getSocketFactory());
builder.socketKeepAlive(options.isSocketKeepAlive());

@ -20,6 +20,7 @@ import java.net.UnknownHostException;
import java.util.List;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.mongodb.connection.Cluster;
@ -120,6 +121,54 @@ public class MongoPropertiesTests {
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()).isEqualTo(mco.isAlwaysUseMBeans());
assertThat(wrappedMco.getConnectionsPerHost()).isEqualTo(mco.getConnectionsPerHost());
assertThat(wrappedMco.getConnectTimeout()).isEqualTo(mco.getConnectTimeout());
assertThat(wrappedMco.isCursorFinalizerEnabled()).isEqualTo(mco.isCursorFinalizerEnabled());
assertThat(wrappedMco.getDescription()).isEqualTo(mco.getDescription());
assertThat(wrappedMco.getMaxWaitTime()).isEqualTo(mco.getMaxWaitTime());
assertThat(wrappedMco.getSocketTimeout()).isEqualTo(mco.getSocketTimeout());
assertThat(wrappedMco.isSocketKeepAlive()).isEqualTo(mco.isSocketKeepAlive());
assertThat(wrappedMco.getThreadsAllowedToBlockForConnectionMultiplier()).isEqualTo(
mco.getThreadsAllowedToBlockForConnectionMultiplier());
assertThat(wrappedMco.getMinConnectionsPerHost()).isEqualTo(mco.getMinConnectionsPerHost());
assertThat(wrappedMco.getMaxConnectionIdleTime()).isEqualTo(mco.getMaxConnectionIdleTime());
assertThat(wrappedMco.getMaxConnectionLifeTime()).isEqualTo(mco.getMaxConnectionLifeTime());
assertThat(wrappedMco.getHeartbeatFrequency()).isEqualTo(mco.getHeartbeatFrequency());
assertThat(wrappedMco.getMinHeartbeatFrequency()).isEqualTo(mco.getMinHeartbeatFrequency());
assertThat(wrappedMco.getHeartbeatConnectTimeout()).isEqualTo(mco.getHeartbeatConnectTimeout());
assertThat(wrappedMco.getHeartbeatSocketTimeout()).isEqualTo(mco.getHeartbeatSocketTimeout());
assertThat(wrappedMco.getLocalThreshold()).isEqualTo(mco.getLocalThreshold());
assertThat(wrappedMco.getRequiredReplicaSetName()).isEqualTo(mco.getRequiredReplicaSetName());
}
private List<ServerAddress> extractServerAddresses(MongoClient client) {
Cluster cluster = (Cluster) ReflectionTestUtils.getField(client, "cluster");
ClusterSettings clusterSettings = (ClusterSettings) ReflectionTestUtils

Loading…
Cancel
Save