...
 
Commits (10)
......@@ -5,4 +5,5 @@ Anton Onyshchenko
Arek Flinik
Arnout Kazemier <info@3rd-Eden.com>
Nebojsa Sabovic
Ron Korving
Tobias Müllerleile
......@@ -142,6 +142,7 @@ Client.config = {
S.streamID = sid++;
S.setTimeout(memcached.timeout);
S.setNoDelay(true);
S.setEncoding('utf8');
S.metaData = [];
S.responseBuffer = "";
S.bufferArray = [];
......@@ -249,7 +250,7 @@ Client.config = {
}
this.connect(server, function allocateMemcachedConnection (error, S) {
if (Client.config.debug) {
if (memcached.debug) {
query.command.split(LINEBREAK).forEach(function errors (line) {
console.log(S.streamID + ' << ' + line);
});
......@@ -545,7 +546,7 @@ Client.config = {
if (S.responseBuffer.substr(S.responseBuffer.length - 2) === LINEBREAK) {
var chunks = S.responseBuffer.split(LINEBREAK);
if (Client.config.debug) {
if (this.debug) {
chunks.forEach(function each (line) {
console.log(S.streamID + ' >> ' + line);
});
......@@ -895,7 +896,7 @@ Client.config = {
privates.singles = function singles (type, callback) {
var memcached = this
, responses = []
, errors = null
, errors
, calls;
// handle multiple servers
......@@ -907,7 +908,7 @@ Client.config = {
if (results) responses = responses.concat(results);
// multi calls should ALWAYS return an array!
if (!--calls) callback(errors, responses);
if (!--calls) callback(errors && errors.length ? errors.pop() : undefined, responses);
}
this.multi(false, function multi (server, keys, index, totals) {
......
{
"name": "memcached"
, "version": "0.0.11"
, "version": "0.0.12"
, "author": "Arnout Kazemier"
, "description": "A fully featured Memcached API client, supporting both single and clustered Memcached servers through consistent hashing and failover/failure. Memcached is rewrite of nMemcached, which will be deprecated in the near future."
, "main": "index"
......
......@@ -32,4 +32,4 @@ exports.numbers = function(n){
}
return a;
};
\ No newline at end of file
};
......@@ -3,145 +3,131 @@
*/
var assert = require('assert')
, should = require('should')
, common = require('./common')
, Memcached = require('../');
global.testnumbers = global.testnumbers || +(Math.random(10) * 1000).toFixed();
global.testnumbers = global.testnumbers || +(Math.random(10) * 1000000).toFixed();
/**
* Expresso test suite for all `get` related
* memcached commands
*/
module.exports = {
/**
* For a proper CAS update in memcached you will need to know the CAS value
* of a given key, this is done by the `gets` command. So we will need to make
* sure that a `cas` key is given.
*/
"set and gets for cas result": function(exit){
var memcached = new Memcached(common.servers.single)
, message = common.alphabet(256)
, testnr = ++global.testnumbers
, callbacks = 0;
memcached.set("test:" + testnr, message, 1000, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.true;
memcached.gets("test:" + testnr, function(error, answer){
++callbacks;
assert.ok(!error);
assert.ok(typeof answer === 'object');
assert.ok(!!answer.cas);
answer["test:" + testnr].should.eql(message);
memcached.end(); // close connections
});
});
// make sure all callbacks are called
exit(function(){
assert.equal(callbacks, 2);
});
}
/**
* Create a successful cas update, so we are sure we send a cas request correctly.
*/
, "successful cas update" : function(exit){
var memcached = new Memcached(common.servers.single)
, message = common.alphabet(256)
, testnr = ++global.testnumbers
, callbacks = 0;
memcached.set("test:" + testnr, message, 1000, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.true;
memcached.gets("test:" + testnr, function(error, answer){
++callbacks;
assert.ok(!error);
assert.ok(!!answer.cas);
// generate new message for the cas update
message = common.alphabet(256);
memcached.cas("test:" + testnr, message, answer.cas, 1000, function(error, answer){
++callbacks;
assert.ok(!error);
assert.ok(!!answer);
memcached.get("test:" + testnr, function(error, answer){
++callbacks;
assert.ok(!error);
answer.should.eql(message);
memcached.end(); // close connections
})
});
});
});
// make sure all callbacks are called
exit(function(){
assert.equal(callbacks, 4);
});
}
/**
* Create a unsuccessful cas update, which would indicate that the server has changed
* while we where doing nothing.
*/
, "unsuccessful cas update" : function(exit){
var memcached = new Memcached(common.servers.single)
, message = common.alphabet(256)
, testnr = ++global.testnumbers
, callbacks = 0;
memcached.set("test:" + testnr, message, 1000, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.true;
memcached.gets("test:" + testnr, function(error, answer){
++callbacks;
assert.ok(!error);
assert.ok(!!answer.cas);
// generate new message
message = common.alphabet(256);
memcached.set("test:" + testnr, message, 1000, function(){
++callbacks;
memcached.cas("test:" + testnr, message, answer.cas, 1000, function(error, answer){
++callbacks;
assert.ok(!error);
assert.ok(!answer);
memcached.get("test:" + testnr, function(error, answer){
++callbacks;
assert.ok(!error);
answer.should.eql(message);
memcached.end(); // close connections
})
});
});
});
});
// make sure all callbacks are called
exit(function(){
assert.equal(callbacks, 5);
});
}
};
\ No newline at end of file
describe("Memcached CAS", function() {
/**
* For a proper CAS update in memcached you will need to know the CAS value
* of a given key, this is done by the `gets` command. So we will need to make
* sure that a `cas` key is given.
*/
it("set and gets for cas result", function(done) {
var memcached = new Memcached(common.servers.single)
, message = common.alphabet(256)
, testnr = ++global.testnumbers
, callbacks = 0;
memcached.set("test:" + testnr, message, 1000, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.true;
memcached.gets("test:" + testnr, function(error, answer){
++callbacks;
assert.ok(!error);
assert.ok(typeof answer === 'object');
assert.ok(!!answer.cas);
answer["test:" + testnr].should.eql(message);
memcached.end(); // close connections
assert.equal(callbacks, 2);
done();
});
});
});
/**
* Create a successful cas update, so we are sure we send a cas request correctly.
*/
it("successful cas update", function(done) {
var memcached = new Memcached(common.servers.single)
, message = common.alphabet(256)
, testnr = ++global.testnumbers
, callbacks = 0;
memcached.set("test:" + testnr, message, 1000, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.true;
memcached.gets("test:" + testnr, function(error, answer){
++callbacks;
assert.ok(!error);
assert.ok(!!answer.cas);
// generate new message for the cas update
message = common.alphabet(256);
memcached.cas("test:" + testnr, message, answer.cas, 1000, function(error, answer){
++callbacks;
assert.ok(!error);
assert.ok(!!answer);
memcached.get("test:" + testnr, function(error, answer){
++callbacks;
assert.ok(!error);
answer.should.eql(message);
memcached.end(); // close connections
assert.equal(callbacks, 4);
done();
})
});
});
});
});
/**
* Create a unsuccessful cas update, which would indicate that the server has changed
* while we where doing nothing.
*/
it("unsuccessful cas update", function(done) {
var memcached = new Memcached(common.servers.single)
, message = common.alphabet(256)
, testnr = ++global.testnumbers
, callbacks = 0;
memcached.set("test:" + testnr, message, 1000, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.true;
memcached.gets("test:" + testnr, function(error, answer){
++callbacks;
assert.ok(!error);
assert.ok(!!answer.cas);
// generate new message
message = common.alphabet(256);
memcached.set("test:" + testnr, message, 1000, function(){
++callbacks;
memcached.cas("test:" + testnr, message, answer.cas, 1000, function(error, answer){
++callbacks;
assert.ok(!error);
assert.ok(!answer);
memcached.get("test:" + testnr, function(error, answer){
++callbacks;
assert.ok(!error);
answer.should.eql(message);
memcached.end(); // close connections
assert.equal(callbacks, 5);
done();
});
});
});
});
});
});
});
\ No newline at end of file
This diff is collapsed.
......@@ -3,170 +3,148 @@
*/
var assert = require('assert')
, should = require('should')
, common = require('./common')
, Memcached = require('../');
global.testnumbers = global.testnumbers || +(Math.random(10) * 1000).toFixed();
global.testnumbers = global.testnumbers || +(Math.random(10) * 1000000).toFixed();
/**
* Expresso test suite for all `get` related
* memcached commands
*/
module.exports = {
/**
* Simple increments.. Just because.. we can :D
*/
"simple incr": function(exit){
var memcached = new Memcached(common.servers.single)
, testnr = ++global.testnumbers
, callbacks = 0;
memcached.set("test:" + testnr, 1, 1000, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.true;
memcached.incr("test:" + testnr, 1, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.equal(2);
memcached.end(); // close connections
});
});
// make sure all callbacks are called
exit(function(){
assert.equal(callbacks, 2);
});
}
/**
* Simple decrement.. So we know that works as well. Nothing special here
* move on.
*/
, "simple decr": function(exit){
var memcached = new Memcached(common.servers.single)
, testnr = ++global.testnumbers
, callbacks = 0;
memcached.set("test:" + testnr, 0, 1000, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.true;
memcached.incr("test:" + testnr, 10, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.equal(10);
memcached.decr("test:" + testnr, 1, function(error, answer){
++callbacks;
assert.ok(!error);
answer.should.be.equal(9);
memcached.end(); // close connections
});
});
});
// make sure all callbacks are called
exit(function(){
assert.equal(callbacks, 3);
});
}
/**
* According to the spec, incr should just work fine on keys that
* have intergers.. So lets test that.
*/
, "Simple increment on a large number": function(exit){
var memcached = new Memcached(common.servers.single)
, message = common.numbers(10)
, testnr = ++global.testnumbers
, callbacks = 0;
memcached.set("test:" + testnr, message, 1000, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.true;
memcached.incr("test:" + testnr, 1, function(error, answer){
++callbacks;
assert.ok(!error);
assert.ok(+answer === (message + 1));
memcached.end(); // close connections
});
});
// make sure all callbacks are called
exit(function(){
assert.equal(callbacks, 2);
});
}
/**
* decrementing on a unkonwn key should fail.
*/
, "decrement on a unknown key": function(exit){
var memcached = new Memcached(common.servers.single)
, testnr = ++global.testnumbers
, callbacks = 0;
memcached.decr("test:" + testnr, 1, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.false;
memcached.end(); // close connections
});
// make sure all callbacks are called
exit(function(){
assert.equal(callbacks, 1);
});
}
/**
* We can only increment on a integer, not on a string.
*/
, "Incrementing on a non string value throws a client_error": function(exit){
var memcached = new Memcached(common.servers.single)
, testnr = ++global.testnumbers
, callbacks = 0;
memcached.set("test:" + testnr, "zing!", 0, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.true;
memcached.incr("test:" + testnr, 1, function(error, ok){
++callbacks;
assert.ok(error);
ok.should.be.false;
memcached.end(); // close connections;
});
});
// make sure all callbacks are called
exit(function(){
assert.equal(callbacks, 2);
});
}
};
\ No newline at end of file
describe("Memcached INCR DECR", function() {
/**
* Simple increments.. Just because.. we can :D
*/
it("simple incr", function(done) {
var memcached = new Memcached(common.servers.single)
, testnr = ++global.testnumbers
, callbacks = 0;
memcached.set("test:" + testnr, 1, 1000, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.true;
memcached.incr("test:" + testnr, 1, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.equal(2);
memcached.end(); // close connections
assert.equal(callbacks, 2);
done();
});
});
});
/**
* Simple decrement.. So we know that works as well. Nothing special here
* move on.
*/
it("simple decr", function(done) {
var memcached = new Memcached(common.servers.single)
, testnr = ++global.testnumbers
, callbacks = 0;
memcached.set("test:" + testnr, 0, 1000, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.true;
memcached.incr("test:" + testnr, 10, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.equal(10);
memcached.decr("test:" + testnr, 1, function(error, answer){
++callbacks;
assert.ok(!error);
answer.should.be.equal(9);
memcached.end(); // close connections
assert.equal(callbacks, 3);
done();
});
});
});
});
/**
* According to the spec, incr should just work fine on keys that
* have intergers.. So lets test that.
*/
it("simple increment on a large number", function(done) {
var memcached = new Memcached(common.servers.single)
, message = common.numbers(10)
, testnr = ++global.testnumbers
, callbacks = 0;
memcached.set("test:" + testnr, message, 1000, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.true;
memcached.incr("test:" + testnr, 1, function(error, answer){
++callbacks;
assert.ok(!error);
assert.ok(+answer === (message + 1));
memcached.end(); // close connections
assert.equal(callbacks, 2);
done();
});
});
});
/**
* decrementing on a unkonwn key should fail.
*/
it("decrement on a unknown key", function(done) {
var memcached = new Memcached(common.servers.single)
, testnr = ++global.testnumbers
, callbacks = 0;
memcached.decr("test:" + testnr, 1, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.false;
memcached.end(); // close connections
assert.equal(callbacks, 1);
done();
});
});
/**
* We can only increment on a integer, not on a string.
*/
it("incrementing on a non string value throws a client_error", function(done) {
var memcached = new Memcached(common.servers.single)
, testnr = ++global.testnumbers
, callbacks = 0;
memcached.set("test:" + testnr, "zing!", 0, function(error, ok){
++callbacks;
assert.ok(!error);
ok.should.be.true;
memcached.incr("test:" + testnr, 1, function(error, ok){
++callbacks;
assert.ok(error);
ok.should.be.false;
memcached.end(); // close connections;
assert.equal(callbacks, 2);
done();
});
});
});
});
\ No newline at end of file