diff --git a/lib/gearmanode/client.js b/lib/gearmanode/client.js index bd49403..44e6053 100644 --- a/lib/gearmanode/client.js +++ b/lib/gearmanode/client.js @@ -24,7 +24,8 @@ var util = require('util'), Job = require('./job').Job, lb = require('./load-balancing'), protocol = require('./protocol'), - common = require('./common'); + common = require('./common'), + JS_CONSTANTS = require('./job-server').CONSTANTS; /** @@ -50,7 +51,7 @@ var Client = exports.Client = function(options) { if (options.hasOwnProperty('loadBalancing')) { delete options.loadBalancing; } if (options.hasOwnProperty('recoverTime')) { delete options.recoverTime; } - returned = common.verifyAndSanitizeOptions(clientOptions, { loadBalancing: 'Sequence', recoverTime: 30000 }); + returned = common.verifyAndSanitizeOptions(clientOptions, { loadBalancing: 'Sequence', recoverTime: JS_CONSTANTS.DEFAULT_RECOVER_TIME }); if (returned instanceof Error) { return returned; } this._type = 'Client'; diff --git a/lib/gearmanode/job-server.js b/lib/gearmanode/job-server.js index fab392c..4960895 100644 --- a/lib/gearmanode/job-server.js +++ b/lib/gearmanode/job-server.js @@ -27,6 +27,12 @@ var net = require('net'), common = require('./common'); +// constants +var constants = exports.CONSTANTS = { + DEFAULT_RECOVER_TIME: 30000 +}; + + /** * @class JobServer * @classdesc A class representing an abstraction to Gearman job server (gearmand). diff --git a/lib/gearmanode/load-balancing.js b/lib/gearmanode/load-balancing.js index 7d523dc..1ebbe15 100644 --- a/lib/gearmanode/load-balancing.js +++ b/lib/gearmanode/load-balancing.js @@ -6,9 +6,10 @@ * */ -var util = require('util'), - winston = require('winston'), - common = require('./common'); +var util = require('util'), + winston = require('winston'), + common = require('./common'); + JS_CONSTANTS = require('./job-server').CONSTANTS; // After what time [s] can be a failed node reused in load balancing. @@ -17,7 +18,7 @@ var util = require('util'), /** * Constructor. - * + * * @params nodeCount count of nodes to be balanced */ var LBStrategy = function(nodeCount) { @@ -25,7 +26,7 @@ var LBStrategy = function(nodeCount) { this.nodeCount = nodeCount; this.badNodes = {}; - this.recoverTime = 30000; + this.recoverTime = JS_CONSTANTS.DEFAULT_RECOVER_TIME; }; /** Static logger. */ @@ -42,7 +43,7 @@ LBStrategy.prototype.nextIndex = common.abstractMethod; /** * Marks an index as good that means it can be used for next server calls. - * + * * @param idx index to be marked as good */ LBStrategy.prototype.goodOne = function(idx) { @@ -106,7 +107,7 @@ LBStrategy.prototype._searchNextGood = function (badIdx) { /** * Implementation of Sequence strategy. * Assigns work in the order of nodes defined by the client initialization. - * + * * @params nodeCount count of nodes to be balanced */ var Sequence = exports.Sequence = function(nodeCount) { @@ -136,7 +137,7 @@ Sequence.prototype.nextIndex = function () { /** * Implementation of Round Robin strategy. * Assigns work in round-robin order per nodes defined by the client initialization. - * + * * @params nodeCount count of nodes to be balanced */ var RoundRobin = exports.RoundRobin = function(nodeCount) { diff --git a/lib/gearmanode/version.js b/lib/gearmanode/version.js index 8688874..9102a73 100644 --- a/lib/gearmanode/version.js +++ b/lib/gearmanode/version.js @@ -19,7 +19,7 @@ exports.VERSION_HISTORY = [ - ['0.9.1', '2015-06-26', 'PR #35, Enh #24'], + ['0.9.1', '2015-06-28', 'PR #35, Enh #24'], ['0.9.0', '2015-06-19', 'PR #29, fully implemented Gearman Protocol'], ['0.2.2', '2015-02-04', 'BF #26'], ['0.2.1', '2015-01-04', 'BF #25'], diff --git a/test/test-load-balancing.js b/test/test-load-balancing.js index 21d8d40..f8738ae 100644 --- a/test/test-load-balancing.js +++ b/test/test-load-balancing.js @@ -18,6 +18,12 @@ describe('load-balancing', function() { describe('#constructor', function() { + it('should return default instance of Sequence', function() { + lb.should.be.an.instanceof(Sequence); + lb.nodeCount.should.equal(2); + Object.keys(lb.badNodes).length.should.equal(0); + lb.recoverTime.should.equal(30000); + }) it('should return error when violated validation', function() { // duplicate servers lb = new Sequence();