2016-07-20 01:42:49 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-07-20 01:56:12 +08:00
|
|
|
require('../../helper');
|
2016-07-20 01:42:49 +08:00
|
|
|
|
2016-07-20 01:56:12 +08:00
|
|
|
var BATCH_SOURCE = '../../../batch/';
|
2016-07-20 01:42:49 +08:00
|
|
|
|
2016-07-20 01:56:12 +08:00
|
|
|
var assert = require('../../support/assert');
|
2016-07-20 01:42:49 +08:00
|
|
|
|
|
|
|
var _ = require('underscore');
|
|
|
|
var RedisPool = require('redis-mpool');
|
2016-08-01 17:48:11 +08:00
|
|
|
var redisUtils = require('../../support/redis_utils');
|
2016-07-20 01:42:49 +08:00
|
|
|
|
2016-10-13 03:32:29 +08:00
|
|
|
|
|
|
|
var Channel = require(BATCH_SOURCE + 'pubsub/channel');
|
2016-10-12 00:28:46 +08:00
|
|
|
var JobPublisher = require(BATCH_SOURCE + 'pubsub/job-publisher');
|
2016-07-20 01:42:49 +08:00
|
|
|
|
2016-08-01 17:48:11 +08:00
|
|
|
var redisPoolPublisher = new RedisPool(_.extend(redisUtils.getConfig(), { name: 'batch-publisher'}));
|
|
|
|
var redisPoolSubscriber = new RedisPool(_.extend(redisUtils.getConfig(), { name: 'batch-subscriber'}));
|
2016-07-20 01:42:49 +08:00
|
|
|
|
|
|
|
var HOST = 'wadus';
|
|
|
|
|
|
|
|
describe('job publisher', function() {
|
|
|
|
var jobPublisher = new JobPublisher(redisPoolPublisher);
|
|
|
|
|
|
|
|
it('.publish() should publish in job channel', function (done) {
|
2016-10-13 03:32:29 +08:00
|
|
|
redisPoolSubscriber.acquire(Channel.DB, function (err, client) {
|
2016-07-20 01:42:49 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2016-10-13 03:32:29 +08:00
|
|
|
client.subscribe(Channel.NAME);
|
2016-07-20 01:42:49 +08:00
|
|
|
|
|
|
|
client.on('message', function (channel, host) {
|
|
|
|
assert.equal(host, HOST);
|
2016-10-13 03:32:29 +08:00
|
|
|
assert.equal(channel, Channel.NAME) ;
|
2016-07-20 01:42:49 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
jobPublisher.publish(HOST);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|