[test] read a large event from the stream

This commit is contained in:
Rob 2017-03-29 09:59:54 +02:00
parent e39280a2dc
commit 883e89abfe

View File

@ -5,7 +5,10 @@ var client = require('../src/client');
module.exports = {
setUp: function(cb) {
this.expectedEvent = {a: uuid.v4(), b: Math.random()};
this.expectedEvent = {
a: uuid.v4(),
b: Math.random()
};
this.expectedEventType = 'anEvent';
this.expectedEventId = uuid.v4();
var event = client.createJsonEventData(this.expectedEventId, this.expectedEvent, null, this.expectedEventType);
@ -86,9 +89,13 @@ module.exports = {
'Read Event With No Access': function(test) {
test.expect(1);
var self = this;
var metadata = {$acl: {$r: '$admins'}};
var metadata = {
$acl: {
$r: '$admins'
}
};
this.conn.setStreamMetadataRaw(self.testStreamName, client.expectedVersion.noStream, metadata)
.then(function(){
.then(function() {
return self.conn.readEvent(self.testStreamName, 0);
})
.then(function(result) {
@ -101,7 +108,36 @@ module.exports = {
if (isAccessDenied) return test.done();
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);