Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[codestyl] tabs, begone!

  • Loading branch information...
commit ea0055d8823362d79567fedc33822735ce50d0d7 1 parent ce72701
@3rd-Eden authored
View
238 tests/memcached-cas.test.js
@@ -13,121 +13,123 @@ global.testnumbers = global.testnumbers || +(Math.random(10) * 1000000).toFixed(
* memcached commands
*/
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();
- });
- });
- });
- });
- });
- });
-});
+ /**
+ * 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();
+ });
+ });
+ });
+ });
+ });
+ });
+});
View
797 tests/memcached-get-set.test.js
@@ -14,397 +14,408 @@ global.testnumbers = global.testnumbers || +(Math.random(10) * 1000000).toFixed(
* memcached commands
*/
describe("Memcached GET SET", function() {
- /**
- * Make sure that the string that we send to the server is correctly
- * stored and retrieved. We will be storing random strings to ensure
- * that we are not retrieving old data.
- */
- it("set and get a regular string", 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.get("test:" + testnr, function(error, answer){
- ++callbacks;
-
- assert.ok(!error);
-
- assert.ok(typeof answer === 'string');
- answer.should.eql(message);
-
- memcached.end(); // close connections
- assert.equal(callbacks, 2);
- done();
-
- });
- });
- });
- /**
- * Set a stringified JSON object, and make sure we only return a string
- * this should not be flagged as JSON object
- */
- it("set and get a JSON.stringify string", function(done) {
- var memcached = new Memcached(common.servers.single)
- , message = JSON.stringify({numbers:common.numbers(256),alphabet:common.alphabet(256),dates:new Date(),arrays: [1,2,3, 'foo', 'bar']})
- , testnr = ++global.testnumbers
- , callbacks = 0;
-
- memcached.set("test:" + testnr, message, 1000, function(error, ok){
- ++callbacks;
-
- assert.ok(!error);
- ok.should.be.true;
-
- memcached.get("test:" + testnr, function(error, answer){
- ++callbacks;
-
- assert.ok(!error);
-
- assert.ok(typeof answer === 'string');
- answer.should.eql(message);
-
- memcached.end(); // close connections
- assert.equal(callbacks, 2);
- done();
-
- });
- });
- });
- /**
- * Setting and getting a unicode value should just work, we need to make sure
- * that we send the correct byteLength because utf8 chars can contain more bytes
- * than "str".length would show, causing the memcached server to complain.
- */
- it("set and get a regular string", function(done) {
- var memcached = new Memcached(common.servers.single)
- , message = 'привет мир, Memcached и nodejs для победы'
- , testnr = ++global.testnumbers
- , callbacks = 0;
-
- memcached.set("test:" + testnr, message, 1000, function(error, ok){
- ++callbacks;
-
- assert.ok(!error);
- ok.should.be.true;
-
- memcached.get("test:" + testnr, function(error, answer){
- ++callbacks;
-
- assert.ok(!error);
-
- assert.ok(typeof answer === 'string');
- answer.should.eql(message);
-
- memcached.end(); // close connections
- assert.equal(callbacks, 2);
- done();
- });
- });
- });
- /**
- * A common action when working with memcached servers, getting a key
- * that does not exist anymore.
- */
- it("get a non existing key", function(done) {
- var memcached = new Memcached(common.servers.single)
- , testnr = ++global.testnumbers
- , callbacks = 0;
-
- memcached.get("test:" + testnr, function(error, answer){
- ++callbacks;
-
- assert.ok(!error);
- answer.should.be.false;
-
- memcached.end(); // close connections
- assert.equal(callbacks, 1);
- done();
- });
- });
- /**
- * Make sure that Numbers are correctly send and stored on the server
- * retrieval of the number based values can be tricky as the client might
- * think that it was a INCR and not a SET operation.. So just to make sure..
- */
- it("set and get a regular number", function(done) {
- var memcached = new Memcached(common.servers.single)
- , message = common.numbers(256)
- , testnr = ++global.testnumbers
- , callbacks = 0;
-
- memcached.set("test:" + testnr, message, 1000, function(error, ok){
- ++callbacks;
-
- assert.ok(!error);
- ok.should.be.true;
-
- memcached.get("test:" + testnr, function(error, answer){
- ++callbacks;
-
- assert.ok(!error);
-
- assert.ok(typeof answer === 'number');
- answer.should.eql(message);
-
- memcached.end(); // close connections
- assert.equal(callbacks, 2);
- done();
- });
- });
- });
- /**
- * Objects should be converted to a JSON string, send to the server
- * and be automagically JSON.parsed when they are retrieved.
- */
- it("set and get a object", function(done) {
- var memcached = new Memcached(common.servers.single)
- , message = {
- numbers: common.numbers(256)
- , alphabet: common.alphabet(256)
- , dates: new Date()
- , arrays: [1,2,3, 'foo', 'bar']
- }
- , testnr = ++global.testnumbers
- , callbacks = 0;
-
- memcached.set("test:" + testnr, message, 1000, function(error, ok){
- ++callbacks;
-
- assert.ok(!error);
- ok.should.be.true;
-
- memcached.get("test:" + testnr, function(error, answer){
- ++callbacks;
-
- assert.ok(!error);
-
- assert.ok(!Array.isArray(answer) && typeof answer == 'object');
- assert.ok(JSON.stringify(message) == JSON.stringify(answer));
- memcached.end(); // close connections
- assert.equal(callbacks, 2);
- done();
- });
- });
-
- });
- /**
- * Arrays should be converted to a JSON string, send to the server
- * and be automagically JSON.parsed when they are retrieved.
- */
- it("set and get a array", function(done) {
- var memcached = new Memcached(common.servers.single)
- , message = [
- {
- numbers: common.numbers(256)
- , alphabet: common.alphabet(256)
- , dates: new Date()
- , arrays: [1,2,3, 'foo', 'bar']
- }
- , {
- numbers: common.numbers(256)
- , alphabet: common.alphabet(256)
- , dates: new Date()
- , arrays: [1,2,3, 'foo', 'bar']
- }
- ]
- , testnr = ++global.testnumbers
- , callbacks = 0;
-
- memcached.set("test:" + testnr, message, 1000, function(error, ok){
- ++callbacks;
-
- assert.ok(!error);
- ok.should.be.true;
-
- memcached.get("test:" + testnr, function(error, answer){
- ++callbacks;
-
- assert.ok(!error);
-
- assert.ok(Array.isArray(answer));
- assert.ok(JSON.stringify(answer) == JSON.stringify(message));
- memcached.end(); // close connections
- assert.equal(callbacks, 2);
- done();
- });
- });
- });
- /**
- * Buffers are commonly used for binary transports So we need to make sure
- * we support them properly. But please note, that we need to compare the
- * strings on a "binary" level, because that is the encoding the Memcached
- * client will be using, as there is no indication of what encoding the
- * buffer is in.
- */
- it("set and get <buffers> with a binary image", function(done) {
- var memcached = new Memcached(common.servers.single)
- , message = fs.readFileSync(__dirname + '/fixtures/hotchicks.jpg')
- , testnr = ++global.testnumbers
- , callbacks = 0;
-
- memcached.set("test:" + testnr, message, 1000, function(error, ok){
- ++callbacks;
-
- assert.ok(!error);
- ok.should.be.true;
-
- memcached.get("test:" + testnr, function(error, answer){
- ++callbacks;
-
- assert.ok(!error);
- assert.ok(answer.toString('binary') === message.toString('binary'));
- memcached.end(); // close connections
- assert.equal(callbacks, 2);
- done();
- });
- });
- });
- /**
- * Get binary of the lipsum.txt, send it over the connection and see
- * if after we retrieved it, it's still the same when we compare the
- * original with the memcached based version.
- *
- * A use case for this would be storing <buffers> with HTML data in
- * memcached as a single cache pool..
- */
- it("set and get <buffers> with a binary text file", function(done) {
- var memcached = new Memcached(common.servers.single)
- , message = fs.readFileSync(__dirname + '/fixtures/lipsum.txt')
- , testnr = ++global.testnumbers
- , callbacks = 0;
-
- memcached.set("test:" + testnr, message, 1000, function(error, ok){
- ++callbacks;
-
- assert.ok(!error);
- ok.should.be.true;
-
- memcached.get("test:" + testnr, function(error, answer){
- ++callbacks;
-
- assert.ok(!error);
- assert.ok(answer.toString('utf8') === answer.toString('utf8'));
- assert.ok(answer.toString('ascii') === answer.toString('ascii'));
- memcached.end(); // close connections
- assert.equal(callbacks, 2);
- done();
- });
- });
- });
- /**
- * Not only small strings, but also large strings should be processed
- * without any issues.
- */
- it("set and get large text files", function(done) {
- var memcached = new Memcached(common.servers.single)
- , message = fs.readFileSync(__dirname + '/fixtures/lipsum.txt', 'utf8')
- , testnr = ++global.testnumbers
- , callbacks = 0;
-
- memcached.set("test:" + testnr, message, 1000, function(error, ok){
- ++callbacks;
-
- assert.ok(!error);
- ok.should.be.true;
-
- memcached.get("test:" + testnr, function(error, answer){
- ++callbacks;
-
- assert.ok(!error);
-
- assert.ok(typeof answer === 'string');
- answer.should.eql(message);
- memcached.end(); // close connections
- assert.equal(callbacks, 2);
- done();
- });
- });
- });
- /**
- * A multi get on a single server is different than a multi server multi get
- * as a multi server multi get will need to do a multi get over multiple servers
- * yes, that's allot of multi's in one single sentence thanks for noticing
- */
- it("multi get single server", function(done) {
- var memcached = new Memcached(common.servers.single)
- , message = common.alphabet(256)
- , message2 = common.alphabet(256)
- , testnr = ++global.testnumbers
- , callbacks = 0;
-
- memcached.set("test1:" + testnr, message, 1000, function(error, ok){
- ++callbacks;
-
- assert.ok(!error);
- ok.should.be.true;
-
- memcached.set("test2:" + testnr, message2, 1000, function(error, ok){
- ++callbacks;
-
- assert.ok(!error);
- ok.should.be.true;
-
- memcached.get(["test1:" + testnr, "test2:" + testnr], function(error, answer){
- ++callbacks;
-
- assert.ok(!error);
-
- assert.ok(typeof answer === 'object');
- answer["test1:" + testnr].should.eql(message);
- answer["test2:" + testnr].should.eql(message2);
-
- memcached.end(); // close connections
- assert.equal(callbacks, 3);
- done();
- });
- });
- });
- });
- /**
- * A multi get on a single server is different than a multi server multi get
- * as a multi server multi get will need to do a multi get over multiple servers
- * yes, that's allot of multi's in one single sentence thanks for noticing
- */
- it("multi get multi server", function(done) {
- var memcached = new Memcached(common.servers.multi)
- , message = common.alphabet(256)
- , message2 = common.alphabet(256)
- , testnr = ++global.testnumbers
- , callbacks = 0;
-
- memcached.set("test1:" + testnr, message, 1000, function(error, ok){
- ++callbacks;
-
- assert.ok(!error);
- ok.should.be.true;
-
- memcached.set("test2:" + testnr, message2, 1000, function(error, ok){
- ++callbacks;
-
- assert.ok(!error);
- ok.should.be.true;
-
- memcached.get(["test1:" + testnr,"test2:" + testnr], function(error, answer){
- ++callbacks;
-
- assert.ok(!error);
-
- assert.ok(typeof answer === 'object');
- answer["test1:" + testnr].should.eql(message);
- answer["test2:" + testnr].should.eql(message2);
-
- memcached.end(); // close connections
- assert.equal(callbacks, 3);
- done();
- });
- });
- });
+ /**
+ * Make sure that the string that we send to the server is correctly
+ * stored and retrieved. We will be storing random strings to ensure
+ * that we are not retrieving old data.
+ */
+ it("set and get a regular string", 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.get("test:" + testnr, function(error, answer){
+ ++callbacks;
+
+ assert.ok(!error);
+
+ assert.ok(typeof answer === 'string');
+ answer.should.eql(message);
+
+ memcached.end(); // close connections
+ assert.equal(callbacks, 2);
+ done();
+
+ });
+ });
+ });
+
+ /**
+ * Set a stringified JSON object, and make sure we only return a string
+ * this should not be flagged as JSON object
+ */
+ it("set and get a JSON.stringify string", function(done) {
+ var memcached = new Memcached(common.servers.single)
+ , message = JSON.stringify({numbers:common.numbers(256),alphabet:common.alphabet(256),dates:new Date(),arrays: [1,2,3, 'foo', 'bar']})
+ , testnr = ++global.testnumbers
+ , callbacks = 0;
+
+ memcached.set("test:" + testnr, message, 1000, function(error, ok){
+ ++callbacks;
+
+ assert.ok(!error);
+ ok.should.be.true;
+
+ memcached.get("test:" + testnr, function(error, answer){
+ ++callbacks;
+
+ assert.ok(!error);
+
+ assert.ok(typeof answer === 'string');
+ answer.should.eql(message);
+
+ memcached.end(); // close connections
+ assert.equal(callbacks, 2);
+ done();
+
+ });
+ });
+ });
+
+ /**
+ * Setting and getting a unicode value should just work, we need to make sure
+ * that we send the correct byteLength because utf8 chars can contain more bytes
+ * than "str".length would show, causing the memcached server to complain.
+ */
+ it("set and get a regular string", function(done) {
+ var memcached = new Memcached(common.servers.single)
+ , message = 'привет мир, Memcached и nodejs для победы'
+ , testnr = ++global.testnumbers
+ , callbacks = 0;
+
+ memcached.set("test:" + testnr, message, 1000, function(error, ok){
+ ++callbacks;
+
+ assert.ok(!error);
+ ok.should.be.true;
+
+ memcached.get("test:" + testnr, function(error, answer){
+ ++callbacks;
+
+ assert.ok(!error);
+
+ assert.ok(typeof answer === 'string');
+ answer.should.eql(message);
+
+ memcached.end(); // close connections
+ assert.equal(callbacks, 2);
+ done();
+ });
+ });
+ });
+
+ /**
+ * A common action when working with memcached servers, getting a key
+ * that does not exist anymore.
+ */
+ it("get a non existing key", function(done) {
+ var memcached = new Memcached(common.servers.single)
+ , testnr = ++global.testnumbers
+ , callbacks = 0;
+
+ memcached.get("test:" + testnr, function(error, answer){
+ ++callbacks;
+
+ assert.ok(!error);
+ answer.should.be.false;
+
+ memcached.end(); // close connections
+ assert.equal(callbacks, 1);
+ done();
+ });
+ });
+
+ /**
+ * Make sure that Numbers are correctly send and stored on the server
+ * retrieval of the number based values can be tricky as the client might
+ * think that it was a INCR and not a SET operation.. So just to make sure..
+ */
+ it("set and get a regular number", function(done) {
+ var memcached = new Memcached(common.servers.single)
+ , message = common.numbers(256)
+ , testnr = ++global.testnumbers
+ , callbacks = 0;
+
+ memcached.set("test:" + testnr, message, 1000, function(error, ok){
+ ++callbacks;
+
+ assert.ok(!error);
+ ok.should.be.true;
+
+ memcached.get("test:" + testnr, function(error, answer){
+ ++callbacks;
+
+ assert.ok(!error);
+
+ assert.ok(typeof answer === 'number');
+ answer.should.eql(message);
+
+ memcached.end(); // close connections
+ assert.equal(callbacks, 2);
+ done();
+ });
+ });
+ });
+
+ /**
+ * Objects should be converted to a JSON string, send to the server
+ * and be automagically JSON.parsed when they are retrieved.
+ */
+ it("set and get a object", function(done) {
+ var memcached = new Memcached(common.servers.single)
+ , message = {
+ numbers: common.numbers(256)
+ , alphabet: common.alphabet(256)
+ , dates: new Date()
+ , arrays: [1,2,3, 'foo', 'bar']
+ }
+ , testnr = ++global.testnumbers
+ , callbacks = 0;
+
+ memcached.set("test:" + testnr, message, 1000, function(error, ok){
+ ++callbacks;
+
+ assert.ok(!error);
+ ok.should.be.true;
+
+ memcached.get("test:" + testnr, function(error, answer){
+ ++callbacks;
+
+ assert.ok(!error);
+
+ assert.ok(!Array.isArray(answer) && typeof answer == 'object');
+ assert.ok(JSON.stringify(message) == JSON.stringify(answer));
+ memcached.end(); // close connections
+ assert.equal(callbacks, 2);
+ done();
+ });
+ });
+
+ });
+
+ /**
+ * Arrays should be converted to a JSON string, send to the server
+ * and be automagically JSON.parsed when they are retrieved.
+ */
+ it("set and get a array", function(done) {
+ var memcached = new Memcached(common.servers.single)
+ , message = [
+ {
+ numbers: common.numbers(256)
+ , alphabet: common.alphabet(256)
+ , dates: new Date()
+ , arrays: [1,2,3, 'foo', 'bar']
+ }
+ , {
+ numbers: common.numbers(256)
+ , alphabet: common.alphabet(256)
+ , dates: new Date()
+ , arrays: [1,2,3, 'foo', 'bar']
+ }
+ ]
+ , testnr = ++global.testnumbers
+ , callbacks = 0;
+
+ memcached.set("test:" + testnr, message, 1000, function(error, ok){
+ ++callbacks;
+
+ assert.ok(!error);
+ ok.should.be.true;
+
+ memcached.get("test:" + testnr, function(error, answer){
+ ++callbacks;
+
+ assert.ok(!error);
+
+ assert.ok(Array.isArray(answer));
+ assert.ok(JSON.stringify(answer) == JSON.stringify(message));
+ memcached.end(); // close connections
+ assert.equal(callbacks, 2);
+ done();
+ });
+ });
+ });
+
+ /**
+ * Buffers are commonly used for binary transports So we need to make sure
+ * we support them properly. But please note, that we need to compare the
+ * strings on a "binary" level, because that is the encoding the Memcached
+ * client will be using, as there is no indication of what encoding the
+ * buffer is in.
+ */
+ it("set and get <buffers> with a binary image", function(done) {
+ var memcached = new Memcached(common.servers.single)
+ , message = fs.readFileSync(__dirname + '/fixtures/hotchicks.jpg')
+ , testnr = ++global.testnumbers
+ , callbacks = 0;
+
+ memcached.set("test:" + testnr, message, 1000, function(error, ok){
+ ++callbacks;
+
+ assert.ok(!error);
+ ok.should.be.true;
+
+ memcached.get("test:" + testnr, function(error, answer){
+ ++callbacks;
+
+ assert.ok(!error);
+ assert.ok(answer.toString('binary') === message.toString('binary'));
+ memcached.end(); // close connections
+ assert.equal(callbacks, 2);
+ done();
+ });
+ });
+ });
+
+ /**
+ * Get binary of the lipsum.txt, send it over the connection and see
+ * if after we retrieved it, it's still the same when we compare the
+ * original with the memcached based version.
+ *
+ * A use case for this would be storing <buffers> with HTML data in
+ * memcached as a single cache pool..
+ */
+ it("set and get <buffers> with a binary text file", function(done) {
+ var memcached = new Memcached(common.servers.single)
+ , message = fs.readFileSync(__dirname + '/fixtures/lipsum.txt')
+ , testnr = ++global.testnumbers
+ , callbacks = 0;
+
+ memcached.set("test:" + testnr, message, 1000, function(error, ok){
+ ++callbacks;
+
+ assert.ok(!error);
+ ok.should.be.true;
+
+ memcached.get("test:" + testnr, function(error, answer){
+ ++callbacks;
+
+ assert.ok(!error);
+ assert.ok(answer.toString('utf8') === answer.toString('utf8'));
+ assert.ok(answer.toString('ascii') === answer.toString('ascii'));
+ memcached.end(); // close connections
+ assert.equal(callbacks, 2);
+ done();
+ });
+ });
+ });
+
+ /**
+ * Not only small strings, but also large strings should be processed
+ * without any issues.
+ */
+ it("set and get large text files", function(done) {
+ var memcached = new Memcached(common.servers.single)
+ , message = fs.readFileSync(__dirname + '/fixtures/lipsum.txt', 'utf8')
+ , testnr = ++global.testnumbers
+ , callbacks = 0;
+
+ memcached.set("test:" + testnr, message, 1000, function(error, ok){
+ ++callbacks;
+
+ assert.ok(!error);
+ ok.should.be.true;
+
+ memcached.get("test:" + testnr, function(error, answer){
+ ++callbacks;
+
+ assert.ok(!error);
+
+ assert.ok(typeof answer === 'string');
+ answer.should.eql(message);
+ memcached.end(); // close connections
+ assert.equal(callbacks, 2);
+ done();
+ });
+ });
+ });
+
+ /**
+ * A multi get on a single server is different than a multi server multi get
+ * as a multi server multi get will need to do a multi get over multiple servers
+ * yes, that's allot of multi's in one single sentence thanks for noticing
+ */
+ it("multi get single server", function(done) {
+ var memcached = new Memcached(common.servers.single)
+ , message = common.alphabet(256)
+ , message2 = common.alphabet(256)
+ , testnr = ++global.testnumbers
+ , callbacks = 0;
+
+ memcached.set("test1:" + testnr, message, 1000, function(error, ok){
+ ++callbacks;
+
+ assert.ok(!error);
+ ok.should.be.true;
+
+ memcached.set("test2:" + testnr, message2, 1000, function(error, ok){
+ ++callbacks;
+
+ assert.ok(!error);
+ ok.should.be.true;
+
+ memcached.get(["test1:" + testnr, "test2:" + testnr], function(error, answer){
+ ++callbacks;
+
+ assert.ok(!error);
+
+ assert.ok(typeof answer === 'object');
+ answer["test1:" + testnr].should.eql(message);
+ answer["test2:" + testnr].should.eql(message2);
+
+ memcached.end(); // close connections
+ assert.equal(callbacks, 3);
+ done();
+ });
+ });
+ });
+ });
+
+ /**
+ * A multi get on a single server is different than a multi server multi get
+ * as a multi server multi get will need to do a multi get over multiple servers
+ * yes, that's allot of multi's in one single sentence thanks for noticing
+ */
+ it("multi get multi server", function(done) {
+ var memcached = new Memcached(common.servers.multi)
+ , message = common.alphabet(256)
+ , message2 = common.alphabet(256)
+ , testnr = ++global.testnumbers
+ , callbacks = 0;
+
+ memcached.set("test1:" + testnr, message, 1000, function(error, ok){
+ ++callbacks;
+
+ assert.ok(!error);
+ ok.should.be.true;
+
+ memcached.set("test2:" + testnr, message2, 1000, function(error, ok){
+ ++callbacks;
+
+ assert.ok(!error);
+ ok.should.be.true;
+
+ memcached.get(["test1:" + testnr,"test2:" + testnr], function(error, answer){
+ ++callbacks;
+
+ assert.ok(!error);
+
+ assert.ok(typeof answer === 'object');
+ answer["test1:" + testnr].should.eql(message);
+ answer["test2:" + testnr].should.eql(message2);
+
+ memcached.end(); // close connections
+ assert.equal(callbacks, 3);
+ done();
+ });
+ });
+ });
});
-});
+});
View
274 tests/memcached-incr-decr.test.js
@@ -13,138 +13,142 @@ global.testnumbers = global.testnumbers || +(Math.random(10) * 1000000).toFixed(
* memcached commands
*/
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();
- });
- });
- });
-});
+ /**
+ * 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();
+ });
+ });
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.