Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: make zk as a parameter (#94)
  • Loading branch information
gxcsoccer authored and fengmk2 committed Aug 16, 2017
1 parent 0446381 commit f175bd7
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 54 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
@@ -1,10 +1,10 @@
language: node_js

node_js:
- "iojs-1"
- "8"
- "6"
- "4"
- "0.12"
- "0.11"
- "0.10"

before_script:
- "./start-local-hbase.sh"
Expand Down
21 changes: 13 additions & 8 deletions lib/client.js
Expand Up @@ -54,15 +54,20 @@ function Client(options) {
this.out = null;
this.socket = null;
this.logger = options.logger || console;
options.zookeeperRoot = options.zookeeperRoot || "/hbase";
if (options.zookeeper && typeof options.zookeeper.quorum === 'string') {
options.zookeeperHosts = options.zookeeper.quorum.split(SERVERNAME_SEPARATOR);

if (options.zk) {
this.zk = options.zk;
} else {
options.zookeeperRoot = options.zookeeperRoot || "/hbase";
if (options.zookeeper && typeof options.zookeeper.quorum === 'string') {
options.zookeeperHosts = options.zookeeper.quorum.split(SERVERNAME_SEPARATOR);
}
this.zk = new ZooKeeperWatcher({
hosts: options.zookeeperHosts,
root: options.zookeeperRoot,
logger: this.logger,
});
}
this.zk = new ZooKeeperWatcher({
hosts: options.zookeeperHosts,
root: options.zookeeperRoot,
logger: this.logger,
});

this.zkStart = 'init';
this.rootRegionZKPath = options.rootRegionZKPath || '/root-region-server';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -7,7 +7,7 @@
"index.js", "lib/"
],
"scripts": {
"test": "make test-all"
"test": "make test"
},
"config": {
"blanket": {
Expand Down
4 changes: 2 additions & 2 deletions start-local-hbase.sh
@@ -1,6 +1,6 @@
export HBASE_FILE=`curl http://www.eu.apache.org/dist/hbase/ | grep -o 'hbase-0.94.[0-9]*' | head -1`
export HBASE_FILE=`curl http://archive.apache.org/dist/hbase/ | grep -o 'hbase-0.94.27' | head -1`
if [ ! -d $HBASE_FILE ]; then
curl http://www.eu.apache.org/dist/hbase/$HBASE_FILE/$HBASE_FILE.tar.gz -o $HBASE_FILE.tar.gz
curl http://archive.apache.org/dist/hbase/$HBASE_FILE/$HBASE_FILE.tar.gz -o $HBASE_FILE.tar.gz
tar -xzf $HBASE_FILE.tar.gz
fi
cp test/conf/hbase-site.xml $HBASE_FILE/conf/
Expand Down
2 changes: 1 addition & 1 deletion stop-local-hbase.sh
@@ -1,2 +1,2 @@
export HBASE_FILE=`curl http://www.eu.apache.org/dist/hbase/ | grep -o 'hbase-0.94.[0-9]*' | head -1`
export HBASE_FILE=`curl http://archive.apache.org/dist/hbase/ | grep -o 'hbase-0.94.27' | head -1`
$HBASE_FILE/bin/stop-hbase.sh
86 changes: 47 additions & 39 deletions test/client.test.js
Expand Up @@ -998,12 +998,18 @@ describe('test/client.test.js', function () {
describe('delete columns', function () {
var data = {'cf1:name-t': 't-test01', 'cf1:value-t': 't-test02'};
var columns = ['cf1:name-t', 'cf1:value-t'];
var rowkey = '58c8MDAwMDAwMDAwMDAwMDAwMQ==1';
before(function (done) {
client.putRow(table, rowkey, data, function (err) {
should.not.exists(err);
done();
setTimeout(done, 100);
});
});
after(function () {
client.deleteRow(table, rowkey, function (err, result) {
should.not.exists(err);
}); // delete
});

it('should work', function (done) {
client.getRow(table, rowkey, columns, function (err, result) {
Expand All @@ -1030,46 +1036,48 @@ describe('test/client.test.js', function () {
var columns = ['cf1:name-t', 'cf1:value-t'];
client.putRow(table, rowkey, data, function (err, result) {
should.not.exists(err);
client.putRow(table, rowkey, data, function (err, result) {
should.not.exists(err);
var get = new Get(rowkey);
get.setMaxVersions(2);
for (var i = 0; i < columns.length; i++) {
var col = columns[i].split(':');
get.addColumn(col[0], col[1]);
}
client.get(table, get, function (err, result) {
setTimeout(function() {
client.putRow(table, rowkey, data, function (err, result) {
should.not.exists(err);
should.exists(result);
var rs = result.getColumn('cf1', 'name-t');
rs.length.should.eql(2);
rs.forEach(function (kv) {
kv.getValue().toString().should.eql('t-test01');
});
//result.should.have.keys('f:name-t', 'f:value-t');
var del = new Delete(rowkey);
del.deleteColumn('cf1', 'name-t');
client.delete(table, del, function (err, result) {
var get = new Get(rowkey);
get.setMaxVersions(2);
for (var i = 0; i < columns.length; i++) {
var col = columns[i].split(':');
get.addColumn(col[0], col[1]);
}
client.get(table, get, function (err, result) {
should.not.exists(err);
var get = new Get(rowkey);
get.setMaxVersions(2);
for (var i = 0; i < columns.length; i++) {
var col = columns[i].split(':');
get.addColumn(col[0], col[1]);
}
client.get(table, get, function (err, result) {
should.exists(result);
var rs = result.getColumn('cf1', 'name-t');
rs.length.should.eql(2);
rs.forEach(function (kv) {
kv.getValue().toString().should.eql('t-test01');
});
//result.should.have.keys('f:name-t', 'f:value-t');
var del = new Delete(rowkey);
del.deleteColumn('cf1', 'name-t');
client.delete(table, del, function (err, result) {
should.not.exists(err);
should.exists(result);
var rs = result.getColumn('cf1', 'name-t');
rs.length.should.eql(1);
rs.forEach(function (kv) {
kv.getValue().toString().should.eql('t-test01');
});
done();
}); // get
}); // delete
}); // get
}); // put version2
var get = new Get(rowkey);
get.setMaxVersions(2);
for (var i = 0; i < columns.length; i++) {
var col = columns[i].split(':');
get.addColumn(col[0], col[1]);
}
client.get(table, get, function (err, result) {
should.not.exists(err);
should.exists(result);
var rs = result.getColumn('cf1', 'name-t');
rs.length.should.eql(1);
rs.forEach(function (kv) {
kv.getValue().toString().should.eql('t-test01');
});
done();
}); // get
}); // delete
}); // get
}); // put version2
}, 10);
}); // put version1
});

Expand Down Expand Up @@ -1254,7 +1262,7 @@ describe('test/client.test.js', function () {
should.not.exists(err);

client.mget(tableName, ['a98eMDAwMDAwMDAwMDAwMDAwMg==md'], ['cf1:history', 'cf1:qualifier2'], function (err, result) {
should.not.exists(err);
should.not.exists(err);
should.exists(result);
result.length.should.eql(1);

Expand Down

0 comments on commit f175bd7

Please sign in to comment.