Skip to content

Commit 9c20da3

Browse files
christophstroblodrotbohm
authored andcommitted
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: spring-projects#394.
1 parent f782338 commit 9c20da3

File tree

7 files changed

+41
-15
lines changed

7 files changed

+41
-15
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ env:
1515
- PROFILE=mongo31
1616
- PROFILE=mongo32
1717
- PROFILE=mongo33
18+
- PROFILE=mongo34-next
1819

1920
# Current MongoDB version is 2.4.2 as of 2016-04, see https://github.com/travis-ci/travis-ci/issues/3694
2021
# apt-get starts a MongoDB instance so it's not started using before_script

pom.xml

+16
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,22 @@
178178

179179
</profile>
180180

181+
<profile>
182+
183+
<id>mongo34-next</id>
184+
<properties>
185+
<mongo>3.4.0-SNAPSHOT</mongo>
186+
</properties>
187+
188+
<repositories>
189+
<repository>
190+
<id>mongo-snapshots</id>
191+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
192+
</repository>
193+
</repositories>
194+
195+
</profile>
196+
181197
<profile>
182198
<id>release</id>
183199
<build>

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2013 the original author or authors.
2+
* Copyright 2011-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,13 +30,15 @@
3030
import com.mongodb.BasicDBObject;
3131
import com.mongodb.DB;
3232
import com.mongodb.Mongo;
33+
import com.mongodb.MongoClient;
3334
import com.mongodb.WriteConcern;
3435

3536
/**
3637
* Log4j appender writing log entries into a MongoDB instance.
3738
*
3839
* @author Jon Brisbin
3940
* @author Oliver Gierke
41+
* @auhtor Christoph Strobl
4042
*/
4143
public class MongoLog4jAppender extends AppenderSkeleton {
4244

@@ -58,8 +60,8 @@ public class MongoLog4jAppender extends AppenderSkeleton {
5860
protected String collectionPattern = "%c";
5961
protected PatternLayout collectionLayout = new PatternLayout(collectionPattern);
6062
protected String applicationId = System.getProperty("APPLICATION_ID", null);
61-
protected WriteConcern warnOrHigherWriteConcern = WriteConcern.SAFE;
62-
protected WriteConcern infoOrLowerWriteConcern = WriteConcern.NORMAL;
63+
protected WriteConcern warnOrHigherWriteConcern = WriteConcern.ACKNOWLEDGED;
64+
protected WriteConcern infoOrLowerWriteConcern = WriteConcern.UNACKNOWLEDGED;
6365
protected Mongo mongo;
6466
protected DB db;
6567

@@ -128,7 +130,7 @@ public void setInfoOrLowerWriteConcern(String wc) {
128130
}
129131

130132
protected void connectToMongo() throws UnknownHostException {
131-
this.mongo = new Mongo(host, port);
133+
this.mongo = new MongoClient(host, port);
132134
this.db = mongo.getDB(database);
133135
}
134136

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

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2013 the original author or authors.
2+
* Copyright 2011-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,37 +22,44 @@
2222

2323
import org.apache.log4j.Logger;
2424
import org.apache.log4j.MDC;
25+
import org.junit.After;
2526
import org.junit.Before;
2627
import org.junit.Test;
2728

29+
import com.mongodb.BasicDBObject;
2830
import com.mongodb.DB;
2931
import com.mongodb.DBCursor;
30-
import com.mongodb.Mongo;
32+
import com.mongodb.MongoClient;
3133

3234
/**
3335
* Integration tests for {@link MongoLog4jAppender}.
3436
*
3537
* @author Jon Brisbin
3638
* @author Oliver Gierke
39+
* @author Christoph Strobl
3740
*/
3841
public class MongoLog4jAppenderIntegrationTests {
3942

4043
static final String NAME = MongoLog4jAppenderIntegrationTests.class.getName();
4144

4245
private static final Logger log = Logger.getLogger(NAME);
43-
Mongo mongo;
46+
MongoClient mongo;
4447
DB db;
4548
String collection;
4649

4750
@Before
4851
public void setUp() throws Exception {
4952

50-
mongo = new Mongo("localhost", 27017);
53+
mongo = new MongoClient("localhost", 27017);
5154
db = mongo.getDB("logs");
5255

5356
Calendar now = Calendar.getInstance();
5457
collection = String.valueOf(now.get(Calendar.YEAR)) + String.format("%1$02d", now.get(Calendar.MONTH) + 1);
55-
db.getCollection(collection).drop();
58+
}
59+
60+
@After
61+
public void tearDown() {
62+
db.getCollection(collection).remove(new BasicDBObject());
5663
}
5764

5865
@Test
@@ -64,7 +71,6 @@ public void testLogging() {
6471
log.error("ERROR message");
6572

6673
DBCursor msgs = db.getCollection(collection).find();
67-
6874
assertThat(msgs.count(), is(4));
6975
}
7076

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,7 @@ public FindCallback(DBObject query) {
22102210
}
22112211

22122212
public FindCallback(DBObject query, DBObject fields) {
2213-
this.query = query;
2213+
this.query = query == null ? new BasicDBObject() : query;
22142214
this.fields = fields;
22152215
}
22162216

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2014 the original author or authors.
2+
* Copyright 2011-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,6 +45,7 @@
4545
* @author Philipp Schneider
4646
* @author Thomas Darimont
4747
* @author Martin Baumgartner
48+
* @author Christoph Strobl
4849
*/
4950
public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver {
5051

@@ -182,7 +183,7 @@ public GridFSFile store(InputStream content, String filename, String contentType
182183
public List<GridFSDBFile> find(Query query) {
183184

184185
if (query == null) {
185-
return getGridFs().find((DBObject) null);
186+
return getGridFs().find(new BasicDBObject());
186187
}
187188

188189
DBObject queryObject = getMappedQuery(query.getQueryObject());

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

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

0 commit comments

Comments
 (0)