Polish contribution

pull/5525/merge
Andy Wilkinson 9 years ago
parent dc8685a927
commit 436da1d5fd

@ -35,6 +35,7 @@ import de.flapdoodle.embed.mongo.config.IMongodConfig;
import de.flapdoodle.embed.mongo.config.MongodConfigBuilder; import de.flapdoodle.embed.mongo.config.MongodConfigBuilder;
import de.flapdoodle.embed.mongo.config.Net; import de.flapdoodle.embed.mongo.config.Net;
import de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder; import de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder;
import de.flapdoodle.embed.mongo.config.Storage;
import de.flapdoodle.embed.mongo.distribution.Feature; import de.flapdoodle.embed.mongo.distribution.Feature;
import de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion; import de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion;
import de.flapdoodle.embed.process.config.IRuntimeConfig; import de.flapdoodle.embed.process.config.IRuntimeConfig;
@ -69,6 +70,7 @@ import org.springframework.util.Assert;
* *
* @author Henryk Konsek * @author Henryk Konsek
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Yogesh Lonkar
* @since 1.3.0 * @since 1.3.0
*/ */
@Configuration @Configuration
@ -126,7 +128,12 @@ public class EmbeddedMongoAutoConfiguration {
MongodConfigBuilder builder = new MongodConfigBuilder() MongodConfigBuilder builder = new MongodConfigBuilder()
.version(featureAwareVersion); .version(featureAwareVersion);
if (this.embeddedProperties.getStorage() != null) { if (this.embeddedProperties.getStorage() != null) {
builder.replication(this.embeddedProperties.getStorage()); builder.replication(
new Storage(this.embeddedProperties.getStorage().getDatabaseDir(),
this.embeddedProperties.getStorage().getReplSetName(),
this.embeddedProperties.getStorage().getOplogSize() != null
? this.embeddedProperties.getStorage().getOplogSize()
: 0));
} }
if (getPort() > 0) { if (getPort() > 0) {
builder.net(new Net(getHost().getHostAddress(), getPort(), builder.net(new Net(getHost().getHostAddress(), getPort(),
@ -139,7 +146,6 @@ public class EmbeddedMongoAutoConfiguration {
return builder.build(); return builder.build();
} }
private int getPort() { private int getPort() {
if (this.properties.getPort() == null) { if (this.properties.getPort() == null) {
return MongoProperties.DEFAULT_PORT; return MongoProperties.DEFAULT_PORT;

@ -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.
@ -28,6 +28,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* Configuration properties for Embedded Mongo. * Configuration properties for Embedded Mongo.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Yogesh Lonkar
* @since 1.3.0 * @since 1.3.0
*/ */
@ConfigurationProperties(prefix = "spring.mongodb.embedded") @ConfigurationProperties(prefix = "spring.mongodb.embedded")
@ -63,29 +64,40 @@ public class EmbeddedMongoProperties {
} }
public Storage getStorage() { public Storage getStorage() {
return storage; return this.storage;
} }
public void setStorage(Storage storage) { public void setStorage(Storage storage) {
this.storage = storage; this.storage = storage;
} }
public static class Storage extends de.flapdoodle.embed.mongo.config.Storage { public static class Storage {
private int oplogSize; /**
* Maximum size of the oplog in megabytes.
*/
private Integer oplogSize;
/**
* Name of the replica set.
*/
private String replSetName; private String replSetName;
/**
* Directory used for data storage.
*/
private String databaseDir; private String databaseDir;
public int getOplogSize() { public Integer getOplogSize() {
return oplogSize; return this.oplogSize;
} }
public void setOplogSize(int oplogSize) { public void setOplogSize(Integer oplogSize) {
this.oplogSize = oplogSize; this.oplogSize = oplogSize;
} }
public String getReplSetName() { public String getReplSetName() {
return replSetName; return this.replSetName;
} }
public void setReplSetName(String replSetName) { public void setReplSetName(String replSetName) {
@ -93,7 +105,7 @@ public class EmbeddedMongoProperties {
} }
public String getDatabaseDir() { public String getDatabaseDir() {
return databaseDir; return this.databaseDir;
} }
public void setDatabaseDir(String databaseDir) { public void setDatabaseDir(String databaseDir) {

@ -16,11 +16,13 @@
package org.springframework.boot.autoconfigure.mongo.embedded; package org.springframework.boot.autoconfigure.mongo.embedded;
import java.io.File;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import com.mongodb.CommandResult; import com.mongodb.CommandResult;
import com.mongodb.MongoClient; import com.mongodb.MongoClient;
import de.flapdoodle.embed.mongo.config.IMongodConfig; import de.flapdoodle.embed.mongo.config.IMongodConfig;
import de.flapdoodle.embed.mongo.config.Storage;
import de.flapdoodle.embed.mongo.distribution.Feature; import de.flapdoodle.embed.mongo.distribution.Feature;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
@ -35,6 +37,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.util.FileSystemUtils;
import org.springframework.util.SocketUtils; import org.springframework.util.SocketUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -113,28 +116,61 @@ public class EmbeddedMongoAutoConfigurationTests {
} }
} }
/**
* test dbpath configuration is loaded for mongodb process.
*/
@Test @Test
public void dbPathIsAvailableInMongoConfiguration() { public void defaultStorageConfiguration() {
ConfigurableApplicationContext parent = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
parent.refresh(); EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.port=0");
try { this.context.register(EmbeddedMongoAutoConfiguration.class,
MongoClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
Storage replication = this.context.getBean(IMongodConfig.class).replication();
assertThat(replication.getOplogSize()).isEqualTo(0);
assertThat(replication.getDatabaseDir()).isNull();
assertThat(replication.getReplSetName()).isNull();
}
@Test
public void mongoWritesToCustomDatabaseDir() {
File customDatabaseDir = new File("target/custom-database-dir");
FileSystemUtils.deleteRecursively(customDatabaseDir);
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context.setParent(parent);
EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.port=0", EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.port=0",
"spring.mongodb.embedded.storage.databaseDir=/Users/yogeshlo/db", "spring.mongodb.embedded.storage.databaseDir="
"spring.mongodb.embedded.storage.oplogSize=0"); + customDatabaseDir.getPath());
this.context.register(EmbeddedMongoAutoConfiguration.class, MongoClientConfiguration.class, this.context.register(EmbeddedMongoAutoConfiguration.class,
MongoClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class); PropertyPlaceholderAutoConfiguration.class);
this.context.refresh(); this.context.refresh();
IMongodConfig mongoConfig = this.context.getBean(IMongodConfig.class); assertThat(customDatabaseDir).isDirectory();
assertThat(mongoConfig.replication().getDatabaseDir()).isEqualTo("/Users/yogeshlo/db"); assertThat(customDatabaseDir.listFiles()).isNotEmpty();
} }
finally {
parent.close(); @Test
public void customOpLogSizeIsAppliedToConfiguration() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.port=0",
"spring.mongodb.embedded.storage.oplogSize=10");
this.context.register(EmbeddedMongoAutoConfiguration.class,
MongoClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(IMongodConfig.class).replication().getOplogSize())
.isEqualTo(10);
} }
@Test
public void customReplicaSetNameIsAppliedToConfiguration() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.port=0",
"spring.mongodb.embedded.storage.replSetName=testing");
this.context.register(EmbeddedMongoAutoConfiguration.class,
MongoClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
assertThat(
this.context.getBean(IMongodConfig.class).replication().getReplSetName())
.isEqualTo("testing");
} }
private void assertVersionConfiguration(String configuredVersion, private void assertVersionConfiguration(String configuredVersion,

@ -730,6 +730,9 @@ content into your application; rather pick only the properties that you need.
# EMBEDDED MONGODB ({sc-spring-boot-autoconfigure}/mongo/embedded/EmbeddedMongoProperties.{sc-ext}[EmbeddedMongoProperties]) # EMBEDDED MONGODB ({sc-spring-boot-autoconfigure}/mongo/embedded/EmbeddedMongoProperties.{sc-ext}[EmbeddedMongoProperties])
spring.mongodb.embedded.features=SYNC_DELAY # Comma-separated list of features to enable. spring.mongodb.embedded.features=SYNC_DELAY # Comma-separated list of features to enable.
spring.mongodb.embedded.storage.databaseDir= # Directory used for data storage.
spring.mongodb.embedded.storage.oplogSize= # Maximum size of the oplog in megabytes.
spring.mongodb.embedded.storage.replSetName= # Name of the replica set.
spring.mongodb.embedded.version=2.6.10 # Version of Mongo to use. spring.mongodb.embedded.version=2.6.10 # Version of Mongo to use.
# REDIS ({sc-spring-boot-autoconfigure}/redis/RedisProperties.{sc-ext}[RedisProperties]) # REDIS ({sc-spring-boot-autoconfigure}/redis/RedisProperties.{sc-ext}[RedisProperties])

Loading…
Cancel
Save