summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/top_rename.js
blob: acdb47837a3f2f537d1cced98cba13749e131f7a (plain)
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
41
42
43
44
45
46
47
48
49
50
/**
 * Ensures that the data managed by Top is removed for the source namespace when renaming the
 * collection.
 */
(function() {

load("jstests/libs/stats.js");

const dbName = "top_rename";
const sourceCollection = "source";
const destCollection = "dest";
const mapReduceCollection = "final";

const testDB = db.getSiblingDB(dbName);
testDB.getCollection(sourceCollection).drop();
testDB.getCollection(destCollection).drop();
testDB.getCollection(mapReduceCollection).drop();

assert.commandWorked(testDB.createCollection(sourceCollection));
assert.doesNotThrow(() => {
    getTop(testDB.getCollection(sourceCollection));
});

assert.commandWorked(testDB.adminCommand(
    {renameCollection: dbName + "." + sourceCollection, to: dbName + "." + destCollection}));
assert.throws(() => {
    getTop(testDB.getCollection(sourceCollection));
});

// Perform an operation on the renamed collection so that it is present in the "top" command's
// output.
assert.commandWorked(testDB.getCollection(destCollection).insert({}));
assert.doesNotThrow(() => {
    getTop(testDB.getCollection(destCollection));
});

// MapReduce creates temporary collections before renaming them in place. Test that these temporary
// collections are not kept in Top's output after the command finishes.
assert.commandWorked(
    testDB.getCollection(destCollection)
        .mapReduce(function() {}, function() {}, {out: {merge: mapReduceCollection}}));

const top = testDB.adminCommand("top");
assert.commandWorked(top);

const mapReduceTmp = ".tmp.";
for (const collection in top.totals) {
    assert.eq(false, collection.includes(mapReduceTmp));
}
}());