@@ -113,6 +113,44 @@ public void testSecondaryReads2() throws Exception {
113
113
verifySecondaryCounts (secondaryCount , testHosts );
114
114
}
115
115
116
+ @ Test (groups = {"basic" })
117
+ public void testSecondaryReads3 () throws Exception {
118
+
119
+ final Mongo mongo = loadMongo ();
120
+
121
+ final CommandResult result = serverStatusCmd (mongo );
122
+
123
+ // If the result is null, this is not a replica set.
124
+ if (result == null ) return ;
125
+
126
+ final List <TestHost > testHosts = new ArrayList <TestHost >();
127
+ final String primaryHostnameAndPort = extractHosts (result , testHosts );
128
+ final DBCollection col = loadCleanDbCollection (mongo );
129
+
130
+ final List <ObjectId > insertedIds = insertTestData (col );
131
+
132
+ // Get the opcounter/query data for the hosts.
133
+ loadQueryCount (testHosts , true );
134
+
135
+ final int secondaryCount = getSecondaryCount (testHosts );
136
+
137
+ // Perform some reads on the secondaries
138
+ col .getDB ().setReadPreference (ReadPreference .SECONDARY );
139
+
140
+ for (int idx =0 ; idx < ITERATION_COUNT ; idx ++) {
141
+ for (ObjectId id : insertedIds ) {
142
+ final BasicDBObject doc = (BasicDBObject )col .findOne (new BasicDBObject ("_id" , id ));
143
+ if (doc == null ) throw new IllegalStateException ("Doc not found" );
144
+ if (!doc .getObjectId ("_id" ).equals (id )) throw new IllegalStateException ("Ids are off" );
145
+ }
146
+ }
147
+
148
+ loadQueryCount (testHosts , false );
149
+
150
+ verifySecondaryCounts (secondaryCount , testHosts );
151
+ }
152
+
153
+
116
154
private Mongo loadMongo () throws Exception {
117
155
return new Mongo (new MongoURI ("mongodb://127.0.0.1:27017,127.0.0.1:27018" ));
118
156
}
0 commit comments