Polishing.
Reformat code. Add missing hints for reflective version detection. Original pull request: #4624 See: #4578
This commit is contained in:
52
Jenkinsfile
vendored
52
Jenkinsfile
vendored
@@ -266,32 +266,32 @@ pipeline {
|
||||
}
|
||||
|
||||
stage("test: MongoDB 7.0 (driver-next)") {
|
||||
agent {
|
||||
label 'data'
|
||||
}
|
||||
options { timeout(time: 30, unit: 'MINUTES') }
|
||||
environment {
|
||||
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
|
||||
DEVELOCITY_CACHE = credentials("${p['develocity.cache.credentials']}")
|
||||
DEVELOCITY_ACCESS_KEY = credentials("${p['develocity.access-key']}")
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
docker.image("harbor-repo.vmware.com/dockerhub-proxy-cache/springci/spring-data-with-mongodb-7.0:${p['java.main.tag']}").inside(p['docker.java.inside.basic']) {
|
||||
sh 'mkdir -p /tmp/mongodb/db /tmp/mongodb/log'
|
||||
sh 'mongod --setParameter transactionLifetimeLimitSeconds=90 --setParameter maxTransactionLockRequestTimeoutMillis=10000 --dbpath /tmp/mongodb/db --replSet rs0 --fork --logpath /tmp/mongodb/log/mongod.log &'
|
||||
sh 'sleep 10'
|
||||
sh 'mongosh --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"'
|
||||
sh 'sleep 15'
|
||||
sh 'MAVEN_OPTS="-Duser.name=' + "${p['jenkins.user.name']}" + ' -Duser.home=/tmp/jenkins-home" ' +
|
||||
"DEVELOCITY_CACHE_USERNAME=${DEVELOCITY_CACHE_USR} " +
|
||||
"DEVELOCITY_CACHE_PASSWORD=${DEVELOCITY_CACHE_PSW} " +
|
||||
"GRADLE_ENTERPRISE_ACCESS_KEY=${DEVELOCITY_ACCESS_KEY} " +
|
||||
"./mvnw -s settings.xml -Pmongo-5.0 clean dependency:list test -Dsort -U -B -Dgradle.cache.local.enabled=false -Dgradle.cache.remote.enabled=false"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
agent {
|
||||
label 'data'
|
||||
}
|
||||
options { timeout(time: 30, unit: 'MINUTES') }
|
||||
environment {
|
||||
ARTIFACTORY = credentials("${p['artifactory.credentials']}")
|
||||
DEVELOCITY_CACHE = credentials("${p['develocity.cache.credentials']}")
|
||||
DEVELOCITY_ACCESS_KEY = credentials("${p['develocity.access-key']}")
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
docker.image("harbor-repo.vmware.com/dockerhub-proxy-cache/springci/spring-data-with-mongodb-7.0:${p['java.main.tag']}").inside(p['docker.java.inside.basic']) {
|
||||
sh 'mkdir -p /tmp/mongodb/db /tmp/mongodb/log'
|
||||
sh 'mongod --setParameter transactionLifetimeLimitSeconds=90 --setParameter maxTransactionLockRequestTimeoutMillis=10000 --dbpath /tmp/mongodb/db --replSet rs0 --fork --logpath /tmp/mongodb/log/mongod.log &'
|
||||
sh 'sleep 10'
|
||||
sh 'mongosh --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"'
|
||||
sh 'sleep 15'
|
||||
sh 'MAVEN_OPTS="-Duser.name=' + "${p['jenkins.user.name']}" + ' -Duser.home=/tmp/jenkins-home" ' +
|
||||
"DEVELOCITY_CACHE_USERNAME=${DEVELOCITY_CACHE_USR} " +
|
||||
"DEVELOCITY_CACHE_PASSWORD=${DEVELOCITY_CACHE_PSW} " +
|
||||
"GRADLE_ENTERPRISE_ACCESS_KEY=${DEVELOCITY_ACCESS_KEY} " +
|
||||
"./mvnw -s settings.xml -Pmongo-5.0 clean dependency:list test -Dsort -U -B -Dgradle.cache.local.enabled=false -Dgradle.cache.remote.enabled=false"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage("test: MongoDB 7.0 (next)") {
|
||||
agent {
|
||||
|
||||
@@ -25,19 +25,25 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Collection of {@link Predicate predicates} to determine dynamic library aspects during AOT computation.
|
||||
* Intended for internal usage only.
|
||||
* Collection of {@link Predicate predicates} to determine dynamic library aspects during AOT computation. Intended for
|
||||
* internal usage only.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @since 4.0
|
||||
*/
|
||||
public class MongoAotPredicates {
|
||||
|
||||
public static final Predicate<Class<?>> IS_SIMPLE_TYPE = (type) -> MongoSimpleTypes.HOLDER.isSimpleType(type) || TypeUtils.type(type).isPartOf("org.bson");
|
||||
public static final Predicate<Class<?>> IS_SIMPLE_TYPE = (type) -> MongoSimpleTypes.HOLDER.isSimpleType(type)
|
||||
|| TypeUtils.type(type).isPartOf("org.bson");
|
||||
public static final Predicate<ReactiveLibrary> IS_REACTIVE_LIBARARY_AVAILABLE = ReactiveWrappers::isAvailable;
|
||||
public static final Predicate<ClassLoader> IS_SYNC_CLIENT_PRESENT = (classLoader) -> ClassUtils.isPresent("com.mongodb.client.MongoClient", classLoader);
|
||||
public static final Predicate<ClassLoader> IS_REACTIVE_CLIENT_PRESENT = (classLoader) -> ClassUtils.isPresent("com.mongodb.reactivestreams.client.MongoClient", classLoader);
|
||||
public static final Predicate<ClassLoader> IS_SYNC_CLIENT_PRESENT = (classLoader) -> ClassUtils
|
||||
.isPresent("com.mongodb.client.MongoClient", classLoader);
|
||||
public static final Predicate<ClassLoader> IS_REACTIVE_CLIENT_PRESENT = (classLoader) -> ClassUtils
|
||||
.isPresent("com.mongodb.reactivestreams.client.MongoClient", classLoader);
|
||||
|
||||
/**
|
||||
* @return {@literal true} if the Project Reactor is present.
|
||||
*/
|
||||
public static boolean isReactorPresent() {
|
||||
return IS_REACTIVE_LIBARARY_AVAILABLE.test(ReactiveWrappers.ReactiveLibrary.PROJECT_REACTOR);
|
||||
}
|
||||
|
||||
@@ -19,13 +19,6 @@ import static org.springframework.data.mongodb.aot.MongoAotPredicates.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.mongodb.MongoClientSettings;
|
||||
import com.mongodb.ServerAddress;
|
||||
import com.mongodb.UnixServerAddress;
|
||||
import com.mongodb.client.MapReduceIterable;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import com.mongodb.client.model.IndexOptions;
|
||||
import com.mongodb.reactivestreams.client.MapReducePublisher;
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
@@ -38,10 +31,17 @@ import org.springframework.data.mongodb.core.mapping.event.ReactiveAfterConvertC
|
||||
import org.springframework.data.mongodb.core.mapping.event.ReactiveAfterSaveCallback;
|
||||
import org.springframework.data.mongodb.core.mapping.event.ReactiveBeforeConvertCallback;
|
||||
import org.springframework.data.mongodb.core.mapping.event.ReactiveBeforeSaveCallback;
|
||||
import org.springframework.data.mongodb.util.MongoClientVersion;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import com.mongodb.MongoClientSettings;
|
||||
import com.mongodb.ServerAddress;
|
||||
import com.mongodb.UnixServerAddress;
|
||||
import com.mongodb.client.MapReduceIterable;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import com.mongodb.client.model.IndexOptions;
|
||||
import com.mongodb.reactivestreams.client.MapReducePublisher;
|
||||
|
||||
/**
|
||||
* {@link RuntimeHintsRegistrar} for repository types and entity callbacks.
|
||||
*
|
||||
@@ -72,7 +72,6 @@ class MongoRuntimeHints implements RuntimeHintsRegistrar {
|
||||
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
|
||||
MemberCategory.INVOKE_PUBLIC_METHODS));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void registerTransactionProxyHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
|
||||
@@ -89,6 +88,7 @@ class MongoRuntimeHints implements RuntimeHintsRegistrar {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static void registerMongoCompatibilityAdapterHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
|
||||
|
||||
hints.reflection() //
|
||||
@@ -96,25 +96,33 @@ class MongoRuntimeHints implements RuntimeHintsRegistrar {
|
||||
.registerType(MongoClientSettings.Builder.class, MemberCategory.INVOKE_PUBLIC_METHODS)
|
||||
.registerType(IndexOptions.class, MemberCategory.INVOKE_PUBLIC_METHODS)
|
||||
.registerType(ServerAddress.class, MemberCategory.INVOKE_PUBLIC_METHODS)
|
||||
.registerType(UnixServerAddress.class, MemberCategory.INVOKE_PUBLIC_METHODS)
|
||||
.registerType(TypeReference.of("com.mongodb.connection.StreamFactoryFactory"), MemberCategory.INTROSPECT_PUBLIC_METHODS);
|
||||
.registerType(UnixServerAddress.class, MemberCategory.INVOKE_PUBLIC_METHODS) //
|
||||
.registerType(TypeReference.of("com.mongodb.connection.StreamFactoryFactory"),
|
||||
MemberCategory.INTROSPECT_PUBLIC_METHODS)
|
||||
.registerType(TypeReference.of("com.mongodb.internal.connection.StreamFactoryFactory"),
|
||||
MemberCategory.INTROSPECT_PUBLIC_METHODS)
|
||||
.registerType(TypeReference.of("com.mongodb.internal.build.MongoDriverVersion"), MemberCategory.PUBLIC_FIELDS);
|
||||
|
||||
if(MongoAotPredicates.isSyncClientPresent(classLoader)) {
|
||||
if (MongoAotPredicates.isSyncClientPresent(classLoader)) {
|
||||
|
||||
hints.reflection() //
|
||||
.registerType(MongoDatabase.class, MemberCategory.INVOKE_PUBLIC_METHODS)
|
||||
.registerType(TypeReference.of("com.mongodb.client.internal.MongoDatabaseImpl"), MemberCategory.INVOKE_PUBLIC_METHODS)
|
||||
.registerType(TypeReference.of("com.mongodb.client.internal.MongoDatabaseImpl"),
|
||||
MemberCategory.INVOKE_PUBLIC_METHODS)
|
||||
.registerType(MapReduceIterable.class, MemberCategory.INVOKE_PUBLIC_METHODS)
|
||||
.registerType(TypeReference.of("com.mongodb.client.internal.MapReduceIterableImpl"), MemberCategory.INVOKE_PUBLIC_METHODS);
|
||||
.registerType(TypeReference.of("com.mongodb.client.internal.MapReduceIterableImpl"),
|
||||
MemberCategory.INVOKE_PUBLIC_METHODS);
|
||||
}
|
||||
|
||||
if(MongoAotPredicates.isReactiveClientPresent(classLoader)) {
|
||||
if (MongoAotPredicates.isReactiveClientPresent(classLoader)) {
|
||||
|
||||
hints.reflection() //
|
||||
.registerType(com.mongodb.reactivestreams.client.MongoDatabase.class, MemberCategory.INVOKE_PUBLIC_METHODS)
|
||||
.registerType(TypeReference.of("com.mongodb.reactivestreams.client.internal.MongoDatabaseImpl"), MemberCategory.INVOKE_PUBLIC_METHODS)
|
||||
.registerType(TypeReference.of("com.mongodb.reactivestreams.client.internal.MongoDatabaseImpl"),
|
||||
MemberCategory.INVOKE_PUBLIC_METHODS)
|
||||
.registerType(MapReducePublisher.class, MemberCategory.INVOKE_PUBLIC_METHODS)
|
||||
.registerType(TypeReference.of("com.mongodb.reactivestreams.client.internal.MapReducePublisherImpl"), MemberCategory.INVOKE_PUBLIC_METHODS);
|
||||
.registerType(TypeReference.of("com.mongodb.reactivestreams.client.internal.MapReducePublisherImpl"),
|
||||
MemberCategory.INVOKE_PUBLIC_METHODS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ public class MongoClientSettingsFactoryBean extends AbstractFactoryBean<MongoCli
|
||||
|
||||
/**
|
||||
* @param socketConnectTimeoutMS in msec
|
||||
* @see com.mongodb.connection.SocketSettings.Builder#connectTimeout(long, TimeUnit)
|
||||
* @see com.mongodb.connection.SocketSettings.Builder#connectTimeout(int, TimeUnit)
|
||||
*/
|
||||
public void setSocketConnectTimeoutMS(int socketConnectTimeoutMS) {
|
||||
this.socketConnectTimeoutMS = socketConnectTimeoutMS;
|
||||
@@ -131,7 +131,7 @@ public class MongoClientSettingsFactoryBean extends AbstractFactoryBean<MongoCli
|
||||
|
||||
/**
|
||||
* @param socketReadTimeoutMS in msec
|
||||
* @see com.mongodb.connection.SocketSettings.Builder#readTimeout(long, TimeUnit)
|
||||
* @see com.mongodb.connection.SocketSettings.Builder#readTimeout(int, TimeUnit)
|
||||
*/
|
||||
public void setSocketReadTimeoutMS(int socketReadTimeoutMS) {
|
||||
this.socketReadTimeoutMS = socketReadTimeoutMS;
|
||||
|
||||
@@ -41,7 +41,7 @@ public class GeospatialIndex implements IndexDefinition {
|
||||
private @Nullable Integer max;
|
||||
private @Nullable Integer bits;
|
||||
private GeoSpatialIndexType type = GeoSpatialIndexType.GEO_2D;
|
||||
private Double bucketSize = MongoClientVersion.isVersion5OrNewer() ? null : 1.0;
|
||||
private Double bucketSize = MongoClientVersion.isVersion5orNewer() ? null : 1.0;
|
||||
private @Nullable String additionalField;
|
||||
private Optional<IndexFilter> filter = Optional.empty();
|
||||
private Optional<Collation> collation = Optional.empty();
|
||||
|
||||
@@ -710,14 +710,17 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
.named(pathAwareIndexName(index.name(), dotPath, persistentProperty.getOwner(), persistentProperty));
|
||||
}
|
||||
|
||||
if(MongoClientVersion.isVersion5OrNewer()) {
|
||||
if (MongoClientVersion.isVersion5orNewer()) {
|
||||
|
||||
Optional<Double> defaultBucketSize = MergedAnnotation.of(GeoSpatialIndexed.class).getDefaultValue("bucketSize", Double.class);
|
||||
Optional<Double> defaultBucketSize = MergedAnnotation.of(GeoSpatialIndexed.class).getDefaultValue("bucketSize",
|
||||
Double.class);
|
||||
if (!defaultBucketSize.isPresent() || index.bucketSize() != defaultBucketSize.get()) {
|
||||
indexDefinition.withBucketSize(index.bucketSize());
|
||||
} else {
|
||||
if(LOGGER.isInfoEnabled()) {
|
||||
LOGGER.info("Ignoring no longer supported default GeoSpatialIndexed.bucketSize on %s for Mongo Client 5 or newer.".formatted(dotPath));
|
||||
if (LOGGER.isInfoEnabled()) {
|
||||
LOGGER.info(
|
||||
"GeoSpatialIndexed.bucketSize no longer supported by Mongo Client 5 or newer. Ignoring bucketSize for path %s."
|
||||
.formatted(dotPath));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -48,10 +48,7 @@ public class MongoClientVersion {
|
||||
static {
|
||||
|
||||
ClassLoader classLoader = MongoClientVersion.class.getClassLoader();
|
||||
Version version = readVersionFromClass(classLoader);
|
||||
if (version == null) {
|
||||
version = guessDriverVersionFromClassPath(classLoader);
|
||||
}
|
||||
Version version = getMongoDbDriverVersion(classLoader);
|
||||
|
||||
CLIENT_VERSION = version;
|
||||
IS_VERSION_5_OR_NEWER = CLIENT_VERSION.isGreaterThanOrEqualTo(Version.parse("5.0"));
|
||||
@@ -84,12 +81,18 @@ public class MongoClientVersion {
|
||||
* @return {@literal true} if the MongoDB Java driver version is 5 or newer.
|
||||
* @since 4.3
|
||||
*/
|
||||
public static boolean isVersion5OrNewer() {
|
||||
public static boolean isVersion5orNewer() {
|
||||
return IS_VERSION_5_OR_NEWER;
|
||||
}
|
||||
|
||||
private static Version getMongoDbDriverVersion(ClassLoader classLoader) {
|
||||
|
||||
Version version = getVersionFromPackage(classLoader);
|
||||
return version == null ? guessDriverVersionFromClassPath(classLoader) : version;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Version readVersionFromClass(ClassLoader classLoader) {
|
||||
private static Version getVersionFromPackage(ClassLoader classLoader) {
|
||||
|
||||
if (ClassUtils.isPresent("com.mongodb.internal.build.MongoDriverVersion", classLoader)) {
|
||||
try {
|
||||
|
||||
@@ -75,7 +75,7 @@ public class MongoCompatibilityAdapter {
|
||||
@Override
|
||||
public <T> T getStreamFactoryFactory() {
|
||||
|
||||
if (MongoClientVersion.isVersion5OrNewer() || getStreamFactoryFactory == null) {
|
||||
if (MongoClientVersion.isVersion5orNewer() || getStreamFactoryFactory == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class MongoCompatibilityAdapter {
|
||||
public static IndexOptionsAdapter indexOptionsAdapter(IndexOptions options) {
|
||||
return bucketSize -> {
|
||||
|
||||
if (MongoClientVersion.isVersion5OrNewer() || setBucketSize == null) {
|
||||
if (MongoClientVersion.isVersion5orNewer() || setBucketSize == null) {
|
||||
throw new UnsupportedOperationException(NO_LONGER_SUPPORTED.formatted("IndexOptions.bucketSize"));
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public class MongoCompatibilityAdapter {
|
||||
public static MapReduceIterableAdapter mapReduceIterableAdapter(Object iterable) {
|
||||
return sharded -> {
|
||||
|
||||
if (MongoClientVersion.isVersion5OrNewer()) {
|
||||
if (MongoClientVersion.isVersion5orNewer()) {
|
||||
throw new UnsupportedOperationException(NO_LONGER_SUPPORTED.formatted("sharded"));
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ public class MongoCompatibilityAdapter {
|
||||
public static MapReducePublisherAdapter mapReducePublisherAdapter(Object publisher) {
|
||||
return sharded -> {
|
||||
|
||||
if (MongoClientVersion.isVersion5OrNewer()) {
|
||||
if (MongoClientVersion.isVersion5orNewer()) {
|
||||
throw new UnsupportedOperationException(NO_LONGER_SUPPORTED.formatted("sharded"));
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ public class MongoCompatibilityAdapter {
|
||||
public static ServerAddressAdapter serverAddressAdapter(ServerAddress serverAddress) {
|
||||
return () -> {
|
||||
|
||||
if (MongoClientVersion.isVersion5OrNewer()) {
|
||||
if (MongoClientVersion.isVersion5orNewer()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -199,6 +199,7 @@ public class MongoCompatibilityAdapter {
|
||||
MongoDatabaseAdapter forDb(com.mongodb.client.MongoDatabase db);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "DataFlowIssue" })
|
||||
public static class MongoDatabaseAdapter {
|
||||
|
||||
@Nullable //
|
||||
@@ -219,7 +220,7 @@ public class MongoCompatibilityAdapter {
|
||||
LIST_COLLECTION_NAMES_METHOD_SESSION = ReflectionUtils.findMethod(MongoDatabase.class, "listCollectionNames",
|
||||
ClientSession.class);
|
||||
|
||||
if (MongoClientVersion.isVersion5OrNewer()) {
|
||||
if (MongoClientVersion.isVersion5orNewer()) {
|
||||
try {
|
||||
collectionNamesReturnType = ClassUtils.forName("com.mongodb.client.ListCollectionNamesIterable",
|
||||
MongoDatabaseAdapter.class.getClassLoader());
|
||||
@@ -267,6 +268,7 @@ public class MongoCompatibilityAdapter {
|
||||
ReactiveMongoDatabaseAdapter forDb(com.mongodb.reactivestreams.client.MongoDatabase db);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "DataFlowIssue" })
|
||||
public static class ReactiveMongoDatabaseAdapter {
|
||||
|
||||
@Nullable //
|
||||
@@ -289,7 +291,7 @@ public class MongoCompatibilityAdapter {
|
||||
com.mongodb.reactivestreams.client.MongoDatabase.class, "listCollectionNames",
|
||||
com.mongodb.reactivestreams.client.ClientSession.class);
|
||||
|
||||
if (MongoClientVersion.isVersion5OrNewer()) {
|
||||
if (MongoClientVersion.isVersion5orNewer()) {
|
||||
try {
|
||||
collectionNamesReturnType = ClassUtils.forName(
|
||||
"com.mongodb.reactivestreams.client.ListCollectionNamesPublisher",
|
||||
@@ -352,7 +354,7 @@ public class MongoCompatibilityAdapter {
|
||||
|
||||
void setStreamFactory(Object streamFactory) {
|
||||
|
||||
if (MongoClientVersion.isVersion5OrNewer() && isStreamFactoryPresent()) {
|
||||
if (MongoClientVersion.isVersion5orNewer() && isStreamFactoryPresent()) {
|
||||
logger.warn("StreamFactoryFactory is no longer available. Use TransportSettings instead.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.mongodb.reactivestreams.client.MapReducePublisher;
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
class MongoRuntimeHintsUnitTests {
|
||||
|
||||
@Test // GH-4578
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
import org.assertj.core.api.Assumptions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.geo.Point;
|
||||
@@ -37,11 +38,11 @@ import org.springframework.data.mongodb.core.index.IndexInfo;
|
||||
import org.springframework.data.mongodb.core.index.IndexOperations;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
import org.springframework.data.mongodb.test.util.EnableIfMongoServerVersion;
|
||||
import org.springframework.data.mongodb.util.MongoClientVersion;
|
||||
|
||||
import com.mongodb.MongoException;
|
||||
import com.mongodb.WriteConcern;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import org.springframework.data.mongodb.util.MongoClientVersion;
|
||||
|
||||
/**
|
||||
* Integration tests for geo-spatial indexing.
|
||||
@@ -88,7 +89,7 @@ public class GeoSpatialIndexTests extends AbstractIntegrationTests {
|
||||
@EnableIfMongoServerVersion(isLessThan = "5.0")
|
||||
public void testHaystackIndex() {
|
||||
|
||||
Assumptions.assumeThat(MongoClientVersion.isVersion5OrNewer()).isFalse();
|
||||
Assumptions.assumeThat(MongoClientVersion.isVersion5orNewer()).isFalse();
|
||||
|
||||
try {
|
||||
template.save(new GeoSpatialEntityHaystack(45.2, 4.6, "Paris"));
|
||||
|
||||
@@ -83,7 +83,7 @@ public class ImperativeIntegrationTests extends SampleTestRunner {
|
||||
|
||||
assertThat(span.getTags()).containsEntry("db.system", "mongodb").containsEntry("net.transport", "IP.TCP");
|
||||
|
||||
if (MongoClientVersion.isVersion5OrNewer()) {
|
||||
if (MongoClientVersion.isVersion5orNewer()) {
|
||||
assertThat(span.getTags()).containsKeys("db.connection_string", "db.name", "db.operation",
|
||||
"db.mongodb.collection", "net.peer.name", "net.peer.port");
|
||||
} else {
|
||||
|
||||
@@ -32,13 +32,13 @@ class MongoClientVersionUnitTests {
|
||||
|
||||
@Test // GH-4578
|
||||
void parsesClientVersionCorrectly() {
|
||||
assertThat(MongoClientVersion.isVersion5OrNewer()).isEqualTo(MongoDriverVersion.VERSION.startsWith("5"));
|
||||
assertThat(MongoClientVersion.isVersion5orNewer()).isEqualTo(MongoDriverVersion.VERSION.startsWith("5"));
|
||||
}
|
||||
|
||||
@Test // GH-4578
|
||||
@ClassPathExclusions(packages = { "com.mongodb.internal.build" })
|
||||
void fallsBackToClassLookupIfDriverVersionNotPresent() {
|
||||
assertThat(MongoClientVersion.isVersion5OrNewer()).isEqualTo(
|
||||
assertThat(MongoClientVersion.isVersion5orNewer()).isEqualTo(
|
||||
ClassUtils.isPresent("com.mongodb.internal.connection.StreamFactoryFactory", this.getClass().getClassLoader()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class MongoCompatibilityAdapterUnitTests {
|
||||
@ExcludeReactiveClientFromClassPath
|
||||
void returnsListCollectionNameIterableTypeCorrectly() {
|
||||
|
||||
String expectedType = MongoClientVersion.isVersion5OrNewer() ? "ListCollectionNamesIterable" : "MongoIterable";
|
||||
String expectedType = MongoClientVersion.isVersion5orNewer() ? "ListCollectionNamesIterable" : "MongoIterable";
|
||||
assertThat(MongoCompatibilityAdapter.mongoDatabaseAdapter().forDb(null).collectionNameIterableType())
|
||||
.satisfies(type -> assertThat(ClassUtils.getShortName(type)).isEqualTo(expectedType));
|
||||
|
||||
@@ -41,7 +41,7 @@ class MongoCompatibilityAdapterUnitTests {
|
||||
@ExcludeSyncClientFromClassPath
|
||||
void returnsListCollectionNamePublisherTypeCorrectly() {
|
||||
|
||||
String expectedType = MongoClientVersion.isVersion5OrNewer() ? "ListCollectionNamesPublisher" : "Publisher";
|
||||
String expectedType = MongoClientVersion.isVersion5orNewer() ? "ListCollectionNamesPublisher" : "Publisher";
|
||||
assertThat(MongoCompatibilityAdapter.reactiveMongoDatabaseAdapter().forDb(null).collectionNamePublisherType())
|
||||
.satisfies(type -> assertThat(ClassUtils.getShortName(type)).isEqualTo(expectedType));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user