summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/directoryperdb.js
blob: 2421dc231728a91614c41fe3a945257f82a18eeb (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
(function() {
    'use strict';

    var baseDir = "jstests_directoryperdb";
    var dbpath = MongoRunner.dataPath + baseDir + "/";

    var isDirectoryPerDBSupported =
        jsTest.options().storageEngine == "mmapv1" ||
        jsTest.options().storageEngine == "wiredTiger" ||
        !jsTest.options().storageEngine;

    var m = MongoRunner.runMongod({
        dbpath: dbpath,
        directoryperdb: ''});

    if (!isDirectoryPerDBSupported) {
        assert.isnull(m, 'storage engine without directoryperdb support should fail to start up');
        return;
    }
    else {
        assert(m, 'storage engine with directoryperdb support failed to start up');
    }

    var db = m.getDB( "foo" );
    db.bar.insert( { x : 1 } );
    assert.eq( 1, db.bar.count() );

    db.adminCommand( {fsync:1} );
    var dbpathFiles = listFiles(dbpath);
    var files = dbpathFiles.filter( function(z) {
        return z.name.endsWith( "/foo" );
    } );
    assert.eq(1, files.length,
              'dbpath does not contain "foo" directory: ' + tojson(dbpathFiles));

    files = listFiles( files[0].name );
    assert( files.length > 0 );

    MongoRunner.stopMongod(m.port);

    // Subsequent attempt to start server using same dbpath without directoryperdb should fail.
    assert.isnull(MongoRunner.runMongod({
        dbpath: dbpath,
        restart: true}));
}());