2016-03-11 23:55:27 +00:00
|
|
|
var client = require('../src/client.js');
|
2016-10-15 22:41:25 +00:00
|
|
|
var GossipSeed = require('../src/gossipSeed');
|
2016-03-11 23:55:27 +00:00
|
|
|
|
2016-03-14 01:38:42 +00:00
|
|
|
var testBase = require('./common/base_test');
|
2016-03-11 23:55:27 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
'Connect To Endpoint Happy Path': function(test) {
|
2017-01-29 02:04:58 +00:00
|
|
|
test.expect(1);
|
2017-01-29 02:35:35 +00:00
|
|
|
var tcpEndpoint = {host: 'localhost', port: 1113};
|
2016-03-14 01:38:42 +00:00
|
|
|
var conn = client.EventStoreConnection.create(testBase.settings(), tcpEndpoint);
|
2016-03-11 23:55:27 +00:00
|
|
|
conn.connect()
|
2016-03-14 01:38:42 +00:00
|
|
|
.catch(function(err) {
|
|
|
|
test.done(err);
|
2016-03-11 23:55:27 +00:00
|
|
|
});
|
|
|
|
conn.on('connected', function(endPoint){
|
2016-03-14 01:38:42 +00:00
|
|
|
test.areEqual("connected endPoint", endPoint, tcpEndpoint);
|
2016-03-11 23:55:27 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
conn.on('error', done);
|
|
|
|
|
2016-03-14 01:38:42 +00:00
|
|
|
function done(err) {
|
2016-03-11 23:55:27 +00:00
|
|
|
conn.close();
|
2016-03-14 01:38:42 +00:00
|
|
|
if (err) return test.done(err);
|
2016-03-11 23:55:27 +00:00
|
|
|
test.done();
|
|
|
|
}
|
|
|
|
},
|
2016-10-15 05:53:23 +00:00
|
|
|
'Connect To Endpoint That Doesn\'t Exist': function(test) {
|
2017-01-29 02:04:58 +00:00
|
|
|
test.expect(1);
|
|
|
|
var tcpEndpoint = {host: 'localhost', port: 11112};
|
2016-03-14 01:38:42 +00:00
|
|
|
var conn = client.EventStoreConnection.create(testBase.settings({maxReconnections:1}), tcpEndpoint);
|
2016-03-11 23:55:27 +00:00
|
|
|
conn.connect()
|
2016-03-14 01:38:42 +00:00
|
|
|
.catch(function (err) {
|
|
|
|
test.done(err);
|
2016-03-11 23:55:27 +00:00
|
|
|
});
|
|
|
|
conn.on('connected', function () {
|
2016-10-18 04:58:28 +00:00
|
|
|
test.ok(false, "Should not be able to connect.");
|
2016-03-11 23:55:27 +00:00
|
|
|
test.done();
|
|
|
|
});
|
2016-03-14 01:38:42 +00:00
|
|
|
conn.on('error', function (err) {
|
|
|
|
test.done(err);
|
2016-03-11 23:55:27 +00:00
|
|
|
});
|
|
|
|
conn.on('closed', function(reason) {
|
|
|
|
test.ok(reason.indexOf("Reconnection limit reached") === 0, "Wrong expected reason.");
|
|
|
|
test.done();
|
|
|
|
});
|
2016-12-07 02:54:04 +00:00
|
|
|
},
|
|
|
|
'Create a connection with tcp://host:port string': function(test) {
|
2017-01-29 02:35:35 +00:00
|
|
|
var conn = client.createConnection({}, 'tcp://localhost:1113');
|
2016-12-07 02:54:04 +00:00
|
|
|
conn.close();
|
|
|
|
test.done();
|
2016-10-18 04:58:28 +00:00
|
|
|
}/*,
|
2016-10-15 22:41:25 +00:00
|
|
|
'Connect to Cluster using gossip seeds': function (test) {
|
|
|
|
test.expect(1);
|
|
|
|
var gossipSeeds = [
|
2017-01-29 02:04:58 +00:00
|
|
|
new GossipSeed({host: 'localhost', port: 1113}),
|
|
|
|
new GossipSeed({host: 'localhost', port: 2113}),
|
|
|
|
new GossipSeed({host: 'localhost', port: 3113})
|
2016-10-15 22:41:25 +00:00
|
|
|
];
|
|
|
|
var conn = client.EventStoreConnection.create(testBase.settings(), gossipSeeds);
|
|
|
|
conn.connect()
|
|
|
|
.catch(function(err) {
|
|
|
|
test.done(err);
|
|
|
|
});
|
|
|
|
conn.on('connected', function(endPoint){
|
|
|
|
test.ok(endPoint, "no endpoint");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
conn.on('error', done);
|
|
|
|
|
|
|
|
function done(err) {
|
|
|
|
conn.close();
|
|
|
|
if (err) return test.done(err);
|
|
|
|
test.done();
|
|
|
|
}
|
2016-10-18 04:58:28 +00:00
|
|
|
}*/
|
2016-03-11 23:55:27 +00:00
|
|
|
};
|
2016-03-14 01:38:42 +00:00
|
|
|
|
|
|
|
testBase.init(module.exports, false);
|