Skip to content

Commit 900c0de

Browse files
committed
JAVA-2227: Fix aggregateToSecondary test so that it works with any type of Mongo deployment.
1 parent b295d2a commit 900c0de

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

src/test/com/mongodb/AggregationTest.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,14 @@ public void testDollarOutOnSecondary() throws UnknownHostException {
188188
assumeTrue(isReplicaSet(cleanupMongo));
189189

190190
ServerAddress primary = new ServerAddress(getPrimaryAsString(cleanupMongo));
191-
MongoClient rsClient = new MongoClient(getMongoClientURI());
192-
DB rsDatabase = rsClient.getDB(database.getName());
193-
DBCollection aggCollection = rsDatabase.getCollection(collection.getName());
194-
aggCollection.drop();
195191

196192
final List<DBObject> pipeline = new ArrayList<DBObject>(prepareData());
197193
pipeline.add(new BasicDBObject("$out", "aggCollection"));
198194
AggregationOptions options = AggregationOptions.builder()
199195
.outputMode(OutputMode.CURSOR)
200196
.build();
201-
Cursor cursor = verify(pipeline, options, ReadPreference.secondary(), aggCollection);
202-
assertEquals(2, rsDatabase.getCollection("aggCollection").count());
197+
Cursor cursor = verify(pipeline, options, ReadPreference.secondary(), collection);
198+
assertEquals(2, database.getCollection("aggCollection").count());
203199
assertEquals(primary.getSocketAddress(), cursor.getServerAddress().getSocketAddress());
204200
}
205201

@@ -209,21 +205,15 @@ public void testAggregateOnSecondary() throws UnknownHostException {
209205
assumeTrue(isReplicaSet(cleanupMongo));
210206

211207
ServerAddress primary = new ServerAddress(getPrimaryAsString(cleanupMongo));
212-
ServerAddress secondary = new ServerAddress(getASecondaryAsString(cleanupMongo));
213-
MongoClient rsClient = new MongoClient(asList(primary, secondary));
214-
DB rsDatabase = rsClient.getDB(database.getName());
215-
rsDatabase.dropDatabase();
216-
DBCollection aggCollection = rsDatabase.getCollection(collection.getName());
217-
aggCollection.drop();
218208

219209
List<DBObject> pipeline = new ArrayList<DBObject>(prepareData());
220210
AggregationOptions options = AggregationOptions.builder()
221211
.outputMode(OutputMode.INLINE)
222212
.build();
223-
Cursor cursor = aggCollection.aggregate(pipeline, options, ReadPreference.secondary());
213+
Cursor cursor = collection.aggregate(pipeline, options, ReadPreference.secondary());
224214
assertNotEquals(primary, cursor.getServerAddress());
225215

226-
AggregationOutput aggregationOutput = aggCollection.aggregate(pipeline, ReadPreference.secondary());
216+
AggregationOutput aggregationOutput = collection.aggregate(pipeline, ReadPreference.secondary());
227217
assertNotEquals(primary, aggregationOutput.getServerUsed());
228218
}
229219

@@ -280,7 +270,7 @@ public void testInvalidPipelineThrowsError() {
280270
}
281271
}
282272

283-
public List<DBObject> prepareData() {
273+
private List<DBObject> prepareData() {
284274
collection.remove(new BasicDBObject());
285275

286276
final DBObject foo = new BasicDBObject("name", "foo").append("count", 5);

0 commit comments

Comments
 (0)