|
|
@ -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,
|
|
|
|