summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/index_check9.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/noPassthroughWithMongod/index_check9.js')
-rw-r--r--jstests/noPassthroughWithMongod/index_check9.js218
1 files changed, 109 insertions, 109 deletions
diff --git a/jstests/noPassthroughWithMongod/index_check9.js b/jstests/noPassthroughWithMongod/index_check9.js
index 3271d7245f5..a801b473a44 100644
--- a/jstests/noPassthroughWithMongod/index_check9.js
+++ b/jstests/noPassthroughWithMongod/index_check9.js
@@ -5,135 +5,135 @@ Random.setRandomSeed();
t = db.test_index_check9;
function doIt() {
+ t.drop();
-t.drop();
+ function sort() {
+ var sort = {};
+ for (var i = 0; i < n; ++i) {
+ sort[fields[i]] = Random.rand() > 0.5 ? 1 : -1;
+ }
+ return sort;
+ }
-function sort() {
- var sort = {};
- for( var i = 0; i < n; ++i ) {
- sort[ fields[ i ] ] = Random.rand() > 0.5 ? 1 : -1;
- }
- return sort;
-}
+ var fields = ['a', 'b', 'c', 'd', 'e'];
+ n = Random.randInt(5) + 1;
+ var idx = sort();
-var fields = [ 'a', 'b', 'c', 'd', 'e' ];
-n = Random.randInt( 5 ) + 1;
-var idx = sort();
+ var chars = "abcdefghijklmnopqrstuvwxyz";
+ var alphas = [];
+ for (var i = 0; i < n; ++i) {
+ alphas.push(Random.rand() > 0.5);
+ }
-var chars = "abcdefghijklmnopqrstuvwxyz";
-var alphas = [];
-for( var i = 0; i < n; ++i ) {
- alphas.push( Random.rand() > 0.5 );
-}
-
-t.ensureIndex( idx );
+ t.ensureIndex(idx);
-function obj() {
- var ret = {};
- for( var i = 0; i < n; ++i ) {
- ret[ fields[ i ] ] = r( alphas[ i ] );
+ function obj() {
+ var ret = {};
+ for (var i = 0; i < n; ++i) {
+ ret[fields[i]] = r(alphas[i]);
+ }
+ return ret;
}
- return ret;
-}
-function r( alpha ) {
- if ( !alpha ) {
- return Random.randInt( 10 );
- } else {
- var len = Random.randInt( 10 );
- buf = "";
- for( var i = 0; i < len; ++i ) {
- buf += chars.charAt( Random.randInt( chars.length ) );
+ function r(alpha) {
+ if (!alpha) {
+ return Random.randInt(10);
+ } else {
+ var len = Random.randInt(10);
+ buf = "";
+ for (var i = 0; i < len; ++i) {
+ buf += chars.charAt(Random.randInt(chars.length));
+ }
+ return buf;
}
- return buf;
}
-}
-function check() {
- var v = t.validate();
- if ( !t.valid ) {
- printjson( t );
- assert( t.valid );
- }
- var spec = {};
- for( var i = 0; i < n; ++i ) {
- var predicateType = Random.randInt( 4 );
- switch( predicateType ) {
- case 0 /* range */ : {
- var bounds = [ r( alphas[ i ] ), r( alphas[ i ] ) ];
- if ( bounds[ 0 ] > bounds[ 1 ] ) {
- bounds.reverse();
- }
- var s = {};
- if ( Random.rand() > 0.5 ) {
- s[ "$gte" ] = bounds[ 0 ];
- } else {
- s[ "$gt" ] = bounds[ 0 ];
- }
- if ( Random.rand() > 0.5 ) {
- s[ "$lte" ] = bounds[ 1 ];
- } else {
- s[ "$lt" ] = bounds[ 1 ];
- }
- spec[ fields[ i ] ] = s;
- break;
+ function check() {
+ var v = t.validate();
+ if (!t.valid) {
+ printjson(t);
+ assert(t.valid);
}
- case 1 /* $in */ : {
- var vals = [];
- var inLength = Random.randInt( 15 );
- for( var j = 0; j < inLength; ++j ) {
- vals.push( r( alphas[ i ] ) );
+ var spec = {};
+ for (var i = 0; i < n; ++i) {
+ var predicateType = Random.randInt(4);
+ switch (predicateType) {
+ case 0 /* range */: {
+ var bounds = [r(alphas[i]), r(alphas[i])];
+ if (bounds[0] > bounds[1]) {
+ bounds.reverse();
+ }
+ var s = {};
+ if (Random.rand() > 0.5) {
+ s["$gte"] = bounds[0];
+ } else {
+ s["$gt"] = bounds[0];
+ }
+ if (Random.rand() > 0.5) {
+ s["$lte"] = bounds[1];
+ } else {
+ s["$lt"] = bounds[1];
+ }
+ spec[fields[i]] = s;
+ break;
+ }
+ case 1 /* $in */: {
+ var vals = [];
+ var inLength = Random.randInt(15);
+ for (var j = 0; j < inLength; ++j) {
+ vals.push(r(alphas[i]));
+ }
+ spec[fields[i]] = {
+ $in: vals
+ };
+ break;
+ }
+ case 2 /* equality */: {
+ spec[fields[i]] = r(alphas[i]);
+ break;
+ }
+ default /* no predicate */:
+ break;
}
- spec[ fields[ i ] ] = { $in: vals };
- break;
- }
- case 2 /* equality */ : {
- spec[ fields[ i ] ] = r( alphas[ i ] );
- break;
- }
- default /* no predicate */ :
- break;
}
+ s = sort();
+ c1 = t.find(spec, {_id: null}).sort(s).hint(idx).toArray();
+ c2 = t.find(spec, {_id: null}).sort(s).hint({$natural: 1}).toArray();
+ count = t.count(spec);
+ assert.eq(c1, c2);
+ assert.eq(c2.length, count);
}
- s = sort();
- c1 = t.find( spec, { _id:null } ).sort( s ).hint( idx ).toArray();
- c2 = t.find( spec, { _id:null } ).sort( s ).hint( {$natural:1} ).toArray();
- count = t.count( spec );
- assert.eq( c1, c2 );
- assert.eq( c2.length, count );
-}
-var bulk = t.initializeUnorderedBulkOp();
-for( var i = 0; i < 10000; ++i ) {
- bulk.insert( obj() );
- if( Random.rand() > 0.999 ) {
- print( i );
- assert.writeOK(bulk.execute());
- check();
- bulk = t.initializeUnorderedBulkOp();
+ var bulk = t.initializeUnorderedBulkOp();
+ for (var i = 0; i < 10000; ++i) {
+ bulk.insert(obj());
+ if (Random.rand() > 0.999) {
+ print(i);
+ assert.writeOK(bulk.execute());
+ check();
+ bulk = t.initializeUnorderedBulkOp();
+ }
}
-}
-bulk = t.initializeUnorderedBulkOp();
-for( var i = 0; i < 100000; ++i ) {
- if ( Random.rand() > 0.9 ) {
- bulk.insert( obj() );
- } else {
- bulk.find( obj() ).remove(); // improve
- }
- if( Random.rand() > 0.999 ) {
- print( i );
- assert.writeOK(bulk.execute());
- check();
- bulk = t.initializeUnorderedBulkOp();
+ bulk = t.initializeUnorderedBulkOp();
+ for (var i = 0; i < 100000; ++i) {
+ if (Random.rand() > 0.9) {
+ bulk.insert(obj());
+ } else {
+ bulk.find(obj()).remove(); // improve
+ }
+ if (Random.rand() > 0.999) {
+ print(i);
+ assert.writeOK(bulk.execute());
+ check();
+ bulk = t.initializeUnorderedBulkOp();
+ }
}
-}
-assert.writeOK(bulk.execute());
-
-check();
+ assert.writeOK(bulk.execute());
+ check();
}
-for( var z = 0; z < 5; ++z ) {
+for (var z = 0; z < 5; ++z) {
doIt();
}