Skip to content

Commit 1a8f519

Browse files
committed
Raise the default version of Mongo to 3.6.5 when using Embedded Mongo
While MongoDB 3.6.7 has been released, 3.6.5 is the latest version that's supported by the version of Embedded Mongo that we're currently using. Closes gh-14476
1 parent 5a2c8b5 commit 1a8f519

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import de.flapdoodle.embed.mongo.config.Storage;
3636
import de.flapdoodle.embed.mongo.distribution.Feature;
3737
import de.flapdoodle.embed.mongo.distribution.IFeatureAwareVersion;
38+
import de.flapdoodle.embed.mongo.distribution.Version;
3839
import de.flapdoodle.embed.mongo.distribution.Versions;
3940
import de.flapdoodle.embed.process.config.IRuntimeConfig;
4041
import de.flapdoodle.embed.process.config.io.ProcessOutput;
@@ -125,11 +126,8 @@ private MongodStarter getMongodStarter(IRuntimeConfig runtimeConfig) {
125126
@Bean
126127
@ConditionalOnMissingBean
127128
public IMongodConfig embeddedMongoConfiguration() throws IOException {
128-
IFeatureAwareVersion featureAwareVersion = Versions.withFeatures(
129-
new GenericVersion(this.embeddedProperties.getVersion()),
130-
this.embeddedProperties.getFeatures().toArray(new Feature[0]));
131129
MongodConfigBuilder builder = new MongodConfigBuilder()
132-
.version(featureAwareVersion);
130+
.version(determineVersion());
133131
EmbeddedMongoProperties.Storage storage = this.embeddedProperties.getStorage();
134132
if (storage != null) {
135133
String databaseDir = storage.getDatabaseDir();
@@ -150,6 +148,20 @@ public IMongodConfig embeddedMongoConfiguration() throws IOException {
150148
return builder.build();
151149
}
152150

151+
private IFeatureAwareVersion determineVersion() {
152+
if (this.embeddedProperties.getFeatures() == null) {
153+
for (Version version : Version.values()) {
154+
if (version.asInDownloadPath()
155+
.equals(this.embeddedProperties.getVersion())) {
156+
return version;
157+
}
158+
}
159+
}
160+
return Versions.withFeatures(
161+
new GenericVersion(this.embeddedProperties.getVersion()),
162+
this.embeddedProperties.getFeatures().toArray(new Feature[0]));
163+
}
164+
153165
private InetAddress getHost() throws UnknownHostException {
154166
if (this.properties.getHost() == null) {
155167
return InetAddress.getByAddress(Network.localhostIsIPv6()

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoProperties.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.boot.autoconfigure.mongo.embedded;
1818

19-
import java.util.Collections;
20-
import java.util.HashSet;
2119
import java.util.Set;
2220

2321
import de.flapdoodle.embed.mongo.distribution.Feature;
@@ -40,15 +38,15 @@ public class EmbeddedMongoProperties {
4038
/**
4139
* Version of Mongo to use.
4240
*/
43-
private String version = "3.2.2";
41+
private String version = "3.6.5";
4442

4543
private final Storage storage = new Storage();
4644

4745
/**
48-
* Comma-separated list of features to enable.
46+
* Comma-separated list of features to enable. Uses the defaults of the configured
47+
* version by default.
4948
*/
50-
private Set<Feature> features = new HashSet<>(
51-
Collections.singletonList(Feature.SYNC_DELAY));
49+
private Set<Feature> features = null;
5250

5351
public String getVersion() {
5452
return this.version;

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,20 @@ public void close() {
6060

6161
@Test
6262
public void defaultVersion() {
63-
assertVersionConfiguration(null, "3.2.2");
63+
assertVersionConfiguration(null, "3.6.5");
6464
}
6565

6666
@Test
6767
public void customVersion() {
68-
assertVersionConfiguration("2.7.1", "2.7.1");
68+
assertVersionConfiguration("3.6.3", "3.6.3");
6969
}
7070

7171
@Test
7272
public void customFeatures() {
73-
load("spring.mongodb.embedded.features=TEXT_SEARCH, SYNC_DELAY");
73+
load("spring.mongodb.embedded.features=TEXT_SEARCH, SYNC_DELAY, ONLY_WITH_SSL, NO_HTTP_INTERFACE_ARG");
7474
assertThat(this.context.getBean(EmbeddedMongoProperties.class).getFeatures())
75-
.contains(Feature.TEXT_SEARCH, Feature.SYNC_DELAY);
75+
.containsExactly(Feature.TEXT_SEARCH, Feature.SYNC_DELAY,
76+
Feature.ONLY_WITH_SSL, Feature.NO_HTTP_INTERFACE_ARG);
7677
}
7778

7879
@Test

0 commit comments

Comments
 (0)