diff options
Diffstat (limited to 'jstests/tool')
-rw-r--r-- | jstests/tool/csv1.js | 43 | ||||
-rw-r--r-- | jstests/tool/dumprestore1.js | 20 | ||||
-rw-r--r-- | jstests/tool/dumprestore2.js | 26 | ||||
-rw-r--r-- | jstests/tool/exportimport1.js | 20 | ||||
-rw-r--r-- | jstests/tool/exportimport2.js | 24 | ||||
-rw-r--r-- | jstests/tool/tool1.js | 64 |
6 files changed, 197 insertions, 0 deletions
diff --git a/jstests/tool/csv1.js b/jstests/tool/csv1.js new file mode 100644 index 0000000..df8aa10 --- /dev/null +++ b/jstests/tool/csv1.js @@ -0,0 +1,43 @@ +// csv1.js + +t = new ToolTest( "csv1" ) + +c = t.startDB( "foo" ); + +base = { a : 1 , b : "foo,bar" , c: 5 }; + +assert.eq( 0 , c.count() , "setup1" ); +c.insert( base ); +delete base._id +assert.eq( 1 , c.count() , "setup2" ); + +t.runTool( "export" , "--out" , t.extFile , "-d" , t.baseName , "-c" , "foo" , "--csv" , "-f" , "a,b,c" ) + +c.drop() +assert.eq( 0 , c.count() , "after drop" ) + +t.runTool( "import" , "--file" , t.extFile , "-d" , t.baseName , "-c" , "foo" , "--type" , "csv" , "-f" , "a,b,c" ); +assert.soon( "c.findOne()" , "no data after sleep" ); +assert.eq( 2 , c.count() , "after restore 2" ); + +a = c.find().sort( { a : 1 } ).toArray(); +delete a[0]._id +delete a[1]._id +assert.eq( tojson( { a : "a" , b : "b" , c : "c" } ) , tojson( a[1] ) , "csv parse 1" ); +assert.eq( tojson( base ) , tojson(a[0]) , "csv parse 0" ) + +c.drop() +assert.eq( 0 , c.count() , "after drop 2" ) + +t.runTool( "import" , "--file" , t.extFile , "-d" , t.baseName , "-c" , "foo" , "--type" , "csv" , "--headerline" ) +assert.soon( "c.findOne()" , "no data after sleep" ); +assert.eq( 1 , c.count() , "after restore 2" ); + +x = c.findOne() +delete x._id; +assert.eq( tojson( base ) , tojson(x) , "csv parse 2" ) + + + + +t.stop() diff --git a/jstests/tool/dumprestore1.js b/jstests/tool/dumprestore1.js new file mode 100644 index 0000000..73f8fea --- /dev/null +++ b/jstests/tool/dumprestore1.js @@ -0,0 +1,20 @@ +// dumprestore1.js + +t = new ToolTest( "dumprestore1" ); + +c = t.startDB( "foo" ); +assert.eq( 0 , c.count() , "setup1" ); +c.save( { a : 22 } ); +assert.eq( 1 , c.count() , "setup2" ); + +t.runTool( "dump" , "--out" , t.ext ); + +c.drop(); +assert.eq( 0 , c.count() , "after drop" ); + +t.runTool( "restore" , "--dir" , t.ext ); +assert.soon( "c.findOne()" , "no data after sleep" ); +assert.eq( 1 , c.count() , "after restore 2" ); +assert.eq( 22 , c.findOne().a , "after restore 2" ); + +t.stop(); diff --git a/jstests/tool/dumprestore2.js b/jstests/tool/dumprestore2.js new file mode 100644 index 0000000..86e65ae --- /dev/null +++ b/jstests/tool/dumprestore2.js @@ -0,0 +1,26 @@ +// dumprestore2.js + +t = new ToolTest( "dumprestore2" ); + +c = t.startDB( "foo" ); +assert.eq( 0 , c.count() , "setup1" ); +c.save( { a : 22 } ); +assert.eq( 1 , c.count() , "setup2" ); +t.stop(); + +t.runTool( "dump" , "--dbpath" , t.dbpath , "--out" , t.ext ); + +resetDbpath( t.dbpath ); +assert.eq( 0 , listFiles( t.dbpath ).length , "clear" ); + +t.runTool( "restore" , "--dbpath" , t.dbpath , "--dir" , t.ext ); + +listFiles( t.dbpath ).forEach( printjson ) + +c = t.startDB( "foo" ); +assert.soon( "c.findOne()" , "no data after startup" ); +assert.eq( 1 , c.count() , "after restore 2" ); +assert.eq( 22 , c.findOne().a , "after restore 2" ); + +t.stop(); + diff --git a/jstests/tool/exportimport1.js b/jstests/tool/exportimport1.js new file mode 100644 index 0000000..22934fe --- /dev/null +++ b/jstests/tool/exportimport1.js @@ -0,0 +1,20 @@ +// exportimport1.js + +t = new ToolTest( "exportimport1" ); + +c = t.startDB( "foo" ); +assert.eq( 0 , c.count() , "setup1" ); +c.save( { a : 22 } ); +assert.eq( 1 , c.count() , "setup2" ); + +t.runTool( "export" , "--out" , t.extFile , "-d" , t.baseName , "-c" , "foo" ); + +c.drop(); +assert.eq( 0 , c.count() , "after drop" , "-d" , t.baseName , "-c" , "foo" );; + +t.runTool( "import" , "--file" , t.extFile , "-d" , t.baseName , "-c" , "foo" ); +assert.soon( "c.findOne()" , "no data after sleep" ); +assert.eq( 1 , c.count() , "after restore 2" ); +assert.eq( 22 , c.findOne().a , "after restore 2" ); + +t.stop(); diff --git a/jstests/tool/exportimport2.js b/jstests/tool/exportimport2.js new file mode 100644 index 0000000..fbcf239 --- /dev/null +++ b/jstests/tool/exportimport2.js @@ -0,0 +1,24 @@ +// exportimport2.js + +t = new ToolTest( "exportimport2" ); + +c = t.startDB( "foo" ); +assert.eq( 0 , c.count() , "setup1" ); +c.save( { a : 22 } ); +assert.eq( 1 , c.count() , "setup2" ); +t.stop(); + +t.runTool( "export" , "--dbpath" , t.dbpath , "--out" , t.extFile , "-d" , t.baseName , "-c" , "foo" ); + +resetDbpath( t.dbpath ); +assert.eq( 0 , listFiles( t.dbpath ).length , "clear" ); + +t.runTool( "import" , "--dbpath" , t.dbpath , "--file" , t.extFile , "-d" , t.baseName , "-c" , "foo" ); + +c = t.startDB( "foo" ); +assert.soon( "c.findOne()" , "no data after startup" ); +assert.eq( 1 , c.count() , "after restore 2" ); +assert.eq( 22 , c.findOne().a , "after restore 2" ); + +t.stop(); + diff --git a/jstests/tool/tool1.js b/jstests/tool/tool1.js new file mode 100644 index 0000000..00e92e7 --- /dev/null +++ b/jstests/tool/tool1.js @@ -0,0 +1,64 @@ +// mongo tool tests, very basic to start with + +baseName = "jstests_tool_tool1"; +dbPath = "/data/db/" + baseName + "/"; +externalPath = "/data/db/" + baseName + "_external/" +externalFile = externalPath + "export.json" + +function fileSize(){ + var l = listFiles( externalPath ); + for ( var i=0; i<l.length; i++ ){ + if ( l[i].name == externalFile ) + return l[i].size; + } + return -1; +} + + +port = allocatePorts( 1 )[ 0 ]; +resetDbpath( externalPath ); + +m = startMongod( "--port", port, "--dbpath", dbPath, "--nohttpinterface", "--bind_ip", "127.0.0.1" ); +c = m.getDB( baseName ).getCollection( baseName ); +c.save( { a: 1 } ); +assert( c.findOne() ); + +runMongoProgram( "mongodump", "--host", "127.0.0.1:" + port, "--out", externalPath ); +c.drop(); +runMongoProgram( "mongorestore", "--host", "127.0.0.1:" + port, "--dir", externalPath ); +assert.soon( "c.findOne()" , "mongodump then restore has no data w/sleep" ); +assert( c.findOne() , "mongodump then restore has no data" ); +assert.eq( 1 , c.findOne().a , "mongodump then restore has no broken data" ); + +resetDbpath( externalPath ); + +assert.eq( -1 , fileSize() , "mongoexport prep invalid" ); +runMongoProgram( "mongoexport", "--host", "127.0.0.1:" + port, "-d", baseName, "-c", baseName, "--out", externalFile ); +assert.lt( 10 , fileSize() , "file size changed" ); + +c.drop(); +runMongoProgram( "mongoimport", "--host", "127.0.0.1:" + port, "-d", baseName, "-c", baseName, "--file", externalFile ); +assert.soon( "c.findOne()" , "mongo import json A" ); +assert( c.findOne() && 1 == c.findOne().a , "mongo import json B" ); + +stopMongod( port ); +resetDbpath( externalPath ); + +runMongoProgram( "mongodump", "--dbpath", dbPath, "--out", externalPath ); +resetDbpath( dbPath ); +runMongoProgram( "mongorestore", "--dbpath", dbPath, "--dir", externalPath ); +m = startMongoProgram( "mongod", "--port", port, "--dbpath", dbPath, "--nohttpinterface", "--bind_ip", "127.0.0.1" ); +c = m.getDB( baseName ).getCollection( baseName ); +assert.soon( "c.findOne()" , "object missing a" ); +assert( 1 == c.findOne().a, "object wrong" ); + +stopMongod( port ); +resetDbpath( externalPath ); + +runMongoProgram( "mongoexport", "--dbpath", dbPath, "-d", baseName, "-c", baseName, "--out", externalFile ); +resetDbpath( dbPath ); +runMongoProgram( "mongoimport", "--dbpath", dbPath, "-d", baseName, "-c", baseName, "--file", externalFile ); +m = startMongoProgram( "mongod", "--port", port, "--dbpath", dbPath, "--nohttpinterface", "--bind_ip", "127.0.0.1" ); +c = m.getDB( baseName ).getCollection( baseName ); +assert.soon( "c.findOne()" , "object missing b" ); +assert( 1 == c.findOne().a, "object wrong" ); |