如何使用Mocha/node.js测试HBase
大家好,我有一份工作,有一个方法可以从给定 Node.js 中的键的 HBase 中提取数据,如下所示:
findHbaseData(field1, field2) {
const key = generateKey(field1, field2);
const data = hbase.get(key);
data['field3'] = data.field3.toUpperCase;
return data
}
Hbase.get 的工作原理如下:
const HBaseRestClient = require('hbase');
const {Connection} = HBaseRestClient
this.client = HBaseRestClient(
this.confHbase // Here I have table name, host and port
);
this.table = this.confHbase.table;
async get(id, columns) {
let schema = this.getSchema(columns)
return await new Promise( (res, rej) => {
const row = this.client.table(this.table).row(id);
if (row) {
let convert = (err, values, response) => {
if (err) {
rej(err);
return;
}
const innerModel = Object.create(this.model);
const result = this.convertRow(values, innerModel, schema, columns);
res(result);
}
if (columns && columns.length) {
let hbaseColumns = this.schemaToHbaseColumns(columns)
row.get(hbaseColumns, convert);
} else {
row.get(convert);
}
}
} );
}
我需要使用 mocha 或 chai 测试此方法(findHbaseData),但我的环境测试(Jenkins)无法访问Hbase,是否可以使用mocha来模拟这种访问并返回假数据,而不是运行真正的hBase.get(key)
? 谢谢!
Hi guys I have a job that has a method that extracts data from HBase given a key in Node.js, something like follows:
findHbaseData(field1, field2) {
const key = generateKey(field1, field2);
const data = hbase.get(key);
data['field3'] = data.field3.toUpperCase;
return data
}
The Hbase.get works like follows:
const HBaseRestClient = require('hbase');
const {Connection} = HBaseRestClient
this.client = HBaseRestClient(
this.confHbase // Here I have table name, host and port
);
this.table = this.confHbase.table;
async get(id, columns) {
let schema = this.getSchema(columns)
return await new Promise( (res, rej) => {
const row = this.client.table(this.table).row(id);
if (row) {
let convert = (err, values, response) => {
if (err) {
rej(err);
return;
}
const innerModel = Object.create(this.model);
const result = this.convertRow(values, innerModel, schema, columns);
res(result);
}
if (columns && columns.length) {
let hbaseColumns = this.schemaToHbaseColumns(columns)
row.get(hbaseColumns, convert);
} else {
row.get(convert);
}
}
} );
}
I need to test this method (findHbaseData) using mocha or chai but my environment test (Jenkins) can't access the Hbase, it's possible to use mocha to simulate this access and return fake data, instead to run the real hBase.get(key)
?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚发现了答案。
我可以创建一个
HBaseRestClient.prototype.get(id,columns)
并从 json 文件读取数据。I just discovered the answer.
I could create a
HBaseRestClient.prototype.get(id,columns)
and read the data from a json file.