Merge pull request #28 from MarshallRJ/test-largeEvents
Test large events
This commit is contained in:
commit
361330629d
|
@ -55,6 +55,21 @@ module.exports = {
|
||||||
test.done(err);
|
test.done(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
'Append Large event': function(test) {
|
||||||
|
test.expect(2);
|
||||||
|
const largeData = Buffer.alloc(3 * 1024 *1024, 1);
|
||||||
|
const event = client.createJsonEventData(uuid.v4(), {a: largeData.toString()}, null, 'largePayloadEvent');
|
||||||
|
|
||||||
|
this.conn.appendToStream(this.testStreamName, client.expectedVersion.any, event)
|
||||||
|
.then(function(result) {
|
||||||
|
test.areEqual("result.nextExpectedVersion", result.nextExpectedVersion, 0);
|
||||||
|
test.ok(result.logPosition, "No log position in result.");
|
||||||
|
test.done();
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
test.done(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
'Append To Stream Wrong Expected Version': function(test) {
|
'Append To Stream Wrong Expected Version': function(test) {
|
||||||
test.expect(1);
|
test.expect(1);
|
||||||
var event = client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'testEvent');
|
var event = client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'testEvent');
|
||||||
|
|
|
@ -5,103 +5,139 @@ var client = require('../src/client');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
setUp: function(cb) {
|
setUp: function(cb) {
|
||||||
this.expectedEvent = {a: uuid.v4(), b: Math.random()};
|
this.expectedEvent = {
|
||||||
|
a: uuid.v4(),
|
||||||
|
b: Math.random()
|
||||||
|
};
|
||||||
this.expectedEventType = 'anEvent';
|
this.expectedEventType = 'anEvent';
|
||||||
this.expectedEventId = uuid.v4();
|
this.expectedEventId = uuid.v4();
|
||||||
var event = client.createJsonEventData(this.expectedEventId, this.expectedEvent, null, this.expectedEventType);
|
var event = client.createJsonEventData(this.expectedEventId, this.expectedEvent, null, this.expectedEventType);
|
||||||
this.conn.appendToStream(this.testStreamName, client.expectedVersion.noStream, event)
|
this.conn.appendToStream(this.testStreamName, client.expectedVersion.noStream, event)
|
||||||
.then(function() {
|
.then(function() {
|
||||||
cb();
|
cb();
|
||||||
})
|
})
|
||||||
.catch(cb);
|
.catch(cb);
|
||||||
},
|
},
|
||||||
'Read Event Happy Path': function(test) {
|
'Read Event Happy Path': function(test) {
|
||||||
test.expect(8);
|
test.expect(8);
|
||||||
var self = this;
|
var self = this;
|
||||||
this.conn.readEvent(this.testStreamName, 0)
|
this.conn.readEvent(this.testStreamName, 0)
|
||||||
.then(function(result) {
|
.then(function(result) {
|
||||||
test.areEqual('status', result.status, client.eventReadStatus.Success);
|
test.areEqual('status', result.status, client.eventReadStatus.Success);
|
||||||
test.areEqual('stream', result.stream, self.testStreamName);
|
test.areEqual('stream', result.stream, self.testStreamName);
|
||||||
test.areEqual('eventNumber', result.eventNumber, 0);
|
test.areEqual('eventNumber', result.eventNumber, 0);
|
||||||
test.ok(result.event !== null, "event is null.");
|
test.ok(result.event !== null, "event is null.");
|
||||||
test.ok(result.event.originalEvent !== null, "event.originalEvent is null.");
|
test.ok(result.event.originalEvent !== null, "event.originalEvent is null.");
|
||||||
var event = JSON.parse(result.event.originalEvent.data.toString());
|
var event = JSON.parse(result.event.originalEvent.data.toString());
|
||||||
test.areEqual('event.eventId', result.event.originalEvent.eventId, self.expectedEventId);
|
test.areEqual('event.eventId', result.event.originalEvent.eventId, self.expectedEventId);
|
||||||
test.areEqual('event.eventType', result.event.originalEvent.eventType, self.expectedEventType);
|
test.areEqual('event.eventType', result.event.originalEvent.eventType, self.expectedEventType);
|
||||||
test.areEqual('decoded event.data', event, self.expectedEvent);
|
test.areEqual('decoded event.data', event, self.expectedEvent);
|
||||||
test.done();
|
test.done();
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
test.done(err);
|
test.done(err);
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
'Read Event From Non-Existing Stream': function(test) {
|
'Read Event From Non-Existing Stream': function(test) {
|
||||||
test.expect(4);
|
test.expect(4);
|
||||||
var anotherStream = 'test' + uuid.v4();
|
var anotherStream = 'test' + uuid.v4();
|
||||||
this.conn.readEvent(anotherStream, 0)
|
this.conn.readEvent(anotherStream, 0)
|
||||||
.then(function(result) {
|
.then(function(result) {
|
||||||
test.areEqual('status', result.status, client.eventReadStatus.NoStream);
|
test.areEqual('status', result.status, client.eventReadStatus.NoStream);
|
||||||
test.areEqual('stream', result.stream, anotherStream);
|
test.areEqual('stream', result.stream, anotherStream);
|
||||||
test.areEqual('eventNumber', result.eventNumber, 0);
|
test.areEqual('eventNumber', result.eventNumber, 0);
|
||||||
test.areEqual('event', result.event, null);
|
test.areEqual('event', result.event, null);
|
||||||
test.done();
|
test.done();
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
test.done(err);
|
test.done(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
'Read Event From Deleted Stream': function(test) {
|
'Read Event From Deleted Stream': function(test) {
|
||||||
test.expect(4);
|
test.expect(4);
|
||||||
var self = this;
|
var self = this;
|
||||||
this.conn.deleteStream(this.testStreamName, 0, true)
|
this.conn.deleteStream(this.testStreamName, 0, true)
|
||||||
.then(function() {
|
.then(function() {
|
||||||
return self.conn.readEvent(self.testStreamName, 0)
|
return self.conn.readEvent(self.testStreamName, 0)
|
||||||
})
|
})
|
||||||
.then(function(result) {
|
.then(function(result) {
|
||||||
test.areEqual('status', result.status, client.eventReadStatus.StreamDeleted);
|
test.areEqual('status', result.status, client.eventReadStatus.StreamDeleted);
|
||||||
test.areEqual('stream', result.stream, self.testStreamName);
|
test.areEqual('stream', result.stream, self.testStreamName);
|
||||||
test.areEqual('eventNumber', result.eventNumber, 0);
|
test.areEqual('eventNumber', result.eventNumber, 0);
|
||||||
test.areEqual('event', result.event, null);
|
test.areEqual('event', result.event, null);
|
||||||
test.done();
|
test.done();
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
test.done(err);
|
test.done(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
'Read Event With Inexisting Version': function(test) {
|
'Read Event With Inexisting Version': function(test) {
|
||||||
test.expect(4);
|
test.expect(4);
|
||||||
var self = this;
|
var self = this;
|
||||||
return self.conn.readEvent(self.testStreamName, 1)
|
return self.conn.readEvent(self.testStreamName, 1)
|
||||||
.then(function(result) {
|
.then(function(result) {
|
||||||
test.areEqual('status', result.status, client.eventReadStatus.NotFound);
|
test.areEqual('status', result.status, client.eventReadStatus.NotFound);
|
||||||
test.areEqual('stream', result.stream, self.testStreamName);
|
test.areEqual('stream', result.stream, self.testStreamName);
|
||||||
test.areEqual('eventNumber', result.eventNumber, 1);
|
test.areEqual('eventNumber', result.eventNumber, 1);
|
||||||
test.areEqual('event', result.event, null);
|
test.areEqual('event', result.event, null);
|
||||||
test.done();
|
test.done();
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
test.done(err);
|
test.done(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
'Read Event With No Access': function(test) {
|
'Read Event With No Access': function(test) {
|
||||||
test.expect(1);
|
test.expect(1);
|
||||||
var self = this;
|
var self = this;
|
||||||
var metadata = {$acl: {$r: '$admins'}};
|
var metadata = {
|
||||||
|
$acl: {
|
||||||
|
$r: '$admins'
|
||||||
|
}
|
||||||
|
};
|
||||||
this.conn.setStreamMetadataRaw(self.testStreamName, client.expectedVersion.noStream, metadata)
|
this.conn.setStreamMetadataRaw(self.testStreamName, client.expectedVersion.noStream, metadata)
|
||||||
.then(function(){
|
.then(function() {
|
||||||
return self.conn.readEvent(self.testStreamName, 0);
|
return self.conn.readEvent(self.testStreamName, 0);
|
||||||
})
|
})
|
||||||
.then(function(result) {
|
.then(function(result) {
|
||||||
test.fail("readEvent succeeded but should have failed.");
|
test.fail("readEvent succeeded but should have failed.");
|
||||||
test.done();
|
test.done();
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
var isAccessDenied = err instanceof client.AccessDeniedError;
|
var isAccessDenied = err instanceof client.AccessDeniedError;
|
||||||
test.ok(isAccessDenied, "readEvent should have failed with AccessDeniedError, got " + err.constructor.name);
|
test.ok(isAccessDenied, "readEvent should have failed with AccessDeniedError, got " + err.constructor.name);
|
||||||
if (isAccessDenied) return test.done();
|
if (isAccessDenied) return test.done();
|
||||||
test.done(err);
|
test.done(err);
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
|
'Read a Large Event': function(test) {
|
||||||
|
test.expect(8);
|
||||||
|
var self = this;
|
||||||
|
const largeData = Buffer.alloc(3 * 1024 * 1024, 1);
|
||||||
|
|
||||||
|
const largeEvent = client.createJsonEventData(uuid.v4(), {
|
||||||
|
a: largeData.toString()
|
||||||
|
}, null, 'largePayloadEvent');
|
||||||
|
|
||||||
|
this.conn.appendToStream(this.testStreamName, client.expectedVersion.any, largeEvent)
|
||||||
|
.then(function(result) {
|
||||||
|
self.conn.readEvent(self.testStreamName, 1)
|
||||||
|
.then(function(result) {
|
||||||
|
test.areEqual('status', result.status, client.eventReadStatus.Success);
|
||||||
|
test.areEqual('stream', result.stream, self.testStreamName);
|
||||||
|
test.areEqual('eventNumber', result.eventNumber, 1);
|
||||||
|
test.ok(result.event !== null, "event is null.");
|
||||||
|
test.ok(result.event.originalEvent !== null, "event.originalEvent is null.");
|
||||||
|
var event = JSON.parse(result.event.originalEvent.data.toString());
|
||||||
|
test.areEqual('event.eventId', result.event.originalEvent.eventId, largeEvent.eventId);
|
||||||
|
test.areEqual('event.eventType', result.event.originalEvent.eventType, 'largePayloadEvent');
|
||||||
|
test.areEqual('decoded event.data', event, JSON.parse(largeEvent.data.toString()));
|
||||||
|
test.done();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
test.done(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
require('./common/base_test').init(module.exports);
|
require('./common/base_test').init(module.exports);
|
Loading…
Reference in New Issue
Block a user