2009-05-20 17:29:40 +02:00
|
|
|
// mongo tool tests, very basic to start with
|
|
|
|
|
|
|
|
baseName = "jstests_tool_tool1";
|
2013-09-26 03:59:42 +02:00
|
|
|
dbPath = MongoRunner.dataPath + baseName + "/";
|
|
|
|
externalPath = MongoRunner.dataPath + baseName + "_external/";
|
2013-10-30 22:17:16 +01:00
|
|
|
externalBaseName = "export.json";
|
|
|
|
externalFile = externalPath + externalBaseName;
|
2009-05-20 17:29:40 +02:00
|
|
|
|
2009-08-24 17:54:44 +02:00
|
|
|
function fileSize(){
|
|
|
|
var l = listFiles( externalPath );
|
|
|
|
for ( var i=0; i<l.length; i++ ){
|
2013-10-30 22:17:16 +01:00
|
|
|
if ( l[i].baseName == externalBaseName )
|
2009-08-24 17:54:44 +02:00
|
|
|
return l[i].size;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-20 17:29:40 +02:00
|
|
|
port = allocatePorts( 1 )[ 0 ];
|
2009-05-20 18:16:25 +02:00
|
|
|
resetDbpath( externalPath );
|
2009-05-20 17:29:40 +02:00
|
|
|
|
2010-10-29 19:38:13 +02:00
|
|
|
m = startMongod( "--port", port, "--dbpath", dbPath, "--nohttpinterface", "--noprealloc" , "--bind_ip", "127.0.0.1" );
|
2009-05-20 17:29:40 +02:00
|
|
|
c = m.getDB( baseName ).getCollection( baseName );
|
|
|
|
c.save( { a: 1 } );
|
2009-08-24 17:54:44 +02:00
|
|
|
assert( c.findOne() );
|
2009-05-20 17:29:40 +02:00
|
|
|
|
2009-08-24 17:54:44 +02:00
|
|
|
runMongoProgram( "mongodump", "--host", "127.0.0.1:" + port, "--out", externalPath );
|
2009-05-20 17:29:40 +02:00
|
|
|
c.drop();
|
2009-08-24 17:54:44 +02:00
|
|
|
runMongoProgram( "mongorestore", "--host", "127.0.0.1:" + port, "--dir", externalPath );
|
2009-08-27 19:45:31 +02:00
|
|
|
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" );
|
2009-05-20 17:29:40 +02:00
|
|
|
|
|
|
|
resetDbpath( externalPath );
|
|
|
|
|
2009-08-24 17:54:44 +02:00
|
|
|
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" );
|
|
|
|
|
2009-05-20 17:29:40 +02:00
|
|
|
c.drop();
|
2009-10-09 20:55:29 +02:00
|
|
|
runMongoProgram( "mongoimport", "--host", "127.0.0.1:" + port, "-d", baseName, "-c", baseName, "--file", externalFile );
|
2009-08-28 19:35:08 +02:00
|
|
|
assert.soon( "c.findOne()" , "mongo import json A" );
|
|
|
|
assert( c.findOne() && 1 == c.findOne().a , "mongo import json B" );
|