Browse Source

DATAMONGO-1504 - Assert compatibility with MongoDB 3.4.

We now make sure to comply to the API requirements of mongo-java-driver 3.4 (in current beta1) by using empty DBObjects instead of null, ignoring non appropriate replication settings and cleaning up tests after execution.

Original pull request: #394.
pull/410/head
Christoph Strobl 9 years ago committed by Oliver Gierke
parent
commit
5fce8bcac6
  1. 1
      .travis.yml
  2. 16
      pom.xml
  3. 10
      spring-data-mongodb-log4j/src/main/java/org/springframework/data/mongodb/log4j/MongoLog4jAppender.java
  4. 18
      spring-data-mongodb-log4j/src/test/java/org/springframework/data/mongodb/log4j/MongoLog4jAppenderIntegrationTests.java
  5. 2
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java
  6. 5
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java
  7. 4
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/performance/PerformanceTests.java

1
.travis.yml

@ -15,6 +15,7 @@ env:
- PROFILE=mongo31 - PROFILE=mongo31
- PROFILE=mongo32 - PROFILE=mongo32
- PROFILE=mongo33 - PROFILE=mongo33
- PROFILE=mongo34-next
# Current MongoDB version is 2.4.2 as of 2016-04, see https://github.com/travis-ci/travis-ci/issues/3694 # Current MongoDB version is 2.4.2 as of 2016-04, see https://github.com/travis-ci/travis-ci/issues/3694
# apt-get starts a MongoDB instance so it's not started using before_script # apt-get starts a MongoDB instance so it's not started using before_script

16
pom.xml

@ -178,6 +178,22 @@
</profile> </profile>
<profile>
<id>mongo34-next</id>
<properties>
<mongo>3.4.0-SNAPSHOT</mongo>
</properties>
<repositories>
<repository>
<id>mongo-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
</profile>
<profile> <profile>
<id>release</id> <id>release</id>
<build> <build>

10
spring-data-mongodb-log4j/src/main/java/org/springframework/data/mongodb/log4j/MongoLog4jAppender.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2011-2013 the original author or authors. * Copyright 2011-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,6 +30,7 @@ import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject; import com.mongodb.BasicDBObject;
import com.mongodb.DB; import com.mongodb.DB;
import com.mongodb.Mongo; import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.WriteConcern; import com.mongodb.WriteConcern;
/** /**
@ -37,6 +38,7 @@ import com.mongodb.WriteConcern;
* *
* @author Jon Brisbin * @author Jon Brisbin
* @author Oliver Gierke * @author Oliver Gierke
* @auhtor Christoph Strobl
*/ */
public class MongoLog4jAppender extends AppenderSkeleton { public class MongoLog4jAppender extends AppenderSkeleton {
@ -58,8 +60,8 @@ public class MongoLog4jAppender extends AppenderSkeleton {
protected String collectionPattern = "%c"; protected String collectionPattern = "%c";
protected PatternLayout collectionLayout = new PatternLayout(collectionPattern); protected PatternLayout collectionLayout = new PatternLayout(collectionPattern);
protected String applicationId = System.getProperty("APPLICATION_ID", null); protected String applicationId = System.getProperty("APPLICATION_ID", null);
protected WriteConcern warnOrHigherWriteConcern = WriteConcern.SAFE; protected WriteConcern warnOrHigherWriteConcern = WriteConcern.ACKNOWLEDGED;
protected WriteConcern infoOrLowerWriteConcern = WriteConcern.NORMAL; protected WriteConcern infoOrLowerWriteConcern = WriteConcern.UNACKNOWLEDGED;
protected Mongo mongo; protected Mongo mongo;
protected DB db; protected DB db;
@ -128,7 +130,7 @@ public class MongoLog4jAppender extends AppenderSkeleton {
} }
protected void connectToMongo() throws UnknownHostException { protected void connectToMongo() throws UnknownHostException {
this.mongo = new Mongo(host, port); this.mongo = new MongoClient(host, port);
this.db = mongo.getDB(database); this.db = mongo.getDB(database);
} }

18
spring-data-mongodb-log4j/src/test/java/org/springframework/data/mongodb/log4j/MongoLog4jAppenderIntegrationTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2011-2013 the original author or authors. * Copyright 2011-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,37 +22,44 @@ import java.util.Calendar;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.MDC; import org.apache.log4j.MDC;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import com.mongodb.BasicDBObject;
import com.mongodb.DB; import com.mongodb.DB;
import com.mongodb.DBCursor; import com.mongodb.DBCursor;
import com.mongodb.Mongo; import com.mongodb.MongoClient;
/** /**
* Integration tests for {@link MongoLog4jAppender}. * Integration tests for {@link MongoLog4jAppender}.
* *
* @author Jon Brisbin * @author Jon Brisbin
* @author Oliver Gierke * @author Oliver Gierke
* @author Christoph Strobl
*/ */
public class MongoLog4jAppenderIntegrationTests { public class MongoLog4jAppenderIntegrationTests {
static final String NAME = MongoLog4jAppenderIntegrationTests.class.getName(); static final String NAME = MongoLog4jAppenderIntegrationTests.class.getName();
private static final Logger log = Logger.getLogger(NAME); private static final Logger log = Logger.getLogger(NAME);
Mongo mongo; MongoClient mongo;
DB db; DB db;
String collection; String collection;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
mongo = new Mongo("localhost", 27017); mongo = new MongoClient("localhost", 27017);
db = mongo.getDB("logs"); db = mongo.getDB("logs");
Calendar now = Calendar.getInstance(); Calendar now = Calendar.getInstance();
collection = String.valueOf(now.get(Calendar.YEAR)) + String.format("%1$02d", now.get(Calendar.MONTH) + 1); collection = String.valueOf(now.get(Calendar.YEAR)) + String.format("%1$02d", now.get(Calendar.MONTH) + 1);
db.getCollection(collection).drop(); }
@After
public void tearDown() {
db.getCollection(collection).remove(new BasicDBObject());
} }
@Test @Test
@ -64,7 +71,6 @@ public class MongoLog4jAppenderIntegrationTests {
log.error("ERROR message"); log.error("ERROR message");
DBCursor msgs = db.getCollection(collection).find(); DBCursor msgs = db.getCollection(collection).find();
assertThat(msgs.count(), is(4)); assertThat(msgs.count(), is(4));
} }

2
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java

@ -2194,7 +2194,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
} }
public FindCallback(DBObject query, DBObject fields) { public FindCallback(DBObject query, DBObject fields) {
this.query = query; this.query = query == null ? new BasicDBObject() : query;
this.fields = fields; this.fields = fields;
} }

5
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2011-2014 the original author or authors. * Copyright 2011-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,6 +45,7 @@ import com.mongodb.gridfs.GridFSInputFile;
* @author Philipp Schneider * @author Philipp Schneider
* @author Thomas Darimont * @author Thomas Darimont
* @author Martin Baumgartner * @author Martin Baumgartner
* @author Christoph Strobl
*/ */
public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver { public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver {
@ -182,7 +183,7 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver
public List<GridFSDBFile> find(Query query) { public List<GridFSDBFile> find(Query query) {
if (query == null) { if (query == null) {
return getGridFs().find((DBObject) null); return getGridFs().find(new BasicDBObject());
} }
DBObject queryObject = getMappedQuery(query.getQueryObject()); DBObject queryObject = getMappedQuery(query.getQueryObject());

4
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/performance/PerformanceTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2015 the original author or authors. * Copyright 2012-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -74,7 +74,7 @@ public class PerformanceTests {
private static final int ITERATIONS = 50; private static final int ITERATIONS = 50;
private static final StopWatch watch = new StopWatch(); private static final StopWatch watch = new StopWatch();
private static final Collection<String> IGNORED_WRITE_CONCERNS = Arrays.asList("MAJORITY", "REPLICAS_SAFE", private static final Collection<String> IGNORED_WRITE_CONCERNS = Arrays.asList("MAJORITY", "REPLICAS_SAFE",
"FSYNC_SAFE", "FSYNCED", "JOURNAL_SAFE", "JOURNALED", "REPLICA_ACKNOWLEDGED"); "FSYNC_SAFE", "FSYNCED", "JOURNAL_SAFE", "JOURNALED", "REPLICA_ACKNOWLEDGED", "W2", "W3");
private static final int COLLECTION_SIZE = 1024 * 1024 * 256; // 256 MB private static final int COLLECTION_SIZE = 1024 * 1024 * 256; // 256 MB
private static final Collection<String> COLLECTION_NAMES = Arrays.asList("template", "driver", "person"); private static final Collection<String> COLLECTION_NAMES = Arrays.asList("template", "driver", "person");

Loading…
Cancel
Save