File: removec.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (40 lines) | stat: -rw-r--r-- 1,100 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Sanity test for removing documents with adjacent index keys.  SERVER-2008

t = db.jstests_removec;
t.drop();
t.ensureIndex( { a:1 } );

/** @return an array containing a sequence of numbers from i to i + 10. */
function runStartingWith( i ) {
    ret = [];
    for( j = 0; j < 11; ++j ) {
        ret.push( i + j );
    }
    return ret;
}

// Insert some documents with adjacent index keys.
for( i = 0; i < 1100; i += 11 ) {
    t.save( { a:runStartingWith( i ) } );
}
db.getLastError();

// Remove and then reinsert random documents in the background.
s = startParallelShell(
                       't = db.jstests_removec;' +
                       'for( j = 0; j < 1000; ++j ) {' +
                       '    o = t.findOne( { a:Random.randInt( 1100 ) } );' +
                       '    t.remove( { _id:o._id } );' +
                       '    t.insert( o );' +
                       '}'
                       );

// Find operations are error free.
for( i = 0; i < 200; ++i ) {
    t.find( { a:{ $gte:0 } } ).hint( { a:1 } ).itcount();
    assert( !db.getLastError() );
}

s();

t.drop();