graphite-client
Advanced tools
Comparing version 1.0.0 to 1.0.1
22
index.js
@@ -5,6 +5,6 @@ var net = require('net'); | ||
function Graphite(host, port, charSet, timeout, timeoutListener) { | ||
function Graphite(host, port, encoding, timeout, timeoutListener) { | ||
this.host = host; | ||
this.port = port; | ||
this.charSet = charSet; | ||
this.encoding = encoding; | ||
this.timeout = timeout; | ||
@@ -17,11 +17,15 @@ this.timeoutListener = timeoutListener; | ||
this.socket = net.connect({host: this.host, port: this.port}, connectListener); | ||
this.socket.setEncoding(this.charSet); | ||
if (this.encoding) { | ||
this.socket.setEncoding(this.encoding); | ||
} | ||
var self = this; | ||
this.socket.setTimeout(this.timeout, function(){ | ||
if (this.timeout) { | ||
var self = this; | ||
this.socket.setTimeout(this.timeout, function(){ | ||
self.timeoutListener(); | ||
self.end(); | ||
self.connect(connectListener); | ||
}); | ||
self.timeoutListener(); | ||
self.end(); | ||
self.connect(connectListener); | ||
}); | ||
} | ||
@@ -28,0 +32,0 @@ this.eventsCallbacks.forEach(function (eventCallback) { |
{ | ||
"name": "graphite-client", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Node.js client for Graphite", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,2 +5,7 @@ # graphite-client | ||
##Install | ||
``` | ||
$ npm install graphite-client | ||
``` | ||
## Usage | ||
@@ -7,0 +12,0 @@ ###Create instance |
@@ -79,6 +79,18 @@ var assert = require('assert'); | ||
}); | ||
}) | ||
describe('connect', function () { | ||
it('should connect to the server and call the callback method', function (done) { | ||
mitm.on("connection", function(socket) { socket.write('connect') }); | ||
var graphite = new Graphite('someHostAddress', 2003, 'UTF-8', 1, null); | ||
graphite.connect(function() { | ||
graphite.end(); | ||
done(); | ||
}); | ||
}); | ||
it('should call the timeout callback on timeout', function (done) { | ||
mitm.on("connection", function(socket) { socket.write('connect') }) | ||
mitm.on("connection", function(socket) { socket.write('connect') }); | ||
@@ -95,14 +107,16 @@ var done_called = false; | ||
graphite.connect(null); | ||
}) | ||
}) | ||
}); | ||
describe('connect', function () { | ||
it('should connect to the server and call the callback method', function (done) { | ||
mitm.on("connection", function(socket) { socket.write('connect') }) | ||
var graphite = new Graphite('someHostAddress', 2003, 'UTF-8', 1, null); | ||
graphite.connect(function() { | ||
graphite.end(); | ||
done(); | ||
it('should connect if timeout is not provided', function (done) { | ||
mitm.on("connection", function(socket) { | ||
if (!done_called) { | ||
done(); | ||
done_called = true; | ||
} | ||
}); | ||
var done_called = false; | ||
var graphite = new Graphite('someHostAddress', 2003, 'UTF-8'); | ||
graphite.connect(null); | ||
}); | ||
@@ -112,3 +126,3 @@ }) | ||
describe('on(error)', function () { | ||
it('should call the error callback', function (done) { | ||
it('before connect() should call the error callback', function (done) { | ||
var graphite = new Graphite('someHostAddress', 2003, 'UTF-8', 1000000); | ||
@@ -125,4 +139,19 @@ | ||
}); | ||
it('after connect() should call the error callback', function (done) { | ||
var graphite = new Graphite('someHostAddress', 2003, 'UTF-8', 1000000); | ||
graphite.connect(null); | ||
graphite.on('error', function() { | ||
graphite.end(); | ||
done(); | ||
}); | ||
graphite.end(); | ||
graphite.write('sdfsd'); | ||
}); | ||
}); | ||
}) |
7812
186
61