1919import com .mongodb .AggregationOptions .OutputMode ;
2020import com .mongodb .util .TestCase ;
2121import org .junit .Before ;
22- import org .junit .Ignore ;
2322import org .junit .Test ;
2423
2524import java .net .UnknownHostException ;
@@ -188,7 +187,7 @@ public void testDollarOutOnSecondary() throws UnknownHostException {
188187 checkServerVersion (2.6 );
189188 assumeTrue (isReplicaSet (cleanupMongo ));
190189
191- ServerAddress primary = new ServerAddress ("localhost" );
190+ ServerAddress primary = new ServerAddress (getPrimaryAsString ( cleanupMongo ) );
192191 MongoClient rsClient = new MongoClient (getMongoClientURI ());
193192 DB rsDatabase = rsClient .getDB (database .getName ());
194193 DBCollection aggCollection = rsDatabase .getCollection (collection .getName ());
@@ -205,25 +204,27 @@ public void testDollarOutOnSecondary() throws UnknownHostException {
205204 }
206205
207206 @ Test
208- @ Ignore
209207 public void testAggregateOnSecondary () throws UnknownHostException {
210208 checkServerVersion (2.6 );
211209 assumeTrue (isReplicaSet (cleanupMongo ));
212210
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 ) );
215213 MongoClient rsClient = new MongoClient (asList (primary , secondary ));
216214 DB rsDatabase = rsClient .getDB (database .getName ());
217215 rsDatabase .dropDatabase ();
218216 DBCollection aggCollection = rsDatabase .getCollection (collection .getName ());
219217 aggCollection .drop ();
220218
221- final List <DBObject > pipeline = new ArrayList <DBObject >(prepareData ());
219+ List <DBObject > pipeline = new ArrayList <DBObject >(prepareData ());
222220 AggregationOptions options = AggregationOptions .builder ()
223221 .outputMode (OutputMode .INLINE )
224222 .build ();
225- Cursor cursor = verify (pipeline , options , ReadPreference .secondary (), aggCollection );
223+ Cursor cursor = aggCollection . aggregate (pipeline , options , ReadPreference .secondary ());
226224 assertNotEquals (primary , cursor .getServerAddress ());
225+
226+ AggregationOutput aggregationOutput = aggCollection .aggregate (pipeline , ReadPreference .secondary ());
227+ assertNotEquals (primary , aggregationOutput .getServerUsed ());
227228 }
228229
229230 @ Test
0 commit comments