Skip to content

Commit

Permalink
Added gridstore stream test
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed May 7, 2012
1 parent 38d6a74 commit 948e53c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
18 changes: 18 additions & 0 deletions test/commands_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ exports['Should Correctly Generate a Query Command'] = function(test) {
test.done();
}

// exports['Should Correctly Generate a isMaster command'] = function(test) {
// var full_collection_name = "admin.$cmd";
// var options = QueryCommand.OPTS_NO_CURSOR_TIMEOUT;
// var numberToSkip = 0;
// var numberToReturn = -1;
// var query = {ismaster:1};
// var query_command = new QueryCommand({bson: new BSON([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey])}, full_collection_name, options, numberToSkip, numberToReturn, query, null);
// for(var i = 0; i < query_command.toBinary().length; i++) {
// console.log(query_command.toBinary()[i])
// }
// // // assert the length of the binary
// // test.equal(62, query_command.toBinary().length);
// // // Generate command with return field filter
// // query_command = new QueryCommand({bson: new BSON([Long, ObjectID, Binary, Code, DBRef, Symbol, Double, Timestamp, MaxKey, MinKey])}, full_collection_name, options, numberToSkip, numberToReturn, query, { a : 1, b : 1, c : 1});
// // test.equal(88, query_command.toBinary().length);
// test.done();
// }

/**
* Retrieve the server information for the current
* instance of the db client
Expand Down
1 change: 0 additions & 1 deletion test/find_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,6 @@ exports.shouldCorrectlyFindAndModifyDocument = function(test) {
collection.insert({'a':2, 'b':2}, {safe:true}, function(err, doc) {
// Let's modify the document in place
collection.findAndModify({'a':2}, [['a', 1]], {'$set':{'b':3}}, {safe:true}, function(err, result, object) {
console.dir(object)
test.equal(2, result.a);
test.equal(2, result.b);

Expand Down
46 changes: 46 additions & 0 deletions test/gridstore/grid_store_stream_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,52 @@ exports.shouldCorrectlyReadFileUsingStream = function(test) {
});
});
}

/**
* A simple example showing how to pipe a file stream through from gridfs to a file
*
* @_class gridstore
* @_function stream
* @ignore
*/
exports.shouldCorrectlyPipeAGridFsToAfile = function(test) {
var db = new Db('integration_tests', new Server("127.0.0.1", 27017,
{auto_reconnect: false, poolSize: 1, ssl:useSSL}), {native_parser: native_parser});

// Establish connection to db
db.open(function(err, db) {
// Open a file for writing
var gridStoreWrite = new GridStore(db, "test_gs_read_stream_pipe", "w");
gridStoreWrite.writeFile("./test/gridstore/test_gs_weird_bug.png", function(err, result) {
// Open the gridStore for reading and pipe to a file
var gridStore = new GridStore(db, "test_gs_read_stream_pipe", "r");
gridStore.open(function(err, gridStore) {
// Grab the read stream
var stream = gridStore.stream(true);
// When the stream is finished close the database
stream.on("end", function(err) {
// Read the original content
var originalData = fs.readFileSync("./test/gridstore/test_gs_weird_bug.png");
// Ensure we are doing writing before attempting to open the file
fs.readFile("./test_gs_weird_bug_streamed.tmp", function(err, streamedData) {
// Compare the data
test.deepEqual(originalData, streamedData);

// Close the database
db.close();
test.done();
});
})

// Create a file write stream
var fileStream = fs.createWriteStream("./test_gs_weird_bug_streamed.tmp");
// Pipe out the data
stream.pipe(fileStream);
})
})
});
}


/**
* @ignore
Expand Down

0 comments on commit 948e53c

Please sign in to comment.