Skip to content

Commit

Permalink
Merge branch 'master' into support_for_generators_with_co_package
Browse files Browse the repository at this point in the history
  • Loading branch information
StarpTech committed May 2, 2017
2 parents ade1067 + afd0567 commit 51c4a5c
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 31 deletions.
64 changes: 64 additions & 0 deletions benchmark/stress_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict'

const Hemera = require('./../packages/hemera')
const Nats = require('nats')

const nats = Nats.connect()
const hemera = new Hemera(nats, {
logLevel: 'silent',
load: {
sampleInterval: 100
}
})

let i = 0
let rounds = 0
let maxRounds = 10
let interval = 2500
let messages = 10000

hemera.ready(() => {

hemera.add({
topic: 'math',
cmd: 'add'
}, function (req, cb) {
cb()
})

function act() {

if (i > messages) {
i = 0
rounds += 1

if (rounds === maxRounds) {
console.log('END: ----------------------')
console.log('Load: ', hemera.load)
return hemera.close()
}

console.log(`ROUND ${rounds}: ----------------------`)
console.log('Load: ', hemera.load)

return setTimeout(act, interval)
}

hemera.act({
topic: 'math',
cmd: 'add',
a: 1,
b: 2
}, function (err, resp) {
i += 1
act()
})
}

console.log(`Send ${messages} msg every ${interval / 1000} sec for at least ${maxRounds} rounds.`)
console.log()

// run
act()

})
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,29 @@
"release": "lerna publish -i",
"test": "nyc mocha -t 5000 \"./test/**/*.js\" \"./packages/hemera-zipkin/test/**/*.js\"",
"coverage": "npm run test && nyc report --reporter=html",
"build:watch": "chokidar \"./packages/hemera/lib/**/*.js\" -c \"lerna run build\"",
"ci": "nyc mocha -t 5000 \"./test/**/*.js\" \"./packages/hemera-zipkin/test/**/*.js\" && nyc report --reporter=text-lcov | coveralls"
},
"engines": {
"node": ">=4.0.0"
},
"license": "MIT",
"devDependencies": {
"async": "^2.3.0",
"async": "2.4.x",
"chokidar-cli": "1.2.x",
"code": "4.0.x",
"coveralls": "2.11.x",
"eslint": "^3.13.1",
"eslint-config-standard": "^6.2.1",
"eslint-plugin-promise": "^3.4.2",
"eslint-plugin-standard": "^2.0.1",
"coveralls": "2.13.x",
"eslint": "3.19.x",
"eslint-config-standard": "10.2.x",
"eslint-plugin-promise": "3.5.x",
"eslint-plugin-standard": "3.0.x",
"hemera-testsuite": "1.1.x",
"istanbul": "0.4.x",
"joi": "10.0.x",
"joi": "10.4.x",
"lerna": "^2.0.0-rc.4",
"mocha": "3.2.x",
"mocha-lcov-reporter": "1.2.x",
"mocha": "3.3.x",
"mocha-lcov-reporter": "1.3.x",
"nats": "0.7.x",
"nyc": "10.0.x",
"nyc": "10.3.x",
"sinon": "2.1.0"
}
}
4 changes: 2 additions & 2 deletions packages/hemera-arango-store/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hemera-arango-store",
"version": "1.1.16",
"version": "1.1.17",
"description": "This is a plugin to use Arangodb with Hemera",
"main": "index.js",
"scripts": {
Expand All @@ -12,7 +12,7 @@
"license": "MIT",
"dependencies": {
"arangojs": "5.4.x",
"hemera-store": "^1.1.5"
"hemera-store": "^1.1.6"
},
"devDependencies": {
"code": "^4.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/hemera-couchbase-store/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hemera-couchbase-store",
"version": "1.0.18",
"version": "1.0.19",
"description": "This is a plugin to use Couchbase with Hemera",
"main": "index.js",
"scripts": {
Expand All @@ -12,7 +12,7 @@
"license": "MIT",
"dependencies": {
"couchbase": "2.3.x",
"hemera-store": "^1.1.5"
"hemera-store": "^1.1.6"
},
"devDependencies": {
"code": "4.0.x",
Expand Down
4 changes: 2 additions & 2 deletions packages/hemera-mongo-store/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hemera-mongo-store",
"version": "1.0.5",
"version": "1.0.6",
"description": "This is a plugin to use Mongodb with Hemera",
"main": "index.js",
"scripts": {
Expand All @@ -18,7 +18,7 @@
"author": "Dustin Deus (https://github.com/StarpTech)",
"license": "MIT",
"dependencies": {
"hemera-store": "^1.1.5",
"hemera-store": "^1.1.6",
"mongodb": "2.2.x"
},
"devDependencies": {
Expand Down
30 changes: 21 additions & 9 deletions packages/hemera-mongo-store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,27 @@ class MongoStore extends Store {
* @memberOf MongoStore
*/
create (req, cb) {
this._driver.insertOne(req.data, this.options.mongo, function (err, resp) {
if (err) {
return cb(err)
}
const result = {
_id: resp.insertedId.toString()
}
cb(err, result)
})
if (req.data instanceof Array) {
this._driver.insertMany(req.data, this.options.mongo, function (err, resp) {
if (err) {
return cb(err)
}
const result = {
_ids: resp.insertedIds
}
cb(err, result)
})
} else if (req.data instanceof Object) {
this._driver.insertOne(req.data, this.options.mongo, function (err, resp) {
if (err) {
return cb(err)
}
const result = {
_id: resp.insertedId.toString()
}
cb(err, result)
})
}
}

/**
Expand Down
19 changes: 18 additions & 1 deletion packages/hemera-mongo-store/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Hemera-mongo-store', function () {
server = HemeraTestsuite.start_server(PORT, {}, () => {
const nats = Nats.connect(noAuthUrl)
hemera = new Hemera(nats, {
logLevel: 'info'
logLevel: 'silent'
})
hemera.use(HemeraMongoStore, {
mongo: {
Expand Down Expand Up @@ -62,6 +62,23 @@ describe('Hemera-mongo-store', function () {
})
})

it('create multiple documents', function (done) {
hemera.act({
topic,
cmd: 'create',
collection: testCollection,
data: [
{ name: 'peter' }, { name: 'parker' }
]
}, function (err, resp) {
expect(err).to.be.not.exists()
expect(resp).to.be.an.object()
expect(resp._ids).to.be.an.array().length(2)

done()
})
})

it('update', function (done) {
hemera.act({
topic,
Expand Down
4 changes: 2 additions & 2 deletions packages/hemera-sql-store/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hemera-sql-store",
"version": "1.0.14",
"version": "1.0.15",
"description": "This is a plugin to use SQL with Hemera",
"main": "index.js",
"scripts": {
Expand All @@ -11,7 +11,7 @@
"author": "Dustin Deus (https://github.com/StarpTech)",
"license": "MIT",
"dependencies": {
"hemera-store": "^1.1.5",
"hemera-store": "^1.1.6",
"hoek": "4.1.x",
"knex": "0.12.x",
"mysql": "2.12.x",
Expand Down
2 changes: 1 addition & 1 deletion packages/hemera-store/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The pattern is:
* `topic`: is the store name to publish to `<name>-store`
* `cmd`: is the command to execute `create`
* `collection`: the name of the table or collection `string`
* `data`: the data which represent the entity to create `object`
* `data`: the data which represent the entity to create `object` or `Array<object>`

Example:
```js
Expand Down
2 changes: 1 addition & 1 deletion packages/hemera-store/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hemera-store",
"version": "1.1.5",
"version": "1.1.6",
"description": "This is a store interface for Hemera to be interoperable with most database interfaces",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 51c4a5c

Please sign in to comment.