19
19
import com .mongodb .AggregationOptions .OutputMode ;
20
20
import com .mongodb .util .TestCase ;
21
21
import org .junit .Before ;
22
- import org .junit .Ignore ;
23
22
import org .junit .Test ;
24
23
25
24
import java .net .UnknownHostException ;
@@ -188,7 +187,7 @@ public void testDollarOutOnSecondary() throws UnknownHostException {
188
187
checkServerVersion (2.6 );
189
188
assumeTrue (isReplicaSet (cleanupMongo ));
190
189
191
- ServerAddress primary = new ServerAddress ("localhost" );
190
+ ServerAddress primary = new ServerAddress (getPrimaryAsString ( cleanupMongo ) );
192
191
MongoClient rsClient = new MongoClient (getMongoClientURI ());
193
192
DB rsDatabase = rsClient .getDB (database .getName ());
194
193
DBCollection aggCollection = rsDatabase .getCollection (collection .getName ());
@@ -205,25 +204,27 @@ public void testDollarOutOnSecondary() throws UnknownHostException {
205
204
}
206
205
207
206
@ Test
208
- @ Ignore
209
207
public void testAggregateOnSecondary () throws UnknownHostException {
210
208
checkServerVersion (2.6 );
211
209
assumeTrue (isReplicaSet (cleanupMongo ));
212
210
213
- ServerAddress primary = new ServerAddress ("localhost" );
214
- ServerAddress secondary = new ServerAddress ("localhost" , 27018 );
211
+ ServerAddress primary = new ServerAddress (getPrimaryAsString ( cleanupMongo ) );
212
+ ServerAddress secondary = new ServerAddress (getASecondaryAsString ( cleanupMongo ) );
215
213
MongoClient rsClient = new MongoClient (asList (primary , secondary ));
216
214
DB rsDatabase = rsClient .getDB (database .getName ());
217
215
rsDatabase .dropDatabase ();
218
216
DBCollection aggCollection = rsDatabase .getCollection (collection .getName ());
219
217
aggCollection .drop ();
220
218
221
- final List <DBObject > pipeline = new ArrayList <DBObject >(prepareData ());
219
+ List <DBObject > pipeline = new ArrayList <DBObject >(prepareData ());
222
220
AggregationOptions options = AggregationOptions .builder ()
223
221
.outputMode (OutputMode .INLINE )
224
222
.build ();
225
- Cursor cursor = verify (pipeline , options , ReadPreference .secondary (), aggCollection );
223
+ Cursor cursor = aggCollection . aggregate (pipeline , options , ReadPreference .secondary ());
226
224
assertNotEquals (primary , cursor .getServerAddress ());
225
+
226
+ AggregationOutput aggregationOutput = aggCollection .aggregate (pipeline , ReadPreference .secondary ());
227
+ assertNotEquals (primary , aggregationOutput .getServerUsed ());
227
228
}
228
229
229
230
@ Test
0 commit comments