File: grow_hash_table.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 (45 lines) | stat: -rw-r--r-- 1,490 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
41
42
43
44
45
// This test creates a large projection, which causes a set of field names to
// be stored in a StringMap (based on UnorderedFastKeyTable).  The hash table
// starts with 20 slots, but must be grown repeatedly to hold the complete set
// of fields.  This test verifies that we can grow the hash table repeatedly
// with no failures.
//
// Related to SERVER-9824.

var testDB = db.getSiblingDB('grow_hash_table');

var doTest = function(count) {
    print('Testing with count of ' + count);
    testDB.dropDatabase();
    var id = { data: 1 };
    var doc = { _id: id };
    var projection = { };

    // Create a document and a projection with fields r1, r2, r3 ...
    for (var i = 1; i <= count; ++i) {
        var r = 'r' + i;
        doc[r] = i;
        projection[r] = 1;
    }

    // Store the document
    testDB.collection.insert(doc);
    var errorObj = testDB.getLastErrorObj();
    assert(errorObj.err == null,
           'Failed to insert document, getLastErrorObj = ' + tojsononeline(errorObj));

    // Try to read the document using a large projection
    try {
        var findCount = testDB.collection.find({ _id: id }, projection).itcount();
        assert(findCount == 1,
               'Failed to find single stored document, find().itcount() == ' + findCount);
    }
    catch (e) {
        testDB.dropDatabase();
        doassert('Test FAILED!  Caught exception ' + tojsononeline(e));
    }
    testDB.dropDatabase();
    jsTest.log('Test PASSED');
}

doTest(10000);