Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use new concurrency feature of viewmodel

  • Loading branch information...
commit d09f11a7f59290f70cfcf1d1f1bfaa792ae0362d 1 parent 81ad5c2
@adrai authored
View
2  .travis.yml
@@ -2,8 +2,8 @@ before_script: "npm install --dev"
language: node_js
node_js:
- - 0.6
- 0.8
+ - 0.1
branches:
only:
View
4 README.md
@@ -51,6 +51,10 @@ See [tests](https://github.com/adrai/node-cqrs-eventdenormalizer/tree/master/tes
# Release Notes
+## v0.2.6
+
+- use new concurrency feature of viewmodel
+
## v0.2.4
- added disableQueuing and ignoreRevision flag
View
10 lib/bases/eventDenormalizerBase.js
@@ -129,6 +129,8 @@ EventDenormalizer.prototype = {
handle: function(evt) {
+ var self = this;
+
// Map events to function names:
// - For the event handler matching the current event, its name is returned
// - For all other event handlers, undefined is returned
@@ -154,10 +156,16 @@ EventDenormalizer.prototype = {
if(this[fnName]) {
// Call the event handler found by map-reduce.
this[fnName](evt, this._getAux(), function(err) {
+ if (err && err.name === 'ConcurrencyError') {
+ return self.handle(evt);
+ }
+ if (err) {
+ throw err;
+ }
eventEmitter.emit('denormalized:' + evt.event, evt);
});
} else {
- throw(new Error('missing handle function'));
+ throw new Error('missing handle function');
}
}
View
4 package.json
@@ -1,7 +1,7 @@
{
"author": "adrai",
"name": "cqrs-eventdenormalizer",
- "version": "0.2.5",
+ "version": "0.2.6",
"private": false,
"main": "index.js",
"engines": {
@@ -15,7 +15,7 @@
"lodash": ">= 1.2.1",
"eventemitter2": ">= 0.4.13",
"node-queue": ">= 0.4.0",
- "viewmodel": ">= 0.5.0"
+ "viewmodel": ">= 0.5.1"
},
"devDependencies": {
"sinon": ">= 1.3.4",
View
48 test/integration/contextEventDenormalizerTest.js
@@ -300,6 +300,43 @@ describe('ContextEventDenormalizer', function() {
});
+ describe('but having a viewmodel beeing updated by someone else in the meantime', function() {
+
+ var denorm,
+ orgFunc;
+
+ beforeEach(function (done) {
+
+ denorm = require('./eventDenormalizers/dummyDenormalizer');
+ orgFunc = denorm._getAux().defaultRevisionUpdateStrategy;
+
+ denorm._getAux().defaultRevisionUpdateStrategy = function(vm, evt) {
+ vm.commit(function() {});
+ denorm._getAux().defaultRevisionUpdateStrategy = orgFunc;
+ };
+
+ dummyRepo.get(evt.payload.id, function(err, vm) {
+ vm._revision = 2;
+ dummyRepo.commit(vm, done);
+ });
+
+ });
+
+ it('it should retry to rehandle the event', function(done) {
+
+ eventEmitter.once('denormalized:' + evt.event, function(data) {
+ dummyRepo.get(data.payload.id, function(err, vm) {
+ expect(vm).to.have.property('id', evt.payload.id);
+ done();
+ });
+ });
+
+ contextEventDenormalizer.denormalize(evt, function(err) {});
+
+ });
+
+ });
+
});
describe('of delete', function() {
@@ -317,7 +354,7 @@ describe('ContextEventDenormalizer', function() {
payload: {
id: '23'
}
- };
+ };
dummyRepo.get('9876', function(err, vm) {
vm._revision = 2;
@@ -397,8 +434,8 @@ describe('ContextEventDenormalizer', function() {
describe('having notified a previous event with the successor revision of the expected revision', function() {
- var firstEvt
- , secondEvt;
+ var firstEvt,
+ secondEvt;
beforeEach(function() {
@@ -429,8 +466,9 @@ describe('ContextEventDenormalizer', function() {
it('it should update the view model with both events in the correct order', function(done) {
- var handlersRun = []
- , todo = 2;
+ var handlersRun = [],
+ todo = 2;
+
function check() {
todo--;
Please sign in to comment.
Something went wrong with that request. Please try again.