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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
// dumprestore8.js
// This file tests that indexes and capped collection options get properly dumped and restored.
// It checks that this works both when doing a full database dump/restore and when doing it just for a single db or collection
t = new ToolTest( "dumprestore8" );
t.startDB( "foo" );
db = t.db;
dbname = db.getName();
dbname2 = "NOT_"+dbname;
db.dropDatabase();
assert.eq( 0 , db.foo.count() , "setup1" );
db.foo.save( { a : 1, b : 1 } );
db.foo.ensureIndex({a:1});
db.foo.ensureIndex({b:1, _id:-1});
assert.eq( 1 , db.foo.count() , "setup2" );
assert.eq( 0 , db.bar.count() , "setup3" );
db.createCollection("bar", {capped:true, size:1000});
for (var i = 0; i < 1000; i++) {
db.bar.save( { x : i } );
}
db.bar.ensureIndex({x:1});
barDocCount = db.bar.count();
assert.gt( barDocCount, 0 , "No documents inserted" );
assert.lt( db.bar.count(), 1000 , "Capped collection didn't evict documents" );
assert.eq( 5 , db.system.indexes.count() , "Indexes weren't created right" );
// Full dump/restore
t.runTool( "dump" , "--out" , t.ext );
db.dropDatabase();
assert.eq( 0 , db.foo.count() , "foo not dropped" );
assert.eq( 0 , db.bar.count() , "bar not dropped" );
assert.eq( 0 , db.system.indexes.count() , "indexes not dropped" );
t.runTool( "restore" , "--dir" , t.ext );
assert.soon( "db.foo.findOne()" , "no data after sleep" );
assert.eq( 1 , db.foo.count() , "wrong number of docs restored to foo" );
assert.eq( barDocCount, db.bar.count(), "wrong number of docs restored to bar" );
for (var i = 0; i < 10; i++) {
db.bar.save({x:i});
}
assert.eq( barDocCount, db.bar.count(), "Capped collection didn't evict documents after restore." );
assert.eq( 5 , db.system.indexes.count() , "Indexes weren't created correctly by restore" );
// Dump/restore single DB
dumppath = t.ext + "singledbdump/";
mkdir(dumppath);
t.runTool( "dump" , "-d", dbname, "--out" , dumppath );
db.dropDatabase();
assert.eq( 0 , db.foo.count() , "foo not dropped2" );
assert.eq( 0 , db.bar.count() , "bar not dropped2" );
assert.eq( 0 , db.system.indexes.count() , "indexes not dropped2" );
t.runTool( "restore" , "-d", dbname2, "--dir" , dumppath + dbname );
db = db.getSiblingDB(dbname2);
assert.soon( "db.foo.findOne()" , "no data after sleep 2" );
assert.eq( 1 , db.foo.count() , "wrong number of docs restored to foo 2" );
assert.eq( barDocCount, db.bar.count(), "wrong number of docs restored to bar 2" );
for (var i = 0; i < 10; i++) {
db.bar.save({x:i});
}
assert.eq( barDocCount, db.bar.count(), "Capped collection didn't evict documents after restore 2." );
assert.eq( 5 , db.system.indexes.count() , "Indexes weren't created correctly by restore 2" );
// Dump/restore single collection
dumppath = t.ext + "singlecolldump/";
mkdir(dumppath);
t.runTool( "dump" , "-d", dbname2, "-c", "bar", "--out" , dumppath );
db.dropDatabase();
assert.eq( 0 , db.bar.count() , "bar not dropped3" );
assert.eq( 0 , db.system.indexes.count() , "indexes not dropped3" );
t.runTool( "restore" , "-d", dbname, "-c", "baz", "--dir" , dumppath + dbname2 + "/bar.bson" );
db = db.getSiblingDB(dbname);
assert.soon( "db.baz.findOne()" , "no data after sleep 2" );
assert.eq( barDocCount, db.baz.count(), "wrong number of docs restored to bar 2" );
for (var i = 0; i < 10; i++) {
db.baz.save({x:i});
}
assert.eq( barDocCount, db.baz.count(), "Capped collection didn't evict documents after restore 3." );
assert.eq( 2 , db.system.indexes.count() , "Indexes weren't created correctly by restore 3" );
t.stop();
|