Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"env": {
"node": true
},
"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": {}
},
"rules": {
"block-scoped-var": 2,
"no-cond-assign": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-ex-assign": 2,
"no-extra-semi": 2,
"no-func-assign": 2,
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-negated-in-lhs": 2,
"no-obj-calls": 2,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-sparse-arrays": 2,
"no-unexpected-multiline": 2,
"no-unreachable": 2,
"no-delete-var": 2,
"no-shadow": 2,
"no-undef": 2,
"radix": 2,
"semi": 2,
"use-isnan": 2,
"valid-jsdoc": 2,
"valid-typeof": 2
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ node_modules/*
.idea/*
*.snap
*.xlog

npm-debug.log
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ script:
- sudo apt-get -y install tarantool
- ./test/box.lua &
- sleep 2
- npm test
- npm run lint
- npm test
34 changes: 19 additions & 15 deletions lib/connection.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global Promise */

'use strict';
var tarantoolConstants = require('./const');
var net = require('net');
Expand All @@ -18,7 +20,7 @@ var exampleCustomMsgpack = {
return msgpack.encode(obj);
},
decode: function(buf){
return msgpack.decode(obj);
return msgpack.decode(buf);
}
};

Expand Down Expand Up @@ -91,7 +93,7 @@ TarantoolConnection.prototype._getSpaceId = function(name){
{
throw new Error('Cannot read a space name or space is not defined');
}
}.bind(this))
}.bind(this));
};

TarantoolConnection.prototype._getIndexId = function(spaceId, indexName){
Expand Down Expand Up @@ -126,7 +128,7 @@ TarantoolConnection.prototype._getMetadata = function(spaceName, indexName){
return this._getSpaceId(spaceName)
.then(function(spaceId){
return Promise.all([spaceId, this._getIndexId(spaceId, indexName)]);
}.bind(this))
}.bind(this));
}
var promises = [];
if (typeof(spaceName) == 'string')
Expand All @@ -143,7 +145,7 @@ TarantoolConnection.prototype._getMetadata = function(spaceName, indexName){
};

TarantoolConnection.prototype.onData = function(data){

var trackResult;
switch(this.state){
case states.PREHELLO:
for (var i = 0; i<this.commandsQueue.length; i++)
Expand All @@ -163,7 +165,7 @@ TarantoolConnection.prototype.onData = function(data){
this.state = states.CONNECTED;
break;
case states.CONNECTED:
var trackResult = this._responseBufferTrack(data);
trackResult = this._responseBufferTrack(data);
if (trackResult.length == 2)
{
this.state = states.AWAITING;
Expand All @@ -185,7 +187,7 @@ TarantoolConnection.prototype.onData = function(data){
}
break;
case states.AWAITING:
var trackResult = this._responseBufferTrack(Buffer.concat([this.buffer, data]), this.awaitingResponseLength);
trackResult = this._responseBufferTrack(Buffer.concat([this.buffer, data]), this.awaitingResponseLength);
if (trackResult.length == 2)
{
this.state = states.AWAITING;
Expand Down Expand Up @@ -257,13 +259,16 @@ TarantoolConnection.prototype._processResponse = function(buffer){
{
this.schemaId = obj[0][5];
}
for(var i = 0; i<this.commandsQueue.length; i++)
if (this.commandsQueue[i][1] == reqId)
{
var task = this.commandsQueue[i];
this.commandsQueue.splice(i, 1);
break;
}
var task;
for(var i = 0; i<this.commandsQueue.length; i++) {
task = this.commandsQueue[i];
if (task[1] == reqId)
{
this.commandsQueue.splice(i, 1);
break;
}
}

var dfd = task[2];
var success = obj[0][0] == 0 ? true : false;
if (this.options.log)
Expand Down Expand Up @@ -577,8 +582,7 @@ function scramble(password, salt){
var step1 = shatransform(password);
var step2 = shatransform(step1);
var step3 = shatransform(Buffer.concat([encSalt.slice(0, 20), step2]));
var scramble = xor(step1, step3);
return scramble;
return xor(step1, step3);
}

TarantoolConnection.prototype._header = function(command, reqId){
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Tarantool driver for 1.6",
"main": "index.js",
"scripts": {
"test": "./node_modules/mocha/bin/mocha -t 5000"
"lint": "eslint ./lib ./test",
"test": "mocha -t 5000"
},
"repository": {
"type": "git",
Expand All @@ -30,6 +31,7 @@
},
"devDependencies": {
"benchmark": "^2.1.0",
"eslint": "^2.5.3",
"mocha": "^2.2.4"
}
}
48 changes: 28 additions & 20 deletions test/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/**
* Created by klond on 05.04.15.
*/

/*eslint-env mocha */
/* global Promise */

var fs = require('fs');
var assert = require('assert');
var TarantoolConnection = require('../lib/connection');
Expand All @@ -18,27 +22,29 @@ describe('Tarantool Connection tests', function(){
it('connect', function(done){
conn.connect().then(function(){
done();
}, function(e){ throw 'not connected'; done();});
}, function(e){ throw 'not connected'; });
});
it('auth', function(done){
conn.connect().then(function(){
return conn.auth('test', 'test');
}, function(e){ throw 'not connected'; done();})
}, function(e){ throw 'not connected'; })
.then(function(){
done();
}, function(e){ throw 'not auth'; done();})
}, function(e){ throw 'not auth'; });
});
});
describe('requests', function(){
var insertTuple = [50, 10, 'my key', 30];
/*eslint-disable no-shadow */
var conn;
/*eslint-enable no-shadow */
before(function(done){
console.log('before call');
try{
conn = new TarantoolConnection({port: 33013});
conn.connect().then(function(){
return conn.auth('test', 'test');
}, function(e){ throw 'not connected'; done();})
}, function(e){ throw 'not connected';})
.then(function(){
return Promise.all([conn.delete(514, 0, [1]),conn.delete(514, 0, [2]),
conn.delete(514, 0, [3]),conn.delete(514, 0, [4]),
Expand Down Expand Up @@ -118,7 +124,7 @@ describe('Tarantool Connection tests', function(){
assert.equal(a.length, 1);
assert.equal(a[0][3], insertTuple[3]+10);
done();
}).catch(function(e){ done(e) });
}).catch(function(e){ done(e); });
});
it('a lot of insert', function(done){
var promises = [];
Expand All @@ -145,35 +151,35 @@ describe('Tarantool Connection tests', function(){
it('call print', function(done){
conn.call('myprint', ['test'])
.then(function(){
done()
done();
})
.catch(function(e){
console.log(e);
done(e);
})
});
});
it('call batch', function(done){
conn.call('batch', [[1], [2], [3]])
.then(function(){
done()
done();
})
.catch(function(e){
console.log(e);
done(e);
})
});
});
it('call get', function(done){
conn.insert(514, [4])
.then(function() {
return conn.call('myget', 4)
return conn.call('myget', 4);
})
.then(function(value){
done()
done();
})
.catch(function(e){
console.log(e);
done(e);
})
});
});
it('get metadata space by name', function(done){
conn._getSpaceId('batched')
Expand All @@ -183,7 +189,7 @@ describe('Tarantool Connection tests', function(){
})
.catch(function(e){
done(e);
})
});
});
it('get metadata index by name', function(done){
conn._getIndexId(514, 'primary')
Expand All @@ -193,7 +199,7 @@ describe('Tarantool Connection tests', function(){
})
.catch(function(e){
done(e);
})
});
});
it('insert with space name', function(done){
conn.insert('test', [999, 999, 'fear'])
Expand Down Expand Up @@ -239,13 +245,15 @@ describe('Tarantool Connection tests', function(){
});
});
describe('upsert', function(){
/*eslint-disable no-shadow */
var conn;
/*eslint-enable no-shadow */
before(function(done){
try{
conn = new TarantoolConnection({port: 33013});
conn.connect().then(function(){
return conn.auth('test', 'test');
}, function(e){ throw 'not connected'; done();})
}, function(e){ throw 'not connected'; })
.then(function(){
return Promise.all([
conn.delete('upstest', 'primary', 1),
Expand Down Expand Up @@ -276,7 +284,7 @@ describe('Tarantool Connection tests', function(){

.catch(function(e){
done(e);
})
});
});
it('update', function(done){
conn.upsert('upstest', 2, [['+', 2, 2]], [2, 4, 3])
Expand All @@ -294,7 +302,7 @@ describe('Tarantool Connection tests', function(){

.catch(function(e){
done(e);
})
});
});
});
describe('connection test with custom msgpack implementation', function(){
Expand All @@ -317,15 +325,15 @@ describe('Tarantool Connection tests', function(){
it('connect', function(done){
customConn.connect().then(function(){
done();
}, function(e){ throw 'not connected'; done();});
}, function(e){ throw 'not connected'; });
});
it('auth', function(done){
customConn.connect().then(function(){
return customConn.auth('test', 'test');
}, function(e){ throw 'not connected'; done();})
}, function(e){ throw 'not connected'; })
.then(function(){
done();
}, function(e){ throw 'not auth'; done();})
}, function(e){ throw 'not auth'; });
});
});
});