~ubuntu-branches/ubuntu/utopic/mongodb/utopic

« back to all changes in this revision

Viewing changes to jstests/mr_killop.js

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-07-03 09:23:46 UTC
  • mfrom: (1.3.10) (44.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20140703092346-c5bvt46wnzougyly
Tags: 1:2.6.3-0ubuntu1
* New upstream stable release:
  - Dropped patches, included upstream:
    + 0003-All-platforms-but-Windows-find-hash-in-std-tr1.patch
    + 0008-Use-system-libstemmer.patch
    + 0011-Use-a-signed-char-to-store-BSONType-enumerations.patch
    + 0001-SERVER-12064-Atomic-operations-for-gcc-non-Intel-arc.patch
    + 0002-SERVER-12065-Support-ARM-and-AArch64-builds.patch
  - d/p/*: Refreshed/rebased remaining patches.
  - Use system provided libyaml-cpp:
    + d/control: Add libyaml-cpp-dev to BD's.
    + d/rules: Enable --with-system-yaml option.
    + d/p/fix-yaml-detection.patch: Fix detection of libyaml-cpp library.
  - d/mongodb-server.mongodb.upstart: Sync changes from upstream.
  - d/control,mongodb-dev.*: Drop mongodb-dev package; it has no reverse
    dependencies and upstream no longer install header files.
  - d/NEWS: Point users to upstream upgrade documentation for upgrades
    from 2.4 to 2.6.
* Merge from Debian unstable.
* d/control: BD on libv8-3.14-dev to ensure that transitioning to new v8
  versions is a explicit action due to changes in behaviour in >= 3.25
  (LP: #1295723).
* d/mongodb-server.prerm: Dropped debug echo call from maintainer script
  (LP: #1294455).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Test killop applied to m/r operations and child ops of m/r operations.
2
 
 
3
 
t = db.jstests_mr_killop;
4
 
t.drop();
5
 
t2 = db.jstests_mr_killop_out;
6
 
t2.drop();
7
 
 
8
 
function debug( x ) {
9
 
//        printjson( x );
10
 
}
11
 
 
12
 
/** @return op code for map reduce op created by spawned shell, or that op's child */
13
 
function op( childLoop ) {
14
 
    p = db.currentOp().inprog;
15
 
    debug( p );
16
 
    for ( var i in p ) {
17
 
        var o = p[ i ];
18
 
        // Identify a map/reduce or where distinct operation by its collection, whether or not
19
 
        // it is currently active.
20
 
        if ( childLoop ) {
21
 
            if ( ( o.active || o.waitingForLock ) &&
22
 
                o.query &&
23
 
                o.query.query &&
24
 
                o.query.query.$where &&
25
 
                o.query.distinct == "jstests_mr_killop" ) {
26
 
                return o.opid;
27
 
            }
28
 
        }
29
 
        else {
30
 
            if ( ( o.active || o.waitingForLock ) &&
31
 
                o.query &&
32
 
                o.query.mapreduce &&
33
 
                o.query.mapreduce == "jstests_mr_killop" ) {
34
 
                return o.opid;
35
 
            }
36
 
        }
37
 
    }
38
 
    return -1;
39
 
}
40
 
 
41
 
/**
42
 
* Run one map reduce with the specified parameters in a parallel shell, kill the
43
 
* map reduce op or its child op with killOp, and wait for the map reduce op to
44
 
* terminate.
45
 
* @param childLoop - if true, a distinct $where op is killed rather than the map reduce op.
46
 
* This is necessay for a child distinct $where of a map reduce op because child
47
 
* ops currently mask parent ops in currentOp.
48
 
*/
49
 
function testOne( map, reduce, finalize, scope, childLoop, wait ) {
50
 
    t.drop();
51
 
    t2.drop();
52
 
    // Ensure we have 2 documents for the reduce to run
53
 
    t.save( {a:1} );
54
 
    t.save( {a:1} );
55
 
    db.getLastError();
56
 
            
57
 
    spec = {
58
 
        mapreduce:"jstests_mr_killop",
59
 
        out:"jstests_mr_killop_out",
60
 
        map: map,
61
 
        reduce: reduce
62
 
    };
63
 
    if ( finalize ) {
64
 
        spec[ "finalize" ] = finalize;
65
 
    }
66
 
    if ( scope ) {
67
 
        spec[ "scope" ] = scope;
68
 
    }
69
 
 
70
 
    // Windows shell strips all double quotes from command line, so use
71
 
    // single quotes.
72
 
    stringifiedSpec = tojson( spec ).toString().replace( /\n/g, ' ' ).replace( /\"/g, "\'" );
73
 
    
74
 
    // The assert below won't be caught by this test script, but it will cause error messages
75
 
    // to be printed.
76
 
    s = startParallelShell( "assert.commandWorked( db.runCommand( " + stringifiedSpec + " ) );" );
77
 
    
78
 
    if ( wait ) {
79
 
        sleep( 2000 );
80
 
    }
81
 
    
82
 
    o = null;
83
 
    assert.soon( function() { o = op( childLoop ); return o != -1 } );
84
 
 
85
 
    res = db.killOp( o );
86
 
    debug( "did kill : " + tojson( res ) );
87
 
    
88
 
    // When the map reduce op is killed, the spawned shell will exit
89
 
    s();
90
 
    debug( "parallel shell completed" );
91
 
    
92
 
    assert.eq( -1, op( childLoop ) );
93
 
}
94
 
 
95
 
/** Test using wait and non wait modes */
96
 
function test( map, reduce, finalize, scope, childLoop ) {
97
 
    testOne( map, reduce, finalize, scope, childLoop, false );
98
 
    testOne( map, reduce, finalize, scope, childLoop, true );
99
 
}
100
 
 
101
 
/** Test looping in map and reduce functions */
102
 
function runMRTests( loop, childLoop ) {
103
 
    test( loop, function( k, v ) { return v[ 0 ]; }, null, null, childLoop );
104
 
    test( function() { emit( this.a, 1 ); }, loop, null, null, childLoop );
105
 
    test( function() { loop(); }, function( k, v ) { return v[ 0 ] },
106
 
         null, { loop: loop }, childLoop );
107
 
}
108
 
 
109
 
/** Test looping in finalize function */
110
 
function runFinalizeTests( loop, childLoop ) {
111
 
    test( function() { emit( this.a, 1 ); }, function( k, v ) { return v[ 0 ] },
112
 
         loop, null, childLoop );
113
 
    test( function() { emit( this.a, 1 ); }, function( k, v ) { return v[ 0 ] },
114
 
         function( a, b ) { loop() }, { loop: loop }, childLoop );
115
 
}
116
 
 
117
 
var loop = function() {
118
 
    while( 1 ) {
119
 
        ;
120
 
    }
121
 
}
122
 
runMRTests( loop, false );
123
 
runFinalizeTests( loop, false );