Allow embedded Mongo's storage to be configured via the environment
Closes gh-5617
This commit is contained in:
parent
f9a86363b5
commit
dc8685a927
|
|
@ -125,6 +125,9 @@ public class EmbeddedMongoAutoConfiguration {
|
|||
this.embeddedProperties.getFeatures());
|
||||
MongodConfigBuilder builder = new MongodConfigBuilder()
|
||||
.version(featureAwareVersion);
|
||||
if (this.embeddedProperties.getStorage() != null) {
|
||||
builder.replication(this.embeddedProperties.getStorage());
|
||||
}
|
||||
if (getPort() > 0) {
|
||||
builder.net(new Net(getHost().getHostAddress(), getPort(),
|
||||
Network.localhostIsIPv6()));
|
||||
|
|
@ -136,6 +139,7 @@ public class EmbeddedMongoAutoConfiguration {
|
|||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
private int getPort() {
|
||||
if (this.properties.getPort() == null) {
|
||||
return MongoProperties.DEFAULT_PORT;
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ public class EmbeddedMongoProperties {
|
|||
*/
|
||||
private String version = "2.6.10";
|
||||
|
||||
private Storage storage;
|
||||
|
||||
/**
|
||||
* Comma-separated list of features to enable.
|
||||
*/
|
||||
|
|
@ -60,4 +62,44 @@ public class EmbeddedMongoProperties {
|
|||
this.features = features;
|
||||
}
|
||||
|
||||
public Storage getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
public void setStorage(Storage storage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
public static class Storage extends de.flapdoodle.embed.mongo.config.Storage {
|
||||
|
||||
private int oplogSize;
|
||||
private String replSetName;
|
||||
private String databaseDir;
|
||||
|
||||
public int getOplogSize() {
|
||||
return oplogSize;
|
||||
}
|
||||
|
||||
public void setOplogSize(int oplogSize) {
|
||||
this.oplogSize = oplogSize;
|
||||
}
|
||||
|
||||
public String getReplSetName() {
|
||||
return replSetName;
|
||||
}
|
||||
|
||||
public void setReplSetName(String replSetName) {
|
||||
this.replSetName = replSetName;
|
||||
}
|
||||
|
||||
public String getDatabaseDir() {
|
||||
return databaseDir;
|
||||
}
|
||||
|
||||
public void setDatabaseDir(String databaseDir) {
|
||||
this.databaseDir = databaseDir;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import java.net.UnknownHostException;
|
|||
|
||||
import com.mongodb.CommandResult;
|
||||
import com.mongodb.MongoClient;
|
||||
import de.flapdoodle.embed.mongo.config.IMongodConfig;
|
||||
import de.flapdoodle.embed.mongo.distribution.Feature;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
|
@ -112,6 +113,30 @@ public class EmbeddedMongoAutoConfigurationTests {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* test dbpath configuration is loaded for mongodb process.
|
||||
*/
|
||||
@Test
|
||||
public void dbPathIsAvailableInMongoConfiguration() {
|
||||
ConfigurableApplicationContext parent = new AnnotationConfigApplicationContext();
|
||||
parent.refresh();
|
||||
try {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.setParent(parent);
|
||||
EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.port=0",
|
||||
"spring.mongodb.embedded.storage.databaseDir=/Users/yogeshlo/db",
|
||||
"spring.mongodb.embedded.storage.oplogSize=0");
|
||||
this.context.register(EmbeddedMongoAutoConfiguration.class, MongoClientConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
IMongodConfig mongoConfig = this.context.getBean(IMongodConfig.class);
|
||||
assertThat(mongoConfig.replication().getDatabaseDir()).isEqualTo("/Users/yogeshlo/db");
|
||||
}
|
||||
finally {
|
||||
parent.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void assertVersionConfiguration(String configuredVersion,
|
||||
String expectedVersion) {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
|
|
|
|||
Loading…
Reference in New Issue