[Groonga-commit] droonga/express-droonga at 9dbe5c7 [master] Add a test for ConnectionPool#fetchCatalog

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Oct 30 15:08:56 JST 2014


YUKI Hiroshi	2014-10-30 15:08:56 +0900 (Thu, 30 Oct 2014)

  New Revision: 9dbe5c702cc23530112c72a978bf1d794d8c6f27
  https://github.com/droonga/express-droonga/commit/9dbe5c702cc23530112c72a978bf1d794d8c6f27

  Message:
    Add a test for ConnectionPool#fetchCatalog

  Modified files:
    test/droonga-protocol/connection-pool.test.js
    test/test-utils.js

  Modified: test/droonga-protocol/connection-pool.test.js (+51 -0)
===================================================================
--- test/droonga-protocol/connection-pool.test.js    2014-10-30 15:07:42 +0900 (b56316a)
+++ test/droonga-protocol/connection-pool.test.js    2014-10-30 15:08:56 +0900 (3a08e07)
@@ -4,6 +4,15 @@ var utils = require('../test-utils');
 
 var ConnectionPool = require('../../lib/droonga-protocol/connection-pool').ConnectionPool;
 
+function singleVolumeWithHostName(hostname, localPath) {
+  localPath = localPath || '000';
+  return {
+    volume: {
+      address: hostname + ':10031/droonga.' + localPath
+    }
+  };
+}
+
 suite('ConnectionPool', function() {
   suite('initialization', function() {
     var connectionPool;
@@ -168,4 +177,46 @@ suite('ConnectionPool', function() {
                         false]);
     });
   });
+
+  suite('communication with the backend', function() {
+    var connectionPool;
+
+    setup(function() {
+      connectionPool = new ConnectionPool({
+        hostNames: [
+          '127.0.0.1'
+        ],
+        connectionClass: utils.ConnectionStub
+      });
+      connectionPool.get().addResult({
+        version: 2,
+        datasets: {
+          main: {
+            replicas: [
+              singleVolumeWithHostName('127.0.0.2'),
+              singleVolumeWithHostName('127.0.0.3')
+            ]
+          }
+        }
+      });
+    });
+
+    teardown(function() {
+      if (connectionPool) {
+        connectionPool.closeAll();
+        connectionPool = undefined;
+      }
+    });
+
+    test('fetchCatalog', function(done) {
+      connectionPool.fetchCatalog()
+        .then(function(catalog) {
+          assert.deepEqual(catalog.allHostNames,
+                           ['127.0.0.2',
+                            '127.0.0.3']);
+          done();
+        })
+        .catch(done);
+    });
+  });
 });

  Modified: test/test-utils.js (+17 -1)
===================================================================
--- test/test-utils.js    2014-10-30 15:07:42 +0900 (a35e2cc)
+++ test/test-utils.js    2014-10-30 15:08:56 +0900 (ed96de7)
@@ -248,6 +248,14 @@ function createStubbedBackendConnection(hostName) {
       return hostName + ':' + testReceivePort + '/' + testTag;
     },
 
+    thenableEmitMessage: function(type, message, options) {
+      return Q.Promise((function(resolve, reject, notify) {
+        this.emitMessage(type, message, function(errorCode, response) {
+          resolve({ errorCode: errorCode, response: response });
+        }, options);
+      }).bind(this));
+    },
+
     emit: function() {},
     on: function() {},
     removeListener: function() {},
@@ -261,11 +269,19 @@ function createStubbedBackendConnection(hostName) {
           message: args.message
         };
       });
-    }
+    },
+    addResult: function(body) {
+      this._toBeReturnedResults.push(body);
+    },
+    _toBeReturnedResults: []
   };
 }
 exports.createStubbedBackendConnection = createStubbedBackendConnection;
 
+exports.ConnectionStub = function(params) {
+  return createStubbedBackendConnection(params.hostName);
+};
+
 function createStubbedBackendConnectionPool(count) {
   count = count || 1;
   var connections = [];
-------------- next part --------------
HTML����������������������������...
다운로드 



More information about the Groonga-commit mailing list
Back to archive index