_.each(values, (value, seriesName) => { if (!this.series[seriesName]) { return; } if (this._isHighwater(seriesName)) { this.series[seriesName].y = _.times(this.limit, _.constant(value)); } else { this.series[seriesName].y.shift(); this.series[seriesName].y.push(value); } });
const slowFunc = function (count) { const begin = Date.now(); // Deliberately unused variable. // eslint-disable-next-line no-unused-vars let values = _.times(count, () => _.random(0, count)); values = _.sortBy(values); return Date.now() - begin; }
it("should direct call action on the specified node", () => { return master.waitForServices("math") .delay(500) .then(() => Promise.all(_.times(6, () => master.call("math.add", { a: 20, b: 30 }, { nodeID: "slaveB" })))) .catch(protectReject) .then(res => { //console.log(res); expect(res).toHaveLength(6); expect(res.filter(o => o.result == 50)).toHaveLength(6); expect(res.filter(o => o.node == "slaveA")).toHaveLength(0); expect(res.filter(o => o.node == "slaveB")).toHaveLength(6); }); });
broker.start() .then(() => broker.repl()) .then(() => { return broker.Promise.all(_.times(10, id => { return broker.call("test.second", { id }); //return broker.emit("user.created", { id }); })); }) /*.then(() => { setInterval(() => broker.call("test.second", { id: id++ }), 200); })*/ .then(res => broker.logger.info("Done!")) .catch(err => broker.logger.error(err.message));
describe("constructor", () => { beforeEach(() => { sandbox.stub(BaseLineGraph.prototype, "_createGraph"); }); it("should use limit from layoutConfig", () => { const limit = 7; options.layoutConfig.view.limit = limit; const baseGraph = new BaseLineGraph(options); expect(baseGraph).to.have.property("limit", limit); expect(baseGraph).to.have.nested.property("series.a.y") .that.deep.equals(_.times(limit, _.constant(0))); }); it("should create graph and set up event listener", () => { const baseGraph = new BaseLineGraph(options); expect(baseGraph).to.be.an.instanceof(BaseView); expect(baseGraph._createGraph).to.have.been.calledOnce; expect(testContainer.screen.on).to.have.been.calledWithExactly("metrics", sinon.match.func); }); });
scale(num, opts) { if (num > this.nodes.length) { // Start new nodes this.logger.info(`Starting ${num - this.nodes.length} new nodes...`); return _.times(num - this.nodes.length, () => this.startNewNode(this.getNextNodeID())); } else if (num < this.nodes.length && num >= 0) { // Stop random nodes this.logger.info(`Stopping ${this.nodes.length - num} nodes...`); const tmp = Array.from(this.nodes); return _.times(this.nodes.length - num, () => { const idx = _.random(tmp.length - 1); const node = tmp.splice(idx, 1)[0]; if (opts.kill) return this.killNode(node); else return this.stopNode(node); }); } }
y: _.times(this.layoutConfig.limit, _.constant(0)), style: { line: seriesConfig.color
const ctxs = _.times(10, i => Context.create(broker, endpoint, { id: i + 1 })); const p = broker.Promise.all(ctxs.map(ctx => newHandler.call(broker, ctx).catch(err => FLOW.push(err.name + "-" + ctx.params.id))));
return master.waitForServices("aes") .delay(500) .then(() => Promise.all(_.times(1, () => { const s1 = fs.createReadStream(filename); return master.call("aes.encrypt", s1)
const ctxs = _.times(10, i => Context.create(broker, endpoint, { id: i + 1, crash: i == 1 || i == 7 })); const p = broker.Promise.all(ctxs.map(ctx => newHandler.call(broker, ctx).catch(err => FLOW.push(err.name + "-" + ctx.params.id))));
_.each(data[0], (value, seriesName) => { if (!this.series[seriesName]) { return; } if (this._isHighwater(seriesName)) { this.series[seriesName].y = _.times(this.limit, _.constant(value)); } else { this.series[seriesName].y = _.times(this.limit, _.constant(0)); } this.series[seriesName].x = xAxis; });
it("should call actions with balancing between 3 nodes", () => { return master.waitForServices("math") .delay(500) .then(() => Promise.all(_.times(6, () => master.call("math.add", { a: 20, b: 30 })))) .catch(protectReject) .then(res => { //console.log(res); expect(res).toHaveLength(6); expect(res.filter(o => o.result == 50)).toHaveLength(6); expect(res.filter(o => o.node == "slaveA")).toHaveLength(2); expect(res.filter(o => o.node == "slaveB")).toHaveLength(2); expect(res.filter(o => o.node == "slaveC")).toHaveLength(2); }); });
const ctxs = _.times(10, i => Context.create(broker, endpoint, { id: i + 1 })); const p = broker.Promise.all(ctxs.map(ctx => newHandler.call(broker, ctx).catch(err => FLOW.push(err.name + "-" + ctx.params.id))));
it("should call actions with balancing between 2 nodes", () => { return master.waitForServices("math") .delay(500) .then(() => Promise.all(_.times(6, () => master.call("math.add", { a: 50, b: 13 })))) .catch(protectReject) .then(res => { //console.log(res); expect(res).toHaveLength(6); expect(res.filter(o => o.result == 63)).toHaveLength(6); expect(res.filter(o => o.node == "slaveA")).toHaveLength(3); expect(res.filter(o => o.node == "slaveB")).toHaveLength(3); }); });
it("should call actions without slaveC node", () => { return master.waitForServices("math") .delay(500) .then(() => Promise.all(_.times(6, () => master.call("math.add", { a: 20, b: 30 })))) .catch(protectReject) .then(res => { //console.log(res); expect(res).toHaveLength(6); expect(res.filter(o => o.result == 50)).toHaveLength(6); expect(res.filter(o => o.node == "slaveA")).toHaveLength(3); expect(res.filter(o => o.node == "slaveB")).toHaveLength(3); expect(res.filter(o => o.node == "slaveC")).toHaveLength(0); }); });