2012-07-12 10:33:10 -07:00
|
|
|
// SERVER-6366
|
|
|
|
|
// relates to SERVER-808
|
|
|
|
|
//
|
|
|
|
|
// This file tests that options are not restored upon
|
|
|
|
|
// mongorestore with --noOptionsRestore
|
|
|
|
|
//
|
|
|
|
|
// It checks that this works both when doing a full
|
|
|
|
|
// database dump/restore and when doing it just for a
|
|
|
|
|
// single db or collection.
|
|
|
|
|
|
2014-12-10 15:23:12 -05:00
|
|
|
|
2012-07-12 10:33:10 -07:00
|
|
|
t = new ToolTest( "dumprestoreWithNoOptions" );
|
|
|
|
|
|
|
|
|
|
t.startDB( "foo" );
|
|
|
|
|
db = t.db;
|
|
|
|
|
|
2014-04-29 11:01:09 -04:00
|
|
|
// We turn this off to prevent the server from touching the 'options' field in system.namespaces.
|
|
|
|
|
// This is important because we check exact values of the 'options' field in this test.
|
|
|
|
|
db.adminCommand({setParameter:1, newCollectionsUsePowerOf2Sizes: false});
|
|
|
|
|
|
2012-07-12 10:33:10 -07:00
|
|
|
dbname = db.getName();
|
|
|
|
|
dbname2 = "NOT_"+dbname;
|
|
|
|
|
|
|
|
|
|
db.dropDatabase();
|
|
|
|
|
|
2015-02-17 18:20:42 -05:00
|
|
|
var defaultFlags = {}
|
2014-11-24 15:03:19 -05:00
|
|
|
|
2014-02-18 21:57:01 -05:00
|
|
|
var options = { capped: true, size: 4096, autoIndexId: true };
|
2012-07-12 10:33:10 -07:00
|
|
|
db.createCollection('capped', options);
|
2014-11-05 17:13:33 -05:00
|
|
|
assert.eq( 1, db.capped.getIndexes().length, "auto index not created" );
|
2012-07-12 10:33:10 -07:00
|
|
|
var cappedOptions = db.capped.exists().options;
|
|
|
|
|
for ( var opt in options ) {
|
2014-02-18 21:57:01 -05:00
|
|
|
assert.eq(options[opt], cappedOptions[opt],
|
|
|
|
|
'invalid option:' + tojson(options) + " " + tojson(cappedOptions));
|
2012-07-12 10:33:10 -07:00
|
|
|
}
|
2014-05-14 14:11:11 -04:00
|
|
|
assert.writeOK(db.capped.insert({ x: 1 }));
|
2012-07-12 10:33:10 -07:00
|
|
|
|
|
|
|
|
// Full dump/restore
|
|
|
|
|
|
|
|
|
|
t.runTool( "dump" , "--out" , t.ext );
|
|
|
|
|
|
|
|
|
|
db.dropDatabase();
|
|
|
|
|
assert.eq( 0, db.capped.count(), "capped not dropped");
|
2014-11-05 17:13:33 -05:00
|
|
|
assert.eq( 0, db.capped.getIndexes().length, "indexes not dropped" );
|
2012-07-12 10:33:10 -07:00
|
|
|
|
2014-12-10 15:23:12 -05:00
|
|
|
t.runTool( "restore" , "--dir" , t.ext , "--noOptionsRestore");
|
2012-07-12 10:33:10 -07:00
|
|
|
|
|
|
|
|
assert.eq( 1, db.capped.count() , "wrong number of docs restored to capped" );
|
|
|
|
|
assert(true !== db.capped.stats().capped, "restore options were not ignored");
|
2014-11-24 15:03:19 -05:00
|
|
|
assert.eq( defaultFlags, db.capped.exists().options,
|
2014-02-18 21:57:01 -05:00
|
|
|
"restore options not ignored: " + tojson( db.capped.exists() ) );
|
2012-07-12 10:33:10 -07:00
|
|
|
|
|
|
|
|
// Dump/restore single DB
|
|
|
|
|
|
|
|
|
|
db.dropDatabase();
|
2014-02-18 21:57:01 -05:00
|
|
|
var options = { capped: true, size: 4096, autoIndexId: true };
|
2012-07-12 10:33:10 -07:00
|
|
|
db.createCollection('capped', options);
|
2014-11-05 17:13:33 -05:00
|
|
|
assert.eq( 1, db.capped.getIndexes().length, "auto index not created" );
|
2012-07-12 10:33:10 -07:00
|
|
|
var cappedOptions = db.capped.exists().options;
|
|
|
|
|
for ( var opt in options ) {
|
|
|
|
|
assert.eq(options[opt], cappedOptions[opt], 'invalid option')
|
|
|
|
|
}
|
2014-05-14 14:11:11 -04:00
|
|
|
assert.writeOK(db.capped.insert({ x: 1 }));
|
2012-07-12 10:33:10 -07:00
|
|
|
|
|
|
|
|
dumppath = t.ext + "noOptionsSingleDump/";
|
|
|
|
|
mkdir(dumppath);
|
|
|
|
|
t.runTool( "dump" , "-d", dbname, "--out" , dumppath );
|
|
|
|
|
|
|
|
|
|
db.dropDatabase();
|
|
|
|
|
assert.eq( 0, db.capped.count(), "capped not dropped");
|
2014-11-05 17:13:33 -05:00
|
|
|
assert.eq( 0, db.capped.getIndexes().length, "indexes not dropped" );
|
2012-07-12 10:33:10 -07:00
|
|
|
|
2014-12-10 15:23:12 -05:00
|
|
|
t.runTool( "restore" , "-d", dbname2, "--dir" , dumppath + dbname, "--noOptionsRestore");
|
2012-07-12 10:33:10 -07:00
|
|
|
|
|
|
|
|
db = db.getSiblingDB(dbname2);
|
|
|
|
|
|
|
|
|
|
assert.eq( 1, db.capped.count() , "wrong number of docs restored to capped" );
|
|
|
|
|
assert(true !== db.capped.stats().capped, "restore options were not ignored");
|
2014-11-24 15:03:19 -05:00
|
|
|
assert.eq( defaultFlags, db.capped.exists().options,
|
2014-10-08 10:57:45 -04:00
|
|
|
"restore options not ignored: " + tojson( db.capped.exists() ) );
|
2012-07-12 10:33:10 -07:00
|
|
|
|
|
|
|
|
// Dump/restore single collection
|
|
|
|
|
|
|
|
|
|
db.dropDatabase();
|
2014-02-18 21:57:01 -05:00
|
|
|
var options = { capped: true, size: 4096, autoIndexId: true };
|
2012-07-12 10:33:10 -07:00
|
|
|
db.createCollection('capped', options);
|
2014-11-05 17:13:33 -05:00
|
|
|
assert.eq( 1, db.capped.getIndexes().length, "auto index not created" );
|
2012-07-12 10:33:10 -07:00
|
|
|
var cappedOptions = db.capped.exists().options;
|
|
|
|
|
for ( var opt in options ) {
|
|
|
|
|
assert.eq(options[opt], cappedOptions[opt], 'invalid option')
|
|
|
|
|
}
|
2014-05-14 14:11:11 -04:00
|
|
|
|
|
|
|
|
assert.writeOK(db.capped.insert({ x: 1 }));
|
2012-07-12 10:33:10 -07:00
|
|
|
|
|
|
|
|
dumppath = t.ext + "noOptionsSingleColDump/";
|
|
|
|
|
mkdir(dumppath);
|
|
|
|
|
dbname = db.getName();
|
|
|
|
|
t.runTool( "dump" , "-d", dbname, "-c", "capped", "--out" , dumppath );
|
|
|
|
|
|
|
|
|
|
db.dropDatabase();
|
|
|
|
|
|
|
|
|
|
assert.eq( 0, db.capped.count(), "capped not dropped");
|
2014-11-05 17:13:33 -05:00
|
|
|
assert.eq( 0, db.capped.getIndexes().length, "indexes not dropped" );
|
2012-07-12 10:33:10 -07:00
|
|
|
|
2014-12-10 15:23:12 -05:00
|
|
|
t.runTool( "restore", "-d", dbname, "--drop", "--noOptionsRestore", dumppath + dbname );
|
2012-07-12 10:33:10 -07:00
|
|
|
|
|
|
|
|
db = db.getSiblingDB(dbname);
|
|
|
|
|
|
|
|
|
|
assert.eq( 1, db.capped.count() , "wrong number of docs restored to capped" );
|
|
|
|
|
assert( true !== db.capped.stats().capped, "restore options were not ignored" );
|
2014-11-24 15:03:19 -05:00
|
|
|
assert.eq( defaultFlags, db.capped.exists().options,
|
2014-10-08 10:57:45 -04:00
|
|
|
"restore options not ignored: " + tojson( db.capped.exists() ) );
|
2012-07-12 10:33:10 -07:00
|
|
|
|
|
|
|
|
t.stop();
|