@@ -103,40 +103,43 @@ namespace {
103
103
test_conn->findOne (TEST_NS, q);
104
104
}
105
105
106
+ BSONObj makeReadPreferenceObject (ReadPreference rp) {
107
+ switch (rp) {
108
+ case ReadPreference_PrimaryOnly:
109
+ return BSON (" mode" << " primary" );
110
+ case ReadPreference_PrimaryPreferred:
111
+ return BSON (" mode" << " primaryPreferred" );
112
+ case ReadPreference_SecondaryOnly:
113
+ return BSON (" mode" << " secondary" );
114
+ case ReadPreference_SecondaryPreferred:
115
+ return BSON (" mode" << " secondaryPreferred" );
116
+ case ReadPreference_Nearest:
117
+ return BSON (" mode" << " nearest" );
118
+ default :
119
+ return BSONObj ();
120
+ }
121
+ }
122
+
123
+ BSONObj makeTestCommand (const std::string& cmdName, ReadPreference rp) {
124
+ BSONObjBuilder cmd;
125
+ cmd.append (" query" , BSON (cmdName << TEST_COLL));
126
+ cmd.append (" $readPreference" , makeReadPreferenceObject (rp));
127
+ return cmd.obj ();
128
+ }
129
+
106
130
void count (const auto_ptr<DBClientReplicaSet>& test_conn, ReadPreference rp) {
107
- Query q = Query (). readPref (rp, BSONArray ()) ;
108
- test_conn->count (TEST_NS, q, QueryOption_SlaveOk );
131
+ BSONObj ignoredResult ;
132
+ test_conn->runCommand (TEST_DB, makeTestCommand ( " count " , rp), ignoredResult );
109
133
}
110
134
111
135
void distinct (const auto_ptr<DBClientReplicaSet>& test_conn, ReadPreference rp) {
112
- Query q = Query (). readPref (rp, BSONArray ()) ;
113
- test_conn->distinct (TEST_NS, " a " , q );
136
+ BSONObj ignoredResult ;
137
+ test_conn->runCommand (TEST_DB, makeTestCommand ( " distinct " , rp), ignoredResult );
114
138
}
115
139
116
140
void collStats (const auto_ptr<DBClientReplicaSet>& test_conn, ReadPreference rp) {
117
- BSONObjBuilder cmd;
118
- cmd.append (" query" , BSON (" collStats" << TEST_COLL));
119
-
120
- switch (rp) {
121
- case ReadPreference_PrimaryOnly:
122
- cmd.append (" $readPreference" , BSON (" mode" << " primary" ));
123
- break ;
124
- case ReadPreference_PrimaryPreferred:
125
- cmd.append (" $readPreference" , BSON (" mode" << " primaryPreferred" ));
126
- break ;
127
- case ReadPreference_SecondaryOnly:
128
- cmd.append (" $readPreference" , BSON (" mode" << " secondary" ));
129
- break ;
130
- case ReadPreference_SecondaryPreferred:
131
- cmd.append (" $readPreference" , BSON (" mode" << " secondaryPreferred" ));
132
- break ;
133
- case ReadPreference_Nearest:
134
- // for completeness
135
- break ;
136
- }
137
-
138
- BSONObj info;
139
- test_conn->runCommand (TEST_DB, cmd.obj (), info);
141
+ BSONObj ignoredResult;
142
+ test_conn->runCommand (TEST_DB, makeTestCommand (" collStats" , rp), ignoredResult);
140
143
}
141
144
142
145
TEST_F (ReadPreferenceTest, RoutingQuery) {
0 commit comments