cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cassandra-node.apache-extras....@codespot.com
Subject [cassandra-node] push by gdusbabek@gmail.com - Always call the ConnectionPool.shutdown()-callback.... on 2012-01-31 17:30 GMT
Date Tue, 31 Jan 2012 17:31:13 GMT
Revision: 54987ca7733d
Author:   Christoph Tavan <dev@tavan.de>
Date:     Mon Jan 30 13:54:09 2012
Log:      Always call the ConnectionPool.shutdown()-callback.

- If shutting down, the callback is being passed an error.

http://code.google.com/a/apache-extras.org/p/cassandra-node/source/detail?r=54987ca7733d

Modified:
  /lib/driver.js
  /test/test_driver.js

=======================================
--- /lib/driver.js	Mon Jan 30 14:58:56 2012
+++ /lib/driver.js	Mon Jan 30 13:54:09 2012
@@ -742,14 +742,15 @@
  PooledConnection.prototype.shutdown = function(callback) {
    var self = this;

+  callback = callback || function() {};
+
    // Start shutdown mode, causes no new execute()'s to be accepted
    if (self.shuttingDown) {
-    return;
+    var err = new Error('Already shutting down.');
+    return callback(err);
    }
    self.shuttingDown = true;

-  callback = callback || function() {};
-
    // Close all open connections as soon as the pool has drained
    self.once('drain', function() {
      self._closeConnections(function() {
=======================================
--- /test/test_driver.js	Mon Jan 30 14:58:56 2012
+++ /test/test_driver.js	Mon Jan 30 13:54:09 2012
@@ -1083,3 +1083,37 @@
      test.finish();
    });
  };
+
+exports.testPooledConnectionShutdownTwice = function(test, assert) {
+  var hosts = ['127.0.0.1:19170'];
+  var conn = new PooledConnection({'hosts':  
hosts, 'keyspace': 'Keyspace1'});
+
+  var expected = 100;
+  var cbcount = 0;
+  var spy = function(err, res) {
+    assert.ifError(err);
+    cbcount++;
+  };
+
+  for (var i = 0; i < expected; i++) {
+    (function(index) {
+      conn.execute('UPDATE CfUtf8 SET ? = ? WHERE KEY = ?',  
['col', 'val', 'key'+index], spy);
+    })(i);
+  }
+
+  assert.ok(!conn.shuttingDown);
+  conn.shutdown(function(err) {
+    assert.ifError(err);
+    assert.equal(cbcount, expected);
+    assert.ok(secondCbCalledImmediatelyWithError);
+    test.finish();
+  });
+
+  // Make sure second callback gets called immediately with an error
+  var secondCbCalledImmediatelyWithError = false;
+  assert.ok(conn.shuttingDown);
+  conn.shutdown(function(err) {
+    assert.ok(err);
+    secondCbCalledImmediatelyWithError = true;
+  });
+};

Mime
View raw message