2016-10-15 05:53:23 +00:00
|
|
|
var util = require('util');
|
|
|
|
var uuid = require('uuid');
|
2019-11-01 18:30:06 +00:00
|
|
|
var client = require('../lib/dist');
|
2016-10-15 05:53:23 +00:00
|
|
|
const adminCredentials = new client.UserCredentials("admin", "changeit");
|
|
|
|
|
|
|
|
function createRandomEvent() {
|
|
|
|
return client.createJsonEventData(uuid.v4(), {a: uuid.v4(), b: Math.random()}, {createdAt: Date.now()}, 'testEvent');
|
|
|
|
}
|
|
|
|
|
2016-10-18 04:58:28 +00:00
|
|
|
var testStreamName = 'test-' + uuid.v4();
|
2016-10-15 05:53:23 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
'Test Create Persistent Subscription': function(test) {
|
|
|
|
var settings = client.PersistentSubscriptionSettings.create();
|
|
|
|
this.conn.createPersistentSubscription(testStreamName, 'consumer-1', settings, adminCredentials)
|
|
|
|
.then(function(result) {
|
|
|
|
test.done();
|
|
|
|
})
|
|
|
|
.catch(function(err) {
|
|
|
|
test.done(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
//TODO: Update Persistent Subscription
|
|
|
|
'Test ConnectTo Persistent Subscription': function(test) {
|
2017-07-17 00:11:54 +00:00
|
|
|
test.expect(4);
|
|
|
|
var receivedEvents = [];
|
2017-01-29 02:04:58 +00:00
|
|
|
var _doneCount = 0;
|
|
|
|
function done(err) {
|
|
|
|
test.ok(!err, err ? err.stack : '');
|
|
|
|
_doneCount++;
|
|
|
|
if (_doneCount < 2) return;
|
|
|
|
test.done();
|
|
|
|
}
|
2016-10-15 05:53:23 +00:00
|
|
|
function eventAppeared(s, e) {
|
2020-09-16 15:23:46 +00:00
|
|
|
receivedEvents.push(e);
|
|
|
|
if (receivedEvents.length === 2) s.stop();
|
2016-10-15 05:53:23 +00:00
|
|
|
}
|
|
|
|
function subscriptionDropped(connection, reason, error) {
|
2017-07-17 00:11:54 +00:00
|
|
|
if (error) return done(error);
|
|
|
|
test.ok(receivedEvents[1].originalEventNumber > receivedEvents[0].originalEventNumber, "Received events are out of order.");
|
|
|
|
done();
|
2016-10-15 05:53:23 +00:00
|
|
|
}
|
2017-07-01 01:54:25 +00:00
|
|
|
var self = this;
|
|
|
|
this.conn.connectToPersistentSubscription(testStreamName, 'consumer-1', eventAppeared, subscriptionDropped)
|
|
|
|
.then(function(subscription) {
|
|
|
|
test.ok(subscription, "Subscription is null.");
|
2017-07-17 00:11:54 +00:00
|
|
|
return self.conn.appendToStream(testStreamName, client.expectedVersion.any, [createRandomEvent(), createRandomEvent()]);
|
2017-07-01 01:54:25 +00:00
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
done();
|
|
|
|
})
|
|
|
|
.catch(done);
|
2016-10-15 05:53:23 +00:00
|
|
|
},
|
|
|
|
'Test Delete Persistent Subscription': function(test) {
|
|
|
|
this.conn.deletePersistentSubscription(testStreamName, 'consumer-1', adminCredentials)
|
|
|
|
.then(function(result) {
|
|
|
|
test.done();
|
|
|
|
})
|
|
|
|
.catch(function(err) {
|
|
|
|
test.done(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-01 18:30:06 +00:00
|
|
|
require('./common/base_test').init(module.exports);
|