Skip to content

Commit

Permalink
Starting refactoring to allow for connection pooling
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed May 27, 2011
1 parent 13076d9 commit efc840c
Show file tree
Hide file tree
Showing 25 changed files with 502 additions and 233 deletions.
418 changes: 313 additions & 105 deletions lib/mongodb/connection.js

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions lib/mongodb/connections/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var Server = exports.Server = function(host, port, options) {
};

Server.prototype.close = function(callback) {
this.connection.close(callback);
this.internalConnection.close(callback);
};

Server.prototype.send = function(command) {
Expand All @@ -35,7 +35,7 @@ Server.prototype.isConnected = function() {

Server.prototype.connect = function(parent, callback) {
var server = this;
this.connection = new Connection(this.host, this.port, this.autoReconnect);
server.connection = new Connection(this.host, this.port, this.autoReconnect);
server.connection.on("connect", function() {
// Create a callback function for a given connection
var connectCallback = function(err, reply) {
Expand Down Expand Up @@ -102,8 +102,4 @@ Server.prototype.checkoutWriter = function() {

Server.prototype.checkoutReader = function() {
return this.connection;
}

Server.prototype.close = function() {
this.connection.close();
}
}
12 changes: 6 additions & 6 deletions test/admin_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: fal
var tests = testCase({
setUp: function(callback) {
client.open(function(err, db_p) {
if(numberOfTestsRun == 0) {
// client.dropDatabase(function(err, done) {
if(numberOfTestsRun == Object.keys(tests).length) {
// If first test drop the db
client.dropDatabase(function(err, done) {
callback();
// });
});
} else {
// Start tests
callback();
}
return callback();
}
});
},

Expand Down
12 changes: 6 additions & 6 deletions test/authentication_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: fal
var tests = testCase({
setUp: function(callback) {
client.open(function(err, db_p) {
if(numberOfTestsRun == 0) {
// client.dropDatabase(function(err, done) {
if(numberOfTestsRun == Object.keys(tests).length) {
// If first test drop the db
client.dropDatabase(function(err, done) {
callback();
// });
});
} else {
// Start tests
callback();
}
return callback();
}
});
},

Expand Down
12 changes: 6 additions & 6 deletions test/collection_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: fal
var tests = testCase({
setUp: function(callback) {
client.open(function(err, db_p) {
if(numberOfTestsRun == 0) {
// client.dropDatabase(function(err, done) {
if(numberOfTestsRun == Object.keys(tests).length) {
// If first test drop the db
client.dropDatabase(function(err, done) {
callback();
// });
});
} else {
// Start tests
callback();
}
return callback();
}
});
},

Expand Down
12 changes: 6 additions & 6 deletions test/cursor_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: fal
var tests = testCase({
setUp: function(callback) {
client.open(function(err, db_p) {
if(numberOfTestsRun == 0) {
// client.dropDatabase(function(err, done) {
if(numberOfTestsRun == Object.keys(tests).length) {
// If first test drop the db
client.dropDatabase(function(err, done) {
callback();
// });
});
} else {
// Start tests
callback();
}
return callback();
}
});
},

Expand Down
12 changes: 6 additions & 6 deletions test/custom_pk_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: fal
var tests = testCase({
setUp: function(callback) {
client.open(function(err, db_p) {
if(numberOfTestsRun == 0) {
// client.dropDatabase(function(err, done) {
if(numberOfTestsRun == Object.keys(tests).length) {
// If first test drop the db
client.dropDatabase(function(err, done) {
callback();
// });
});
} else {
// Start tests
callback();
}
return callback();
}
});
},

Expand Down
12 changes: 6 additions & 6 deletions test/db_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: fal
var tests = testCase({
setUp: function(callback) {
client.open(function(err, db_p) {
if(numberOfTestsRun == 0) {
// client.dropDatabase(function(err, done) {
if(numberOfTestsRun == Object.keys(tests).length) {
// If first test drop the db
client.dropDatabase(function(err, done) {
callback();
// });
});
} else {
// Start tests
callback();
}
return callback();
}
});
},

Expand Down
12 changes: 6 additions & 6 deletions test/error_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: fal
var tests = testCase({
setUp: function(callback) {
client.open(function(err, db_p) {
if(numberOfTestsRun == 0) {
// client.dropDatabase(function(err, done) {
if(numberOfTestsRun == Object.keys(tests).length) {
// If first test drop the db
client.dropDatabase(function(err, done) {
callback();
// });
});
} else {
// Start tests
callback();
}
return callback();
}
});
},

Expand Down
12 changes: 6 additions & 6 deletions test/find_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: fal
var tests = testCase({
setUp: function(callback) {
client.open(function(err, db_p) {
if(numberOfTestsRun == 0) {
// client.dropDatabase(function(err, done) {
if(numberOfTestsRun == Object.keys(tests).length) {
// If first test drop the db
client.dropDatabase(function(err, done) {
callback();
// });
});
} else {
// Start tests
callback();
}
return callback();
}
});
},

Expand Down
12 changes: 6 additions & 6 deletions test/gridstore/grid_store_file_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: fal
var tests = testCase({
setUp: function(callback) {
client.open(function(err, db_p) {
if(numberOfTestsRun == 0) {
// client.dropDatabase(function(err, done) {
if(numberOfTestsRun == Object.keys(tests).length) {
// If first test drop the db
client.dropDatabase(function(err, done) {
callback();
// });
});
} else {
// Start tests
callback();
}
return callback();
}
});
},

Expand Down
12 changes: 6 additions & 6 deletions test/gridstore/grid_store_stream_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: fal
var tests = testCase({
setUp: function(callback) {
client.open(function(err, db_p) {
if(numberOfTestsRun == 0) {
// client.dropDatabase(function(err, done) {
if(numberOfTestsRun == Object.keys(tests).length) {
// If first test drop the db
client.dropDatabase(function(err, done) {
callback();
// });
});
} else {
// Start tests
callback();
}
return callback();
}
});
},

Expand Down
12 changes: 6 additions & 6 deletions test/gridstore/grid_store_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: fal
var tests = testCase({
setUp: function(callback) {
client.open(function(err, db_p) {
if(numberOfTestsRun == 0) {
// client.dropDatabase(function(err, done) {
if(numberOfTestsRun == Object.keys(tests).length) {
// If first test drop the db
client.dropDatabase(function(err, done) {
callback();
// });
});
} else {
// Start tests
callback();
}
return callback();
}
});
},

Expand Down
12 changes: 6 additions & 6 deletions test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: fal
var tests = testCase({
setUp: function(callback) {
client.open(function(err, db_p) {
if(numberOfTestsRun == 0) {
// client.dropDatabase(function(err, done) {
if(numberOfTestsRun == Object.keys(tests).length) {
// If first test drop the db
client.dropDatabase(function(err, done) {
callback();
// });
});
} else {
// Start tests
callback();
}
return callback();
}
});
},

Expand Down
13 changes: 8 additions & 5 deletions test/insert_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: fal
var tests = testCase({
setUp: function(callback) {
client.open(function(err, db_p) {
if(numberOfTestsRun > 0) return callback();
// If first test drop the db
// client.dropDatabase(function(err, done) {
callback();
// });
if(numberOfTestsRun == Object.keys(tests).length) {
// If first test drop the db
client.dropDatabase(function(err, done) {
callback();
});
} else {
return callback();
}
});
},

Expand Down
12 changes: 6 additions & 6 deletions test/map_reduce_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: fal
var tests = testCase({
setUp: function(callback) {
client.open(function(err, db_p) {
if(numberOfTestsRun == 0) {
// client.dropDatabase(function(err, done) {
if(numberOfTestsRun == Object.keys(tests).length) {
// If first test drop the db
client.dropDatabase(function(err, done) {
callback();
// });
});
} else {
// Start tests
callback();
}
return callback();
}
});
},

Expand Down
12 changes: 6 additions & 6 deletions test/objectid_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: fal
var tests = testCase({
setUp: function(callback) {
client.open(function(err, db_p) {
if(numberOfTestsRun == 0) {
// client.dropDatabase(function(err, done) {
if(numberOfTestsRun == Object.keys(tests).length) {
// If first test drop the db
client.dropDatabase(function(err, done) {
callback();
// });
});
} else {
// Start tests
callback();
}
return callback();
}
});
},

Expand Down
12 changes: 6 additions & 6 deletions test/regexp_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: fal
var tests = testCase({
setUp: function(callback) {
client.open(function(err, db_p) {
if(numberOfTestsRun == 0) {
// client.dropDatabase(function(err, done) {
if(numberOfTestsRun == Object.keys(tests).length) {
// If first test drop the db
client.dropDatabase(function(err, done) {
callback();
// });
});
} else {
// Start tests
callback();
}
return callback();
}
});
},

Expand Down
12 changes: 6 additions & 6 deletions test/remove_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ var client = new Db(MONGODB, new Server("127.0.0.1", 27017, {auto_reconnect: fal
var tests = testCase({
setUp: function(callback) {
client.open(function(err, db_p) {
if(numberOfTestsRun == 0) {
// client.dropDatabase(function(err, done) {
if(numberOfTestsRun == Object.keys(tests).length) {
// If first test drop the db
client.dropDatabase(function(err, done) {
callback();
// });
});
} else {
// Start tests
callback();
}
return callback();
}
});
},

Expand Down
Loading

0 comments on commit efc840c

Please sign in to comment.