Skip to content

Commit

Permalink
CAP-70 Added tests for the distinct command with and without an index
Browse files Browse the repository at this point in the history
  • Loading branch information
sverch committed Jan 10, 2014
1 parent 0dc1601 commit aa020ca
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,52 @@ namespace Commands {
}
}
};

/*
* Performs a distinct command to get the total number of distinct values for the field "x"
*/
struct DistinctWithIndex {
bool readOnly() { return true; }
void reset() {
clearDB();
ensureIndex(-1, BSON("x" << 1));
for (int i = 0; i < iterations; i++) {
insert(-1, BSON("x" << 1));
insert(-1, BSON("x" << 2));
insert(-1, BSON("x" << 3));
}
getLastError();
}
void run(int threadId, int totalThreads){
for (int i = 0; i < iterations / totalThreads; i++) {
command(threadId, BSON("distinct" << _coll << "key" << "x" <<
"query" << BSON("x" << 2)));
}
}
};

/*
* Performs a distinct command to get the total number of distinct values for the field "x"
*/
struct DistinctWithoutIndex {
bool readOnly() { return true; }
void reset() {
clearDB();
for (int i = 0; i < iterations; i++) {
insert(-1, BSON("x" << 1));
insert(-1, BSON("x" << 2));
insert(-1, BSON("x" << 3));
}
getLastError();
}
void run(int threadId, int totalThreads){
for (int i = 0; i < iterations / totalThreads; i++) {
command(threadId, BSON("distinct" << _coll << "key" << "x" <<
"query" << BSON("x" << 2)));
}
}
};

} // namespace Commands

namespace{
Expand Down Expand Up @@ -1679,6 +1725,9 @@ namespace{
add< Commands::CountsFullCollection >();
add< Commands::CountsIntIDRange >();
add< Commands::FindAndModifyInserts >();
add< Commands::DistinctWithIndex >();
add< Commands::DistinctWithoutIndex >();

}
} theTestSuite;
}
Expand Down

0 comments on commit aa020ca

Please sign in to comment.