File: dumprestore4.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 (42 lines) | stat: -rw-r--r-- 1,423 bytes parent folder | download | duplicates (8)
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
// dumprestore4.js -- see SERVER-2186

// The point of this test is to ensure that mongorestore successfully
// constructs indexes when the database being restored into has a
// different name than the database dumped from.  There are 2
// issues here: (1) if you dumped from database "A" and restore into
// database "B", B should have exactly the right indexes; (2) if for
// some reason you have another database called "A" at the time of the
// restore, mongorestore shouldn't touch it.

t = new ToolTest( "dumprestore4" );

c = t.startDB( "dumprestore4" );

db=t.db

dbname = db.getName();
dbname2 = "NOT_"+dbname;

db2=db.getSisterDB( dbname2 );

db.dropDatabase(); // make sure it's empty
db2.dropDatabase(); // make sure everybody's empty

assert.eq( 0 , db.system.indexes.count() , "setup1" );
c.ensureIndex({ x : 1} );
assert.eq( 2 , db.system.indexes.count() , "setup2" ); // _id and x_1

assert.eq( 0, t.runTool( "dump" , "-d" , dbname, "--out", t.ext ), "dump")

// to ensure issue (2), we have to clear out the first db.
// By inspection, db.dropIndexes() doesn't get rid of the _id index on c,
// so we have to drop the collection.
c.drop();
assert.eq( 0, t.runTool( "restore" , "--dir" , t.ext + "/" + dbname, "-d", dbname2 ), "restore" );

// issue (1)
assert.eq( 2 , db2.system.indexes.count() , "after restore 1" );
// issue (2)
assert.eq( 0 , db.system.indexes.count() , "after restore 2" );

t.stop();