Use Long in Stream catchup subscription

Use Long in tests
Bump version to 2.0
This commit is contained in:
2017-11-08 12:45:22 -08:00
parent 4584517ede
commit e79ad8f9c4
12 changed files with 94 additions and 78 deletions

View File

@ -2,11 +2,14 @@ var uuid = require('uuid');
var client = require('../src/client');
var Long = require('long');
var ANY_VERSION = Long.fromNumber(client.expectedVersion.any);
var NOSTREAM_VERSION = Long.fromNumber(client.expectedVersion.noStream);
module.exports = {
'Append One Event To Stream Happy Path': function(test) {
test.expect(2);
var event = client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'testEvent');
this.conn.appendToStream(this.testStreamName, client.expectedVersion.any, event)
this.conn.appendToStream(this.testStreamName, ANY_VERSION, event)
.then(function(result) {
test.areEqual("nextExpectedVersion", result.nextExpectedVersion, Long.fromNumber(0));
test.ok(result.logPosition, "No log position in result.");
@ -26,7 +29,7 @@ module.exports = {
else
events.push(client.createJsonEventData(uuid.v4(), {b: Math.random(), a: uuid.v4()}, null, 'otherEvent'));
}
this.conn.appendToStream(this.testStreamName, client.expectedVersion.any, events)
this.conn.appendToStream(this.testStreamName, ANY_VERSION, events)
.then(function(result) {
test.areEqual("result.nextExpectedVersion", result.nextExpectedVersion, Long.fromNumber(expectedVersion));
test.ok(result.logPosition, "No log position in result.");
@ -46,7 +49,7 @@ module.exports = {
else
events.push(client.createJsonEventData(uuid.v4(), {b: Math.random(), a: uuid.v4()}, null, 'otherEvent'));
}
this.conn.appendToStream(this.testStreamName, client.expectedVersion.any, events)
this.conn.appendToStream(this.testStreamName, ANY_VERSION, events)
.then(function(result) {
test.areEqual("result.nextExpectedVersion", result.nextExpectedVersion, Long.fromNumber(expectedVersion));
test.ok(result.logPosition, "No log position in result.");
@ -61,7 +64,7 @@ module.exports = {
const largeData = Buffer.alloc(3 * 1024 *1024, " ");
const event = client.createJsonEventData(uuid.v4(), {a: largeData.toString()}, null, 'largePayloadEvent');
this.conn.appendToStream(this.testStreamName, client.expectedVersion.any, event)
this.conn.appendToStream(this.testStreamName, ANY_VERSION, event)
.then(function(result) {
test.areEqual("result.nextExpectedVersion", result.nextExpectedVersion, Long.fromNumber(0));
test.ok(result.logPosition, "No log position in result.");
@ -74,7 +77,7 @@ module.exports = {
'Append To Stream Wrong Expected Version': function(test) {
test.expect(1);
var event = client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'testEvent');
this.conn.appendToStream(this.testStreamName, 10, event)
this.conn.appendToStream(this.testStreamName, Long.fromNumber(10), event)
.then(function(result) {
test.fail("Append succeeded but should have failed.");
test.done();
@ -89,10 +92,10 @@ module.exports = {
'Append To Stream Deleted': function(test) {
test.expect(1);
var self = this;
this.conn.deleteStream(this.testStreamName, client.expectedVersion.noStream, true)
this.conn.deleteStream(this.testStreamName, NOSTREAM_VERSION, true)
.then(function() {
var event = client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'testEvent');
return self.conn.appendToStream(self.testStreamName, client.expectedVersion.any, event)
return self.conn.appendToStream(self.testStreamName, ANY_VERSION, event)
})
.then(function(result) {
test.fail("Append succeeded but should have failed.");
@ -109,10 +112,10 @@ module.exports = {
test.expect(1);
var self = this;
var metadata = {$acl: {$w: "$admins"}};
this.conn.setStreamMetadataRaw(this.testStreamName, client.expectedVersion.noStream, metadata)
this.conn.setStreamMetadataRaw(this.testStreamName, NOSTREAM_VERSION, metadata)
.then(function() {
var event = client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'testEvent');
return self.conn.appendToStream(self.testStreamName, client.expectedVersion.any, event)
return self.conn.appendToStream(self.testStreamName, ANY_VERSION, event)
})
.then(function(result) {
test.fail("Append succeeded but should have failed.");

View File

@ -1,5 +1,6 @@
var uuid = require('uuid');
var client = require('../src/client');
var Long = require('long');
module.exports = {
setUp: function(cb) {
@ -16,7 +17,7 @@ module.exports = {
'Test Delete Stream Soft Happy Path': function(test) {
test.expect(4);
var self = this;
this.conn.deleteStream(this.testStreamName, 1, false)
this.conn.deleteStream(this.testStreamName, Long.fromNumber(1), false)
.then(function(result) {
test.ok(result.logPosition, "No log position in result.");
return self.conn.getStreamMetadataRaw(self.testStreamName);
@ -34,7 +35,7 @@ module.exports = {
'Test Delete Stream Hard Happy Path': function(test) {
test.expect(4);
var self = this;
this.conn.deleteStream(this.testStreamName, 1, true)
this.conn.deleteStream(this.testStreamName, Long.fromNumber(1), true)
.then(function(result) {
test.ok(result.logPosition, "No log position in result.");
return self.conn.getStreamMetadataRaw(self.testStreamName);
@ -51,7 +52,7 @@ module.exports = {
},
'Test Delete Stream With Wrong Expected Version': function(test) {
test.expect(1);
this.conn.deleteStream(this.testStreamName, 10)
this.conn.deleteStream(this.testStreamName, Long.fromNumber(10))
.then(function(result) {
test.fail("Delete succeeded but should have failed.");
test.done();
@ -68,7 +69,7 @@ module.exports = {
var self = this;
this.conn.setStreamMetadataRaw(this.testStreamName, client.expectedVersion.any, {$acl: {$d: "$admins"}})
.then(function() {
return self.conn.deleteStream(self.testStreamName, 10);
return self.conn.deleteStream(self.testStreamName, Long.fromNumber(10));
})
.then(function(result) {
test.fail("Delete succeeded but should have failed.");
@ -86,7 +87,7 @@ module.exports = {
var self = this;
this.conn.deleteStream(this.testStreamName, 1, true)
.then(function() {
return self.conn.deleteStream(self.testStreamName, 1, true);
return self.conn.deleteStream(self.testStreamName, Long.fromNumber(1), true);
})
.then(function(result) {
test.fail("Delete succeeded but should have failed.");

View File

@ -1,10 +1,11 @@
var util = require('util');
var uuid = require('uuid');
var client = require('../src/client');
const Long = require('long');
const EMPTY_VERSION = Long.fromNumber(client.expectedVersion.emptyStream);
module.exports = {
'Test Set Stream Metadata Raw': function(test) {
this.conn.setStreamMetadataRaw(this.testStreamName, client.expectedVersion.emptyStream, {$maxCount: 100})
this.conn.setStreamMetadataRaw(this.testStreamName, EMPTY_VERSION, {$maxCount: 100})
.then(function(result) {
test.done();
})

View File

@ -1,8 +1,10 @@
var util = require('util');
var uuid = require('uuid');
var client = require('../src/client');
var Long = require('long');
var NOSTREAM_VERSION = Long.fromNumber(client.expectedVersion.noStream);
var ANY_VERSION = Long.fromNumber(client.expectedVersion.any);
module.exports = {
setUp: function(cb) {
this.expectedEvent = {
@ -12,7 +14,7 @@ module.exports = {
this.expectedEventType = 'anEvent';
this.expectedEventId = uuid.v4();
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, NOSTREAM_VERSION, event)
.then(function() {
cb();
})
@ -21,7 +23,7 @@ module.exports = {
'Read Event Happy Path': function(test) {
test.expect(8);
var self = this;
this.conn.readEvent(this.testStreamName, 0)
this.conn.readEvent(this.testStreamName, Long.fromNumber(0))
.then(function(result) {
test.areEqual('status', result.status, client.eventReadStatus.Success);
test.areEqual('stream', result.stream, self.testStreamName);
@ -41,7 +43,7 @@ module.exports = {
'Read Event From Non-Existing Stream': function(test) {
test.expect(4);
var anotherStream = 'test' + uuid.v4();
this.conn.readEvent(anotherStream, 0)
this.conn.readEvent(anotherStream, Long.fromNumber(0))
.then(function(result) {
test.areEqual('status', result.status, client.eventReadStatus.NoStream);
test.areEqual('stream', result.stream, anotherStream);
@ -58,7 +60,7 @@ module.exports = {
var self = this;
this.conn.deleteStream(this.testStreamName, 0, true)
.then(function() {
return self.conn.readEvent(self.testStreamName, 0)
return self.conn.readEvent(self.testStreamName, Long.fromNumber(0))
})
.then(function(result) {
test.areEqual('status', result.status, client.eventReadStatus.StreamDeleted);
@ -74,7 +76,7 @@ module.exports = {
'Read Event With Inexisting Version': function(test) {
test.expect(4);
var self = this;
return self.conn.readEvent(self.testStreamName, 1)
return self.conn.readEvent(self.testStreamName, Long.fromNumber(1))
.then(function(result) {
test.areEqual('status', result.status, client.eventReadStatus.NotFound);
test.areEqual('stream', result.stream, self.testStreamName);
@ -94,9 +96,9 @@ module.exports = {
$r: '$admins'
}
};
this.conn.setStreamMetadataRaw(self.testStreamName, client.expectedVersion.noStream, metadata)
this.conn.setStreamMetadataRaw(self.testStreamName, NOSTREAM_VERSION, metadata)
.then(function() {
return self.conn.readEvent(self.testStreamName, 0);
return self.conn.readEvent(self.testStreamName, Long.fromNumber(0));
})
.then(function(result) {
test.fail("readEvent succeeded but should have failed.");
@ -118,9 +120,9 @@ module.exports = {
a: largeData.toString()
}, null, 'largePayloadEvent');
this.conn.appendToStream(this.testStreamName, client.expectedVersion.any, largeEvent)
this.conn.appendToStream(this.testStreamName, ANY_VERSION, largeEvent)
.then(function(result) {
self.conn.readEvent(self.testStreamName, 1)
self.conn.readEvent(self.testStreamName, Long.fromNumber(1))
.then(function(result) {
test.areEqual('status', result.status, client.eventReadStatus.Success);
test.areEqual('stream', result.stream, self.testStreamName);

View File

@ -1,16 +1,17 @@
var util = require('util');
var uuid = require('uuid');
var client = require('../src/client');
var Long = require('long');
const streamSize = 100;
var NOSTREAM_VERSION = Long.fromNumber(client.expectedVersion.noStream);
module.exports = {
setUp: function(cb) {
this.eventsData = [];
for(var i = 0; i < streamSize; i++)
this.eventsData.push(client.createJsonEventData(uuid.v4(), {a: uuid.v4(), b: Math.random()}, null, 'anEvent'));
this.conn.appendToStream(this.testStreamName, client.expectedVersion.noStream, this.eventsData)
this.conn.appendToStream(this.testStreamName, NOSTREAM_VERSION, this.eventsData)
.then(function() {
cb();
})
@ -19,7 +20,7 @@ module.exports = {
'Read Stream Events Backward Happy Path': function(test) {
test.expect(7 + (streamSize * 6));
var self = this;
this.conn.readStreamEventsBackward(this.testStreamName, streamSize-1, streamSize)
this.conn.readStreamEventsBackward(this.testStreamName, Long.fromNumber(streamSize-1), streamSize)
.then(function(slice) {
test.areEqual('slice.status', slice.status, client.eventReadStatus.Success);
test.areEqual('slice.stream', slice.stream, self.testStreamName);
@ -42,7 +43,7 @@ module.exports = {
'Read Stream Events Backward With Non-Existing Stream': function(test) {
test.expect(4);
var anotherStream = 'test' + uuid.v4();
this.conn.readStreamEventsBackward(anotherStream, streamSize-1, streamSize)
this.conn.readStreamEventsBackward(anotherStream, Long.fromNumber(streamSize-1), streamSize)
.then(function(slice) {
test.areEqual('slice.status', slice.status, client.sliceReadStatus.StreamNotFound);
test.areEqual('slice.stream', slice.stream, anotherStream);
@ -57,9 +58,9 @@ module.exports = {
'Read Stream Events Backward With Deleted Stream': function(test) {
test.expect(4);
var self = this;
this.conn.deleteStream(this.testStreamName, streamSize-1, true)
this.conn.deleteStream(this.testStreamName, Long.fromNumber(streamSize-1), true)
.then(function() {
return self.conn.readStreamEventsBackward(self.testStreamName, streamSize-1, streamSize)
return self.conn.readStreamEventsBackward(self.testStreamName, Long.fromNumber(streamSize-1), streamSize)
})
.then(function(slice) {
test.areEqual('slice.status', slice.status, client.eventReadStatus.StreamDeleted);
@ -75,7 +76,7 @@ module.exports = {
'Read Stream Events Backward With Inexisting Version': function(test) {
test.expect(4);
var self = this;
return self.conn.readStreamEventsBackward(self.testStreamName, streamSize * 2, streamSize)
return self.conn.readStreamEventsBackward(self.testStreamName, Long.fromNumber(streamSize * 2), streamSize)
.then(function(slice) {
test.areEqual('slice.status', slice.status, client.eventReadStatus.Success);
test.areEqual('slice.stream', slice.stream, self.testStreamName);
@ -91,9 +92,9 @@ module.exports = {
test.expect(1);
var self = this;
var metadata = {$acl: {$r: '$admins'}};
this.conn.setStreamMetadataRaw(self.testStreamName, client.expectedVersion.noStream, metadata)
this.conn.setStreamMetadataRaw(self.testStreamName, NOSTREAM_VERSION, metadata)
.then(function(){
return self.conn.readStreamEventsBackward(self.testStreamName, streamSize-1, streamSize);
return self.conn.readStreamEventsBackward(self.testStreamName, Long.fromNumber(streamSize-1), streamSize);
})
.then(function(slice) {
test.fail("readStreamEventsBackward succeeded but should have failed.");

View File

@ -1,16 +1,17 @@
var util = require('util');
var uuid = require('uuid');
var client = require('../src/client');
var Long = require('long');
const streamSize = 100;
var NOSTREAM_VERSION = Long.fromNumber(client.expectedVersion.noStream);
module.exports = {
setUp: function(cb) {
this.eventsData = [];
for(var i = 0; i < streamSize; i++)
this.eventsData.push(client.createJsonEventData(uuid.v4(), {a: uuid.v4(), b: Math.random()}, null, 'anEvent'));
this.conn.appendToStream(this.testStreamName, client.expectedVersion.noStream, this.eventsData)
this.conn.appendToStream(this.testStreamName, NOSTREAM_VERSION, this.eventsData)
.then(function() {
cb();
})
@ -19,7 +20,7 @@ module.exports = {
'Read Stream Events Forward Happy Path': function(test) {
test.expect(7 + (streamSize * 11));
var self = this;
this.conn.readStreamEventsForward(this.testStreamName, 0, streamSize)
this.conn.readStreamEventsForward(this.testStreamName, Long.fromNumber(0), streamSize)
.then(function(slice) {
test.areEqual('slice.status', slice.status, client.eventReadStatus.Success);
test.areEqual('slice.stream', slice.stream, self.testStreamName);
@ -41,7 +42,7 @@ module.exports = {
'Read Stream Events Forward With Non-Existing Stream': function(test) {
test.expect(4);
var anotherStream = 'test' + uuid.v4();
this.conn.readStreamEventsForward(anotherStream, 0, streamSize)
this.conn.readStreamEventsForward(anotherStream, Long.fromNumber(0), streamSize)
.then(function(slice) {
test.areEqual('slice.status', slice.status, client.sliceReadStatus.StreamNotFound);
test.areEqual('slice.stream', slice.stream, anotherStream);
@ -56,9 +57,9 @@ module.exports = {
'Read Stream Events Forward With Deleted Stream': function(test) {
test.expect(4);
var self = this;
this.conn.deleteStream(this.testStreamName, streamSize-1, true)
this.conn.deleteStream(this.testStreamName, Long.fromNumber(streamSize-1), true)
.then(function() {
return self.conn.readStreamEventsForward(self.testStreamName, 0, streamSize)
return self.conn.readStreamEventsForward(self.testStreamName, Long.fromNumber(0), streamSize)
})
.then(function(slice) {
test.areEqual('slice.status', slice.status, client.eventReadStatus.StreamDeleted);
@ -74,7 +75,7 @@ module.exports = {
'Read Stream Events Forward With Inexisting Version': function(test) {
test.expect(4);
var self = this;
return self.conn.readStreamEventsForward(self.testStreamName, streamSize * 2, streamSize)
return self.conn.readStreamEventsForward(self.testStreamName, Long.fromNumber(streamSize * 2), streamSize)
.then(function(slice) {
test.areEqual('slice.status', slice.status, client.eventReadStatus.Success);
test.areEqual('slice.stream', slice.stream, self.testStreamName);
@ -90,9 +91,9 @@ module.exports = {
test.expect(1);
var self = this;
var metadata = {$acl: {$r: '$admins'}};
this.conn.setStreamMetadataRaw(self.testStreamName, client.expectedVersion.noStream, metadata)
this.conn.setStreamMetadataRaw(self.testStreamName, NOSTREAM_VERSION, metadata)
.then(function(){
return self.conn.readStreamEventsForward(self.testStreamName, 0, streamSize);
return self.conn.readStreamEventsForward(self.testStreamName, Long.fromNumber(0), streamSize);
})
.then(function(slice) {
test.fail("readStreamEventsForward succeeded but should have failed.");

View File

@ -1,6 +1,6 @@
var util = require('util');
var uuid = require('uuid');
var client = require('../src/client');
var Long = require('long');
function createRandomEvent() {
return client.createJsonEventData(uuid.v4(), {a: uuid.v4(), b: Math.random()}, {createdAt: Date.now()}, 'testEvent');
@ -123,7 +123,7 @@ module.exports = {
var events = [createRandomEvent(), createRandomEvent()];
this.conn.appendToStream(self.testStreamName, client.expectedVersion.noStream, events)
.then(function() {
var subscription = self.conn.subscribeToStreamFrom(self.testStreamName, 0, false, eventAppeared, liveProcessingStarted, subscriptionDropped);
var subscription = self.conn.subscribeToStreamFrom(self.testStreamName, Long.fromNumber(0), false, eventAppeared, liveProcessingStarted, subscriptionDropped);
test.areEqual("subscription.streamId", subscription.streamId, self.testStreamName);
test.areEqual("subscription.isSubscribedToAll", subscription.isSubscribedToAll, false);

View File

@ -2,13 +2,17 @@ var uuid = require('uuid');
var Long = require('long');
var client = require('../src/client');
var ANY_VERSION = Long.fromNumber(client.expectedVersion.any);
var NOSTREAM_VERSION = Long.fromNumber(client.expectedVersion.noStream);
var EMPTY_VERSION = Long.fromNumber(client.expectedVersion.emptyStream);
module.exports = {
setUp: function(cb) {
cb();
},
'Start A Transaction Happy Path': function(test) {
test.expect(1);
this.conn.startTransaction(this.testStreamName, client.expectedVersion.noStream)
this.conn.startTransaction(this.testStreamName, NOSTREAM_VERSION)
.then(function(trx) {
test.ok(Long.isLong(trx.transactionId), "trx.transactionId should be a Long.");
test.done();
@ -32,7 +36,7 @@ module.exports = {
var self = this;
this.conn.deleteStream(this.testStreamName, client.expectedVersion.emptyStream)
.then(function() {
return self.conn.startTransaction(self.testStreamName, client.expectedVersion.any);
return self.conn.startTransaction(self.testStreamName, ANY_VERSION);
})
.then(function(trx) {
test.fail("Start Transaction with deleted stream succeeded.");
@ -50,9 +54,9 @@ module.exports = {
test.expect(1);
var self = this;
var metadata = {$acl: {$w: "$admins"}};
this.conn.setStreamMetadataRaw(this.testStreamName, -1, metadata)
this.conn.setStreamMetadataRaw(this.testStreamName, EMPTY_VERSION, metadata)
.then(function() {
return self.conn.startTransaction(self.testStreamName, client.expectedVersion.any);
return self.conn.startTransaction(self.testStreamName, ANY_VERSION);
})
.then(function(trx) {
test.fail("Start Transaction with no access succeeded.");
@ -67,7 +71,7 @@ module.exports = {
},
'Continue A Transaction Happy Path': function(test) {
var self = this;
this.conn.startTransaction(this.testStreamName, client.expectedVersion.emptyStream)
this.conn.startTransaction(this.testStreamName, EMPTY_VERSION)
.then(function(trx) {
return trx.write(client.createJsonEventData(uuid.v4(), {a: Math.random()}, null, 'anEvent'))
.then(function () {
@ -88,7 +92,7 @@ module.exports = {
'Write/Commit Transaction Happy Path': function(test) {
test.expect(2);
var self = this;
this.conn.startTransaction(this.testStreamName, client.expectedVersion.emptyStream)
this.conn.startTransaction(this.testStreamName, EMPTY_VERSION)
.then(function(trx) {
self.events = [];
for(var i = 0; i < 15; i++) {
@ -139,9 +143,9 @@ module.exports = {
'Write/Commit Transaction With Deleted Stream': function(test) {
test.expect(1);
var self = this;
this.conn.deleteStream(this.testStreamName, client.expectedVersion.emptyStream, true)
this.conn.deleteStream(this.testStreamName, EMPTY_VERSION, true)
.then(function() {
return self.conn.startTransaction(self.testStreamName, client.expectedVersion.any);
return self.conn.startTransaction(self.testStreamName, ANY_VERSION);
})
.then(function(trx) {
return trx.write(client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'anEvent'))
@ -163,10 +167,10 @@ module.exports = {
'Write/Commit Transaction With No Write Access': function(test) {
test.expect(1);
var self = this;
this.conn.startTransaction(this.testStreamName, client.expectedVersion.any)
this.conn.startTransaction(this.testStreamName, ANY_VERSION)
.then(function(trx) {
var metadata = {$acl: {$w: "$admins"}};
return self.conn.setStreamMetadataRaw(self.testStreamName, -1, metadata)
return self.conn.setStreamMetadataRaw(self.testStreamName, EMPTY_VERSION, metadata)
.then(function () {
return trx.write(client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'anEvent'))
.then(function () {