Skip to content

Commit

Permalink
SERVER-32755 Expand unique index microbenchmark coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sulabhM committed Mar 5, 2018
1 parent 1c2adce commit edc96ac
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
73 changes: 73 additions & 0 deletions testcases/simple_insert.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,76 @@ tests.push( { name: "Insert.LargeDocVector",
doc: docs }
] } );

/*
* Setup: Create an empty collection and a unique index on a field.
* Test: Insert documents into collection using sequential int for the indexed
* field.
* Notes: Let mongod create missing _id field
*
*/
tests.push( { name: "Insert.UniqueIndex",
tags: ['insert','uniqueidx', 'regression'],
pre: function( collection ) {
var testDB = collection.getDB();
var collName = collection.getName();
collection.drop();
testDB.createCollection( collName );
collection.ensureIndex( { a: 1 }, { unique: true } );
},
ops: [
{ op: "insert",
doc:
{ a: { "#SEQ_INT":
{ seq_id: 0, start: 0, step: 1, unique: true } } } }
] } );

/*
* Setup: Create an empty collection and a unique compound index on two fields.
* Test: Insert documents into collection using sequential int for the indexed
* fields.
* Notes: Let mongod create missing _id field
*
*/
tests.push( { name: "Insert.UniqueIndexCompound",
tags: ['insert','uniqueidx','regression'],
pre: function( collection ) {
var testDB = collection.getDB();
var collName = collection.getName();
collection.drop();
testDB.createCollection( collName );
collection.ensureIndex( { a: 1, b: 1 }, { unique: true } );
},
ops: [
{ op: "insert",
doc:
{ a: { "#SEQ_INT":
{ seq_id: 0, start: 0, step: 1, unique: true } },
b: { "#SEQ_INT":
{ seq_id: 0, start: 0, step: 1, unique: true } } } }
] } );

/*
* Setup: Create an empty collection and a unique compound index on two fields,
* with different ordering for both the fields.
* Test: Insert documents into collection using sequential int for the indexed
* fields.
* Notes: Let mongod create missing _id field
*
*/
tests.push( { name: "Insert.UniqueIndexCompoundReverse",
tags: ['insert','uniqueidx','regression'],
pre: function( collection ) {
var testDB = collection.getDB();
var collName = collection.getName();
collection.drop();
testDB.createCollection( collName );
collection.ensureIndex( { a: 1, b: -1 }, { unique: true } );
},
ops: [
{ op: "insert",
doc:
{ a: { "#SEQ_INT":
{ seq_id: 0, start: 0, step: 1, unique: true } },
b: { "#SEQ_INT":
{ seq_id: 0, start: 0, step: 1, unique: true } } } }
] } );
26 changes: 26 additions & 0 deletions testcases/simple_remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,29 @@ tests.push( { name: "Remove.IntNonIdIndex",
{ op: "insert",
doc: { x : { "#VARIABLE" : "x" } } },
] } );

/*
* Setup: Populate a collection with an integer field of unique values
* Create a unique index on the integer field
* Test: Each thread works in a range of 100 documents; remove (and re-insert)
* a random document in its range based on the indexed integer field
*/
tests.push( { name: "Remove.IntNonIdUniqueIndex",
tags: ['remove','uniqueidx','regression'],
pre: function( collection ) {
collection.drop();
var docs = [];
for ( var i = 0; i < 4800; i++ ) {
docs.push( { x : i } );
}
collection.insert(docs);
collection.getDB().getLastError();
collection.ensureIndex( { x : 1 }, { unique: true } );
},
ops: [
{ op: "let", target: "x", value: {"#RAND_INT_PLUS_THREAD": [0,100]}},
{ op: "remove",
query: { x : { "#VARIABLE" : "x" } } },
{ op: "insert",
doc: { x : { "#VARIABLE" : "x" } } },
] } );
49 changes: 49 additions & 0 deletions testcases/simple_update.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,52 @@ tests.push( { name: "Update.MatchedElementWithinArray",
}}
},
] } );

/**
* Setup: Populate a collection with an integer field X set to 0 and an
* incrementing integer field A. Create a unique index on A.
* Test: Each thread works in a range of 100 documents; randomly selects a
* document using field A and increments X.
*/
tests.push( { name: "Update.UniqueIndex",
tags: ['update','uniqueidx','regression'],
pre: function( collection ) {
collection.drop();
var docs = [];
for ( var i = 0; i < 4800; i++ ) {
docs.push( { a : i, x : 0 } );
}
collection.insert(docs);
collection.getDB().getLastError();
collection.ensureIndex( { a: 1 }, { unique: true } );
},
ops: [
{ op: "update",
query: { a : { "#RAND_INT_PLUS_THREAD" : [ 0, 100 ] } },
update: { $inc : { x : 1 } } },
] } );

/**
* Setup: Populate a collection with an integer field X set to 0 and two
* incrementing integer fields A, B. Create a unique compound index on
* fields A and B, with reverse ordering for A than B.
* Test: Each thread works in a range of 100 documents; randomly selects a
* document using field A and increments X.
*/
tests.push( { name: "Update.UniqueIndexCompoundReverse",
tags: ['update','uniqueidx','regression'],
pre: function( collection ) {
collection.drop();
var docs = [];
for ( var i = 0; i < 4800; i++ ) {
docs.push( { a : i, b : i, x : 0 } );
}
collection.insert(docs);
collection.getDB().getLastError();
collection.ensureIndex( { a: -1, b: 1 }, { unique: true } );
},
ops: [
{ op: "update",
query: { a : { "#RAND_INT_PLUS_THREAD" : [ 0, 100 ] } },
update: { $inc : { x : 1 } } },
] } );

0 comments on commit edc96ac

Please sign in to comment.