From 1a4ad96dd02839d9a7a63994299e4322f2763748 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 17 Sep 2018 12:29:48 +0100 Subject: [PATCH] Raised 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 --- .../EmbeddedMongoAutoConfiguration.java | 20 +++++++++++++++---- .../embedded/EmbeddedMongoProperties.java | 12 +++++------ .../EmbeddedMongoAutoConfigurationTests.java | 11 +++++----- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java index 2fbd777fef..3c46b86434 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java @@ -35,6 +35,7 @@ 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.IFeatureAwareVersion; +import de.flapdoodle.embed.mongo.distribution.Version; import de.flapdoodle.embed.mongo.distribution.Versions; import de.flapdoodle.embed.process.config.IRuntimeConfig; import de.flapdoodle.embed.process.config.io.ProcessOutput; @@ -125,11 +126,8 @@ public class EmbeddedMongoAutoConfiguration { @Bean @ConditionalOnMissingBean public IMongodConfig embeddedMongoConfiguration() throws IOException { - IFeatureAwareVersion featureAwareVersion = Versions.withFeatures( - new GenericVersion(this.embeddedProperties.getVersion()), - this.embeddedProperties.getFeatures().toArray(new Feature[0])); MongodConfigBuilder builder = new MongodConfigBuilder() - .version(featureAwareVersion); + .version(determineVersion()); EmbeddedMongoProperties.Storage storage = this.embeddedProperties.getStorage(); if (storage != null) { String databaseDir = storage.getDatabaseDir(); @@ -149,6 +147,20 @@ public class EmbeddedMongoAutoConfiguration { return builder.build(); } + private IFeatureAwareVersion determineVersion() { + if (this.embeddedProperties.getFeatures() == null) { + for (Version version : Version.values()) { + if (version.asInDownloadPath() + .equals(this.embeddedProperties.getVersion())) { + return version; + } + } + } + return Versions.withFeatures( + new GenericVersion(this.embeddedProperties.getVersion()), + this.embeddedProperties.getFeatures().toArray(new Feature[0])); + } + private InetAddress getHost() throws UnknownHostException { if (this.properties.getHost() == null) { return InetAddress.getByAddress(Network.localhostIsIPv6() diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoProperties.java index 9814ba06f3..3ba0f415ca 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package org.springframework.boot.autoconfigure.mongo.embedded; -import java.util.Collections; -import java.util.HashSet; import java.util.Set; import de.flapdoodle.embed.mongo.distribution.Feature; @@ -37,15 +35,15 @@ public class EmbeddedMongoProperties { /** * Version of Mongo to use. */ - private String version = "3.2.2"; + private String version = "3.6.5"; private final Storage storage = new Storage(); /** - * Comma-separated list of features to enable. + * Comma-separated list of features to enable. Uses the defaults of the configured + * version by default. */ - private Set features = new HashSet<>( - Collections.singletonList(Feature.SYNC_DELAY)); + private Set features = null; public String getVersion() { return this.version; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java index 554e47f4b8..4d80236099 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,19 +60,20 @@ public class EmbeddedMongoAutoConfigurationTests { @Test public void defaultVersion() { - assertVersionConfiguration(null, "3.2.2"); + assertVersionConfiguration(null, "3.6.5"); } @Test public void customVersion() { - assertVersionConfiguration("2.7.1", "2.7.1"); + assertVersionConfiguration("3.6.3", "3.6.3"); } @Test public void customFeatures() { - load("spring.mongodb.embedded.features=TEXT_SEARCH, SYNC_DELAY"); + load("spring.mongodb.embedded.features=TEXT_SEARCH, SYNC_DELAY, ONLY_WITH_SSL, NO_HTTP_INTERFACE_ARG"); assertThat(this.context.getBean(EmbeddedMongoProperties.class).getFeatures()) - .contains(Feature.TEXT_SEARCH, Feature.SYNC_DELAY); + .containsExactly(Feature.TEXT_SEARCH, Feature.SYNC_DELAY, + Feature.ONLY_WITH_SSL, Feature.NO_HTTP_INTERFACE_ARG); } @Test