K6 extension to perform tests on couchbase.
- Supports inserting a document.
- Supports Batch insertion.
- Support findOne (Fetch by primary key)
- Testing query performance
- Prepared statement query performance
import xk6_couchbase from 'k6/x/couchbase';
const client = xk6_couchbase.newClient('localhost', '<username>', '<password>');
export default () => {
let doc = {
correlationId: `test--couchbase`,
title: 'Perf test experiment',
url: 'example.com',
locale: 'en',
time: `${new Date(Date.now()).toISOString()}`
};
client.insert("test", "_default", "_default", makeId(15), doc);
}
function makeId(length) {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
let counter = 0;
while (counter < length) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
counter += 1;
}
return result;
}
import xk6_couchbase from 'k6/x/couchbase';
const client = xk6_couchbase.newClient('localhost', '<username>', '<password>');
const batchsize = 50;
export default () => {
var docobjs = {}
for (var i = 0; i < batchsize; i++) {
docobjs[makeId(15)] = getRecord();
}
client.insertBatch("test", "_default", "_default", docobjs);
}
function getRecord() {
return {
correlationId: `test--couchbase`,
title: 'Perf test experiment',
url: 'example.com',
locale: 'en',
time: `${new Date(Date.now()).toISOString()}`
};
}
function makeId(length) {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
let counter = 0;
while (counter < length) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
counter += 1;
}
return result;
}
import xk6_couchbase from 'k6/x/couchbase';
const client = xk6_couchbase.newClient('localhost', '<username>', '<password>');
export default () => {
// syntax :: client.findOne("<db>", "<scope>", "<keyspace>", "<docId>");
var res = client.findOne("test", "_default", "_default", "002wPJwiJArcUpz");
console.log(res);
}
import xk6_couchbase from 'k6/x/couchbase';
const client = xk6_couchbase.newClient('localhost', '<username>', '<password>');
export default () => {
var res = client.find("select * from test._default._default use keys \"00096zszpZaT47X\"");
//console.log(res);
}
import xk6_couchbase from 'k6/x/couchbase';
const client = xk6_couchbase.newClient('localhost', '<username>', '<password>');
export default () => {
var res = client.findByPreparedStmt("select * from test._default._default use keys \"00096zszpZaT47X\"");
//console.log(res);
}