summaryrefslogtreecommitdiff
path: root/jstests/concurrency
diff options
context:
space:
mode:
authorKamran Khan <kamran.khan@mongodb.com>2015-06-05 13:02:03 -0400
committerKamran Khan <kamran.khan@mongodb.com>2015-06-05 13:02:03 -0400
commit1cf11a282870c26ce7d963fb3a6c3329b39d90a2 (patch)
tree92a097894dc69a57f97295e907e37dc99343613d /jstests/concurrency
parent99dff01e969a8f8bd06e0f064ad42ca06f2c0a2c (diff)
downloadmongo-1cf11a282870c26ce7d963fb3a6c3329b39d90a2.tar.gz
SERVER-18178 Convert the mr_drop.js test to an FSM workload
The FSM workload interleaves mapReduce commands, collection drops, and database drops to verify server availability when drops occur during various mapReduce phases.
Diffstat (limited to 'jstests/concurrency')
-rw-r--r--jstests/concurrency/fsm_workloads/map_reduce_drop.js118
1 files changed, 118 insertions, 0 deletions
diff --git a/jstests/concurrency/fsm_workloads/map_reduce_drop.js b/jstests/concurrency/fsm_workloads/map_reduce_drop.js
new file mode 100644
index 00000000000..193debd6301
--- /dev/null
+++ b/jstests/concurrency/fsm_workloads/map_reduce_drop.js
@@ -0,0 +1,118 @@
+'use strict';
+
+/**
+ * map_reduce_drop.js
+ *
+ * This workload generates random data and inserts it into a collection.
+ * It then runs simultaneous mapReduce commands while dropping the source
+ * collection or source database. It repopulates the data before each
+ * mapReduce in an attempt to ensure that the mapReduce commands are
+ * actually doing work.
+ *
+ * This workload serves as a regression test for SERVER-6757, SERVER-15087,
+ * and SERVER-15842.
+ */
+
+var $config = (function() {
+
+ // Use a unique database name for this workload because we'll be dropping
+ // the db periodically. (Using the default database would cause other
+ // workloads to fail when running multiple workloads in parallel or in
+ // composed mode.)
+ var uniqueDBName = 'map_reduce_drop';
+
+ var data = {
+ mapper: function mapper() {
+ emit(this.key, 1);
+ },
+ reducer: function reducer() {
+ // This dummy reducer is present to enable the database and collection
+ // drops to occur during different phases of the mapReduce.
+ return 1;
+ },
+ numDocs: 250
+ };
+
+ var states = (function() {
+
+ function dropColl(db, collName) {
+ var mapReduceDB = db.getSiblingDB(uniqueDBName);
+
+ // We don't check the return value of drop() because the collection
+ // might not exist due to a drop() in another thread.
+ mapReduceDB[collName].drop();
+ }
+
+ function dropDB(db, collName) {
+ var mapReduceDB = db.getSiblingDB(uniqueDBName);
+
+ var res = mapReduceDB.dropDatabase();
+ assertAlways.commandWorked(res);
+ }
+
+ function mapReduce(db, collName) {
+ var mapReduceDB = db.getSiblingDB(uniqueDBName);
+
+ // Try to ensure that some documents have been inserted before running
+ // the mapReduce command. Although it's possible for the documents to
+ // be dropped by another thread, some mapReduce commands should end up
+ // running on non-empty collections by virtue of the number of
+ // iterations and threads in this workload.
+ var bulk = mapReduceDB[collName].initializeUnorderedBulkOp();
+ for (var i = 0; i < this.numDocs; ++i) {
+ bulk.insert({ key: Random.randInt(10000) });
+ }
+ var res = bulk.execute();
+ assertAlways.writeOK(res);
+
+ var options = {
+ finalize: function finalize(key, reducedValue) {
+ return reducedValue;
+ },
+ out: collName + '_out'
+ };
+
+ try {
+ mapReduceDB[collName].mapReduce(this.mapper, this.reducer, options);
+ }
+ catch (e) {
+ // Ignore all mapReduce exceptions. This workload is only concerned
+ // with verifying server availability.
+ }
+ }
+
+ return {
+ dropColl: dropColl,
+ dropDB: dropDB,
+ mapReduce: mapReduce
+ };
+
+ })();
+
+ var transitions = {
+ dropColl: { mapReduce: 1 },
+ dropDB: { mapReduce: 1 },
+ mapReduce: { mapReduce: 0.7, dropDB: 0.05, dropColl: 0.25 }
+ };
+
+ function teardown(db, collName, cluster) {
+ var mapReduceDB = db.getSiblingDB(uniqueDBName);
+
+ // Ensure that the database that was created solely for this workload
+ // has been dropped, in case it hasn't already been dropped by a
+ // worker thread.
+ var res = mapReduceDB.dropDatabase();
+ assertAlways.commandWorked(res);
+ }
+
+ return {
+ threadCount: 5,
+ iterations: 10,
+ data: data,
+ states: states,
+ startState: 'mapReduce',
+ transitions: transitions,
+ teardown: teardown
+ };
+
+})();