YUKI Hiroshi
null+****@clear*****
Fri Oct 17 18:31:42 JST 2014
YUKI Hiroshi 2014-10-17 18:31:42 +0900 (Fri, 17 Oct 2014) New Revision: 556772f8b657f578557461fd5951b13e615e6c21 https://github.com/droonga/express-droonga/commit/556772f8b657f578557461fd5951b13e615e6c21 Message: Use more meaningful name: ConnectionPool. Because it is not just a collection of connections (in the future)! Modified files: index.js lib/adapter/http.js lib/adapter/socket.io.js test/adapter/api/groonga/basic.test.js test/adapter/api/groonga/load.test.js test/adapter/http.test.js test/adapter/http/register.test.js test/adapter/socket.io.test.js test/express-adapter.test.js test/test-utils.js Renamed files: lib/droonga-protocol/connection-pool.js (from lib/droonga-protocol/connections.js) test/droonga-protocol/connection-pool.test.js (from test/droonga-protocol/connections.test.js) Modified: index.js (+7 -7) =================================================================== --- index.js 2014-10-17 18:17:26 +0900 (753de64) +++ index.js 2014-10-17 18:31:42 +0900 (d48b282) @@ -1,5 +1,5 @@ var express = require('express'); -var Connections = require('./lib/droonga-protocol/connections').Connections; +var ConnectionPool = require('./lib/droonga-protocol/connection-pool').ConnectionPool; var httpAdapter = require('./lib/adapter/http'); var socketIoAdapter = require('./lib/adapter/socket.io'); var dashboardUI = require('./lib/ui/dashboard'); @@ -10,8 +10,8 @@ function droonga(application, params) { params.logger = params.logger || new ConsoleLogger(); - params.connections = params.connections || new Connections(params); - var connections = params.connections; + params.connectionPool = params.connectionPool || new ConnectionPool(params); + var connectionPool = params.connectionPool; params.prefix = params.prefix || ''; params.prefix = params.prefix.replace(/\/$/, ''); @@ -21,19 +21,19 @@ function droonga(application, params) { if (params.server) { socketIoAdapter.register(application, params.server, params); params.server.on('error', function(error) { - connections.closeAll(); + connectionPool.closeAll(); }); params.server.on('close', function() { // The connection can be mocked/stubbed. We don't need to close // such a fake connection. - if (typeof connections.closeAll == 'function') - connections.closeAll(); + if (typeof connectionPool.closeAll == 'function') + connectionPool.closeAll(); }); } dashboardUI.register(application, params); - application.connections = connections; + application.connectionPool = connectionPool; } exports.initialize = droonga; Modified: lib/adapter/http.js (+8 -8) =================================================================== --- lib/adapter/http.js 2014-10-17 18:17:26 +0900 (9f285aa) +++ lib/adapter/http.js 2014-10-17 18:31:42 +0900 (fae0099) @@ -5,7 +5,7 @@ var ConsoleLogger = require('../console-logger').ConsoleLogger; function createRequestResponseHandler(params) { params = params || {}; - var connections = params.connections; + var connectionPool = params.connectionPool; var commandName = params.name; var definition = params.definition; var logger = definition.logger; @@ -47,7 +47,7 @@ function createRequestResponseHandler(params) { response.status(error.code || 500).jsonp(errorBody); return; } - var connection = connections.get(); + var connection = connectionPool.get(); var wrappedConnection = new wrapper.DroongaProtocolConnectionWrapper(connection, callback, options); if (definition.onRequest) { try { @@ -70,7 +70,7 @@ exports.createRequestResponseHandler = createRequestResponseHandler; function createGenericHandler(params) { params = params || {}; - var connections = params.connections; + var connectionPool = params.connectionPool; var commandName = params.name; var definition = params.definition; @@ -94,7 +94,7 @@ function createGenericHandler(params) { response.status(error.code || 500).jsonp(errorBody); return; } - var connection = connections.get(); + var connection = connectionPool.get(); var wrappedConnection = new wrapper.DroongaProtocolConnectionWrapper(connection, options); try { definition.onHandle(request, response, wrappedConnection); @@ -124,9 +124,9 @@ exports.getRegistrationMethod = getRegistrationMethod; exports.register = function(application, params) { params = params || {}; - var connections = params.connections; - if (!connections) - throw new Error('Connections to the backend is required!'); + var connectionPool = params.connectionPool; + if (!connectionPool) + throw new Error('ConnectionPool to backends is required!'); var prefix = params.prefix || ''; prefix = prefix.replace(/\/$/, ''); @@ -165,7 +165,7 @@ exports.register = function(application, params) { } var handler = creator({ - connections: connections, + connectionPool: connectionPool, name: definition.command || commandName, definition: definition }); Modified: lib/adapter/socket.io.js (+4 -4) =================================================================== --- lib/adapter/socket.io.js 2014-10-17 18:17:26 +0900 (d8e1301) +++ lib/adapter/socket.io.js 2014-10-17 18:31:42 +0900 (c651abf) @@ -28,13 +28,13 @@ exports.sanitizeBackendMessage = sanitizeBackendMessage; exports.register = function(application, server, params) { params = params || {}; - var connections = params.connections; - if (!connections) - throw new Error('Connections to the backend is required!'); + var connectionPool = params.connectionPool; + if (!connectionPool) + throw new Error('ConnectionPool to backends is required!'); //TODO: we have to support multiple connections!! // this is just workaround: use the first connection always. - var connection = connections.get(); + var connection = connectionPool.get(); function createClientMessageHandler(commandName, commandDefinition, socket, handlerOptions) { handlerOptions = handlerOptions || {}; Renamed: lib/droonga-protocol/connection-pool.js (+12 -10) 74% =================================================================== --- lib/droonga-protocol/connections.js 2014-10-17 18:17:26 +0900 (4343552) +++ lib/droonga-protocol/connection-pool.js 2014-10-17 18:31:42 +0900 (4c33ab3) @@ -1,16 +1,18 @@ /** - * var connections = new Connections({ tag: 'droonga', - * defaultDataset: 'example', - * hostNames: ['127.0.0.1', ...], - * port: 24224, - * receiveHostName: '127.0.0.1', - * receivePort: 10030 }); + * var connectionPool = new ConnectionPool({ + * tag: 'droonga', + * defaultDataset: 'example', + * hostNames: ['127.0.0.1', ...], + * port: 24224, + * receiveHostName: '127.0.0.1', + * receivePort: 10030 + * }); */ var Connection = require('./connection').Connection; var ConsoleLogger = require('../console-logger').ConsoleLogger; -function Connections(params) { +function ConnectionPool(params) { this._params = params || {}; if (!this._params.logger) @@ -35,13 +37,13 @@ function Connections(params) { this._params.hostNames = Object.keys(uniqueHostNames); if (this._params.hostNames.length == 0) - throw new Error('Connections: you must give one or more host name(s)!'); + throw new Error('ConnectionPool: you must give one or more host name(s)!'); this._connections = {}; this._instantiate(); } -Connections.prototype = { +ConnectionPool.prototype = { _instantiate: function() { this._params.hostNames.forEach(function(hostName) { if (this._connections[hostName]) @@ -82,4 +84,4 @@ Connections.prototype = { } }; -exports.Connections = Connections; +exports.ConnectionPool = ConnectionPool; Modified: test/adapter/api/groonga/basic.test.js (+4 -4) =================================================================== --- test/adapter/api/groonga/basic.test.js 2014-10-17 18:17:26 +0900 (e6f1948) +++ test/adapter/api/groonga/basic.test.js 2014-10-17 18:31:42 +0900 (aaf42f7) @@ -9,7 +9,7 @@ var httpAdapter = require('../../../../lib/adapter/http'); var groongaAPI = require('../../../../lib/adapter/api/groonga'); suite('adapter/api/groonga: basic commands', function() { - var connections; + var connectionPool; var application; var server; var backend; @@ -19,11 +19,11 @@ suite('adapter/api/groonga: basic commands', function() { .then(function(result) { backend = result.backend; server = result.server; - connections = result.connections; + connectionPool = result.connectionPool; application = result.application; httpAdapter.register(application, { prefix: '', - connections: connections, + connectionPool: connectionPool, plugins: [groongaAPI] }); done(); @@ -35,7 +35,7 @@ suite('adapter/api/groonga: basic commands', function() { utils.teardownApplication({ backend: backend, server: server, - connections: connections + connectionPool: connectionPool }); }); Modified: test/adapter/api/groonga/load.test.js (+4 -4) =================================================================== --- test/adapter/api/groonga/load.test.js 2014-10-17 18:17:26 +0900 (98deb95) +++ test/adapter/api/groonga/load.test.js 2014-10-17 18:31:42 +0900 (e38e597) @@ -9,7 +9,7 @@ var httpAdapter = require('../../../../lib/adapter/http'); var groongaAPI = require('../../../../lib/adapter/api/groonga'); suite('adapter/api/groonga: load', function() { - var connections; + var connectionPool; var application; var server; var backend; @@ -21,11 +21,11 @@ suite('adapter/api/groonga: load', function() { .then(function(result) { backend = result.backend; server = result.server; - connections = result.connections; + connectionPool = result.connectionPool; application = result.application; httpAdapter.register(application, { prefix: '', - connections: connections, + connectionPool: connectionPool, plugins: [groongaAPI] }); done(); @@ -37,7 +37,7 @@ suite('adapter/api/groonga: load', function() { utils.teardownApplication({ backend: backend, server: server, - connections: connections + connectionPool: connectionPool }); }); Modified: test/adapter/http.test.js (+15 -15) =================================================================== --- test/adapter/http.test.js 2014-10-17 18:17:26 +0900 (bcac847) +++ test/adapter/http.test.js 2014-10-17 18:31:42 +0900 (91ff6c1) @@ -16,7 +16,7 @@ suite('HTTP Adapter', function() { var application = express(); var registeredCommands = httpAdapter.register(application, { prefix: '', - connections: utils.createStubbedBackendConnections(), + connectionPool: utils.createStubbedBackendConnectionPool(), plugins: [ api.API_REST, api.API_SOCKET_IO, @@ -59,7 +59,7 @@ suite('HTTP Adapter', function() { }) }; - var connections; + var connectionPool; var application; var server; var backend; @@ -69,7 +69,7 @@ suite('HTTP Adapter', function() { .then(function(result) { backend = result.backend; server = result.server; - connections = result.connections; + connectionPool = result.connectionPool; application = result.application; done(); }) @@ -79,13 +79,13 @@ suite('HTTP Adapter', function() { teardown(function() { utils.teardownApplication({ backend: backend, server: server, - connections: connections }); + connectionPool: connectionPool }); }); test('to the document root', function(done) { httpAdapter.register(application, { prefix: '', - connections: connections, + connectionPool: connectionPool, plugins: [ api.API_REST, api.API_SOCKET_IO, @@ -118,7 +118,7 @@ suite('HTTP Adapter', function() { test('under specified path', function(done) { httpAdapter.register(application, { prefix: '/path/to/droonga', - connections: connections, + connectionPool: connectionPool, plugins: [ api.API_REST, api.API_SOCKET_IO, @@ -161,12 +161,12 @@ suite('HTTP Adapter', function() { test('search', function(done) { var receiverCallback = {}; - var connections = utils.createStubbedBackendConnections(); - var connection = connections.get(); + var connectionPool = utils.createStubbedBackendConnectionPool(); + var connection = connectionPool.get(); var application = express(); httpAdapter.register(application, { prefix: '', - connections: connections, + connectionPool: connectionPool, plugins: [ api.API_REST ] @@ -204,12 +204,12 @@ suite('HTTP Adapter', function() { test('droonga', function(done) { var receiverCallback = {}; - var connections = utils.createStubbedBackendConnections(); - var connection = connections.get(); + var connectionPool = utils.createStubbedBackendConnectionPool(); + var connection = connectionPool.get(); var application = express(); httpAdapter.register(application, { prefix: '', - connections: connections, + connectionPool: connectionPool, plugins: [ api.API_DROONGA ] @@ -265,11 +265,11 @@ suite('HTTP Adapter', function() { test('round-robin', function(done) { var receiverCallback = {}; - var connections = utils.createStubbedBackendConnections(3); + var connectionPool = utils.createStubbedBackendConnectionPool(3); var application = express(); httpAdapter.register(application, { prefix: '', - connections: connections, + connectionPool: connectionPool, plugins: [ testPlugin ] @@ -289,7 +289,7 @@ suite('HTTP Adapter', function() { .then(function(response) { responses.push(response); }) .then(function() { assert.deepEqual( - connections.connections.map(function(connection) { + connectionPool.connections.map(function(connection) { return connection.emitMessageCalledArguments.map(function(args) { return { type: args.type, Modified: test/adapter/http/register.test.js (+1 -1) =================================================================== --- test/adapter/http/register.test.js 2014-10-17 18:17:26 +0900 (c3fb4b6) +++ test/adapter/http/register.test.js 2014-10-17 18:31:42 +0900 (4c61c33) @@ -52,7 +52,7 @@ suite('adapter/http.register', function() { var application = new StubApplication(); httpAdapter.register(application, { prefix: '', - connections: utils.createStubbedBackendConnections(), + connectionPool: utils.createStubbedBackendConnectionPool(), plugins: plugins }); return application.paths(); Modified: test/adapter/socket.io.test.js (+20 -20) =================================================================== --- test/adapter/socket.io.test.js 2014-10-17 18:17:26 +0900 (2364ee7) +++ test/adapter/socket.io.test.js 2014-10-17 18:31:42 +0900 (25d967b) @@ -10,7 +10,7 @@ var api = require('../../lib/adapter/api'); var scoketIoAPI = require('../../lib/adapter/api/socket.io'); suite('Socket.IO Adapter', function() { - var connections; + var connectionPool; var connection; var server; var clientSockets; @@ -86,7 +86,7 @@ suite('Socket.IO Adapter', function() { } utils.teardownApplication({ backend: backend, server: server, - connections: connections }); + connectionPool: connectionPool }); } suite('registration', function() { @@ -110,10 +110,10 @@ suite('Socket.IO Adapter', function() { utils.setupServer(application) .then(function(newServer) { server = newServer; - connections = utils.createStubbedBackendConnections(); - connection = connections.get(); + connectionPool = utils.createStubbedBackendConnectionPool(); + connection = connectionPool.get(); var registeredCommands = socketIoAdapter.register(application, server, { - connections: connections, + connectionPool: connectionPool, plugins: [ api.API_REST, api.API_SOCKET_IO, @@ -160,10 +160,10 @@ suite('Socket.IO Adapter', function() { utils.setupServer(application) .then(function(newServer) { server = newServer; - connections = utils.createStubbedBackendConnections(); - connection = connections.get(); + connectionPool = utils.createStubbedBackendConnectionPool(); + connection = connectionPool.get(); socketIoAdapter.register(application, server, { - connections: connections, + connectionPool: connectionPool, plugins: [ api.API_REST, api.API_SOCKET_IO, @@ -193,12 +193,12 @@ suite('Socket.IO Adapter', function() { utils.setupApplication() .then(function(result) { server = result.server; - connections = result.connections; - connection = connections.get(); + connectionPool = result.connectionPool; + connection = connectionPool.get(); backend = result.backend; socketIoAdapter.register(result.application, server, { tag: utils.testTag, - connections: connections, + connectionPool: connectionPool, plugins: [ api.API_REST, api.API_SOCKET_IO, @@ -288,12 +288,12 @@ suite('Socket.IO Adapter', function() { utils.setupApplication() .then(function(result) { server = result.server; - connections = result.connections; - connection = connections.get(); + connectionPool = result.connectionPool; + connection = connectionPool.get(); backend = result.backend; socketIoAdapter.register(result.application, server, { tag: utils.testTag, - connections: connections, + connectionPool: connectionPool, plugins: [ api.API_REST, api.API_SOCKET_IO, @@ -367,12 +367,12 @@ suite('Socket.IO Adapter', function() { utils.setupApplication() .then(function(result) { server = result.server; - connections = result.connections; - connection = connections.get(); + connectionPool = result.connectionPool; + connection = connectionPool.get(); backend = result.backend; socketIoAdapter.register(result.application, server, { tag: utils.testTag, - connections: connections, + connectionPool: connectionPool, plugins: [ api.API_REST, api.API_SOCKET_IO, @@ -466,12 +466,12 @@ suite('Socket.IO Adapter', function() { utils.setupApplication() .then(function(result) { server = result.server; - connections = result.connections; - connection = connections.get(); + connectionPool = result.connectionPool; + connection = connectionPool.get(); backend = result.backend; socketIoAdapter.register(result.application, server, { tag: utils.testTag, - connections: connections, + connectionPool: connectionPool, plugins: [ api.API_REST, api.API_SOCKET_IO, Renamed: test/droonga-protocol/connection-pool.test.js (+23 -23) 58% =================================================================== --- test/droonga-protocol/connections.test.js 2014-10-17 18:17:26 +0900 (90c28e6) +++ test/droonga-protocol/connection-pool.test.js 2014-10-17 18:31:42 +0900 (024b19e) @@ -2,91 +2,91 @@ var assert = require('chai').assert; var utils = require('../test-utils'); -var Connections = require('../../lib/droonga-protocol/connections').Connections; +var ConnectionPool = require('../../lib/droonga-protocol/connection-pool').ConnectionPool; -suite('Connections', function() { +suite('ConnectionPool', function() { suite('initialization', function() { - var connections; + var connectionPool; teardown(function() { - if (connections) { - connections.closeAll(); - connections = undefined; + if (connectionPool) { + connectionPool.closeAll(); + connectionPool = undefined; } }); test('single', function() { - connections = new Connections({ + connectionPool = new ConnectionPool({ hostNames: [ '127.0.0.1' ] }); - assert.equal(connections.count, 1); + assert.equal(connectionPool.count, 1); }); test('multiple', function() { - connections = new Connections({ + connectionPool = new ConnectionPool({ hostNames: [ '127.0.0.1', '127.0.0.2' ] }); - assert.equal(connections.count, 2); + assert.equal(connectionPool.count, 2); }); test('duplicated', function() { - connections = new Connections({ + connectionPool = new ConnectionPool({ hostNames: [ '127.0.0.1', '127.0.0.1' ] }); - assert.equal(connections.count, 1); + assert.equal(connectionPool.count, 1); }); }); suite('get', function() { - var connections; + var connectionPool; teardown(function() { - if (connections) { - connections.closeAll(); - connections = undefined; + if (connectionPool) { + connectionPool.closeAll(); + connectionPool = undefined; } }); test('single', function() { - connections = new Connections({ + connectionPool = new ConnectionPool({ hostNames: [ '127.0.0.1' ] }); - var connection = connections.get(); + var connection = connectionPool.get(); assert.isNotNull(connection); assert.equal(connection.hostName, '127.0.0.1'); }); test('multiple', function() { - connections = new Connections({ + connectionPool = new ConnectionPool({ hostNames: [ '127.0.0.1', '127.0.0.2', '127.0.0.3' ] }); - var connection = connections.get(); + var connection = connectionPool.get(); assert.isNotNull(connection); assert.equal(connection.hostName, '127.0.0.1'); - connection = connections.get(); + connection = connectionPool.get(); assert.isNotNull(connection); assert.equal(connection.hostName, '127.0.0.2'); - connection = connections.get(); + connection = connectionPool.get(); assert.isNotNull(connection); assert.equal(connection.hostName, '127.0.0.3'); - connection = connections.get(); + connection = connectionPool.get(); assert.isNotNull(connection); assert.equal(connection.hostName, '127.0.0.1'); }); Modified: test/express-adapter.test.js (+9 -9) =================================================================== --- test/express-adapter.test.js 2014-10-17 18:17:26 +0900 (f3143ee) +++ test/express-adapter.test.js 2014-10-17 18:31:42 +0900 (4391244) @@ -32,7 +32,7 @@ suite('Adaption for express application', function() { suite('REST API registeration', function() { var backend; - var connections; + var connectionPool; var application; var server; @@ -41,7 +41,7 @@ suite('Adaption for express application', function() { .then(function(result) { backend = result.backend; server = result.server; - connections = result.connections; + connectionPool = result.connectionPool; application = result.application; done(); }) @@ -51,13 +51,13 @@ suite('Adaption for express application', function() { teardown(function() { utils.teardownApplication({ backend: backend, server: server, - connections: connections }); + connectionPool: connectionPool }); }); test('to the document root', function(done) { application.droonga({ prefix: '', - connections: connections, + connectionPool: connectionPool, plugins: [testRestPlugin, testSocketPlugin] }); @@ -82,7 +82,7 @@ suite('Adaption for express application', function() { test('under specified path', function(done) { application.droonga({ prefix: '/path/to/droonga', - connections: connections, + connectionPool: connectionPool, plugins: [testRestPlugin, testSocketPlugin] }); @@ -112,7 +112,7 @@ suite('Adaption for express application', function() { suite('Socket.IO API registeration', function() { var application; - var connections; + var connectionPool; var server; var clientSocket; var backend; @@ -122,7 +122,7 @@ suite('Adaption for express application', function() { .then(function(result) { backend = result.backend; server = result.server; - connections = result.connections; + connectionPool = result.connectionPool; application = result.application; done(); }) @@ -136,12 +136,12 @@ suite('Adaption for express application', function() { } utils.teardownApplication({ backend: backend, server: server, - connections: connections }); + connectionPool: connectionPool }); }); test('request-response', function(done) { application.droonga({ - connections: connections, + connectionPool: connectionPool, server: server, plugins: [testRestPlugin, testSocketPlugin] }); Modified: test/test-utils.js (+10 -10) =================================================================== --- test/test-utils.js 2014-10-17 18:17:26 +0900 (40ca3fd) +++ test/test-utils.js 2014-10-17 18:31:42 +0900 (1db8348) @@ -12,7 +12,7 @@ var FluentReceiver = require('../lib/droonga-protocol/receiver').FluentReceiver; exports.FluentReceiver = FluentReceiver; var Connection = require('../lib/droonga-protocol/connection').Connection; -var Connections = require('../lib/droonga-protocol/connections').Connections; +var ConnectionPool = require('../lib/droonga-protocol/connection-pool').ConnectionPool; var ConsoleLogger = require('../lib/console-logger').ConsoleLogger; var logger = new ConsoleLogger(); @@ -239,7 +239,7 @@ function createStubbedBackendConnection(hostName) { } exports.createStubbedBackendConnection = createStubbedBackendConnection; -function createStubbedBackendConnections(count) { +function createStubbedBackendConnectionPool(count) { count = count || 1; var connections = []; for (var i = 0; i < count; i++) { @@ -260,7 +260,7 @@ function createStubbedBackendConnections(count) { connections: connections }; } -exports.createStubbedBackendConnections = createStubbedBackendConnections; +exports.createStubbedBackendConnectionPool = createStubbedBackendConnectionPool; function setupApplication() { var application = express(); @@ -273,7 +273,7 @@ function setupApplication() { .then(exports.createBackendCb()) .then(function(newBackend) { backend = newBackend; - var connections = new Connections({ + var connectionPool = new ConnectionPool({ tag: testTag, defaultDataset: 'test-dataset', hostName: ['127.0.0.1'], @@ -286,7 +286,7 @@ function setupApplication() { backend: backend, server: server, application: application, - connections: connections + connectionPool: connectionPool }; }); } @@ -299,12 +299,12 @@ function teardownApplication(params) { params.backend.close(); params.backend = undefined; } - if (params.application && params.application.connections) { - params.application.connections.closeAll(); + if (params.application && params.application.connectionPool) { + params.application.connectionPool.closeAll(); params.application = undefined; - } else if (params.connections) { - params.connections.closeAll(); - params.connections = undefined; + } else if (params.connectionPool) { + params.connectionPool.closeAll(); + params.connectionPool = undefined; } if (params.server) { params.server.close(); -------------- next part -------------- HTML����������������������������... Descargar