Use Long in Stream catchup subscription
Use Long in tests Bump version to 2.0
This commit is contained in:
parent
4584517ede
commit
e79ad8f9c4
7
index.d.ts
vendored
7
index.d.ts
vendored
|
@ -98,8 +98,7 @@ export class FileLogger implements Logger {
|
|||
error(fmt: string, ...args: any[]): void;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
// Expose results
|
||||
export interface WriteResult {
|
||||
readonly nextExpectedVersion: Long;
|
||||
readonly logPosition: Position;
|
||||
|
@ -261,9 +260,9 @@ export interface EventStoreNodeConnection {
|
|||
readAllEventsBackward(position: Position, maxCount: number, resolveLinkTos?: boolean, userCredentials?: UserCredentials): Promise<AllEventsSlice>;
|
||||
// subscription actions
|
||||
subscribeToStream(stream: string, resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreSubscription>, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreSubscription>, userCredentials?: UserCredentials): Promise<EventStoreSubscription>;
|
||||
subscribeToStreamFrom(stream: string, lastCheckpoint: number | null, resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreCatchUpSubscription>, liveProcessingStarted?: LiveProcessingStartedCallback, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreCatchUpSubscription>, userCredentials?: UserCredentials, readBatchSize?: number): EventStoreCatchUpSubscription;
|
||||
subscribeToStreamFrom(stream: string, lastCheckpoint: Long|number|null, resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreCatchUpSubscription>, liveProcessingStarted?: LiveProcessingStartedCallback, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreCatchUpSubscription>, userCredentials?: UserCredentials, readBatchSize?: number): EventStoreCatchUpSubscription;
|
||||
subscribeToAll(resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreSubscription>, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreSubscription>, userCredentials?: UserCredentials): Promise<EventStoreSubscription>;
|
||||
subscribeToAllFrom(lastCheckpoint: Position | null, resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreCatchUpSubscription>, liveProcessingStarted?: LiveProcessingStartedCallback, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreCatchUpSubscription>, userCredentials?: UserCredentials, readBatchSize?: number): EventStoreCatchUpSubscription;
|
||||
subscribeToAllFrom(lastCheckpoint: Position|null, resolveLinkTos: boolean, eventAppeared: EventAppearedCallback<EventStoreCatchUpSubscription>, liveProcessingStarted?: LiveProcessingStartedCallback, subscriptionDropped?: SubscriptionDroppedCallback<EventStoreCatchUpSubscription>, userCredentials?: UserCredentials, readBatchSize?: number): EventStoreCatchUpSubscription;
|
||||
// persistent subscriptions
|
||||
createPersistentSubscription(stream: string, groupName: string, settings: PersistentSubscriptionSettings, userCredentials?: PersistentSubscriptionSettings): Promise<PersistentSubscriptionCreateResult>;
|
||||
updatePersistentSubscription(stream: string, groupName: string, settings: PersistentSubscriptionSettings, userCredentials?: PersistentSubscriptionSettings): Promise<PersistentSubscriptionUpdateResult>;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "node-eventstore-client",
|
||||
"version": "0.1.8",
|
||||
"version": "0.2.0",
|
||||
"description": "A port of the EventStore .Net ClientAPI to Node.js",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
|
|
|
@ -247,7 +247,7 @@ EventStoreNodeConnection.prototype.readEvent = function(stream, eventNumber, res
|
|||
ensure.notNullOrEmpty(stream, "stream");
|
||||
ensure.isLongOrInteger(eventNumber, "eventNumber");
|
||||
eventNumber = Long.fromValue(eventNumber);
|
||||
resolveLinkTos = !!resolveLinkTos;
|
||||
resolveLinkTos = Boolean(resolveLinkTos);
|
||||
userCredentials = userCredentials || null;
|
||||
|
||||
if (typeof stream !== 'string' || stream === '') throw new TypeError("stream must be an non-empty string.");
|
||||
|
@ -286,7 +286,7 @@ EventStoreNodeConnection.prototype.readStreamEventsForward = function(
|
|||
ensure.isInteger(count, "count");
|
||||
ensure.positive(count, "count");
|
||||
if (count > MaxReadSize) throw new Error(util.format("Count should be less than %d. For larger reads you should page.", MaxReadSize));
|
||||
resolveLinkTos = !!resolveLinkTos;
|
||||
resolveLinkTos = Boolean(resolveLinkTos);
|
||||
userCredentials = userCredentials || null;
|
||||
|
||||
var self = this;
|
||||
|
@ -320,7 +320,7 @@ EventStoreNodeConnection.prototype.readStreamEventsBackward = function(
|
|||
ensure.isInteger(count, "count");
|
||||
ensure.positive(count, "count");
|
||||
if (count > MaxReadSize) throw new Error(util.format("Count should be less than %d. For larger reads you should page.", MaxReadSize));
|
||||
resolveLinkTos = !!resolveLinkTos;
|
||||
resolveLinkTos = Boolean(resolveLinkTos);
|
||||
userCredentials = userCredentials || null;
|
||||
|
||||
var self = this;
|
||||
|
@ -351,7 +351,7 @@ EventStoreNodeConnection.prototype.readAllEventsForward = function(
|
|||
ensure.isInteger(maxCount, "maxCount");
|
||||
ensure.positive(maxCount, "maxCount");
|
||||
if (maxCount > MaxReadSize) throw new Error(util.format("Count should be less than %d. For larger reads you should page.", MaxReadSize));
|
||||
resolveLinkTos = !!resolveLinkTos;
|
||||
resolveLinkTos = Boolean(resolveLinkTos);
|
||||
userCredentials = userCredentials || null;
|
||||
|
||||
var self = this;
|
||||
|
@ -382,7 +382,7 @@ EventStoreNodeConnection.prototype.readAllEventsBackward = function(
|
|||
ensure.isInteger(maxCount, "maxCount");
|
||||
ensure.positive(maxCount, "maxCount");
|
||||
if (maxCount > MaxReadSize) throw new Error(util.format("Count should be less than %d. For larger reads you should page.", MaxReadSize));
|
||||
resolveLinkTos = !!resolveLinkTos;
|
||||
resolveLinkTos = Boolean(resolveLinkTos);
|
||||
userCredentials = userCredentials || null;
|
||||
|
||||
var self = this;
|
||||
|
@ -432,7 +432,7 @@ EventStoreNodeConnection.prototype.subscribeToStream = function(
|
|||
* Subscribe to a stream from position
|
||||
* @public
|
||||
* @param {!string} stream
|
||||
* @param {?number} lastCheckpoint
|
||||
* @param {?number|Position} lastCheckpoint
|
||||
* @param {!boolean} resolveLinkTos
|
||||
* @param {!function} eventAppeared
|
||||
* @param {function} [liveProcessingStarted]
|
||||
|
@ -446,7 +446,10 @@ EventStoreNodeConnection.prototype.subscribeToStreamFrom = function(
|
|||
userCredentials, readBatchSize
|
||||
) {
|
||||
if (typeof stream !== 'string' || stream === '') throw new TypeError("stream must be a non-empty string.");
|
||||
if (lastCheckpoint !== null && typeof lastCheckpoint !== 'number') throw new TypeError("lastCheckpoint must be a number or null.");
|
||||
if (lastCheckpoint !== null) {
|
||||
ensure.isLongOrInteger(lastCheckpoint);
|
||||
lastCheckpoint = Long.fromValue(lastCheckpoint);
|
||||
}
|
||||
if (typeof eventAppeared !== 'function') throw new TypeError("eventAppeared must be a function.");
|
||||
|
||||
var catchUpSubscription =
|
||||
|
@ -536,7 +539,7 @@ EventStoreNodeConnection.prototype.connectToPersistentSubscription = function(
|
|||
subscriptionDropped = subscriptionDropped || null;
|
||||
userCredentials = userCredentials || null;
|
||||
bufferSize = bufferSize === undefined ? 10 : bufferSize;
|
||||
autoAck = autoAck === undefined ? true : !!autoAck;
|
||||
autoAck = autoAck === undefined ? true : Boolean(autoAck);
|
||||
|
||||
var subscription = new EventStorePersistentSubscription(
|
||||
groupName, stream, eventAppeared, subscriptionDropped, userCredentials, this._settings.log,
|
||||
|
@ -686,9 +689,9 @@ EventStoreNodeConnection.prototype.getStreamMetadataRaw = function(stream, userC
|
|||
return new results.RawStreamMetadataResult(stream, false, Long.fromValue(version), data);
|
||||
case results.EventReadStatus.NotFound:
|
||||
case results.EventReadStatus.NoStream:
|
||||
return new results.RawStreamMetadataResult(stream, false, -1, null);
|
||||
return new results.RawStreamMetadataResult(stream, false, Long.fromValue(-1), null);
|
||||
case results.EventReadStatus.StreamDeleted:
|
||||
return new results.RawStreamMetadataResult(stream, true, 0x7fffffff, null);
|
||||
return new results.RawStreamMetadataResult(stream, true, Long.fromValue(0x7fffffff), null);
|
||||
default:
|
||||
throw new Error(util.format("Unexpected ReadEventResult: %s.", res.status));
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var util = require('util');
|
||||
var Long = require('long');
|
||||
|
||||
var EventStoreCatchUpSubscription = require('./eventStoreCatchUpSubscription');
|
||||
var SliceReadStatus = require('./sliceReadStatus');
|
||||
|
@ -14,8 +15,8 @@ function EventStoreStreamCatchUpSubscription(
|
|||
|
||||
//Ensure.NotNullOrEmpty(streamId, "streamId");
|
||||
|
||||
this._lastProcessedEventNumber = fromEventNumberExclusive === null ? -1 : fromEventNumberExclusive;
|
||||
this._nextReadEventNumber = fromEventNumberExclusive === null ? 0 : fromEventNumberExclusive + 1;
|
||||
this._lastProcessedEventNumber = fromEventNumberExclusive === null ? Long.fromNumber(-1) : fromEventNumberExclusive;
|
||||
this._nextReadEventNumber = fromEventNumberExclusive === null ? Long.fromNumber(0) : fromEventNumberExclusive.add(1);
|
||||
}
|
||||
util.inherits(EventStoreStreamCatchUpSubscription, EventStoreCatchUpSubscription);
|
||||
|
||||
|
@ -47,14 +48,14 @@ EventStoreStreamCatchUpSubscription.prototype._readEventsTill = function(
|
|||
return processEvents(slice.events, 0)
|
||||
.then(function() {
|
||||
self._nextReadEventNumber = slice.nextEventNumber;
|
||||
var done = Promise.resolve(lastEventNumber === null ? slice.isEndOfStream : slice.nextEventNumber > lastEventNumber);
|
||||
var done = Promise.resolve(lastEventNumber === null ? slice.isEndOfStream : slice.nextEventNumber.compare(lastEventNumber) > 0);
|
||||
if (!done && slice.isEndOfStream)
|
||||
return delay(100, false);
|
||||
return done;
|
||||
});
|
||||
break;
|
||||
case SliceReadStatus.StreamNotFound:
|
||||
if (lastEventNumber && lastEventNumber !== -1)
|
||||
if (lastEventNumber && lastEventNumber.compare(-1) !== 0)
|
||||
throw new Error(util.format("Impossible: stream %s disappeared in the middle of catching up subscription.", self.streamId));
|
||||
return true;
|
||||
case SliceReadStatus.StreamDeleted:
|
||||
|
@ -80,7 +81,7 @@ EventStoreStreamCatchUpSubscription.prototype._readEventsTill = function(
|
|||
EventStoreStreamCatchUpSubscription.prototype._tryProcess = function(e) {
|
||||
var processed = false;
|
||||
var promise;
|
||||
if (e.originalEventNumber > this._lastProcessedEventNumber) {
|
||||
if (e.originalEventNumber.compare(this._lastProcessedEventNumber) > 0) {
|
||||
promise = this._eventAppeared(this, e);
|
||||
this._lastProcessedEventNumber = e.originalEventNumber;
|
||||
processed = true;
|
||||
|
@ -88,7 +89,7 @@ EventStoreStreamCatchUpSubscription.prototype._tryProcess = function(e) {
|
|||
if (this._verbose)
|
||||
this._log.debug("Catch-up Subscription to %s: %s event (%s, %d, %s @ %d).",
|
||||
this.isSubscribedToAll ? '<all>' : this.streamId, processed ? "processed" : "skipping",
|
||||
e.originalEvent.eventStreamId, e.originalEvent.eventNumber, e.originalEvent.eventType, e.originalEventNumber)
|
||||
e.originalEvent.eventStreamId, e.originalEvent.eventNumber, e.originalEvent.eventType, e.originalEventNumber);
|
||||
return (promise && promise.then) ? promise : Promise.resolve();
|
||||
};
|
||||
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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();
|
||||
})
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 () {
|
||||
|
|
Loading…
Reference in New Issue
Block a user