18 - Changing all hostname to host, fixing some async issues in tests

This commit is contained in:
Nicolas Dextraze 2017-01-28 18:04:58 -08:00
parent f97b7fff8e
commit 006b5b4791
29 changed files with 246 additions and 90 deletions

3
.gitignore vendored
View File

@ -40,3 +40,6 @@ lib/
.eslintrc.json .eslintrc.json
jsconfig.json jsconfig.json
docs/ docs/
# Vagrant
.vagrant

View File

@ -47,10 +47,10 @@ var esClient = require('eventstore-node');
var uuid = require('uuid'); var uuid = require('uuid');
var streamName = "testStream"; var streamName = "testStream";
var esConnection = esClient.createConnection({}, {"hostname": "localhost", "port": 1113}); var esConnection = esClient.createConnection({}, "tcp://localhost:1113");
esConnection.connect(); esConnection.connect();
esConnection.once('connected', function (tcpEndPoint) { esConnection.once('connected', function (tcpEndPoint) {
console.log('Connected to eventstore at ' + tcpEndPoint.hostname + ":" + tcpEndPoint.port); console.log('Connected to eventstore at ' + tcpEndPoint.host + ":" + tcpEndPoint.port);
}); });
var eventId = uuid.v4(); var eventId = uuid.v4();

115
Vagrantfile vendored
View File

@ -10,63 +10,78 @@ Vagrant.configure("2") do |config|
# For a complete reference, please see the online documentation at # For a complete reference, please see the online documentation at
# https://docs.vagrantup.com. # https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for config.vm.define "es_cluster_1" do |es_cluster_1|
# boxes at https://atlas.hashicorp.com/search. es_cluster_1.vm.box = "ubuntu/trusty64"
config.vm.box = "ubuntu/trusty64"
# Disable automatic box update checking. If you disable this, then es_cluster_1.vm.box_check_update = false
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port es_cluster_1.vm.network "private_network", ip: "192.168.33.10"
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine es_cluster_1.vm.provider "virtualbox" do |vb|
# using a specific IP. vb.memory = "512"
config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# Customize the amount of memory on the VM:
vb.memory = "1024"
end end
#
# View the documentation for the provider you are using for more
# information on available options.
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies es_cluster_1.vm.provision "shell", inline: <<-SHELL
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
config.vm.provision "shell", inline: <<-SHELL
curl -s https://packagecloud.io/install/repositories/EventStore/EventStore-OSS/script.deb.sh | sudo bash curl -s https://packagecloud.io/install/repositories/EventStore/EventStore-OSS/script.deb.sh | sudo bash
sudo apt install EventStore-OSS sudo apt install EventStore-OSS
sudo echo "---" > /etc/eventstore/eventstore.conf
sudo echo "RunProjections: None" >> /etc/eventstore/eventstore.conf
sudo echo "IntIp: 192.168.33.10" >> /etc/eventstore/eventstore.conf
sudo echo "ExtIp: 192.168.33.10" >> /etc/eventstore/eventstore.conf
sudo echo "ClusterSize: 3" >> /etc/eventstore/eventstore.conf
sudo echo "DiscoverViaDns: False" >> /etc/eventstore/eventstore.conf
sudo echo "GossipSeed: ['192.168.33.11:2112','192.168.33.12:2112']" >> /etc/eventstore/eventstore.conf
sudo service eventstore start sudo service eventstore start
SHELL SHELL
end
config.vm.define "es_cluster_2" do |es_cluster_2|
es_cluster_2.vm.box = "ubuntu/trusty64"
es_cluster_2.vm.box_check_update = false
es_cluster_2.vm.network "private_network", ip: "192.168.33.11"
es_cluster_2.vm.provider "virtualbox" do |vb|
vb.memory = "512"
end
es_cluster_2.vm.provision "shell", inline: <<-SHELL
curl -s https://packagecloud.io/install/repositories/EventStore/EventStore-OSS/script.deb.sh | sudo bash
sudo apt install EventStore-OSS
sudo echo "---" > /etc/eventstore/eventstore.conf
sudo echo "RunProjections: None" >> /etc/eventstore/eventstore.conf
sudo echo "IntIp: 192.168.33.11" >> /etc/eventstore/eventstore.conf
sudo echo "ExtIp: 192.168.33.11" >> /etc/eventstore/eventstore.conf
sudo echo "ClusterSize: 3" >> /etc/eventstore/eventstore.conf
sudo echo "DiscoverViaDns: False" >> /etc/eventstore/eventstore.conf
sudo echo "GossipSeed: ['192.168.33.10:2112','192.168.33.12:2112']" >> /etc/eventstore/eventstore.conf
sudo service eventstore start
SHELL
end
config.vm.define "es_cluster_3" do |es_cluster_3|
es_cluster_3.vm.box = "ubuntu/trusty64"
es_cluster_3.vm.box_check_update = false
es_cluster_3.vm.network "private_network", ip: "192.168.33.12"
es_cluster_3.vm.provider "virtualbox" do |vb|
vb.memory = "512"
end
es_cluster_3.vm.provision "shell", inline: <<-SHELL
curl -s https://packagecloud.io/install/repositories/EventStore/EventStore-OSS/script.deb.sh | sudo bash
sudo apt install EventStore-OSS
sudo echo "---" > /etc/eventstore/eventstore.conf
sudo echo "RunProjections: None" >> /etc/eventstore/eventstore.conf
sudo echo "IntIp: 192.168.33.12" >> /etc/eventstore/eventstore.conf
sudo echo "ExtIp: 192.168.33.12" >> /etc/eventstore/eventstore.conf
sudo echo "ClusterSize: 3" >> /etc/eventstore/eventstore.conf
sudo echo "DiscoverViaDns: False" >> /etc/eventstore/eventstore.conf
sudo echo "GossipSeed: ['192.168.33.10:2112','192.168.33.11:2112']" >> /etc/eventstore/eventstore.conf
sudo service eventstore start
SHELL
end
end end

2
index.d.ts vendored
View File

@ -25,7 +25,7 @@ export function createEventData(eventId: string, type: string, isJson: boolean,
export interface TcpEndPoint { export interface TcpEndPoint {
port: number; port: number;
hostname: string; host: string;
} }
export class GossipSeed { export class GossipSeed {

View File

@ -6,9 +6,9 @@ var settings = {
log: new client.FileLogger('./simple-verbose.log') log: new client.FileLogger('./simple-verbose.log')
}; };
var gossipSeeds = [ var gossipSeeds = [
new client.GossipSeed({hostname: 'localhost', port: 1113}), new client.GossipSeed({host: '192.168.33.10', port: 2113}),
new client.GossipSeed({hostname: 'localhost', port: 2113}), new client.GossipSeed({host: '192.168.33.11', port: 2113}),
new client.GossipSeed({hostname: 'localhost', port: 3113}) new client.GossipSeed({host: '192.168.33.12', port: 2113})
]; ];
var conn = client.createConnection(settings, gossipSeeds); var conn = client.createConnection(settings, gossipSeeds);
conn.connect() conn.connect()

View File

@ -5,7 +5,7 @@ var uuid = require('uuid');
var esConnection = esClient.createConnection({}, {"hostname": "localhost", "port": 1113}); var esConnection = esClient.createConnection({}, {"hostname": "localhost", "port": 1113});
esConnection.connect(); esConnection.connect();
esConnection.once('connected', function (tcpEndPoint) { esConnection.once('connected', function (tcpEndPoint) {
console.log('Connected to eventstore at ' + tcpEndPoint.hostname + ":" + tcpEndPoint.port); console.log('Connected to eventstore at ' + tcpEndPoint.host + ":" + tcpEndPoint.port);
var userId = uuid.v4(); var userId = uuid.v4();
// This event could happen as a result of (e.g.) a 'CreateUser(id, username, password)' command. // This event could happen as a result of (e.g.) a 'CreateUser(id, username, password)' command.
var userCreatedEvent = { var userCreatedEvent = {

View File

@ -9,7 +9,7 @@ const resolveLinkTos = false;
var esConnection = esClient.createConnection({}, {"hostname": "localhost", "port": 1113}); var esConnection = esClient.createConnection({}, {"hostname": "localhost", "port": 1113});
esConnection.connect(); esConnection.connect();
esConnection.once('connected', function (tcpEndPoint) { esConnection.once('connected', function (tcpEndPoint) {
console.log('Connected to eventstore at ' + tcpEndPoint.hostname + ":" + tcpEndPoint.port); console.log('Connected to eventstore at ' + tcpEndPoint.host + ":" + tcpEndPoint.port);
esConnection.subscribeToAll(resolveLinkTos, eventAppeared, subscriptionDropped, credentialsForAllEventsStream) esConnection.subscribeToAll(resolveLinkTos, eventAppeared, subscriptionDropped, credentialsForAllEventsStream)
.then(function(subscription) { .then(function(subscription) {
console.log("subscription.isSubscribedToAll: " + subscription.isSubscribedToAll); console.log("subscription.isSubscribedToAll: " + subscription.isSubscribedToAll);

View File

@ -9,7 +9,7 @@ const credentialsForAllEventsStream = new esClient.UserCredentials("admin", "cha
var esConnection = esClient.createConnection({}, {"hostname": "localhost", "port": 1113}); var esConnection = esClient.createConnection({}, {"hostname": "localhost", "port": 1113});
esConnection.connect(); esConnection.connect();
esConnection.once('connected', function (tcpEndPoint) { esConnection.once('connected', function (tcpEndPoint) {
console.log('Connected to eventstore at ' + tcpEndPoint.hostname + ":" + tcpEndPoint.port); console.log('Connected to eventstore at ' + tcpEndPoint.host + ":" + tcpEndPoint.port);
var subscription = esConnection.subscribeToAllFrom(null, true, eventAppeared, liveProcessingStarted, subscriptionDropped, credentialsForAllEventsStream); var subscription = esConnection.subscribeToAllFrom(null, true, eventAppeared, liveProcessingStarted, subscriptionDropped, credentialsForAllEventsStream);
console.log("subscription.isSubscribedToAll: " + subscription.isSubscribedToAll); console.log("subscription.isSubscribedToAll: " + subscription.isSubscribedToAll);
}); });

View File

@ -134,7 +134,6 @@ ClusterDnsEndPointDiscoverer.prototype._getGossipCandidatesFromDns = function ()
ClusterDnsEndPointDiscoverer.prototype._tryGetGossipFrom = function (endPoint) { ClusterDnsEndPointDiscoverer.prototype._tryGetGossipFrom = function (endPoint) {
var options = { var options = {
host: endPoint.endPoint.host, host: endPoint.endPoint.host,
hostname: endPoint.endPoint.hostname,
port: endPoint.endPoint.port, port: endPoint.endPoint.port,
path: '/gossip?format=json' path: '/gossip?format=json'
}; };

View File

@ -30,17 +30,20 @@ OperationsManager.prototype.getActiveOperation = function(correlationId) {
return this._activeOperations.get(correlationId); return this._activeOperations.get(correlationId);
}; };
OperationsManager.prototype.cleanUp = function() { function cleanUpError(connName, state, operation) {
var connectionClosedError = new Error(util.format("Connection '%s' was closed.", this._connectionName)); return new Error(util.format("Connection '%s' was closed. %s %s.", connName, state, operation.toString()));
}
OperationsManager.prototype.cleanUp = function() {
var self = this;
this._activeOperations.forEach(function(correlationId, operation){ this._activeOperations.forEach(function(correlationId, operation){
operation.operation.fail(connectionClosedError); operation.operation.fail(cleanUpError(self._connectionName, 'Active', operation));
}); });
this._waitingOperations.forEach(function(operation) { this._waitingOperations.forEach(function(operation) {
operation.operation.fail(connectionClosedError); operation.operation.fail(cleanUpError(self._connectionName, 'Waiting', operation));
}); });
this._retryPendingOperations.forEach(function(operation) { this._retryPendingOperations.forEach(function(operation) {
operation.operation.fail(connectionClosedError); operation.operation.fail(cleanUpError(self._connectionName, 'Pending', operation));
}); });
this._activeOperations.clear(); this._activeOperations.clear();

View File

@ -49,7 +49,7 @@ function merge(a,b) {
} }
function createFromTcpEndpoint(settings, tcpEndpoint, connectionName) { function createFromTcpEndpoint(settings, tcpEndpoint, connectionName) {
if (!tcpEndpoint.port || !tcpEndpoint.hostname) throw new TypeError('endPoint object must have hostname and port properties.'); if (!tcpEndpoint.port || !tcpEndpoint.host) throw new TypeError('endPoint object must have host and port properties.');
var mergedSettings = merge(defaultConnectionSettings, settings || {}); var mergedSettings = merge(defaultConnectionSettings, settings || {});
var endpointDiscoverer = new StaticEndpointDiscoverer(tcpEndpoint, settings.useSslConnection); var endpointDiscoverer = new StaticEndpointDiscoverer(tcpEndpoint, settings.useSslConnection);
return new EventStoreNodeConnection(mergedSettings, null, endpointDiscoverer, connectionName || null); return new EventStoreNodeConnection(mergedSettings, null, endpointDiscoverer, connectionName || null);
@ -59,11 +59,11 @@ function createFromStringEndpoint(settings, endPoint, connectionName) {
var m = endPoint.match(/^(tcp|discover):\/\/([^:]+):?(\d+)?$/); var m = endPoint.match(/^(tcp|discover):\/\/([^:]+):?(\d+)?$/);
if (!m) throw new Error('endPoint string must be tcp://hostname[:port] or discover://dns[:port]'); if (!m) throw new Error('endPoint string must be tcp://hostname[:port] or discover://dns[:port]');
var scheme = m[1]; var scheme = m[1];
var hostname = m[2]; var host = m[2];
var port = m[3] ? parseInt(m[3]) : 1113; var port = m[3] ? parseInt(m[3]) : 1113;
if (scheme === 'tcp') { if (scheme === 'tcp') {
var tcpEndpoint = { var tcpEndpoint = {
hostname: hostname, host: host,
port: port port: port
}; };
return createFromTcpEndpoint(settings, tcpEndpoint, connectionName); return createFromTcpEndpoint(settings, tcpEndpoint, connectionName);

View File

@ -1,5 +1,5 @@
module.exports = function GossipSeed(endPoint, hostName) { module.exports = function GossipSeed(endPoint, hostName) {
//if (typeof endPoint !== 'object' || !endPoint.hostname || !endPoint.port) throw new TypeError('endPoint must be have hostname and port properties.'); if (typeof endPoint !== 'object' || !endPoint.host || !endPoint.port) throw new TypeError('endPoint must be have host and port properties.');
Object.defineProperties(this, { Object.defineProperties(this, {
endPoint: { endPoint: {
enumerable: true, enumerable: true,

View File

@ -136,7 +136,7 @@ TcpConnection.createConnectingConnection = function(
onConnectionEstablished, onConnectionFailed, onConnectionClosed onConnectionEstablished, onConnectionFailed, onConnectionClosed
) { ) {
var connection = new TcpConnection(log, connectionId, remoteEndPoint, onConnectionClosed); var connection = new TcpConnection(log, connectionId, remoteEndPoint, onConnectionClosed);
var socket = net.connect(remoteEndPoint.port, remoteEndPoint.hostname); var socket = net.connect(remoteEndPoint.port, remoteEndPoint.host);
function onError(err) { function onError(err) {
if (onConnectionFailed) if (onConnectionFailed)
onConnectionFailed(connection, err); onConnectionFailed(connection, err);

View File

@ -3,6 +3,7 @@ var client = require('../src/client');
module.exports = { module.exports = {
'Append One Event To Stream Happy Path': function(test) { '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'); 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, client.expectedVersion.any, event)
.then(function(result) { .then(function(result) {
@ -15,6 +16,7 @@ module.exports = {
}); });
}, },
'Append Multiple Events To Stream Happy Path': function(test) { 'Append Multiple Events To Stream Happy Path': function(test) {
test.expect(2);
const expectedVersion = 25; const expectedVersion = 25;
var events = []; var events = [];
for(var i = 0; i <= expectedVersion; i++) { for(var i = 0; i <= expectedVersion; i++) {
@ -34,6 +36,7 @@ module.exports = {
}); });
}, },
'Append To Stream Wrong Expected Version': function(test) { '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'); 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, 10, event)
.then(function(result) { .then(function(result) {
@ -48,6 +51,7 @@ module.exports = {
}); });
}, },
'Append To Stream Deleted': function(test) { 'Append To Stream Deleted': function(test) {
test.expect(1);
var self = this; var self = this;
this.conn.deleteStream(this.testStreamName, client.expectedVersion.noStream, true) this.conn.deleteStream(this.testStreamName, client.expectedVersion.noStream, true)
.then(function() { .then(function() {
@ -66,6 +70,7 @@ module.exports = {
}); });
}, },
'Append To Stream Access Denied': function(test) { 'Append To Stream Access Denied': function(test) {
test.expect(1);
var self = this; var self = this;
var metadata = {$acl: {$w: "$admins"}}; var metadata = {$acl: {$w: "$admins"}};
this.conn.setStreamMetadataRaw(this.testStreamName, client.expectedVersion.noStream, metadata) this.conn.setStreamMetadataRaw(this.testStreamName, client.expectedVersion.noStream, metadata)

View File

@ -0,0 +1,38 @@
var client = require('../../src/client');
var uuid = require('uuid');
var settings = {
log: {
info: console.log,
error: console.log,
debug: console.log
}
};
var gossipSeeds = [
new client.GossipSeed({host: 'localhost', port: 1113}),
new client.GossipSeed({host: 'localhost', port: 2113}),
new client.GossipSeed({host: 'localhost', port: 3113})
];
var conn = client.createConnection(settings, gossipSeeds);
console.log('Connecting...');
conn.on('connected', function (tcpEndPoint) {
console.log('Connect to', tcpEndPoint);
setTimeout(function () {
conn.appendToStream('test-' + uuid.v4(), client.expectedVersion.noStream, [
client.createJsonEventData(uuid.v4(), {abc: 123}, {}, 'myEvent')
]);
}, 5000);
});
conn.on('error', function (err) {
console.log(err.stack);
});
conn.on('closed', function (reason) {
console.log('Connection closed:', reason);
process.exit(-1);
});
conn.connect()
.catch(function (err) {
console.log(err.stack);
process.exit(-1);
});

View File

@ -12,7 +12,7 @@ if (process.env.TESTS_VERBOSE_LOGGING === '1') {
settings.log = new FileLogger('test-verbose.log'); settings.log = new FileLogger('test-verbose.log');
} }
var tcpEndPoint = {hostname: 'localhost', port: 1113}; var tcpEndPoint = {host: '192.168.33.10', port: 1113};
function setUp(cb) { function setUp(cb) {
this.log = settings.log; this.log = settings.log;

View File

@ -5,7 +5,8 @@ var testBase = require('./common/base_test');
module.exports = { module.exports = {
'Connect To Endpoint Happy Path': function(test) { 'Connect To Endpoint Happy Path': function(test) {
var tcpEndpoint = {hostname: 'localhost', port: 1113}; test.expect(1);
var tcpEndpoint = {host: '192.168.33.10', port: 1113};
var conn = client.EventStoreConnection.create(testBase.settings(), tcpEndpoint); var conn = client.EventStoreConnection.create(testBase.settings(), tcpEndpoint);
conn.connect() conn.connect()
.catch(function(err) { .catch(function(err) {
@ -24,7 +25,8 @@ module.exports = {
} }
}, },
'Connect To Endpoint That Doesn\'t Exist': function(test) { 'Connect To Endpoint That Doesn\'t Exist': function(test) {
var tcpEndpoint = {hostname: 'localhost', port: 11112}; test.expect(1);
var tcpEndpoint = {host: 'localhost', port: 11112};
var conn = client.EventStoreConnection.create(testBase.settings({maxReconnections:1}), tcpEndpoint); var conn = client.EventStoreConnection.create(testBase.settings({maxReconnections:1}), tcpEndpoint);
conn.connect() conn.connect()
.catch(function (err) { .catch(function (err) {
@ -43,16 +45,16 @@ module.exports = {
}); });
}, },
'Create a connection with tcp://host:port string': function(test) { 'Create a connection with tcp://host:port string': function(test) {
var conn = client.createConnection({}, 'tcp://localhost:2113'); var conn = client.createConnection({}, 'tcp://192.168.33.10:1113');
conn.close(); conn.close();
test.done(); test.done();
}/*, }/*,
'Connect to Cluster using gossip seeds': function (test) { 'Connect to Cluster using gossip seeds': function (test) {
test.expect(1); test.expect(1);
var gossipSeeds = [ var gossipSeeds = [
new GossipSeed({hostname: 'localhost', port: 1113}), new GossipSeed({host: 'localhost', port: 1113}),
new GossipSeed({hostname: 'localhost', port: 2113}), new GossipSeed({host: 'localhost', port: 2113}),
new GossipSeed({hostname: 'localhost', port: 3113}) new GossipSeed({host: 'localhost', port: 3113})
]; ];
var conn = client.EventStoreConnection.create(testBase.settings(), gossipSeeds); var conn = client.EventStoreConnection.create(testBase.settings(), gossipSeeds);
conn.connect() conn.connect()

View File

@ -14,6 +14,7 @@ module.exports = {
.catch(cb); .catch(cb);
}, },
'Test Delete Stream Soft Happy Path': function(test) { 'Test Delete Stream Soft Happy Path': function(test) {
test.expect(4);
var self = this; var self = this;
this.conn.deleteStream(this.testStreamName, 1, false) this.conn.deleteStream(this.testStreamName, 1, false)
.then(function(result) { .then(function(result) {
@ -31,6 +32,7 @@ module.exports = {
}); });
}, },
'Test Delete Stream Hard Happy Path': function(test) { 'Test Delete Stream Hard Happy Path': function(test) {
test.expect(4);
var self = this; var self = this;
this.conn.deleteStream(this.testStreamName, 1, true) this.conn.deleteStream(this.testStreamName, 1, true)
.then(function(result) { .then(function(result) {
@ -48,6 +50,7 @@ module.exports = {
}); });
}, },
'Test Delete Stream With Wrong Expected Version': function(test) { 'Test Delete Stream With Wrong Expected Version': function(test) {
test.expect(1);
this.conn.deleteStream(this.testStreamName, 10) this.conn.deleteStream(this.testStreamName, 10)
.then(function(result) { .then(function(result) {
test.fail("Delete succeeded but should have failed."); test.fail("Delete succeeded but should have failed.");
@ -61,6 +64,7 @@ module.exports = {
}); });
}, },
'Test Delete Stream With No Access': function(test) { 'Test Delete Stream With No Access': function(test) {
test.expect(1);
var self = this; var self = this;
this.conn.setStreamMetadataRaw(this.testStreamName, client.expectedVersion.any, {$acl: {$d: "$admins"}}) this.conn.setStreamMetadataRaw(this.testStreamName, client.expectedVersion.any, {$acl: {$d: "$admins"}})
.then(function() { .then(function() {
@ -78,6 +82,7 @@ module.exports = {
}); });
}, },
'Test Delete Stream Hard When Already Deleted': function(test) { 'Test Delete Stream Hard When Already Deleted': function(test) {
test.expect(1);
var self = this; var self = this;
this.conn.deleteStream(this.testStreamName, 1, true) this.conn.deleteStream(this.testStreamName, 1, true)
.then(function() { .then(function() {

View File

@ -22,14 +22,26 @@ module.exports = {
}, },
//TODO: Update Persistent Subscription //TODO: Update Persistent Subscription
'Test ConnectTo Persistent Subscription': function(test) { 'Test ConnectTo Persistent Subscription': function(test) {
test.expect(2);
var _doneCount = 0;
function done(err) {
test.ok(!err, err ? err.stack : '');
_doneCount++;
if (_doneCount < 2) return;
test.done();
}
function eventAppeared(s, e) { function eventAppeared(s, e) {
s.stop(); s.stop();
} }
function subscriptionDropped(connection, reason, error) { function subscriptionDropped(connection, reason, error) {
test.done(error); done(error);
} }
var subscription = this.conn.connectToPersistentSubscription(testStreamName, 'consumer-1', eventAppeared, subscriptionDropped); var subscription = this.conn.connectToPersistentSubscription(testStreamName, 'consumer-1', eventAppeared, subscriptionDropped);
this.conn.appendToStream(testStreamName, client.expectedVersion.any, [createRandomEvent()]); this.conn.appendToStream(testStreamName, client.expectedVersion.any, [createRandomEvent()])
.then(function () {
done();
})
.catch(done);
}, },
'Test Delete Persistent Subscription': function(test) { 'Test Delete Persistent Subscription': function(test) {
this.conn.deletePersistentSubscription(testStreamName, 'consumer-1', adminCredentials) this.conn.deletePersistentSubscription(testStreamName, 'consumer-1', adminCredentials)

View File

@ -37,6 +37,7 @@ module.exports = {
}) })
}, },
'Read All Events Backward Happy Path': function(test) { 'Read All Events Backward Happy Path': function(test) {
test.expect(4 + maxCount);
var self = this; var self = this;
this.conn.readAllEventsBackward(client.positions.end, maxCount, false, allCredentials) this.conn.readAllEventsBackward(client.positions.end, maxCount, false, allCredentials)
.then(function(slice) { .then(function(slice) {
@ -56,6 +57,7 @@ module.exports = {
}) })
}, },
'Read All Events Backward With No Access': function(test) { 'Read All Events Backward With No Access': function(test) {
test.expect(1);
this.conn.readAllEventsBackward(client.positions.end, maxCount) this.conn.readAllEventsBackward(client.positions.end, maxCount)
.then(function(slice) { .then(function(slice) {
test.fail("readAllEventsBackward succeeded but should have failed."); test.fail("readAllEventsBackward succeeded but should have failed.");

View File

@ -37,6 +37,7 @@ module.exports = {
}) })
}, },
'Read All Events Forward Happy Path': function(test) { 'Read All Events Forward Happy Path': function(test) {
test.expect(5 + maxCount);
this.conn.readAllEventsForward(client.positions.start, maxCount, false, allCredentials) this.conn.readAllEventsForward(client.positions.start, maxCount, false, allCredentials)
.then(function(slice) { .then(function(slice) {
test.areEqual('slice.readDirection', slice.readDirection, 'forward'); test.areEqual('slice.readDirection', slice.readDirection, 'forward');
@ -57,6 +58,7 @@ module.exports = {
}) })
}, },
'Read All Events Forward With No Access': function(test) { 'Read All Events Forward With No Access': function(test) {
test.expect(1);
this.conn.readAllEventsForward(client.positions.start, maxCount) this.conn.readAllEventsForward(client.positions.start, maxCount)
.then(function(slice) { .then(function(slice) {
test.fail("readAllEventsForward succeeded but should have failed."); test.fail("readAllEventsForward succeeded but should have failed.");

View File

@ -16,6 +16,7 @@ module.exports = {
.catch(cb); .catch(cb);
}, },
'Read Event Happy Path': function(test) { 'Read Event Happy Path': function(test) {
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) {
@ -35,6 +36,7 @@ module.exports = {
}) })
}, },
'Read Event From Non-Existing Stream': function(test) { 'Read Event From Non-Existing Stream': function(test) {
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) {
@ -49,6 +51,7 @@ module.exports = {
}); });
}, },
'Read Event From Deleted Stream': function(test) { 'Read Event From Deleted Stream': function(test) {
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() {
@ -66,6 +69,7 @@ module.exports = {
}); });
}, },
'Read Event With Inexisting Version': function(test) { 'Read Event With Inexisting Version': function(test) {
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) {
@ -80,6 +84,7 @@ module.exports = {
}); });
}, },
'Read Event With No Access': function(test) { 'Read Event With No Access': function(test) {
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)

View File

@ -16,6 +16,7 @@ module.exports = {
.catch(cb); .catch(cb);
}, },
'Read Stream Events Backward Happy Path': function(test) { 'Read Stream Events Backward Happy Path': function(test) {
test.expect(7 + (streamSize * 6));
var self = this; var self = this;
this.conn.readStreamEventsBackward(this.testStreamName, streamSize-1, streamSize) this.conn.readStreamEventsBackward(this.testStreamName, streamSize-1, streamSize)
.then(function(slice) { .then(function(slice) {
@ -38,6 +39,7 @@ module.exports = {
}) })
}, },
'Read Stream Events Backward With Non-Existing Stream': function(test) { 'Read Stream Events Backward With Non-Existing Stream': function(test) {
test.expect(4);
var anotherStream = 'test' + uuid.v4(); var anotherStream = 'test' + uuid.v4();
this.conn.readStreamEventsBackward(anotherStream, streamSize-1, streamSize) this.conn.readStreamEventsBackward(anotherStream, streamSize-1, streamSize)
.then(function(slice) { .then(function(slice) {
@ -52,6 +54,7 @@ module.exports = {
}); });
}, },
'Read Stream Events Backward With Deleted Stream': function(test) { 'Read Stream Events Backward With Deleted Stream': function(test) {
test.expect(4);
var self = this; var self = this;
this.conn.deleteStream(this.testStreamName, streamSize-1, true) this.conn.deleteStream(this.testStreamName, streamSize-1, true)
.then(function() { .then(function() {
@ -69,6 +72,7 @@ module.exports = {
}); });
}, },
'Read Stream Events Backward With Inexisting Version': function(test) { 'Read Stream Events Backward With Inexisting Version': function(test) {
test.expect(4);
var self = this; var self = this;
return self.conn.readStreamEventsBackward(self.testStreamName, streamSize * 2, streamSize) return self.conn.readStreamEventsBackward(self.testStreamName, streamSize * 2, streamSize)
.then(function(slice) { .then(function(slice) {
@ -83,6 +87,7 @@ module.exports = {
}); });
}, },
'Read Stream Events Backward With No Access': function(test) { 'Read Stream Events Backward With No Access': function(test) {
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)

View File

@ -16,6 +16,7 @@ module.exports = {
.catch(cb); .catch(cb);
}, },
'Read Stream Events Forward Happy Path': function(test) { 'Read Stream Events Forward Happy Path': function(test) {
test.expect(7 + (streamSize * 6));
var self = this; var self = this;
this.conn.readStreamEventsForward(this.testStreamName, 0, streamSize) this.conn.readStreamEventsForward(this.testStreamName, 0, streamSize)
.then(function(slice) { .then(function(slice) {
@ -37,6 +38,7 @@ module.exports = {
}) })
}, },
'Read Stream Events Forward With Non-Existing Stream': function(test) { 'Read Stream Events Forward With Non-Existing Stream': function(test) {
test.expect(4);
var anotherStream = 'test' + uuid.v4(); var anotherStream = 'test' + uuid.v4();
this.conn.readStreamEventsForward(anotherStream, 0, streamSize) this.conn.readStreamEventsForward(anotherStream, 0, streamSize)
.then(function(slice) { .then(function(slice) {
@ -51,6 +53,7 @@ module.exports = {
}); });
}, },
'Read Stream Events Forward With Deleted Stream': function(test) { 'Read Stream Events Forward With Deleted Stream': function(test) {
test.expect(4);
var self = this; var self = this;
this.conn.deleteStream(this.testStreamName, streamSize-1, true) this.conn.deleteStream(this.testStreamName, streamSize-1, true)
.then(function() { .then(function() {
@ -68,6 +71,7 @@ module.exports = {
}); });
}, },
'Read Stream Events Forward With Inexisting Version': function(test) { 'Read Stream Events Forward With Inexisting Version': function(test) {
test.expect(4);
var self = this; var self = this;
return self.conn.readStreamEventsForward(self.testStreamName, streamSize * 2, streamSize) return self.conn.readStreamEventsForward(self.testStreamName, streamSize * 2, streamSize)
.then(function(slice) { .then(function(slice) {
@ -82,6 +86,7 @@ module.exports = {
}); });
}, },
'Read Stream Events Forward With No Access': function(test) { 'Read Stream Events Forward With No Access': function(test) {
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)

View File

@ -9,10 +9,18 @@ function createRandomEvent() {
module.exports = { module.exports = {
'Test Subscribe to All From': function(test) { 'Test Subscribe to All From': function(test) {
test.expect(4);
var self = this; var self = this;
var liveProcessing = false; var liveProcessing = false;
var catchUpEvents = []; var catchUpEvents = [];
var liveEvents = []; var liveEvents = [];
var _doneCount = 0;
function done(err) {
test.ok(!err, err ? err.stack : '');
_doneCount++;
if (_doneCount < 2) return;
test.done();
}
function eventAppeared(s, e) { function eventAppeared(s, e) {
if (liveProcessing) { if (liveProcessing) {
liveEvents.push(e); liveEvents.push(e);
@ -24,12 +32,16 @@ module.exports = {
function liveProcessingStarted() { function liveProcessingStarted() {
liveProcessing = true; liveProcessing = true;
var events = [createRandomEvent()]; var events = [createRandomEvent()];
self.conn.appendToStream(self.testStreamName, client.expectedVersion.any, events); self.conn.appendToStream(self.testStreamName, client.expectedVersion.any, events)
.then(function () {
done();
})
.catch(done);
} }
function subscriptionDropped(connection, reason, error) { function subscriptionDropped(connection, reason, error) {
test.ok(liveEvents.length === 1, "Expecting 1 live event, got " + liveEvents.length); test.ok(liveEvents.length === 1, "Expecting 1 live event, got " + liveEvents.length);
test.ok(catchUpEvents.length > 1, "Expecting at least 1 catchUp event, got " + catchUpEvents.length); test.ok(catchUpEvents.length > 1, "Expecting at least 1 catchUp event, got " + catchUpEvents.length);
test.done(error); done(error);
} }
var subscription = this.conn.subscribeToAllFrom(null, false, eventAppeared, liveProcessingStarted, subscriptionDropped, allCredentials); var subscription = this.conn.subscribeToAllFrom(null, false, eventAppeared, liveProcessingStarted, subscriptionDropped, allCredentials);
} }

View File

@ -6,6 +6,15 @@ module.exports = {
'Test Subscribe To All Happy Path': function(test) { 'Test Subscribe To All Happy Path': function(test) {
const resolveLinkTos = false; const resolveLinkTos = false;
const numberOfPublishedEvents = 5; const numberOfPublishedEvents = 5;
test.expect(numberOfPublishedEvents + 4);
var _doneCount = 0;
function done(err) {
test.ok(!err, err ? err.stack : '');
if (++_doneCount < 2) return;
test.done();
}
var publishedEvents = []; var publishedEvents = [];
for(var i=0;i<numberOfPublishedEvents;i++) for(var i=0;i<numberOfPublishedEvents;i++)
publishedEvents.push(client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'anEvent')); publishedEvents.push(client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'anEvent'));
@ -25,10 +34,10 @@ module.exports = {
if (receivedEvents.length === numberOfPublishedEvents) subscription.close(); if (receivedEvents.length === numberOfPublishedEvents) subscription.close();
} }
function subscriptionDropped(subscription, reason, error) { function subscriptionDropped(subscription, reason, error) {
if (error) return test.done(error); if (error) return done(error);
testAllPublishedEventsAppeared(); testAllPublishedEventsAppeared();
testEventsAppearedInCorrectOrder(); testEventsAppearedInCorrectOrder();
test.done(); done();
} }
var self = this; var self = this;
this.conn.subscribeToAll(resolveLinkTos, eventAppeared, subscriptionDropped, allCredentials) this.conn.subscribeToAll(resolveLinkTos, eventAppeared, subscriptionDropped, allCredentials)
@ -37,6 +46,9 @@ module.exports = {
return self.conn.appendToStream(self.testStreamName, client.expectedVersion.emptyStream, publishedEvents); return self.conn.appendToStream(self.testStreamName, client.expectedVersion.emptyStream, publishedEvents);
}) })
.then(function () {
done();
})
.catch(test.done) .catch(test.done)
} }
}; };

View File

@ -8,10 +8,19 @@ function createRandomEvent() {
module.exports = { module.exports = {
'Test Subscribe to Stream From Happy Path': function(test) { 'Test Subscribe to Stream From Happy Path': function(test) {
test.expect(8);
var self = this; var self = this;
var liveProcessing = false; var liveProcessing = false;
var catchUpEvents = []; var catchUpEvents = [];
var liveEvents = []; var liveEvents = [];
var _doneCount = 0;
function done(err) {
test.ok(!err, err ? err.stack : '');
if (++_doneCount < 2) return;
test.done();
}
function eventAppeared(s, e) { function eventAppeared(s, e) {
if (liveProcessing) { if (liveProcessing) {
liveEvents.push(e); liveEvents.push(e);
@ -23,12 +32,16 @@ module.exports = {
function liveProcessingStarted() { function liveProcessingStarted() {
liveProcessing = true; liveProcessing = true;
var events = [createRandomEvent()]; var events = [createRandomEvent()];
self.conn.appendToStream(self.testStreamName, client.expectedVersion.any, events); self.conn.appendToStream(self.testStreamName, client.expectedVersion.any, events)
.then(function () {
done();
})
.catch(done);
} }
function subscriptionDropped(connection, reason, error) { function subscriptionDropped(connection, reason, error) {
test.ok(liveEvents.length === 1, "Expecting 1 live event, got " + liveEvents.length); test.ok(liveEvents.length === 1, "Expecting 1 live event, got " + liveEvents.length);
test.ok(catchUpEvents.length >= 1, "Expecting at least 1 catchUp event, got " + catchUpEvents.length); test.ok(catchUpEvents.length >= 1, "Expecting at least 1 catchUp event, got " + catchUpEvents.length);
test.done(error); done(error);
} }
var events = [createRandomEvent()]; var events = [createRandomEvent()];
@ -40,7 +53,8 @@ module.exports = {
test.areEqual("subscription.isSubscribedToAll", subscription.isSubscribedToAll, false); test.areEqual("subscription.isSubscribedToAll", subscription.isSubscribedToAll, false);
test.areEqual("subscription.readBatchSize", subscription.readBatchSize, 500); test.areEqual("subscription.readBatchSize", subscription.readBatchSize, 500);
test.areEqual("subscription.maxPushQueueSize", subscription.maxPushQueueSize, 10000); test.areEqual("subscription.maxPushQueueSize", subscription.maxPushQueueSize, 10000);
}); })
.catch(test.done);
} }
}; };

View File

@ -5,10 +5,18 @@ module.exports = {
'Test Subscribe To Stream Happy Path': function(test) { 'Test Subscribe To Stream Happy Path': function(test) {
const resolveLinkTos = false; const resolveLinkTos = false;
const numberOfPublishedEvents = 5; const numberOfPublishedEvents = 5;
test.expect(numberOfPublishedEvents + 6);
var publishedEvents = []; var publishedEvents = [];
for(var i=0;i<numberOfPublishedEvents;i++) for(var i=0;i<numberOfPublishedEvents;i++)
publishedEvents.push(client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'anEvent')); publishedEvents.push(client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'anEvent'));
var _doneCount = 0;
function done(err) {
test.ok(!err, err ? err.stack : '');
if (++_doneCount < 2) return;
test.done();
}
function testAllPublishedEventsAppeared() { function testAllPublishedEventsAppeared() {
test.areEqual("receivedEvents.length", receivedEvents.length, numberOfPublishedEvents); test.areEqual("receivedEvents.length", receivedEvents.length, numberOfPublishedEvents);
} }
@ -24,10 +32,10 @@ module.exports = {
if (receivedEvents.length === numberOfPublishedEvents) subscription.close(); if (receivedEvents.length === numberOfPublishedEvents) subscription.close();
} }
function subscriptionDropped(subscription, reason, error) { function subscriptionDropped(subscription, reason, error) {
if (error) return test.done(error); if (error) return done(error);
testAllPublishedEventsAppeared(); testAllPublishedEventsAppeared();
testEventsAppearedInCorrectOrder(); testEventsAppearedInCorrectOrder();
test.done(); done();
} }
var self = this; var self = this;
this.conn.subscribeToStream(this.testStreamName, resolveLinkTos, eventAppeared, subscriptionDropped) this.conn.subscribeToStream(this.testStreamName, resolveLinkTos, eventAppeared, subscriptionDropped)
@ -38,6 +46,9 @@ module.exports = {
return self.conn.appendToStream(self.testStreamName, client.expectedVersion.emptyStream, publishedEvents); return self.conn.appendToStream(self.testStreamName, client.expectedVersion.emptyStream, publishedEvents);
}) })
.then(function () {
done();
})
.catch(test.done) .catch(test.done)
} }
}; };

View File

@ -7,6 +7,7 @@ module.exports = {
cb(); cb();
}, },
'Start A Transaction Happy Path': function(test) { 'Start A Transaction Happy Path': function(test) {
test.expect(1);
this.conn.startTransaction(this.testStreamName, client.expectedVersion.noStream) this.conn.startTransaction(this.testStreamName, client.expectedVersion.noStream)
.then(function(trx) { .then(function(trx) {
test.ok(Long.isLong(trx.transactionId), "trx.transactionId should be a Long."); test.ok(Long.isLong(trx.transactionId), "trx.transactionId should be a Long.");
@ -46,6 +47,7 @@ module.exports = {
}, },
*/ */
'Start A Transaction With No Access': function(test) { 'Start A Transaction With No Access': function(test) {
test.expect(1);
var self = this; var self = this;
var metadata = {$acl: {$w: "$admins"}}; var metadata = {$acl: {$w: "$admins"}};
this.conn.setStreamMetadataRaw(this.testStreamName, -1, metadata) this.conn.setStreamMetadataRaw(this.testStreamName, -1, metadata)
@ -84,6 +86,7 @@ module.exports = {
.catch(test.done); .catch(test.done);
}, },
'Write/Commit Transaction Happy Path': function(test) { 'Write/Commit Transaction Happy Path': function(test) {
test.expect(2);
var self = this; var self = this;
this.conn.startTransaction(this.testStreamName, client.expectedVersion.emptyStream) this.conn.startTransaction(this.testStreamName, client.expectedVersion.emptyStream)
.then(function(trx) { .then(function(trx) {
@ -114,6 +117,7 @@ module.exports = {
.catch(test.done); .catch(test.done);
}, },
'Write/Commit Transaction With Wrong Expected Version': function(test) { 'Write/Commit Transaction With Wrong Expected Version': function(test) {
test.expect(1);
this.conn.startTransaction(this.testStreamName, 10) this.conn.startTransaction(this.testStreamName, 10)
.then(function(trx) { .then(function(trx) {
return trx.write(client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'anEvent')) return trx.write(client.createJsonEventData(uuid.v4(), {a: Math.random(), b: uuid.v4()}, null, 'anEvent'))
@ -133,6 +137,7 @@ module.exports = {
}); });
}, },
'Write/Commit Transaction With Deleted Stream': function(test) { 'Write/Commit Transaction With Deleted Stream': function(test) {
test.expect(1);
var self = this; var self = this;
this.conn.deleteStream(this.testStreamName, client.expectedVersion.emptyStream, true) this.conn.deleteStream(this.testStreamName, client.expectedVersion.emptyStream, true)
.then(function() { .then(function() {
@ -156,6 +161,7 @@ module.exports = {
}); });
}, },
'Write/Commit Transaction With No Write Access': function(test) { 'Write/Commit Transaction With No Write Access': function(test) {
test.expect(1);
var self = this; var self = this;
this.conn.startTransaction(this.testStreamName, client.expectedVersion.any) this.conn.startTransaction(this.testStreamName, client.expectedVersion.any)
.then(function(trx) { .then(function(trx) {