Socket
Socket
Sign inDemoInstall

aerospike

Package Overview
Dependencies
Maintainers
3
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aerospike - npm Package Compare versions

Comparing version 1.0.54 to 1.0.55

.editorconfig

175

benchmarks/alerts.js

@@ -1,19 +0,35 @@

var winston;
var nodemailer;
var transporter;
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
var winston
var nodemailer
var transporter
var severity = {
HIGH: 0,
MEDIUM: 1,
LOW: 2
};
HIGH: 0,
MEDIUM: 1,
LOW: 2
}
var action = {
SENDEMAIL:0,
PRINTCONSOLE:1,
PRINTFILE:2
};
SENDEMAIL: 0,
PRINTCONSOLE: 1,
PRINTFILE: 2
}
var mediumSevCount = 0;
var lowSevCount = 0;
var mediumSevCount = 0
var lowSevCount = 0

@@ -23,78 +39,73 @@ // setup winston logger to log it to file or console

// send emails in case of errors.
var alertMode;
function setupAlertSystem(alert) {
if( alert.mode === "EMAIL") {
nodemailer = require('nodemailer');
transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'gmail account',
pass: 'password'
}
});
alertMode = alert.mode;
var alertMode
function setupAlertSystem (alert) {
if (alert.mode === 'EMAIL') {
nodemailer = require('nodemailer')
transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'gmail account',
pass: 'password'
}
})
alertMode = alert.mode
} else {
winston = require('winston')
if (alert.mode === 'FILE') {
winston.add(winston.transports.file, {filename: alert.filename})
winston.remove(winston.transports.Console)
}
else {
winston = require('winston');
if(alert.mode === "FILE") {
winston.add(winston.transports.file,{ filename: alert.filename});
winston.remove(winston.transports.Console);
}
alertMode = alert.mode
}
alertMode = alert.mode
}
}
function handleAlert(alertInfo, sev) {
var generateAlert = false;
switch(sev) {
case severity.HIGH: {
generateAlert = true;
break;
function handleAlert (alertInfo, sev) {
var generateAlert = false
switch (sev) {
case severity.HIGH:
generateAlert = true
break
case severity.MEDIUM:
mediumSevCount++
if (mediumSevCount % 3 === 0) {
generateAlert = true
}
break
case severity.LOW:
lowSevCount++
if (lowSevCount % 6 === 0) {
generateAlert = true
}
break
default:
// do nothing
break
}
if (generateAlert) {
if (alertMode === 'EMAIL') {
// send an email.
var email = {
from: 'Aerospike alert account',
to: 'gayathri@aerospike.com',
subject: 'Nodejs Longevity Alert',
text: JSON.stringify(alertInfo)
}
transporter.sendMail(email, function (error, info) {
if (error) {
console.log(error)
}
case severity.MEDIUM: {
mediumSevCount++;
if( mediumSevCount%3 == 0) {
generateAlert = true;
}
break;
}
case severity.LOW: {
lowSevCount++;
if( lowSevCount%6 == 0) {
generateAlert = true;
}
break;
}
default:
// do nothing
break;
})
} else if (alertMode === 'FILE' || alertMode === 'CONSOLE') {
winston.info(alertInfo)
}
if (generateAlert) {
if(alertMode === "EMAIL") {
//send an email.
var email = {
from: 'Aerospike alert account',
to: 'gayathri@aerospike.com',
subject: 'Nodejs Longevity Alert',
text: JSON.stringify(alertInfo)
}
transporter.sendMail(mail, function(error,info) {
if(error) {
console.log(error);
}
});
}
else if(alertMode === "FILE" || alertMode === "CONSOLE") {
winston.info(alertInfo);
}
} else {
// should we store the temporary information in some structure.
}
} else {
// should we store the temporary information in some structure.
}
}
module.exports = {
handleAlert : handleAlert,
setupAlertSystem: setupAlertSystem,
severity : severity,
action : action
};
handleAlert: handleAlert,
setupAlertSystem: setupAlertSystem,
severity: severity,
action: action
}

@@ -1,308 +0,293 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/***********************************************************************
*
* node inspect.js -h
*
***********************************************************************/
// *****************************************************************************
// node inspect.js -h
// *****************************************************************************
var spawn = require('child_process').spawn;
var spawn = require('child_process').spawn
var cluster = require('cluster');
var yargs = require('yargs');
var os = require('os');
var path = require('path');
var util = require('util');
var winston = require('winston');
var stats = require('./stats');
var cluster = require('cluster')
var yargs = require('yargs')
var os = require('os')
var stats = require('./stats')
// *****************************************************************************
// Options Parsing
// *****************************************************************************
/***********************************************************************
*
* Options Parsing
*
***********************************************************************/
var argp = yargs
.usage("$0 [options]")
.options({
help: {
boolean: true,
describe: "Display this message."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
log: {
alias: "l",
default: 1,
describe: "Log level [0-5]."
},
namespace: {
alias: "n",
default: "test",
describe: "Key namespace."
},
set: {
alias: "s",
default: "demo",
describe: "Key set."
},
reads: {
alias: "R",
default: 1,
describe: "The read in the read/write ratio."
},
writes: {
alias: "W",
default: 1,
describe: "The write in the read/write ratio."
},
keyrange: {
alias: "K",
default: 1000,
describe: "The number of keys to use."
}
});
.usage('$0 [options]')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
log: {
alias: 'l',
default: 1,
describe: 'Log level [0-5].'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Key namespace.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Key set.'
},
reads: {
alias: 'R',
default: 1,
describe: 'The read in the read/write ratio.'
},
writes: {
alias: 'W',
default: 1,
describe: 'The write in the read/write ratio.'
},
keyrange: {
alias: 'K',
default: 1000,
describe: 'The number of keys to use.'
}
})
var argv = argp.argv;
var argv = argp.argv
if ( argv.help === true) {
argp.showHelp()
return;
if (argv.help === true) {
argp.showHelp()
process.exit()
}
if ( !cluster.isMaster ) {
console.error('main.js must not run as a child process.');
return;
if (!cluster.isMaster) {
console.error('main.js must not run as a child process.')
process.exit()
}
/***********************************************************************
*
* Globals
*
***********************************************************************/
// *****************************************************************************
// Globals
// *****************************************************************************
var cpus = os.cpus();
var cpus = os.cpus()
var P_MIN = 1, P_MAX = cpus.length, P_STEP = 1;
var I_MIN = 1, I_MAX = 1, I_STEP = 1;
var O_MIN = 1, O_MAX = 100, O_STEP = 8;
var P_MIN = 1
var P_MAX = cpus.length
var P_STEP = 1
var I_MIN = 1
var I_MAX = 1
var I_STEP = 1
var O_MIN = 1
var O_MAX = 100
var O_STEP = 8
/***********************************************************************
*
* Functions
*
***********************************************************************/
// *****************************************************************************
// Functions
// *****************************************************************************
var results = [];
var errors = [];
var results = []
var errors = []
function report_step(p, i, o, code, stdout, stderr) {
function report_step (p, i, o, code, stdout, stderr) {
console.log('processes: %d, iterations: %d, operations: %d, status: %d', p, i, o, code)
console.log('processes: %d, iterations: %d, operations: %d, status: %d', p, i, o, code);
console.log()
console.log();
var result
var result;
if (code === 0) {
result = JSON.parse(stdout)
if ( code === 0 ) {
console.log(' tps (per process):')
console.log(' min: %d, max: %d, mean: %d',
result.tps.min,
result.tps.max,
result.tps.mean
)
result = JSON.parse(stdout);
console.log(' times (ms):')
console.log(' min: %d, max: %d, mean: %d',
result.times.min.toFixed(2),
result.times.max.toFixed(2),
result.times.mean.toFixed(2)
)
console.log(' tps (per process):');
console.log(' min: %d, max: %d, mean: %d',
result.tps.min,
result.tps.max,
result.tps.mean
);
console.log(' duration:')
stats.print_histogram(result.durations, console.log, ' ')
console.log(' times (ms):');
console.log(' min: %d, max: %d, mean: %d',
result.times.min.toFixed(2),
result.times.max.toFixed(2),
result.times.mean.toFixed(2)
);
console.log(' status codes:')
stats.print_histogram(result.status_codes, console.log, ' ')
console.log(' duration:')
stats.print_histogram(result.durations, console.log,' ');
results.push(result)
} else {
stderr.split('\n').forEach(function (l) {
console.log(' error: %s', l)
})
errors.push([p, i, o, code, stderr])
}
console.log(' status codes:')
stats.print_histogram(result.status_codes, console.log,' ');
results.push(result);
}
else {
stderr.split("\n").forEach(function(l){
console.log(' error: %s', l);
});
errors.push([p, i, o, code, stderr]);
}
console.log();
console.log()
}
function report_final() {
function report_final () {
console.log()
console.log('SUMMARY')
console.log()
console.log();
console.log("SUMMARY");
console.log();
var matched = results.filter(function (res) {
var ops = res.operations
return (res.durations['<= 1'] / ops * 100).toFixed(0) >= 90 &&
(res.durations['> 1'] / ops * 100).toFixed(0) <= 10 &&
(res.durations['> 2'] / ops * 100).toFixed(0) <= 2 &&
(res.durations['<= 1'] + res.durations['> 1'] + res.durations['> 2'] === ops)
})
var matched = results.filter(function(res) {
var ops = res.operations;
return (res.durations['<= 1'] / ops * 100).toFixed(0) >= 90 &&
(res.durations['> 1'] / ops * 100).toFixed(0) <= 10 &&
(res.durations['> 2'] / ops * 100).toFixed(0) <= 2 &&
(res.durations['<= 1'] + res.durations['> 1'] + res.durations['> 2'] == ops);
})
matched.forEach(function (res) {
console.log(' processes: %d, iterations: %d, operations: %d',
res.configuration.processes,
res.configuration.iterations,
res.configuration.operations
)
console.log(' tps: {min: %d, max: %d, avg: %d}',
res.tps.min,
res.tps.max,
res.tps.mean
)
console.log(' time: {min: %d, max: %d, avg: %d}',
res.times.min.toFixed(2),
res.times.max.toFixed(2),
res.times.mean.toFixed(2)
)
console.log(' duration:')
stats.print_histogram(res.durations, console.log, ' ')
})
matched.forEach(function(res) {
console.log(' processes: %d, iterations: %d, operations: %d',
res.configuration.processes,
res.configuration.iterations,
res.configuration.operations
);
console.log(' tps: {min: %d, max: %d, avg: %d}',
res.tps.min,
res.tps.max,
res.tps.mean
);
console.log(' time: {min: %d, max: %d, avg: %d}',
res.times.min.toFixed(2),
res.times.max.toFixed(2),
res.times.mean.toFixed(2)
);
console.log(' duration:')
stats.print_histogram(res.durations, console.log,' ');
});
var group_ops = {}
var group_ops = {};
matched.forEach(function (res) {
var ops = res.configuration.operations
var group = (group_ops[ops] || [])
group.push(res)
group_ops[ops] = group
})
matched.forEach(function(res) {
var ops = res.configuration.operations;
var group = (group_ops[ops] || [])
group.push(res);
group_ops[ops] = group;
})
console.log();
console.log();
for ( var k in group_ops ) {
var ops = group_ops[k];
console.log("operations: %d", k);
for(var o=0; o<ops.length; o++) {
var op = ops[o];
console.log(' p: %d, tps: {l: %d, u: %d, m: %d}, time: {l: %d, u: %d, m: %d}, dur: {0: %d, 1: %d, 2: %d}',
op.configuration.processes,
op.tps.min,
op.tps.max,
op.tps.mean,
op.times.min.toFixed(2),
op.times.max.toFixed(2),
op.times.mean.toFixed(2),
op.durations['<= 1'],
op.durations['> 1'],
op.durations['> 2']
);
}
console.log()
console.log()
for (var k in group_ops) {
var ops = group_ops[k]
console.log('operations: %d', k)
for (var o = 0; o < ops.length; o++) {
var op = ops[o]
console.log(' p: %d, tps: {l: %d, u: %d, m: %d}, time: {l: %d, u: %d, m: %d}, dur: {0: %d, 1: %d, 2: %d}',
op.configuration.processes,
op.tps.min,
op.tps.max,
op.tps.mean,
op.times.min.toFixed(2),
op.times.max.toFixed(2),
op.times.mean.toFixed(2),
op.durations['<= 1'],
op.durations['> 1'],
op.durations['> 2']
)
}
console.log();
}
console.log()
var o_hist = {}
var o_hist = {};
matched.forEach(function (res) {
var ops = res.configuration.operations
o_hist[ops] = (o_hist[ops] || 0) + 1
})
matched.forEach(function(res) {
var ops = res.configuration.operations;
o_hist[ops] = (o_hist[ops] || 0) + 1;
})
console.log()
console.log('Number of Concurrent Transactions:')
stats.print_histogram(o_hist, console.log, ' ')
console.log();
console.log('Number of Concurrent Transactions:')
stats.print_histogram(o_hist, console.log,' ');
console.log();
console.log()
}
function exec(p, i, o) {
function exec (p, i, o) {
var stdout = new Buffer('')
var stderr = new Buffer('')
var stdout = new Buffer("");
var stderr = new Buffer("");
var prog = 'node'
var prog = 'node';
var args = ['main.js',
'-h', argv.host, '-p', argv.port, '-t', argv.timeout,
'-n', argv.namespace, '-s', argv.set,
'-R', argv.reads, '-W', argv.writes, '-K', argv.keyrange,
'-P', p, '-I', i, '-O', o,
'--silent', '--json'
]
var args = ['main.js',
'-h', argv.host, '-p', argv.port, '-t', argv.timeout,
'-n', argv.namespace, '-s', argv.set,
'-R', argv.reads, '-W', argv.writes, '-K', argv.keyrange,
'-P', p, '-I', i, '-O', o,
'--silent', '--json'
];
var proc = spawn(prog, args)
var proc = spawn(prog, args);
proc.stdout.on('data', function (data) {
stdout = Buffer.concat([stdout, data])
})
proc.stdout.on('data', function(data) {
stdout = Buffer.concat([stdout,data])
});
proc.stderr.on('data', function (data) {
stderr = Buffer.concat([stderr, data])
})
proc.stderr.on('data', function(data) {
stderr = Buffer.concat([stderr,data])
});
proc.on('close', function(code) {
report_step(p, i, o, code, stdout.toString(), stderr.toString());
step(p, i, o);
});
proc.on('close', function (code) {
report_step(p, i, o, code, stdout.toString(), stderr.toString())
step(p, i, o)
})
}
function step(p, i, o) {
o += O_STEP;
function step (p, i, o) {
o += O_STEP
if ( o > O_MAX ) {
i += I_STEP;
o = O_MIN;
}
if (o > O_MAX) {
i += I_STEP
o = O_MIN
}
if ( i > I_MAX ) {
p += P_STEP;
i = I_MIN;
o = O_MIN;
}
if (i > I_MAX) {
p += P_STEP
i = I_MIN
o = O_MIN
}
if ( p > P_MAX ) {
report_final();
return;
}
if (p > P_MAX) {
report_final()
return
}
return exec(p, i, o);
return exec(p, i, o)
}
exec(P_MIN, I_MIN, O_MIN);
exec(P_MIN, I_MIN, O_MIN)

@@ -1,273 +0,121 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/***********************************************************************
*
* node -O 10000 -P 4 -R 0.5
*
***********************************************************************/
// *****************************************************************************
// node -O 10000 -P 4 -R 0.5
// *****************************************************************************
var aerospike = require('aerospike');
var cluster = require('cluster');
var yargs = require('yargs');
var os = require('os');
var path = require('path');
var util = require('util');
var winston = require('winston');
var stats = require('./stats');
var alerts = require('./alerts');
var argv = require('./config.json');
var aerospike = require('aerospike')
var cluster = require('cluster')
var winston = require('winston')
var stats = require('./stats')
var alerts = require('./alerts')
var argv = require('./config.json')
/***********************************************************************
*
* Globals
*
***********************************************************************/
// *****************************************************************************
// Globals
// *****************************************************************************
var cpus = os.cpus();
var kB = 1024;
var MB = kB * 1024;
var GB = MB * 1024;
var OP_TYPES = 4 // READ, WRITE, SCAN and QUERY
var STATS = 3 // OPERATIONS, TIMEOUTS and ERRORS
var OP_TYPES = 4; // READ, WRITE, SCAN and QUERY
var STATS = 3; // OPERATIONS, TIMEOUTS and ERRORS
var queryWorkers = 0
var scanWorkers = 0
var online = 0
var exited = 0
var rwOnline = 0
var queryOnline = 0
var scanOnline = 0
var queryWorkers= 0;
var scanWorkers = 0;
var online = 0;
var exited = 0;
var rwOnline = 0;
var queryOnline = 0;
var scanOnline = 0;
var timerId;
//
// Number of completed operations(READ & WRITE), timed out operations and operations that ran into error per second
//
var interval_stats = new Array(OP_TYPES)
reset_interval_stats()
var iterations_results = [];
/**
* Number of completed operations(READ & WRITE), timed out operations and operations that ran into error per second
*/
var interval_stats = new Array(OP_TYPES);
reset_interval_stats();
/***********************************************************************
*
* Options Parsing
*
***********************************************************************/
/*var argp = yargs
.usage("$0 [options]")
.options({
help: {
boolean: true,
describe: "Display this message."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 0,
describe: "Timeout in milliseconds."
},
ttl:{
default: 10000,
describe: "Time to live for the record (seconds). Units may be used: 1h, 30m, 30s"
},
log: {
alias: "l",
default: 1,
describe: "Log level [0-5]."
},
namespace: {
alias: "n",
default: "test",
describe: "Key namespace."
},
set: {
alias: "s",
default: "demo",
describe: "Key set."
},
user: {
alias: "U",
default:null,
describe: "Username to connect to a secure cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to a secure cluster"
},
json: {
alias: "j",
default: false,
describe: "Display report in JSON format."
},
silent: {
default: false,
describe: "Supress the tps statistics printed every second."
},
longevity: {
default: false,
describe: "Print intermediate output from workers."
},
alerts: {
default: 'CONSOLE',
describe: "alerts generated can be redirected to FILE, CONSOLE, EMAIL" +
"for directing alerts to files, filename must be specified"
},
filename: {
default: undefined,
describe: "Filename to which the alerts must be written to"
},
operations: {
alias: "O",
default: 100,
describe: "Total number of operations to perform per iteration per process."
},
iterations: {
alias: "I",
default: undefined,
describe: "Total number of iterations to perform per process."
},
processes: {
alias: "N",
default: cpus.length,
describe: "Total number of child processes."
},
time: {
alias: "T",
default: undefined,
describe: "Total amount of time to run the benchmark (seconds). Units may be used: 1h, 30m, 30s"
},
reads: {
alias: "R",
default: 1,
describe: "The read in the read/write ratio."
},
writes: {
alias: "W",
default: 1,
describe: "The write in the read/write ratio."
},
keyrange: {
alias: "K",
default: 100000,
describe: "The number of keys to use."
},
datatype: {
default: "INTEGER",
describe: "The datatype of the record."
},
datasize: {
default: 1024,
describe: "Size of the record."
},
'summary': {
boolean: true,
default: true,
describe: "Produces a summary report (tables, charts, etc) at the end."
}
});
var argv = argp.argv;*/
if( argv.querySpec !== undefined) {
queryWorkers = argv.querySpec.length;
if (argv.querySpec !== undefined) {
queryWorkers = argv.querySpec.length
}
if( argv.scanSpec !== undefined) {
scanWorkers = argv.scanSpec.length;
if (argv.scanSpec !== undefined) {
scanWorkers = argv.scanSpec.length
}
var rwWorkers = argv.processes - queryWorkers - scanWorkers;
var rwWorkers = argv.processes - queryWorkers - scanWorkers
if ( !cluster.isMaster ) {
console.error('main.js must not run as a child process.');
return;
if (!cluster.isMaster) {
console.error('main.js must not run as a child process.')
process.exit()
}
var FOPS = (argv.operations / (argv.reads + argv.writes));
var ROPS = FOPS * argv.reads;
var WOPS = FOPS * argv.writes;
var ROPSPCT = ROPS / argv.operations * 100;
var WOPSPCT = WOPS / argv.operations * 100;
var FOPS = (argv.operations / (argv.reads + argv.writes))
var ROPS = FOPS * argv.reads
var WOPS = FOPS * argv.writes
var ROPSPCT = ROPS / argv.operations * 100
var WOPSPCT = WOPS / argv.operations * 100
if ( (ROPS + WOPS) < argv.operations ) {
DOPS = argv.operations - (ROPS + WOPS);
ROPS += DOPS;
if ((ROPS + WOPS) < argv.operations) {
var DOPS = argv.operations - (ROPS + WOPS)
ROPS += DOPS
}
if(argv.time !== undefined){
argv.time = stats.parse_time_to_secs(argv.time);
argv.iterations = undefined;
if (argv.time !== undefined) {
argv.time = stats.parse_time_to_secs(argv.time)
argv.iterations = undefined
}
var alert = { mode: argv.alert, filename: argv.filename}
alerts.setupAlertSystem(alert);
var alert = {mode: argv.alert, filename: argv.filename}
alerts.setupAlertSystem(alert)
/***********************************************************************
*
* Logging
*
***********************************************************************/
// *****************************************************************************
// Logging
// *****************************************************************************
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
level: 'info',
silent: false,
colorize: true
})
]
});
transports: [
new (winston.transports.Console)({
level: 'info',
silent: false,
colorize: true
})
]
})
/***********************************************************************
*
* Functions
*
***********************************************************************/
// *****************************************************************************
// Functions
// *****************************************************************************
function finalize() {
if ( argv.summary === true && rwWorkers > 0) {
return stats.report_final(argv, console.log);
}
function finalize () {
if (argv.summary === true && rwWorkers > 0) {
return stats.report_final(argv, console.log)
}
}
function worker_spawn() {
var worker = cluster.fork();
worker.iteration = 0;
worker.on('message', worker_results(worker));
}
function worker_spawn () {
var worker = cluster.fork()
worker.iteration = 0
worker.on('message', worker_results(worker))
}
function worker_exit(worker) {
worker.send(['end']);
function worker_exit (worker) {
worker.send(['end'])
}
function worker_shutdown() {
Object.keys(cluster.workers).forEach(function(id) {
worker_exit(cluster.workers[id]);
});
function worker_shutdown () {
Object.keys(cluster.workers).forEach(function (id) {
worker_exit(cluster.workers[id])
})
}

@@ -278,21 +126,19 @@

*/
function worker_probe() {
Object.keys(cluster.workers).forEach(function(id) {
cluster.workers[id].send(['trans']);
});
function worker_probe () {
Object.keys(cluster.workers).forEach(function (id) {
cluster.workers[id].send(['trans'])
})
}
function rwWorkerJob(worker) {
var option = {
namespace : argv.namespace,
set : argv.set,
keyRange : argv.keyRange,
rops : ROPS,
wops : WOPS,
binSpec : argv.binSpec
};
worker.iteration++;
worker.send(['run', option]);
function rwWorkerJob (worker) {
var option = {
namespace: argv.namespace,
set: argv.set,
keyRange: argv.keyRange,
rops: ROPS,
wops: WOPS,
binSpec: argv.binSpec
}
worker.iteration++
worker.send(['run', option])
}

@@ -303,28 +149,26 @@

// this can be enhanced for that.
function queryWorkerJob(worker, id) {
var stmt = {};
var queryConfig = argv.querySpec[id];
if(queryConfig.qtype === "Range") {
stmt.filters = [aerospike.filter.range(queryConfig.bin,queryConfig.min, queryConfig.max)];
}
else if(queryConfig.qtype === "Equal") {
stmt.filters = [aerospike.filter.equal(queryConfig.bin, queryConfig.value)];
}
function queryWorkerJob (worker, id) {
var stmt = {}
var queryConfig = argv.querySpec[id]
if (queryConfig.qtype === 'Range') {
stmt.filters = [aerospike.filter.range(queryConfig.bin, queryConfig.min, queryConfig.max)]
} else if (queryConfig.qtype === 'Equal') {
stmt.filters = [aerospike.filter.equal(queryConfig.bin, queryConfig.value)]
}
var options = {
namespace : argv.namespace,
set : argv.set,
statement : stmt
}
worker.send(['query', options]);
var options = {
namespace: argv.namespace,
set: argv.set,
statement: stmt
}
worker.send(['query', options])
}
function scanWorkerJob(worker) {
var options = {
namespace : argv.namespace,
set : argv.set,
statement : argv.scanSpec
}
worker.send(['query', options]);
function scanWorkerJob (worker) {
var options = {
namespace: argv.namespace,
set: argv.set,
statement: argv.scanSpec
}
worker.send(['query', options])
}

@@ -336,70 +180,67 @@

*/
var counter = 0; // Number of times worker_results_interval is called
function worker_results_interval(worker, interval_worker_stats){
for ( i = 0; i < OP_TYPES; i++ ) {
for (j = 0; j < STATS; j++)
interval_stats[i][j] = interval_stats[i][j] + interval_worker_stats[i][j];
var counter = 0 // Number of times worker_results_interval is called
function worker_results_interval (worker, interval_worker_stats) {
for (var i = 0; i < OP_TYPES; i++) {
for (var j = 0; j < STATS; j++) {
interval_stats[i][j] = interval_stats[i][j] + interval_worker_stats[i][j]
}
if (++counter % argv.processes === 0){
print_interval_stats();
}
}
if (++counter % argv.processes === 0) {
print_interval_stats()
}
}
function print_interval_stats(){
if( rwWorkers > 0) {
logger.info("%s read(tps=%d timeouts=%d errors=%d) write(tps=%d timeouts=%d errors=%d) ",
new Date().toString(), interval_stats[0][0],interval_stats[0][1],interval_stats[0][2],
interval_stats[1][0], interval_stats[1][1],interval_stats[1][2])
}
if( queryWorkers ) {
logger.info("%s query(records = %d timeouts = %d errors = %d)",
new Date().toString(), interval_stats[2][0], interval_stats[2][1], interval_stats[2][2]);
}
if( scanWorkers ) {
logger.info("%s scan(records = %d timeouts = %d errors = %d)",
new Date().toString(), interval_stats[3][0], interval_stats[3][1], interval_stats[3][2]);
}
function print_interval_stats () {
if (rwWorkers > 0) {
logger.info('%s read(tps=%d timeouts=%d errors=%d) write(tps=%d timeouts=%d errors=%d) ',
new Date().toString(), interval_stats[0][0], interval_stats[0][1], interval_stats[0][2],
interval_stats[1][0], interval_stats[1][1], interval_stats[1][2])
}
if (queryWorkers) {
logger.info('%s query(records = %d timeouts = %d errors = %d)',
new Date().toString(), interval_stats[2][0], interval_stats[2][1], interval_stats[2][2])
}
if (scanWorkers) {
logger.info('%s scan(records = %d timeouts = %d errors = %d)',
new Date().toString(), interval_stats[3][0], interval_stats[3][1], interval_stats[3][2])
}
}
function worker_results_iteration (worker, op_stats) {
stats.iteration(op_stats)
if (argv.iterations === undefined || worker.iteration < argv.iterations || argv.time !== undefined) {
rwWorkerJob(worker)
} else {
worker_exit(worker)
}
}
function worker_results_iteration(worker, op_stats) {
stats.iteration(op_stats);
if ( argv.iterations === undefined || worker.iteration < argv.iterations || argv.time !== undefined ) {
rwWorkerJob(worker);
function worker_results (worker) {
return function (message) {
if (message[0] === 'stats') {
worker_results_iteration(worker, message[1])
} else if (message[0] === 'alert') {
alerts.handleAlert(message[1].alert, message[1].severity)
} else {
worker_results_interval(worker, message[1])
}
else {
worker_exit(worker);
}
}
}
function worker_results(worker) {
return function(message) {
if ( message[0] === 'stats' ) {
worker_results_iteration(worker, message[1]);
} else if( message[0] === 'alert') {
alerts.handleAlert(message[1].alert, message[1].severity);
} else{
worker_results_interval(worker,message[1]);
}
};
}
/**
* * Print config information
* */
var keyrange = argv.keyRange.max - argv.keyRange.min;
var keyrange = argv.keyRange.max - argv.keyRange.min
logger.info("host: "+argv.host+" port:"+argv.port+", namespace: "+argv.namespace+", set: " + argv.set + ", worker processes: " +argv.processes+
", keys: " +keyrange + ", read: "+ ROPSPCT + "%, write: "+ WOPSPCT+"%");
logger.info('host: ' + argv.host + ' port:' + argv.port + ', namespace: ' + argv.namespace + ', set: ' + argv.set + ', worker processes: ' + argv.processes +
', keys: ' + keyrange + ', read: ' + ROPSPCT + '%, write: ' + WOPSPCT + '%')
/**
* Flush out the current interval_stats and probe the worker every second.
*/
if(!argv.silent){
setInterval(function(){
reset_interval_stats();
worker_probe(cluster);
},1000);
if (!argv.silent) {
setInterval(function () {
reset_interval_stats()
worker_probe(cluster)
}, 1000)
}

@@ -410,83 +251,74 @@

*/
function reset_interval_stats(){
interval_stats = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]];
function reset_interval_stats () {
interval_stats = [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
}
// *****************************************************************************
// Event Listeners
// *****************************************************************************
/***********************************************************************
*
* Event Listeners
*
***********************************************************************/
process.on('exit', function () {
logger.debug('Exiting.')
if (exited === online) {
return finalize()
}
})
process.on('exit', function() {
logger.debug('Exiting.');
if ( exited == online ) {
return finalize();
}
});
process.on('SIGINT', function () {
logger.debug('Recevied SIGINT.')
})
process.on('SIGINT', function() {
logger.debug('Recevied SIGINT.');
});
process.on('SIGTERM', function () {
logger.debug('Received SIGTERM.')
})
process.on('SIGTERM', function() {
logger.debug('Received SIGTERM.');
});
cluster.on('online', function (worker) {
online++
if (rwOnline < rwWorkers) {
rwOnline++
rwWorkerJob(worker)
} else if (queryOnline < queryWorkers) {
queryWorkerJob(worker, queryOnline)
queryOnline++
} else if (scanOnline < scanWorkers) {
scanOnline++
scanWorkerJob(worker)
}
})
cluster.on('online', function(worker) {
online++;
if(rwOnline < rwWorkers) {
rwOnline++;
rwWorkerJob(worker);
}
else if( queryOnline < queryWorkers) {
queryWorkerJob(worker, queryOnline);
queryOnline++;
}
else if( scanOnline < scanWorkers) {
scanOnline++;
scanWorkerJob(worker);
}
});
cluster.on('disconnect', function (worker, code, signal) {
logger.debug('[worker: %d] Disconnected.', worker.process.pid, code)
})
cluster.on('disconnect', function(worker, code, signal) {
logger.debug("[worker: %d] Disconnected.", worker.process.pid, code);
});
cluster.on('exit', function (worker, code, signal) {
if (code !== 0) {
// non-ok status code
logger.error('[worker: %d] Exited: %d', worker.process.pid, code)
process.exit(1)
} else {
logger.debug('[worker: %d] Exited: %d', worker.process.pid, code)
exited++
}
if (exited === online) {
process.exit(0)
}
})
cluster.on('exit', function(worker, code, signal) {
if ( code !== 0 ) {
// non-ok status code
logger.error("[worker: %d] Exited: %d", worker.process.pid, code);
process.exit(1);
}
else {
logger.debug("[worker: %d] Exited: %d", worker.process.pid, code);
exited++;
}
if ( exited == online ) {
process.exit(0);
}
});
// *****************************************************************************
// Setup Workers
// *****************************************************************************
/***********************************************************************
*
* Setup Workers
*
***********************************************************************/
if ( argv.time !== undefined ) {
timerId = setTimeout(function(){
worker_shutdown(cluster);
}, argv.time*1000);
if (argv.time !== undefined) {
setTimeout(function () {
worker_shutdown(cluster)
}, argv.time * 1000)
}
cluster.setupMaster({
exec : "worker.js",
silent : false
});
exec: 'worker.js',
silent: false
})
for ( p = 0; p < argv.processes; p++ ) {
worker_spawn();
for (var p = 0; p < argv.processes; p++) {
worker_spawn()
}

@@ -1,353 +0,329 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
var Table = require('cli-table')
var yargs = require('yargs')
var Table = require('cli-table');
var yargs = require('yargs');
var MEM_MATCH = /(\d+(\.\d+)?) MB/
var TABLE_CHARS = {
'top': '',
'top-mid': '',
'top-left': '',
'top-right': '',
'bottom': '',
'bottom-mid': '',
'bottom-left': '',
'bottom-right': '',
'left': '' ,
'left-mid': '' ,
'mid': '' ,
'mid-mid': '',
'right': '',
'right-mid': '',
'middle': ''
};
'top': '',
'top-mid': '',
'top-left': '',
'top-right': '',
'bottom': '',
'bottom-mid': '',
'bottom-left': '',
'bottom-right': '',
'left': '',
'left-mid': '',
'mid': '',
'mid-mid': '',
'right': '',
'right-mid': '',
'middle': ''
}
var TABLE_STYLE = {
'padding-left': 4,
'padding-right': 0,
'head': ['blue'],
'border': ['grey'],
'compact': true
};
'padding-left': 4,
'padding-right': 0,
'head': ['blue'],
'border': ['grey'],
'compact': true
}
var RANGE_COUNT = 0;
var ITERATION_COUNT = 0;
var RANGE_COUNT = 0
var ITERATION_COUNT = 0
var mem_cnt = 0
var mem_min
var mem_max
var mem_ranges = []
var mem_cnt = 0;
var mem_min;
var mem_max;
var mem_ranges = [];
// *****************************************************************************
// Options Parsing
// *****************************************************************************
/***********************************************************************
*
* Options Parsing
*
***********************************************************************/
var argp = yargs
.usage("$0 [options]")
.options({
help: {
boolean: true,
describe: "Display this message."
},
factor: {
alias: "f",
default: 1,
describe: "Factor to filter by."
},
start: {
alias: "s",
default: undefined,
describe: "Start GC range."
},
end: {
alias: "e",
default: undefined,
describe: "End GC range."
}
});
.usage('$0 [options]')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
factor: {
alias: 'f',
default: 1,
describe: 'Factor to filter by.'
},
start: {
alias: 's',
default: undefined,
describe: 'Start GC range.'
},
end: {
alias: 'e',
default: undefined,
describe: 'End GC range.'
}
})
var argv = argp.argv;
var argv = argp.argv
if ( argv.help === true) {
argp.showHelp()
return;
if (argv.help === true) {
argp.showHelp()
process.exit()
}
/***********************************************************************
*
* Functions
*
***********************************************************************/
// *****************************************************************************
// Functions
// *****************************************************************************
var MEM_MAX_MB = 100;
var MEM_BUCKETS = 100;
var MEM_MAX_MB = 100
var MEM_BUCKETS = 100
function memory_bar(min_used_mb, max_used_mb) {
function memory_bar (min_used_mb, max_used_mb) {
var min_used_len = Math.floor(min_used_mb / MEM_MAX_MB * MEM_BUCKETS)
var min_used_bar = new Buffer(min_used_len)
if (min_used_len > 0) {
min_used_bar.fill(']')
}
var min_used_len = Math.floor(min_used_mb / MEM_MAX_MB * MEM_BUCKETS);
var min_used_bar = new Buffer(min_used_len);
if ( min_used_len > 0 ) {
min_used_bar.fill(']');
}
var max_used_len = Math.floor(max_used_mb / MEM_MAX_MB * MEM_BUCKETS)
var max_used_bar = new Buffer(max_used_len - min_used_len)
if (max_used_len > 0) {
max_used_bar.fill(']')
}
var max_used_len = Math.floor(max_used_mb / MEM_MAX_MB * MEM_BUCKETS);
var max_used_bar = new Buffer(max_used_len - min_used_len);
if ( max_used_len > 0 ) {
max_used_bar.fill(']');
}
return min_used_bar.toString().blue + max_used_bar.toString().red;
return min_used_bar.toString().blue + max_used_bar.toString().red
}
function report() {
function report () {
var minhist = {}
var maxhist = {}
var stephist = {}
var minhist = {};
var maxhist = {};
var stephist = {};
var rtable = new Table({
head: ['min', 'min diff', 'max', 'max diff', 'steps', 'size'],
chars: TABLE_CHARS,
style: TABLE_STYLE
})
var rtable = new Table({
head: ['min', 'min diff', 'max', 'max diff', 'steps', 'size'],
chars: TABLE_CHARS,
style: TABLE_STYLE
});
var l
var l;
var unfiltered = mem_ranges
var unfiltered = mem_ranges;
var filtered = unfiltered.filter(function (r, i) {
if (argv.factor && i % argv.factor !== 0) {
return false
}
if (argv.start && i < argv.start) {
return false
}
if (argv.end && i > argv.end) {
return false
}
return true
})
var filtered = unfiltered.filter(function(r,i) {
if ( argv.factor && i % argv.factor !== 0 ) {
return false;
}
if ( argv.start && i < argv.start ) {
return false;
}
if ( argv.end && i > argv.end ) {
return false;
}
return true;
});
filtered.forEach(function (r, i) {
var minceil = Math.ceil(r[0])
minhist[minceil] = (minhist[minceil] || 0) + 1
filtered.forEach(function(r, i) {
var maxceil = Math.ceil(r[1])
maxhist[maxceil] = (maxhist[maxceil] || 0) + 1
var minceil = Math.ceil(r[0]);
minhist[minceil] = (minhist[minceil]||0) + 1;
var step = Math.ceil(r[2])
stephist[step] = (stephist[step] || 0) + 1
var maxceil = Math.ceil(r[1])
maxhist[maxceil] = (maxhist[maxceil]||0) + 1;
if (l) {
rtable.push([
r[0],
(r[0] - l[0]).toFixed(3),
r[1],
(r[1] - l[1]).toFixed(3),
r[2],
(r[1] - r[0]).toFixed(3),
memory_bar(r[0], r[1])
])
} else {
rtable.push([
r[0],
0.00,
r[1],
0.00,
r[2],
(r[1] - r[0]).toFixed(3),
memory_bar(r[0], r[1])
])
}
l = r
})
var step = Math.ceil(r[2])
stephist[step] = (stephist[step]||0) + 1;
var k
if ( l ) {
rtable.push([
r[0],
(r[0]-l[0]).toFixed(3),
r[1],
(r[1]-l[1]).toFixed(3),
r[2],
(r[1]-r[0]).toFixed(3),
memory_bar(r[0],r[1])
]);
}
else {
rtable.push([
r[0],
0.00,
r[1],
0.00,
r[2],
(r[1]-r[0]).toFixed(3),
memory_bar(r[0],r[1])
]);
}
l = r;
});
var minhead = []
var minbody = []
for (k in minhist) {
minhead.push('<' + k)
minbody.push(minhist[k])
}
var mintable = new Table({
head: minhead,
chars: TABLE_CHARS,
style: TABLE_STYLE
})
mintable.push(minbody)
var k;
var maxhead = []
var maxbody = []
for (k in maxhist) {
maxhead.push('<' + k)
maxbody.push(maxhist[k])
}
var maxtable = new Table({
head: maxhead,
chars: TABLE_CHARS,
style: TABLE_STYLE
})
maxtable.push(maxbody)
var minhead = [];
var minbody = [];
for ( k in minhist ) {
minhead.push('<'+k)
minbody.push(minhist[k])
}
var mintable = new Table({
head: minhead,
chars: TABLE_CHARS,
style: TABLE_STYLE
});
mintable.push(minbody);
var stephead = []
var stepbody = []
for (k in stephist) {
stephead.push(k)
stepbody.push(stephist[k])
}
var steptable = new Table({
head: stephead,
chars: TABLE_CHARS,
style: TABLE_STYLE
})
steptable.push(stepbody)
// *****************************************************************************
var maxhead = [];
var maxbody = [];
for ( k in maxhist ) {
maxhead.push('<'+k)
maxbody.push(maxhist[k])
console.log()
console.log('Heap Usage (MB)'.grey)
rtable.toString().split('\n').forEach(function (l) {
if (l.length > 0) {
console.log(l)
}
var maxtable = new Table({
head: maxhead,
chars: TABLE_CHARS,
style: TABLE_STYLE
});
maxtable.push(maxbody);
})
var stephead = [];
var stepbody = [];
for ( k in stephist ) {
stephead.push(k)
stepbody.push(stephist[k])
console.log()
console.log('Heap Used Lower Bound (MB)'.grey)
mintable.toString().split('\n').forEach(function (l) {
if (l.length > 0) {
console.log(l)
}
var steptable = new Table({
head: stephead,
chars: TABLE_CHARS,
style: TABLE_STYLE
});
steptable.push(stepbody);
})
console.log()
console.log('Heap Used Upper Bound (MB)'.grey)
maxtable.toString().split('\n').forEach(function (l) {
if (l.length > 0) {
console.log(l)
}
})
/**************************************************************************/
console.log()
console.log('Iterations / GC'.grey)
steptable.toString().split('\n').forEach(function (l) {
if (l.length > 0) {
console.log(l)
}
})
console.log();
console.log('Heap Usage (MB)'.grey);
rtable.toString().split("\n").forEach(function(l) {
if ( l.length > 0 ) {
console.log(l);
}
});
console.log()
console.log('%s %d', 'Number of Iterations:'.grey, ITERATION_COUNT)
console.log('%s %d', 'Number of GC executions (unfiltered):'.grey, unfiltered.length)
console.log('%s %d', 'Number of GC executions (filtered):'.grey, filtered.length)
console.log();
console.log('Heap Used Lower Bound (MB)'.grey);
mintable.toString().split("\n").forEach(function(l) {
if ( l.length > 0 ) {
console.log(l);
}
});
console.log();
console.log('Heap Used Upper Bound (MB)'.grey);
maxtable.toString().split("\n").forEach(function(l) {
if ( l.length > 0 ) {
console.log(l);
}
});
console.log();
console.log('Iterations / GC'.grey);
steptable.toString().split("\n").forEach(function(l) {
if ( l.length > 0 ) {
console.log(l);
}
});
console.log();
console.log('%s %d', 'Number of Iterations:'.grey, ITERATION_COUNT);
console.log('%s %d', 'Number of GC executions (unfiltered):'.grey, unfiltered.length);
console.log('%s %d', 'Number of GC executions (filtered):'.grey, filtered.length);
console.log();
console.log()
}
function readline(line) {
function readline (line) {
if (line.trim().length === 0) {
return line
}
if ( line.trim().length === 0 ) {
return l;
}
var matches = line.match(MEM_MATCH)
if (!matches || !matches[1]) {
console.error('RegEx match failed on: |%s|', line, matches)
process.exit(1)
}
var matches = line.match(MEM_MATCH);
if ( ! matches || ! matches[1] ) {
console.error('RegEx match failed on: |%s|', line, matches);
process.exit(1);
}
var mem = parseFloat(matches[1])
var mem = parseFloat(matches[1]);
if (mem_min === undefined) {
mem_min = mem
mem_cnt = 0
}
if ( mem_min === undefined ) {
mem_min = mem;
mem_cnt = 0;
}
if (mem_max === undefined || mem > mem_max) {
mem_max = mem
mem_cnt++
} else {
// this is where the magic happens
if ( mem_max === undefined || mem > mem_max ) {
mem_max = mem;
mem_cnt++;
}
else {
// this is where the magic happens
// we will filter based on a factor
mem_ranges.push([mem_min, mem_max, mem_cnt])
// we will filter based on a factor
mem_ranges.push([mem_min, mem_max, mem_cnt]);
// reset
mem_min = mem
mem_max = mem
mem_cnt = 0
RANGE_COUNT++
}
// reset
mem_min = mem;
mem_max = mem;
mem_cnt = 0;
RANGE_COUNT++;
}
ITERATION_COUNT++;
ITERATION_COUNT++
}
/***********************************************************************
*
* Event Listeners
*
***********************************************************************/
// *****************************************************************************
// Event Listeners
// *****************************************************************************
var last_line;
var last_line
process.stdin.on('data', function(chunk) {
process.stdin.on('data', function (chunk) {
var i = 0
var j = 0
var i = 0, j = 0;
var line;
for ( i=0, j=chunk.indexOf('\n', i); j != -1; i=j+1, j=chunk.indexOf('\n', i)) {
if ( last_line ) {
readline(last_line + chunk.slice(i,j));
last_line = undefined;
}
else {
readline(chunk.slice(i,j));
}
for (i = 0, j = chunk.indexOf('\n', i); j !== -1; i = j + 1, j = chunk.indexOf('\n', i)) {
if (last_line) {
readline(last_line + chunk.slice(i, j))
last_line = undefined
} else {
readline(chunk.slice(i, j))
}
}
if ( chunk.length > i ) {
last_line = chunk.slice(i);
}
});
if (chunk.length > i) {
last_line = chunk.slice(i)
}
})
process.stdin.on('end', function() {
report();
});
process.stdin.on('end', function () {
report()
})
/***********************************************************************
*
* Run
*
***********************************************************************/
// *****************************************************************************
// Run
// *****************************************************************************
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.resume()
process.stdin.setEncoding('utf8')

@@ -1,310 +0,229 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
var Table = require('cli-table')
var util = require('util');
var Table = require('cli-table');
var colors = require('colors');
const OPERATION_STATUS = 0
const OPERATION_TIME_START = 1
const OPERATION_TIME_END = 2
OPERATION_STATUS = 0;
OPERATION_TIME_START = 1;
OPERATION_TIME_END = 2;
OPERATION_NFIELDS = 3; // the number of fields (should always be last/largest value)
WORKER_ID = 0;
WORKER_PID = 1;
WORKER_MEMORY = 2;
WORKER_NFIELDS = 3;
// histograms
// 1. For status code of each operation.
// 2. Latency histogram.
var hist = {};
var hist = {}
var time_hist = {
'<= 1': 0,
'> 1': 0,
'> 2': 0,
'> 4': 0,
'> 8': 0,
'> 16': 0,
'> 32': 0
};
TABLE_CHARS = {
'top': '',
'top-mid': '',
'top-left': '',
'top-right': '',
'bottom': '',
'bottom-mid': '',
'bottom-left': '',
'bottom-right': '',
'left': '' ,
'left-mid': '' ,
'mid': '' ,
'mid-mid': '',
'right': '',
'right-mid': '',
'middle': ''
};
TABLE_STYLE = {
'padding-left': 4,
'padding-right': 0,
'head': ['blue'],
'border': ['grey'],
'compact': true
};
function sum(l,r) {
return l+r;
'<= 1': 0,
'> 1': 0,
'> 2': 0,
'> 4': 0,
'> 8': 0,
'> 16': 0,
'> 32': 0
}
function min(l,r) {
return l < r ? l : r;
const TABLE_CHARS = {
'top': '',
'top-mid': '',
'top-left': '',
'top-right': '',
'bottom': '',
'bottom-mid': '',
'bottom-left': '',
'bottom-right': '',
'left': '',
'left-mid': '',
'mid': '',
'mid-mid': '',
'right': '',
'right-mid': '',
'middle': ''
}
function max(l,r) {
return l > r ? l : r;
const TABLE_STYLE = {
'padding-left': 4,
'padding-right': 0,
'head': ['blue'],
'border': ['grey'],
'compact': true
}
function equals(stat,value) {
return function(it) {
return it.stats[stat] === value;
};
function sum (l, r) {
return l + r
}
function select(stat) {
return function(it) {
return it.stats[stat];
};
function duration (start, end) {
var s = (end[0] - start[0]) * 1000000000
var ns = s + end[1] - start[1]
var ms = ns / 1000000
return ms
}
function duration(start, end) {
var s = (end[0] - start[0]) * 1000000000;
var ns = s + end[1] - start[1];
var ms = ns / 1000000;
return ms;
function parse_time_to_secs (time) {
if (time !== undefined) {
var time_match = time.toString().match(/(\d+)([smh])?/)
if (time_match !== null) {
if (time_match[2] !== null) {
time = parseInt(time_match[1], 10)
var time_unit = time_match[2]
switch (time_unit) {
case 'm':
time = time * 60
break
case 'h':
time = time * 60 * 60
break
}
}
}
}
return time
}
function parse_time_to_secs(time){
if ( time !== undefined ) {
var time_match = time.toString().match(/(\d+)([smh])?/);
if ( time_match !== null ) {
if ( time_match[2] !== null ) {
time = parseInt(time_match[1],10);
var time_unit = time_match[2];
switch( time_unit ) {
case 'm':
time = time * 60;
break;
case 'h':
time = time * 60 * 60;
break;
}
}
}
function time_histogram (operations) {
operations.map(function (op) {
return duration(op[OPERATION_TIME_START], op[OPERATION_TIME_END])
}).forEach(function (dur) {
var d = Math.floor(dur)
if (d > 32) {
time_hist['> 32']++
}
return time;
if (d > 16) {
time_hist['> 16']++
} else if (d > 8) {
time_hist['> 8']++
} else if (d > 4) {
time_hist['> 4']++
} else if (d > 2) {
time_hist['> 2']++
} else if (d > 1) {
time_hist['> 1']++
} else {
time_hist['<= 1']++
}
})
}
function number_format (v, precision) {
return v.toFixed(precision || 0).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}
function time_histogram(operations) {
function time_units (v) {
var u = v === 1 ? 'second' : 'seconds'
if (Math.abs(v) >= 60) {
v = v / 60
u = v === 1 ? 'minute' : 'minutes'
}
operations.map(function(op) {
return duration(op[OPERATION_TIME_START],op[OPERATION_TIME_END]);
}).forEach(function(dur){
var d = Math.floor(dur);
if ( d > 32 ) {
time_hist['> 32']++;
}
if ( d > 16 ) {
time_hist['> 16']++;
}
else if ( d > 8 ) {
time_hist['> 8']++
}
else if ( d > 4 ) {
time_hist['> 4']++
}
else if ( d > 2 ) {
time_hist['> 2']++;
}
else if ( d > 1 ) {
time_hist['> 1']++;
}
else {
time_hist['<= 1']++;
}
});
if (Math.abs(v) >= 60) {
v = v / 60
u = v === 1 ? 'hour' : 'hours'
}
return number_format(v, 2) + ' ' + u
}
function number_format(v, precision) {
return v.toFixed(precision ? precision : 0).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
function status_histogram (operations) {
operations.map(function (op) {
return op[OPERATION_STATUS]
}).forEach(function (status) {
hist[status] = (hist[status] || 0) + 1
})
}
function byte_units(v) {
var u = 'B';
if ( Math.abs(v) >= 1024 ) {
v = v / 1024;
u = 'kB';
function print_table (table, print, prefix) {
table.toString().split('\n').forEach(function (l) {
if (l.length > 0) {
print((prefix || '') + l)
}
if ( Math.abs(v) >= 1024 ) {
v = v / 1024;
u = 'MB';
}
if ( Math.abs(v) >= 1024 ) {
v = v / 1024;
u = 'GB';
}
if ( Math.abs(v) >= 1024 ) {
v = v / 1024;
u = 'TB';
}
if ( Math.abs(v) >= 1024 ) {
v = v / 1024;
u = 'PB';
}
return number_format(v,2) + ' ' + u;
})
}
function time_units(v) {
var u = v === 1 ? 'second' : 'seconds';
function print_histogram (histogram, print, prefix) {
var total = Object.keys(histogram).map(function (k) {
return histogram[k]
}).reduce(sum)
if ( Math.abs(v) >= 60 ) {
v = v / 60;
u = v === 1 ? 'minute' : 'minutes';
}
var thead = []
var tbody = []
if ( Math.abs(v) >= 60 ) {
v = v / 60;
u = v === 1 ? 'hour' : 'hours';
}
for (var k in histogram) {
thead.push(k)
tbody.push(number_format(histogram[k] / total * 100, 1) + '%')
}
return number_format(v,2) + ' ' + u;
}
var table = new Table({
head: thead,
chars: TABLE_CHARS,
style: TABLE_STYLE
})
function status_histogram(operations) {
table.push(tbody)
operations.map(function(op) {
return op[OPERATION_STATUS];
}).forEach(function(status){
hist[status] = (hist[status] || 0) + 1;
});
print_table(table, print, prefix)
}
function merge_histogram(h1, h2) {
var hist = {};
var k;
for ( k in h1 ) {
hist[k] = (hist[k] || 0) + h1[k];
}
for ( k in h2 ) {
hist[k] = (hist[k] || 0) + h2[k];
}
return hist;
function iteration (operations) {
status_histogram(operations)
time_histogram(operations)
}
function print_table(table, print, prefix) {
table.toString().split("\n").forEach(function(l) {
if ( l.length > 0 ) {
print((prefix || '') + l);
}
function report_final (argv, print) {
if (!argv.json) {
var configTable = new Table({
chars: TABLE_CHARS,
style: TABLE_STYLE
})
}
function print_histogram(histogram, print, prefix) {
configTable.push({'operations': argv.operations})
configTable.push({'iterations': argv.iterations === undefined ? 'undefined' : argv.iterations})
configTable.push({'processes': argv.processes})
configTable.push({'time': argv.time === undefined ? 'undefined' : time_units(argv.time)})
var total = Object.keys(histogram).map(function(k){
return histogram[k];
}).reduce(sum);
var thead = [];
var tbody = [];
for( var k in histogram ) {
thead.push(k);
tbody.push(number_format(histogram[k] / total * 100, 1) + "%");
print()
print('SUMMARY')
print()
print(' Configuration')
print_table(configTable, print)
print()
print(' Durations')
print_histogram(time_hist, print)
print()
print(' Status Codes')
print_histogram(hist, print)
print()
} else {
var output = {
configuration: {
operations: argv.operations,
iterations: argv.iterations,
processes: argv.processes
},
durations: time_hist,
status_codes: hist
}
console.log('%j', output)
}
var table = new Table({
head: thead,
chars: TABLE_CHARS,
style: TABLE_STYLE
});
table.push(tbody);
print_table(table, print, prefix);
return 0
}
function iteration(operations) {
status_histogram(operations);
time_histogram(operations);
}
function report_final(argv, print) {
if ( !argv.json ) {
var configTable = new Table({
chars: TABLE_CHARS,
style: TABLE_STYLE
});
configTable.push({'operations': argv.operations})
configTable.push({'iterations': argv.iterations === undefined ? 'undefined' : argv.iterations});
configTable.push({'processes': argv.processes});
configTable.push({'time': argv.time === undefined ? 'undefined' : time_units(argv.time)});
print();
print("SUMMARY");
print();
print(" Configuration");
print_table(configTable, print);
print();
print(" Durations");
print_histogram(time_hist, print);
print();
print(" Status Codes");
print_histogram(hist, print);
print();
}
else {
var output = {
configuration: {
operations: argv.operations,
iterations: argv.iterations,
processes: argv.processes
},
durations: time_hist,
status_codes: hist
};
console.log("%j",output);
}
return 0;
}
module.exports = {
iteration: iteration,
print_histogram: print_histogram,
report_final: report_final,
parse_time_to_secs: parse_time_to_secs
iteration: iteration,
print_histogram: print_histogram,
report_final: report_final,
parse_time_to_secs: parse_time_to_secs
}

@@ -1,265 +0,118 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/***********************************************************************
*
* Benchmark Worker, run operations and report results.
*
***********************************************************************/
// *****************************************************************************
// Benchmark Worker, run operations and report results.
// *****************************************************************************
var aerospike = require('aerospike');
var cluster = require('cluster');
var fs = require('fs');
var yargs = require('yargs');
var path = require('path');
var util = require('util');
var winston = require('winston');
var stats = require('./stats');
var status = aerospike.status;
var alerts = require('./alerts.js');
var argv = require("./config.json");
/**********************************************************************
*
* MACROS
*
*********************************************************************/
var aerospike = require('aerospike')
var cluster = require('cluster')
var util = require('util')
var winston = require('winston')
var stats = require('./stats')
var status = aerospike.status
var alerts = require('./alerts.js')
var argv = require('./config.json')
var OP_TYPES = 4; // READ, WRITE, QUERY and SCAN
var STATS = 3; // OPERATIONS, TIMEOUTS and ERRORS
var READ = 0;
var WRITE = 1;
var QUERY = 2;
var SCAN = 3;
var TPS = 0;
var TIMEOUT = 1;
var ERROR = 2;
/***********************************************************************
*
* Options Parsing
*
***********************************************************************/
/*var argp = yargs
.usage("$0 [options]")
.options({
help: {
boolean: true,
describe: "Display this message."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 0,
describe: "Timeout in milliseconds."
},
ttl:{
default: 10000,
describe: "Time to live for the record (seconds). Units may be used: 1h, 30m, 30s"
},
log: {
alias: "l",
default: 1,
describe: "Log level [0-5]"
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default:null,
describe: "Username to connect to a secure cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to a secure cluster"
},
json: {
alias: "j",
default: false,
describe: "Display report in JSON format."
},
silent: {
default: false,
describe: "Supress the tps statistics printed every second."
},
longevity: {
default: false,
describe: "Print intermediate output from workers."
},
operations: {
alias: "O",
default: 100,
describe: "Total number of operations to perform per iteration per process."
},
iterations: {
alias: "I",
default: undefined,
describe: "Total number of iterations to perform per process."
},
time: {
alias: "T",
default: undefined,
describe: "Total amount of time to run the benchmark (seconds). Units may be used: 1h, 30m, 30s"
},
reads: {
alias: "R",
default: 1,
describe: "The read in the read/write ratio."
},
writes: {
alias: "W",
default: 1,
describe: "The write in the read/write ratio."
},
keyrange: {
alias: "K",
default: 100000,
describe: "The number of keys to use."
},
datatype: {
default: "INTEGER",
describe: "The datatype of the record."
},
datasize: {
default: 1024,
describe: "Size of the record."
},
'chart-memory': {
boolean: false,
default: false,
describe: "Chart the memory used before printing the summary."
},
'summary': {
boolean: true,
default: true,
describe: "Produces a summary report (tables, charts, etc) at the end."
}
// *****************************************************************************
// MACROS
// *****************************************************************************
});
var OP_TYPES = 4 // READ, WRITE, QUERY and SCAN
var READ = 0
var WRITE = 1
var QUERY = 2
var SCAN = 3
var TPS = 0
var TIMEOUT = 1
var ERROR = 2
var argv = argp.argv;
if ( argv.help === true) {
argp.showHelp();
return;
}*/
if ( !cluster.isWorker ) {
console.error('worker.js must only be run as a child process of main.js.');
return;
if (!cluster.isWorker) {
console.error('worker.js must only be run as a child process of main.js.')
process.exit()
}
argv.ttl = stats.parse_time_to_secs(argv.ttl);
argv.ttl = stats.parse_time_to_secs(argv.ttl)
// variables to track memory growth(RSS) of worker process.
var heapMemory = 0;
var initialFlux = true;
var memGrowth = 0;
var FLUX_PERIOD = 5;
/***********************************************************************
*
* Logging
*
***********************************************************************/
var heapMemory = 0
var initialFlux = true
var memGrowth = 0
var FLUX_PERIOD = 5
function logger_timestamp() {
return util.format('[worker: %d] [%s]', process.pid, process.hrtime());
}
// *****************************************************************************
// Logging
// *****************************************************************************
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
level: 'info',
silent: false,
colorize: true
})
]
});
transports: [
new (winston.transports.Console)({
level: 'info',
silent: false,
colorize: true
})
]
})
/***********************************************************************
*
* Aerospike Client
*
***********************************************************************/
// *****************************************************************************
// Aerospike Client
// *****************************************************************************
var config = {
hosts: [
{ addr: argv.host, port: argv.port }
],
policies: {
timeout: argv.timeout
},
sharedMemory: {
key: 0xA5000000,
maxNodes: 16,
maxNamespaces: 8,
takeoverThresholdSeconds : 30
}
};
hosts: [
{ addr: argv.host, port: argv.port }
],
policies: {
timeout: argv.timeout
},
sharedMemory: {
key: 0xA5000000,
maxNodes: 16,
maxNamespaces: 8,
takeoverThresholdSeconds: 30
}
}
if(argv.user !== null)
{
config.user = argv.user;
if (argv.user !== null) {
config.user = argv.user
}
if(argv.password !== null)
{
config.password = argv.password;
if (argv.password !== null) {
config.password = argv.password
}
var client = aerospike.client(config);
var client = aerospike.client(config)
client.connect(function(err) {
if ( err.code !== 0 ) {
logger.error("Aerospike server connection error: ", err);
process.exit(1);
}
});
client.connect(function (err) {
if (err.code !== 0) {
logger.error('Aerospike server connection error: ', err)
process.exit(1)
}
})
/***********************************************************************
*
* Operations
*
***********************************************************************/
// *****************************************************************************
// Operations
// *****************************************************************************
/**
* key are in range [min ... max]
*/
function keygen(min, max) {
var rand = Math.floor(Math.random() * 0x100000000) % (max-min+1) + min;
return rand < 1 ? 1 : rand;
function keygen (min, max) {
var rand = Math.floor(Math.random() * 0x100000000) % (max - min + 1) + min
return rand < 1 ? 1 : rand
}
var STRING_DATA = "This the test data to be written to the server";
var STRING_DATA = 'This the test data to be written to the server'
/**

@@ -271,44 +124,40 @@ * Generate a record with string and blob in it if run for longevity.

*/
function recordgen( key, binSpec ) {
var data = {};
var i = 0;
do {
var bin= binSpec[i];
switch (bin.type) {
case "INTEGER" : {
data[bin.name] = key;
break;
}
case "STRING" : {
data[bin.name] = STRING_DATA;
while ( data[bin.name].length < bin.size ) {
data[bin.name] += STRING_DATA;
}
data[bin.name] += key;
break;
}
case "BYTES" : {
var buf_data = STRING_DATA;
while( buf_data.length < bin.size ) {
buf_data += STRING_DATA;
}
data[bin.name] = new Buffer(buf_data);
break;
}
default :
data.num = key;
break;
function recordgen (key, binSpec) {
var data = {}
var i = 0
do {
var bin = binSpec[i]
switch (bin.type) {
case 'INTEGER':
data[bin.name] = key
break
case 'STRING':
data[bin.name] = STRING_DATA
while (data[bin.name].length < bin.size) {
data[bin.name] += STRING_DATA
}
i++;
} while(i < binSpec.length);
return data;
data[bin.name] += key
break
case 'BYTES':
var buf_data = STRING_DATA
while (buf_data.length < bin.size) {
buf_data += STRING_DATA
}
data[bin.name] = new Buffer(buf_data)
break
default:
data.num = key
break
}
i++
} while (i < binSpec.length)
return data
}
function get(key, done) {
var time_start = process.hrtime()
client.get( key, function(_error, _record, _metadata, _key) {
var time_end = process.hrtime();
done(_error.code, time_start, time_end, READ);
});
function get (key, done) {
var time_start = process.hrtime()
client.get(key, function (_error, _record, _metadata, _key) {
var time_end = process.hrtime()
done(_error.code, time_start, time_end, READ)
})
}

@@ -318,66 +167,61 @@

var metadata = {
ttl: argv.ttl
};
ttl: argv.ttl
}
function put(options, done) {
var time_start = process.hrtime();
client.put(options.key, options.record, metadata, function(_error, _record, _metadata, _key) {
var time_end = process.hrtime();
done(_error.code, time_start, time_end, WRITE);
});
function put (options, done) {
var time_start = process.hrtime()
client.put(options.key, options.record, metadata, function (_error, _record, _metadata, _key) {
var time_end = process.hrtime()
done(_error.code, time_start, time_end, WRITE)
})
}
// Structure to store per second statistics.
var interval_data = new Array(OP_TYPES);
reset_interval_data();
var interval_data = new Array(OP_TYPES)
reset_interval_data()
function run(options) {
function run (options) {
var expected = options.rops + options.wops
var completed = 0
var expected = options.rops + options.wops;
var completed = 0;
// @ TO-DO optimization.
// Currently stats of all the operations is collected and sent to
// master at the end of an iteration.
// Master puts the stats in appropriate histogram.
// Consider having histogram for each worker Vs sending the
// results in an array - Which one is more memory efficient.
var operations = Array(expected)
var read_ops = options.rops
var write_ops = options.wops
// @ TO-DO optimization.
// Currently stats of all the operations is collected and sent to
// master at the end of an iteration.
// Master puts the stats in appropriate histogram.
// Consider having histogram for each worker Vs sending the
// results in an array - Which one is more memory efficient.
var operations = Array(expected);
var read_ops = options.rops;
var write_ops = options.wops;
function done (op_status, op_time_start, op_time_end, op_type) {
operations[completed] = [op_status, op_time_start, op_time_end]
interval_data[op_type][TPS]++
if (op_status === status.AEROSPIKE_ERR_TIMEOUT) {
interval_data[op_type][TIMEOUT]++
} else if (op_status !== status.AEROSPIKE_OK && op_status !== status.AEROSPIKE_ERR_TIMEOUT) {
interval_data[op_type][ERROR]++
}
function done(op_status, op_time_start, op_time_end, op_type) {
completed++
operations[completed] = [op_status, op_time_start, op_time_end];
interval_data[op_type][TPS]++;
if(op_status === status.AEROSPIKE_ERR_TIMEOUT){
interval_data[op_type][TIMEOUT]++;
}
else if(op_status !== status.AEROSPIKE_OK && op_status !== status.AEROSPIKE_ERR_TIMEOUT){
interval_data[op_type][ERROR]++;
}
completed++;
if ( completed >= expected ) {
process.send(['stats',operations]);
}
if (completed >= expected) {
process.send(['stats', operations])
}
}
while( write_ops > 0 || read_ops > 0) {
var k = keygen(options.keyRange.min,options.keyRange.max);
var key = { ns: options.namespace, set: options.set, key: k}
var record = recordgen(k, options.binSpec)
var ops = { key : key, record : record};
if( write_ops > 0) {
write_ops--;
put(ops, done);
}
if( read_ops > 0) {
read_ops--;
get(key, done);
};
while (write_ops > 0 || read_ops > 0) {
var k = keygen(options.keyRange.min, options.keyRange.max)
var key = {ns: options.namespace, set: options.set, key: k}
var record = recordgen(k, options.binSpec)
var ops = {key: key, record: record}
if (write_ops > 0) {
write_ops--
put(ops, done)
}
if (read_ops > 0) {
read_ops--
get(key, done)
}
}
}

@@ -388,5 +232,5 @@

*/
function respond(){
process.send(['trans',interval_data]);
reset_interval_data();
function respond () {
process.send(['trans', interval_data])
reset_interval_data()
}

@@ -397,7 +241,7 @@

*/
function reset_interval_data(){
interval_data[READ] = [0, 0, 0]; // [reads_performed, reads_timeout, reads_error]
interval_data[WRITE] = [0, 0, 0]; // [writes_performed, writes_timeout, writes_error]
interval_data[QUERY] = [0, 0, 0]; // [QueryRecords, query_timeout, query_error]
interval_data[SCAN] = [0, 0, 0];
function reset_interval_data () {
interval_data[READ] = [0, 0, 0] // [reads_performed, reads_timeout, reads_error]
interval_data[WRITE] = [0, 0, 0] // [writes_performed, writes_timeout, writes_error]
interval_data[QUERY] = [0, 0, 0] // [QueryRecords, query_timeout, query_error]
interval_data[SCAN] = [0, 0, 0]
}

@@ -409,81 +253,74 @@

function executeJob(options, opType, callback) {
var job = client.query(options.namespace, options.set, options.statement);
var stream = job.execute();
stream.on('data', function(record) {
// count the records returned
interval_data[opType][TPS]++;
});
stream.on('error', function(error) {
interval_data[opType][ERROR]++;
if(error.code == status.AEROSPIKE_ERR_TIMEOUT){
interval_data[opType][TIMEOUT]++;
}
});
stream.on('end', function(){
// update a stat for number of jobs completed.
callback(options);
});
function executeJob (options, opType, callback) {
var job = client.query(options.namespace, options.set, options.statement)
var stream = job.execute()
stream.on('data', function (record) {
// count the records returned
interval_data[opType][TPS]++
})
stream.on('error', function (error) {
interval_data[opType][ERROR]++
if (error.code === status.AEROSPIKE_ERR_TIMEOUT) {
interval_data[opType][TIMEOUT]++
}
})
stream.on('end', function () {
// update a stat for number of jobs completed.
callback(options)
})
}
var runLongRunningJob = function(options) {
if( options.statement.filters === undefined) {
executeJob(options, SCAN, runLongRunningJob);
}
else {
executeJob(options, QUERY, runLongRunningJob);
}
var runLongRunningJob = function (options) {
if (options.statement.filters === undefined) {
executeJob(options, SCAN, runLongRunningJob)
} else {
executeJob(options, QUERY, runLongRunningJob)
}
}
var monitorMemory = function() {
var currentMemory = process.memoryUsage();
currentMemory.pid = process.pid;
if( heapMemory < currentMemory.heapUsed) {
memGrowth++;
if(!initialFlux && memGrowth >= FLUX_PERIOD) {
var alertData =
{
alert: currentMemory,
severity: alerts.severity.HIGH
};
memGrowth = 0;
process.send(['alert',alertData]);
}
else if(initialFlux && memGrowth >= FLUX_PERIOD) {
initialFlux = false;
memGrowth = 0;
}
var monitorMemory = function () {
var currentMemory = process.memoryUsage()
currentMemory.pid = process.pid
if (heapMemory < currentMemory.heapUsed) {
memGrowth++
if (!initialFlux && memGrowth >= FLUX_PERIOD) {
var alertData = {
alert: currentMemory,
severity: alerts.severity.HIGH
}
memGrowth = 0
process.send(['alert', alertData])
} else if (initialFlux && memGrowth >= FLUX_PERIOD) {
initialFlux = false
memGrowth = 0
}
heapMemory = currentMemory.heapUsed;
}
heapMemory = currentMemory.heapUsed
}
// log the memory footprint of the process every 10 minutes.
// when it is run in longevity mode.
if(argv.longevity) {
setInterval(monitorMemory, 6000);
if (argv.longevity) {
setInterval(monitorMemory, 6000)
}
/***********************************************************************
*
* Event Listeners
*
***********************************************************************/
// *****************************************************************************
// Event Listeners
// *****************************************************************************
/**
* Listen for exit signal from parent. Hopefully we can do a clean
* shutdown and emit results.
*/
process.on('exit', function() {
logger.debug('Exiting.');
});
//
// Listen for exit signal from parent. Hopefully we can do a clean
// shutdown and emit results.
//
process.on('exit', function () {
logger.debug('Exiting.')
})
process.on('SIGINT', function() {
logger.debug('Received SIGINT.');
process.exit(0);
});
process.on('SIGINT', function () {
logger.debug('Received SIGINT.')
process.exit(0)
})
process.on('SIGTERM', function() {
logger.debug('Received SIGTERM.');
process.exit(0);
});
process.on('SIGTERM', function () {
logger.debug('Received SIGTERM.')
process.exit(0)
})

@@ -504,12 +341,14 @@ /**

*/
process.on('message', function(msg) {
logger.debug('command: ', util.inspect(msg[0]));
switch( msg[0] ) {
case 'run' : return run(msg[1]); break;
case 'query' : return runLongRunningJob(msg[1]);
case 'trans' : return respond(); break; // Listening on trans event. (this event occurs every second)
default: return process.exit(0);
}
});
process.on('message', function (msg) {
logger.debug('command: ', util.inspect(msg[0]))
switch (msg[0]) {
case 'run':
return run(msg[1])
case 'query':
return runLongRunningJob(msg[1])
case 'trans':
return respond()
default:
return process.exit(0)
}
})

@@ -5,13 +5,13 @@ # Aerospike Module

- [Fields](#fields)
- [filter](#filter)
- [filter](#filter)
- [log](#log)
- [operators](#operators)
- [policies](#Policies)
- [status](#status)
- [scanStatus](#scanStatus)
- [scanPriority](#scanPriority)
- [operators](#operators)
- [policies](#Policies)
- [status](#status)
- [scanStatus](#scanStatus)
- [scanPriority](#scanPriority)
- [Functions](#functions)
- [client()](#client)
- [client()](#client)
- [Double()](#Double)
- [key()](#key)
- [key()](#key)

@@ -215,3 +215,3 @@

```js
var key = aerospike.key("test", "demo", 123)
var key = aerospike.key('test', 'demo', 123)
```

@@ -218,0 +218,0 @@

@@ -28,2 +28,3 @@ # Client Class

- [createStringIndex()](#createStringIndex)
- [createGeo2DSphereIndex()](#createGeo2DSphereIndex)
- [execute()](#execute)

@@ -65,3 +66,3 @@ - [exists()](#exists)

- `key` – A [Key object](datamodel.md#key), used to locate the record in the cluster.
- `bins` – A [Record Object](datamodel.md#record), used to specify the bins to be added with integer values.
- `bins` – A [Record Object](datamodel.md#record), used to specify the bins to be added with integer values.
- `metadata` – (optional) A [Metadata object](datamodel.md#metadata).

@@ -81,5 +82,9 @@ - `policy` – (optional) A [Operate Policy object](policies.md#OperatePolicy) to use for this operation.

client.add(key, bins, function(error, record, metadata, key) {
// do something
});
client.add(key, bins, function (error, record, metadata, key) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -100,3 +105,3 @@ <!--

- `key` – A [Key object](datamodel.md#key), used to locate the record in the cluster.
- `bins` – A [Record Object](datamodel.md#record), used to specify the bins to be added with integer values.
- `bins` – A [Record Object](datamodel.md#record), used to specify the bins to be added with integer values.
- `metadata` – (optional) A [Metadata object](datamodel.md#metadata).

@@ -117,7 +122,11 @@ - `policy` – (optional) A [Operate Policy object](policies.md#OperatePolicy) to use for this operation.

```js
var bins = {LastMovieSeen: "Imitation Game"}
var bins = {LastMovieSeen: 'Imitation Game'}
client.append(key, bins, function(error, record, metadata, key) {
// do something
});
client.append(key, bins, function (error, record, metadata, key) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -161,18 +170,22 @@

client.batchExists(keys, function(error, results) {
for ( var i = 0; i<results.length; i++) {
var result = results[i];
switch ( result.status ) {
case status.AEROSPIKE_OK:
// record found
break;
case status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
// record not found
break;
default:
// error while reading record
break;
client.batchExists(keys, function (error, results) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
for (var i = 0; i < results.length; i++) {
var result = results[i]
switch (result.status) {
case status.AEROSPIKE_OK:
// record found
break
case status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
// record not found
break
default:
// error while reading record
break
}
}
}
});
})
```

@@ -217,19 +230,24 @@

client.batchGet(keys, function(error, results) {
for ( var i = 0; i<results.length; i++) {
var result = results[i];
switch ( result.status ) {
case status.AEROSPIKE_OK:
// record found
break;
case status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
// record not found
break;
default:
// error while reading record
break;
client.batchGet(keys, function (error, results) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
for (var i = 0; i < results.length; i++) {
var result = results[i]
switch (result.status) {
case status.AEROSPIKE_OK:
// record found
break
case status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
// record not found
break
default:
// error while reading record
break
}
}
}
});
})
```
<!--

@@ -244,3 +262,3 @@ ################################################################################

Reads a batch of records from the database cluster.
Reads a subset of bins for a batch of records from the database cluster.

@@ -273,21 +291,24 @@ Parameters:

]
var bins = ['s', 'i']
var bins = ['name', 'age'];
client.batchSelect(keys, bins, function(error, results) {
for ( var i = 0; i<results.length; i++) {
var result = results[i];
switch ( result.status ) {
case status.AEROSPIKE_OK:
// record found
break;
case status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
// record not found
break;
default:
// error while reading record
break;
client.batchSelect(keys, bins, function (error, results) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
for (var i = 0; i < results.length; i++) {
var result = results[i]
switch (result.status) {
case status.AEROSPIKE_OK:
// record found
break
case status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
// record not found
break
default:
// error while reading record
break
}
}
}
});
})
```

@@ -335,8 +356,7 @@

client.connect(function (error) {
if ( error.status == aerospike.Status.AEROSPIKE_OK ) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
else {
// handle failure
}
})

@@ -354,10 +374,10 @@ ```

Creates an integer index. It's an asynchronous API that issues the index create command
to aerospike cluster. To verify that index has been created and populated with all the
data use [indexCreateWait()](#indexCreateWait) API.
to the aerospike cluster. To verify that the index has been created and populated with all the
data use the [indexCreateWait()](#indexCreateWait) API.
Parameters:
- `args` - An object with these entries. ns, set, bin, index, policy.
- `ns` - namespace on which index is to be created
- `ns` - namespace on which index is to be created
- `set` - set on which index is to be created
- `bin` - bin to be indexed
- `bin` - bin to be indexed
- `index` - name of the index to be created

@@ -373,12 +393,12 @@ - `policy` - (optional) The [Info Policy object](policies.md#InfoPolicy) to use for this operation.

```js
var args = { ns: "test", set: "demo", bin: "bin1", index:"index_name"}
var args = {ns: 'test', set: 'demo', bin: 'bin1', index: 'index_name'}
client.createIntegerIndex(args, function (error) {
if ( error.status == aerospike.Status.AEROSPIKE_OK ) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
else {
// handle failure
}
})
```
<!--

@@ -393,11 +413,11 @@ ################################################################################

Creates a string index. It's an asynchronous API that issues the index create command
to aerospike cluster. To verify that index has been created and populated with all the
data use [indexCreateWait()](#indexCreateWait) API.
Creates a string index. It's an asynchronous API that issues the index create command
to the aerospike cluster. To verify that the index has been created and populated with all the
data use the [indexCreateWait()](#indexCreateWait) API.
Parameters:
- `args` - An object with these entries. ns, set, bin, index, policy.
- `ns` - namespace on which index is to be created
- `ns` - namespace on which index is to be created
- `set` - set on which index is to be created
- `bin` - bin to be indexed
- `bin` - bin to be indexed
- `index` - name of the index to be created

@@ -413,9 +433,46 @@ - `policy` - (optional) The [Info Policy object](policies.md#InfoPolicy) to use for this operation.

```js
var args = { ns: "test", set: "demo", bin: "bin1", index: "index_name"}
var args = {ns: 'test', set: 'demo', bin: 'bin1', index: 'index_name'}
client.createStringIndex(args, function (error) {
if ( error.status == aerospike.Status.AEROSPIKE_OK ) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
else {
})
```
<!--
################################################################################
createGeo2DSphereIndex()
################################################################################
-->
<a name="createGeo2DSphereIndex"></a>
### createGeo2DSphereIndex(args, callback)
Creates a geospatial index. It's an asynchronous API that issues the index create command
to the aerospike cluster. To verify that the index has been created and populated with all the
data use the [indexCreateWait()](#indexCreateWait) API.
Parameters:
- `args` - An object with these entries. ns, set, bin, index, policy.
- `ns` - namespace on which index is to be created
- `set` - set on which index is to be created
- `bin` - bin to be indexed
- `index` - name of the index to be created
- `policy` - (optional) The [Info Policy object](policies.md#InfoPolicy) to use for this operation.
- `callback` – The function to call when the operation completes.
The parameters for the `callback` argument:
- `error` – An [Error object](datamodel.md#error), which contains the status of the connect call.
Example:
```js
var args = {ns: 'test', set: 'demo', bin: 'bin1', index: 'index_name'}
client.createStringIndex(args, function (error) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}

@@ -447,3 +504,3 @@ })

the operation.
- `response` - The value returned from the udf function.
- `response` - The value returned from the udf function.

@@ -453,10 +510,13 @@ Example:

var key = aerospike.key
var udfArgs = { module : "udf_module", funcname: "udf_function", args:[args, to, udf, function] }
var udfArgs = {module: 'udf_module', funcname: 'udf_function', args: ['abc', 123, 4.5]}
client.execute(key('test','demo','key1'), udfArgs, function(error, res, key) {
// do something
});
client.execute(key('test', 'demo', 'key1'), udfArgs, function (error, res, key) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```
<!--

@@ -492,5 +552,15 @@ ################################################################################

client.exists(key('test','demo','key1'), function(error, metadata, key) {
// do something
});
client.exists(key('test', 'demo', 'key1'), function (error, metadata, key) {
switch (error.code) {
case status.AEROSPIKE_OK:
// record exists
break
case status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
// record does not exist
break
default:
// handle error
break
}
})
```

@@ -529,6 +599,11 @@

client.get(key('test','demo','key1'), function(error, record, metadata) {
// do something
});
client.get(key('test', 'demo', 'key1'), function (error, record, metadata) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```
<!--

@@ -548,3 +623,3 @@ ################################################################################

- `namespace` – The namespace on which the index is present.
- `index` – The name of the index to be created.
- `index` – The name of the index to be created.
- `policy` – (optional) The [Info Policy object](policies.md#InfoPolicy) to use for this operation.

@@ -563,4 +638,8 @@ - `callback` – The function to call when the operation completes with the results of the operation.

client.indexRemove('test', 'index', function(error) {
// do something
client.indexRemove('test', 'index', function (error) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
});

@@ -605,5 +684,9 @@ ```

```js
client.info("statistics", function(err, response, host) {
// do something
});
client.info('statistics', function (error, response, host) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -614,5 +697,9 @@

```js
client.info("statistics", {addr: "127.0.0.1", port: 3000}, function(error, response, host) {
// do something
});
client.info('statistics', {addr: '127.0.0.1', port: 3000}, function (error, response, host) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -635,3 +722,3 @@

- `namespace` – The namespace on which the index is created.
- `index` – The name of the index created.
- `index` – The name of the index created.
- `pollInterval`- The poll interval in milliseconds to check the index creation status.

@@ -649,14 +736,15 @@ - `callback` – The function to call when the operation completes with the results of the operation.

```js
var args = { ns: "test", set: "demo", bin: "bin1", index:"index_name"}
var args = {ns: 'test', set: 'demo', bin: 'bin1', index: 'index_name'}
client.createIntegerIndex(args, function (error) {
if ( error.status == aerospike.Status.AEROSPIKE_OK ) {
client.indexCreateWait('test', 'index', 1000, function(error) {
if(error.code !== aerospike.status.AEROSPIKE_OK) {
// index creation failed.
}
});
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
client.indexCreateWait('test', 'index_name', 1000, function (error) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
}
else {
// Index create request failed.
}
})

@@ -675,7 +763,6 @@

creates a new [LargeList](largelist.md) object, which is used to perform all LDT operations in the database.
Creates a new [LargeList](largelist.md) object, which is used to perform all LDT operations in the database.
Parameters:
- `key` - A [Key object](datamodel.md#key), used to locate the record in the cluster.
- `key` - A [Key object](datamodel.md#key), used to locate the record in the cluster.
- `binName` - Name of the Large Data Type Bin.

@@ -685,9 +772,9 @@ - `applyPolicy` - (optional) A [Apply Policy object](policies.md#ApplyPolicy) to use for this operation.

default list.
Example:
```js
var key = { ns: "test", set: "demo", key: "ldt_key"}
var binName = "ldtBinName";
var policy = { timeout: 1000 }
var key = {ns: 'test', set: 'demo', key: 'ldt_key'}
var binName = 'ldtBinName';
var policy = {timeout: 1000}
var llist = client.LargeList(key, binName, policy);

@@ -736,5 +823,9 @@ ```

client.operate(key, ops, function(error, record, metadata, key) {
// do something
});
client.operate(key, ops, function (error, record, metadata, key) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -755,3 +846,3 @@ <!--

- `key` – A [Key object](datamodel.md#key), used to locate the record in the cluster.
- `bins` – A [Record Object](datamodel.md#record), used to specify the bins to be added with integer values.
- `bins` – A [Record Object](datamodel.md#record), used to specify the bins to be added with integer values.
- `metadata` – (optional) A [Metadata object](datamodel.md#metadata).

@@ -772,7 +863,11 @@ - `policy` – (optional) A [Operate Policy object](policies.md#OperatePolicy) to use for this operation.

```js
var bins = {FirstMovieSeen: "12 Angry Man"}
var bins = {FirstMovieSeen: '12 Angry Man'}
client.prepend(key, bins, function(error, record, metadata, key) {
// do something
});
client.prepend(key, bins, function (error, record, metadata, key) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -815,5 +910,9 @@

client.put(key('test','demo','key1'), rec, function(error, key) {
// do something
});
client.put(key('test', 'demo', 'key1'), rec, function (error, key) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -829,14 +928,13 @@ <!--

creates a new [query](query.md) object, which is used to define query in the database.
Creates a new [query](query.md) object, which is used to define query in the database.
Parameters:
- `namespace` - Namespace to be queried.
- `namespace` - Namespace to be queried.
- `set` - Set on which the query has to be executed.
- `statement` - an Instance of [Statement](query.md#Statement), which specifies the properties of
a given query.
a given query.
Example:
```js
var query = client.query(ns, set);
var query = client.query(ns, set)
```

@@ -873,5 +971,9 @@

client.remove(key('test','demo','key1'), function(error, key) {
// do something
});
client.remove(key('test', 'demo', 'key1'), function (error, key) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -909,6 +1011,11 @@

client.select(key('test','demo','key1'), ["name","age"] function(error, record, metadata, key) {
// do something
});
client.select(key('test', 'demo', 'key1'), ['name', 'age'], function (error, record, metadata, key) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```
<!--

@@ -923,3 +1030,3 @@ ################################################################################

Registers an UDF to the database cluster. To verify that UDF is present in all the nodes
Registers an UDF to the database cluster. To verify that UDF is present in all the nodes
refer [udfRegisterWait()](#udfREgisterWait)

@@ -941,5 +1048,9 @@

client.udfRegister("path/to/file/filename", function(error) {
// do something
});
client.udfRegister('path/to/file/filename', function (error) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -956,3 +1067,3 @@

Wait until the UDF registration succeeds in aerospike cluster. This function returns only when the
Wait until the UDF registration succeeds in aerospike cluster. This function returns only when the
UDF registered is available with all the nodes in aerospike cluster.

@@ -975,11 +1086,15 @@

client.udfRegister("path/to/file/filename", function(error) {
if(error.code === aerospike.status.AEROSPIKE_OK) {
client.udfRegisterWait( filename, 1000, function(err) {
if(err.code !== aerospike.status.AEROSPIKE_OK) {
// error in registration.
}
});
}
});
client.udfRegister('path/to/file/filename', function (error) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
client.udfRegisterWait(filename, 1000, function (error) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
}
})
```

@@ -1011,6 +1126,9 @@

```js
client.udfRemove("udfModuleName", function(error) {
// do something
});
client.udfRemove('udfModuleName', function (error) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -1017,0 +1135,0 @@

@@ -8,3 +8,3 @@ # Configuration

```js
var aerospike = require('aerospike');
var aerospike = require('aerospike')

@@ -14,9 +14,9 @@ var config = {

// security feature is available only in Enterprise edition of Aerospike.
user: "username",
password: "password",
user: 'username',
password: 'password',
hosts: [
// add three nodes in the cluster.
{ addr: "192.168.0.1", port: 3000 },
{ addr: "192.168.0.2", port: 3000 },
{ addr: "192.168.0.3", port: 3000 }
{ addr: '192.168.0.1', port: 3000 },
{ addr: '192.168.0.2', port: 3000 },
{ addr: '192.168.0.3', port: 3000 }
],

@@ -26,14 +26,16 @@ policies = {

timeout: 100
}
},
connTimeoutMs: 1000, // initial connection timeout
tenderInterval: 1000, // tender interval
log : {
level: aerospike.log.INFO,
file : fd // fd opened by the application using fs.open()
file: fd // fd opened by the application using fs.open()
},
modlua: {
systemPath: 'path to system UDF files',
userPath: 'path to user UDF files'
systemPath: 'path to system UDF files',
userPath: 'path to user UDF files'
}
};
}
var client = aerospike.client(config);
var client = aerospike.client(config)
```

@@ -44,8 +46,9 @@

## Configuration Attributes
### `username` attribute
User authentication to cluster. Leave empty for clusters running without restricted access.
User authentication to cluster. Leave empty for clusters running without restricted access.
### `password` Attribute
Password authentication to cluster. The hashed value of the password will be stored by the client
and sent to server in same format. Leave empty for clusters running without restricted access.
### `password` attribute
Password authentication to cluster. The hashed value of the password will be stored by the client
and sent to server in same format. Leave empty for clusters running without restricted access.

@@ -61,2 +64,10 @@ ### `hosts` attribute

### `connTimeoutMs` attribute
Intial host connection timeout in milliseconds. The timeout when opening a connection to the server host for the first time. Default is 1000 ms.
### `tenderInterval` attribute
Polling interval in milliseconds for cluster tender. Default is 1000 ms.
### `policies` attribute

@@ -74,5 +85,7 @@

- `read` – The global policy for read operations, defined using a [Read Policy Object](policies.md#ReadPolicy)
- `remove` – The global policy for write operations, defined using a [Remove Policy Object](policies.md#RemovePolicy)
- `scan` – The global policy for scan operations, defined using a [Scan Policy Object](policies.md#ScanPolicy)
- `write` – The global policy for write operations, defined using a [Write Policy Object](policies.md#WritePolicy)
### `log` attribute

@@ -87,2 +100,3 @@

### `modlua` attribute

@@ -89,0 +103,0 @@

@@ -16,3 +16,2 @@ # Data Model

Example of a record with 5 fields:

@@ -22,7 +21,7 @@

var record = {
int_bin : 123,
str_bin : "xyz",
buff_bin : new Buffer("hello world!"),
arr_bin : [1, 2, 3],
obj_bin : { num: 123, str : "abc", buff: new Buffer([0xa, 0xb, 0xc])}
int_bin: 123,
str_bin: 'xyz',
buff_bin: new Buffer('hello world!'),
arr_bin: [1, 2, 3],
obj_bin: {num: 123, str: 'abc', buff: new Buffer([0xa, 0xb, 0xc])}
}

@@ -43,3 +42,3 @@ ```

- `gen` – (optional) The generation (version) of the record. Must be an Integer.
- `ttl` – (optional) The time-to-live (expiration) of the record. Must be an Integer.
- `ttl` – (optional) The time-to-live in seconds (expiration) of the record. Must be an Integer.

@@ -78,4 +77,4 @@ Example:

var key = {
ns: "test",
set: "demo",
ns: 'test',
set: 'demo',
key: 123

@@ -88,3 +87,3 @@ }

```js
aerospike.key("test", "demo", 123)
aerospike.key('test', 'demo', 123)
```

@@ -104,3 +103,3 @@ <!--

- `funcname` – The UDF function to be invoked in the database.
- `args` - (optional) The arguments to be passed to the UDF function.
- `args` - (optional) The arguments to be passed to the UDF function.
Example:

@@ -112,3 +111,3 @@

funcname: udf_funcname,
args: [123, "str"]
args: [123, 'str']
}

@@ -138,2 +137,1 @@ ```

- `line` – The line number in which the error occured.

@@ -15,3 +15,3 @@ # Filters

]
};
}

@@ -62,5 +62,5 @@ client.query(ns, set, queryArgs)

- `min` – The minimum value of the bin, the records with bin value equal to or greater than
min will be returned as part of query result (min value is inclusive).
- `max` - The maximum value of the bin, the records with bin value equal to or less than max
will be returned as part of query result ( max value is inclusive).
min will be returned as part of query result (min value is inclusive).
- `max` - The maximum value of the bin, the records with bin value equal to or less than max
will be returned as part of query result ( max value is inclusive).
```js

@@ -67,0 +67,0 @@ filter.range('b', 1, 1000)

@@ -25,3 +25,3 @@ # Introduction

```node
var aerospike = require('aerospike');
var aerospike = require('aerospike')
```

@@ -36,3 +36,3 @@

hosts: [
{ addr: "localhost", port: 3000 }
{ addr: 'localhost', port: 3000 }
]

@@ -45,3 +45,3 @@ }

```node
var client = aerospike.connect(config);
var client = aerospike.connect(config)
```

@@ -48,0 +48,0 @@

@@ -6,10 +6,10 @@ # LargeList Class

```js
var aerospike = require('aerospike');
var config = { hosts: [ addr: localhost, port: 3000]}
var client = aerospike.client(config);
var key = { ns:"test", set:"demo", key:"llistKey"}
var policy = { timeout: 1000}
var binName = "LDTbin"
var createModule = "ListInitializer"
var llist = client.LargeList(key, binName, policy);
var aerospike = require('aerospike')
var config = {hosts: [ addr: localhost, port: 3000]}
var client = aerospike.client(config)
var key = {ns: 'test', set: 'demo', key: 'llistKey'}
var policy = {timeout: 1000}
var binName = 'LDTbin'
var createModule = 'ListInitializer'
var llist = client.LargeList(key, binName, policy);

@@ -67,3 +67,3 @@ ```

- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
the operation.
- `response` - The value returned from by the LDT function `add`.

@@ -73,7 +73,9 @@

```js
llist.add({"key":"ldt_key", "value":"ldtvalue"}, function(err, res){
//check for err.code
if(err.code != aerospike.status.AEROSPIKE_OK)
//signals error.
});
llist.add({'key': 'ldt_key', 'value': 'ldtvalue'}, function (error, response){
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})

@@ -98,8 +100,8 @@ ```

- `[value]` - Values to add
- `callback`- The function to call when the operation completes with the results of the operation.
- `callback` - The function to call when the operation completes with the results of the operation.
The parameters for `callback` argument:
- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
- `response` - The value returned from by the LDT function `add`.

@@ -109,9 +111,10 @@

```js
var valArray = [ {"key":"ldt_key", "value":"ldtvalue"}, {"key":"ldt_array", "value":"ldtarrayvalue"}]
llist.add(valArray, function(err, res){
//check for err.code
if(err.code != aerospike.status.AEROSPIKE_OK)
//signals error.
});
var valArray = [{'key': 'ldt_key', 'value': 'ldtvalue'}, {'key': 'ldt_array', 'value': 'ldtarrayvalue'}]
llist.add(valArray, function (error, response){
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -133,20 +136,22 @@

- `value` - Value to update
- `callback`- The function to call when the operation completes with the results of the operation.
- `value` - Value to update
- `callback` - The function to call when the operation completes with the results of the operation.
The parameters for `callback` argument:
- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
- `response` - The value returned from by the LDT function `add`.
- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
- `response` - The value returned from by the LDT function `add`.
Example:
```js
llist.update({"key":"ldt_key", "value":"ldtupdatedvalue"}, function(err, res){
//check for err.code
if(err.code != aerospike.status.AEROSPIKE_OK)
//signals error.
});
llist.update({'key': 'ldt_key', 'value': 'ldtupdatedvalue'}, function (error, response){
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```
```
<!--

@@ -173,3 +178,3 @@ ################################################################################

- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
the operation.
- `response`- The value returned from by the LDT function `add`.

@@ -179,10 +184,12 @@

```js
var valArray = [ {"key":"ldt_key", "value":"ldtupdatevalue"}, {"key":"ldt_array", "value":"ldtarrayupdatedvalue"}]
llist.update(valArray, function(err, res){
//check for err.code
if(err.code != aerospike.status.AEROSPIKE_OK)
//signals error.
});
var valArray = [{'key': 'ldt_key', 'value': 'ldtupdatevalue'}, {'key': 'ldt_array', 'value': 'ldtarrayupdatedvalue'}]
llist.update(valArray, function (error, response){
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```
```
<!--

@@ -206,3 +213,3 @@ ################################################################################

- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
the operation.
- `response` - The value returned from by the LDT function `add`.

@@ -212,9 +219,11 @@

```js
llist.delete({"key":"ldt_key"}, function(err, res){
//check for err.code
if(err.code != aerospike.status.AEROSPIKE_OK)
//signals error.
});
llist.delete({'key': 'ldt_key'}, function (error, response){
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```
```
<!--

@@ -239,3 +248,3 @@ ################################################################################

- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
the operation.
- `response`- The value returned from by the LDT function `add`.

@@ -245,9 +254,10 @@

```js
var valArray = [ {"key":"ldt_key"},{"key":"ldt_array"}]
llist.remove(valArray, function(err, res){
//check for err.code
if(err.code != aerospike.status.AEROSPIKE_OK)
//signals error.
});
var valArray = [{'key': 'ldt_key'}, {'key': 'ldt_array'}]
llist.remove(valArray, function (error, response){
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -275,3 +285,3 @@

- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
the operation.
- `response` - The count of entries removed.

@@ -281,9 +291,11 @@

```js
llist.remove("begin", "end", function(err, res){
//check for err.code
if(err.code != aerospike.status.AEROSPIKE_OK)
//signals error.
});
llist.remove('begin', 'end', function (error, response){
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```
```
<!--

@@ -308,3 +320,3 @@ ################################################################################

- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
the operation.
- `response`- List of entries selected.

@@ -314,8 +326,9 @@

```js
llist.find("search_key", function(err, res){
//check for err.code
if(err.code != aerospike.status.AEROSPIKE_OK)
//signals error.
});
llist.find('search_key', function (error, response){
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -338,3 +351,3 @@

- `filter` - A [UDFArgs object](datamodel.md#UDFArgs) used for specifying LUA file, function
and arguments to Lua function.
and arguments to Lua function.
- `callback`- The function to call when the operation completes with the results of the operation.

@@ -345,3 +358,3 @@

- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
the operation.
- `response`- List of entries selected.

@@ -351,9 +364,10 @@

```js
var filter = { module : "udf_module", funcname: "udf_function", args:[args, to, udf, function] }
llist.find("search_key", filter, function(err, res){
//check for err.code
if(err.code != aerospike.status.AEROSPIKE_OK)
//signals error.
});
var filter = {module: 'udf_module', funcname: 'udf_function', args: ['abc', 123, 4.5]}
llist.find('search_key', filter, function (error, response){
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -381,3 +395,3 @@

- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
the operation.
- `response` - The list of entries selected.

@@ -387,8 +401,9 @@

```js
llist.range("begin", "end", function(err, res){
//check for err.code
if(err.code != aerospike.status.AEROSPIKE_OK)
//signals error.
});
llist.range('begin', 'end', function (error, response){
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -412,3 +427,3 @@

- `filter`- A [UDFArgs object](datamodel.md#UDFArgs) used for specifying the Lua file, function
and arguments to the Lua function.
and arguments to the Lua function.
- `callback`- The function to call when the operation completes with the results of the operation.

@@ -419,3 +434,3 @@

- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
the operation.
- `response` - The list of entries selected.

@@ -426,9 +441,10 @@

var filter = { module : "udf_module", funcname: "udf_function", args:[args, to, udf, function] }
llist.range("begin", "end", filter, function(err, res){
//check for err.code
if(err.code != aerospike.status.AEROSPIKE_OK)
//signals error.
});
var filter = {module: 'udf_module', funcname: 'udf_function', args: ['abc', 123, 4.5]}
llist.range('begin', 'end', filter, function (error, response){
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -454,3 +470,3 @@

- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
the operation.
- `response`- All the entries in the list.

@@ -460,8 +476,9 @@

```js
llist.scan(function(err, res){
//check for err.code
if(err.code != aerospike.status.AEROSPIKE_OK)
//signals error.
});
llist.scan(function (error, response){
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -483,3 +500,3 @@

- `udfArgs` - A [UDFArgs object](datamodel.md#UDFArgs) used for specifying for specifying the Lua file, function
and arguments to the Lua function.
and arguments to the Lua function.
- `callback`- The function to call when the operation completes with the results of the operation.

@@ -490,3 +507,3 @@

- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
the operation.
- `response`-list of entries selected.

@@ -496,9 +513,10 @@

```js
var udfargs = { module : "udf_module", funcname: "udf_function", args:[args, to, udf, function] }
llist.filter(function(err, res){
//check for err.code
if(err.code != aerospike.status.AEROSPIKE_OK)
//signals error.
});
var udfargs = {module: 'udf_module', funcname: 'udf_function', args: ['abc', 123, 4.5]}
llist.filter(function (error, response){
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -524,3 +542,3 @@

- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
the operation.
- `response`- `undefined`

@@ -530,8 +548,9 @@

```js
llist.destroy(function(err, res){
//check for err.code
if(err.code != aerospike.status.AEROSPIKE_OK)
//signals error.
});
llist.destroy(function (error, response){
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -557,3 +576,3 @@

- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
the operation.
- `response`- Size of the list.

@@ -563,8 +582,9 @@

```js
llist.size(function(err, res){
//check for err.code
if(err.code != aerospike.status.AEROSPIKE_OK)
//signals error.
});
llist.size(function (error, respone){
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -589,3 +609,3 @@ <!--

- `error` - The [Error object](datamodel.md#error) representing the status of
the operation.
the operation.
- `response`- Map of list configuration parameters.

@@ -595,9 +615,9 @@

```js
llist.getConfig(function(err, res){
//check for err.code
if(err.code != aerospike.status.AEROSPIKE_OK)
//signals error.
});
llist.getConfig(function (error, response){
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -6,3 +6,3 @@ #log

```js
var aerospike = require('aerospike');
var aerospike = require('aerospike')

@@ -9,0 +9,0 @@ aerospike.log.INFO

@@ -18,3 +18,9 @@ # Operators

client.operate(key, ops, callback)
client.operate(key, ops, function (error, record, meta, key) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -416,2 +422,1 @@

// returns: 3
```

@@ -11,3 +11,2 @@ # Policies

<a name="Objects"></a>

@@ -21,3 +20,9 @@ ## Objects

```js
client.get(key, {timeout: 1000}, callback);
client.get(key, {timeout: 1000}, function (error, record, meta, key) {
if (error && error.code !== status.AEROSPIKE_OK) {
// handle failure
} else {
// handle success
}
})
```

@@ -33,3 +38,3 @@ <!--

A policy effecting the behavior of UDF execution.
A policy affecting the behavior of UDF execution.

@@ -39,9 +44,9 @@ Attributes:

- `key` – Specifies the behavior for the key.
For values, see [Key Policy Values](policies.md#key).
For values, see [Key Policy Values](policies.md#key).
- `timeout` – Maximum time in milliseconds to wait for the operation to
complete. If 0 (zero), then the value will default to
global default timeout value
- `commitLevel` - Commit Level of the operation. Specifies whether to be commited
only in Master replica copy or all the replica copies.
For values, see [Commit Level Policy Values](policies.md#commitLevel).
- `commitLevel` - Commit Level of the operation. Specifies whether to be commited
only in Master replica copy or all the replica copies.
For values, see [Commit Level Policy Values](policies.md#commitLevel).

@@ -57,3 +62,3 @@ <!--

A policy effecting the behavior of batch operations.
A policy affecting the behavior of batch operations.

@@ -75,3 +80,3 @@ Attributes:

A policy effecting the behavior of info operations.
A policy affecting the behavior of info operations.

@@ -86,3 +91,2 @@ Attributes:

<!--

@@ -97,3 +101,3 @@ ################################################################################

A policy effecting the behavior of operate operations.
A policy affecting the behavior of operate operations.

@@ -112,9 +116,9 @@ Attributes:

- `commitLevel` - Commit Level of the operation. Specifies whether to be commited
only in Master replica copy or all the replica copies.
For values, see [Commit Level Policy Values](policies.md#commitLevel).
- `replica` - Specifies which partition replica to read from.
For values, see [Replica Policy](policies.md#replica).
only in Master replica copy or all the replica copies.
For values, see [Commit Level Policy Values](policies.md#commitLevel).
- `replica` - Specifies which partition replica to read from.
For values, see [Replica Policy](policies.md#replica).
- `consistencyLevel` - Specifies the number of replicas to be consulted in a read operation
to provide the desired consistency guarantee.
For values, see [Consistency Level Policy Values](policies.md#consistencyLevel).
to provide the desired consistency guarantee.
For values, see [Consistency Level Policy Values](policies.md#consistencyLevel).

@@ -124,2 +128,19 @@

################################################################################
QueryPolicy
################################################################################
-->
<a name="QueryPolicy"></a>
### Query Policy Object
A policy affecting the behaviour of query operations.
Attributes:
- `timeout` – Integer datatype. Maximum time in milliseconds to wait for
the operation to complete. If 0 (zero), then the value
will default to global default timeout value.
<!--
################################################################################
ReadPolicy

@@ -132,3 +153,3 @@ ################################################################################

A policy effecting the behaviour of read operations.
A policy affecting the behaviour of read operations.

@@ -142,9 +163,8 @@ Attributes:

will default to global default timeout value.
- `replica` - Specifies which partition replica to read from.
For values, see [Replica Policy](policies.md#replica).
- `replica` - Specifies which partition replica to read from.
For values, see [Replica Policy](policies.md#replica).
- `consistencyLevel` - Specifies the number of replicas to be consulted in a read operation
to provide the desired consistency guarantee.
For values, see [Consistency Level Policy Values](policies.md#consistencyLevel).
to provide the desired consistency guarantee.
For values, see [Consistency Level Policy Values](policies.md#consistencyLevel).
<!--

@@ -159,6 +179,9 @@ ################################################################################

A policy effecting the behaviour of remove operations.
A policy affecting the behaviour of remove operations.
Attributes:
- `timeout` – Integer datatype. Maximum time in milliseconds to wait for
the operation to complete. If 0 (zero), then the value
will default to global default timeout value.
- `gen` – Specifies the behavior for the generation value.

@@ -172,7 +195,25 @@ For values, see [Generation Policy Values](policies.md#gen).

- `commitLevel` - Commit Level of the operation. Specifies whether to be commited
only in Master replica copy or all the replica copies.
For values, see [Commit Level Policy Values](policies.md#commitLevel).
only in Master replica copy or all the replica copies.
For values, see [Commit Level Policy Values](policies.md#commitLevel).
<!--
################################################################################
ScanPolicy
################################################################################
-->
<a name="ScanPolicy"></a>
### Scan Policy Object
A policy affecting the behaviour of scan operations.
Attributes:
- `timeout` – Integer datatype. Maximum time in milliseconds to wait for
the operation to complete. If 0 (zero), then the value
will default to global default timeout value.
- `failOnClusterChange` – Boolean datatype. Abort the scan if the cluster is not in a stable state.
<!--
################################################################################
WritePolicy

@@ -185,3 +226,3 @@ ################################################################################

A policy effecting the behaviour of write operations.
A policy affecting the behaviour of write operations.

@@ -202,6 +243,5 @@ Attributes:

- `commitLevel` - Commit Level of the operation. Specifies whether to be commited
only in Master replica copy or all the replica copies.
For values, see [Commit Level Policy Values](policies.md#commitLevel).
only in Master replica copy or all the replica copies.
For values, see [Commit Level Policy Values](policies.md#commitLevel).
<a name="Values"></a>

@@ -212,7 +252,6 @@ ## Values

An enumeration of the values are available in `aerospike.policy` object, which can be accessed similarly to:
```js
var aerospike = require('aerospike');
var aerospike = require('aerospike')

@@ -411,2 +450,1 @@ aerospike.policy.gen.GT

```

@@ -8,5 +8,5 @@ # Query Class

```js
var aerospike = require('aerospike');
var client = aerospike.client(config);
var query = client.query(ns, set, stmt);
var aerospike = require('aerospike')
var client = aerospike.client(config)
var query = client.query(ns, set, stmt)

@@ -70,3 +70,3 @@ ```

`concurrent` is a bool value, setting to true results in parallel scanning of data in
all nodes in Aerospike cluster.
all nodes in Aerospike cluster.

@@ -88,24 +88,23 @@

```js
var statement = { filters:[filter.equal('a', 'abc')]}
var statement = {filters: [filter.equal('a', 'abc')]}
// NOTE bin a has to be indexed for it to be queried.
//To projects bins 'a' and 'b' alone
statement.select = ['a', 'b']
// NOTE bin a has to be indexed for it to be queried.
//To projects bins 'a' and 'b' alone
statement.select = ['a', 'b']
var query = client.query(ns, set, statement); // returns a query object.
var query = client.query(ns, set, statement) // returns a query object.
var dataCallback = function(record) {
// process the scanned record
}
var errorCallback = function(error) {
// process the error
}
var endCallback = function() {
//process the end of query results.
}
var stream = query.execute(); // returns a stream object.
stream.on('data', dataCallback);
stream.on('error', errorCallback);
stream.on('end', endCallback);
var dataCallback = function (record) {
// process the scanned record
}
var errorCallback = function (error) {
// process the error
}
var endCallback = function () {
//process the end of query results
}
var stream = query.execute() // returns a stream object.
stream.on('data', dataCallback)
stream.on('error', errorCallback)
stream.on('end', endCallback)
```

@@ -131,27 +130,28 @@

```js
var statement = { filters:[filter.equal['a', 'abc'],
aggregationUDF: {module: 'agg_module', funcname: 'agg_func'}
}
var statement = {
filters: [filter.equal['a', 'abc'],
aggregationUDF: {module: 'agg_module', funcname: 'agg_func'}
}
// NOTE bin a has to be indexed for it to be queried.
//To projects bins 'a' and 'b' alone
statement.select = ['a', 'b']
// NOTE bin a has to be indexed for it to be queried.
//To projects bins 'a' and 'b' alone
statement.select = ['a', 'b']
var query = client.query(ns, set, statement); // returns a query object.
var query = client.query(ns, set, statement) // returns a query object
var dataCallback = function(result) {
//process the result of aggregation
}
var errorCallback = function(error) {
//process the error
}
var endCallback = function() {
//process the end of aggregation
}
var stream = query.execute(); // returns a stream object.
stream.on('data', dataCallback);
stream.on('error', errorCallback);
stream.on('end', endCallback);
var dataCallback = function (result) {
//process the result of aggregation
}
var errorCallback = function (error) {
//process the error
}
var endCallback = function( ) {
//process the end of aggregation
}
var stream = query.execute() // returns a stream object
stream.on('data', dataCallback)
stream.on('error', errorCallback)
stream.on('end', endCallback)
```
```
<!--

@@ -172,23 +172,22 @@ ################################################################################

```js
// no filters should be applied during query instantiation.
// however 0 or more bins can be projected.
var statement = {nobins: false, concurrent: true, select: ['a', 'b']}
var query = client.query(ns, set ) // returns a query object.
// no filters should be applied during query instantiation.
// however 0 or more bins can be projected.
var statement = { nobins: false, concurrent: true, select: ['a', 'b']}
var query = client.query(ns, set ); // returns a query object.
var dataCallback = function (record) {
//process the record
}
var errorCallback = function (error) {
//do something
}
var endCallback = function () {
//process the end of scan
}
var stream = query.execute() // returns a stream object
stream.on('data', dataCallback)
stream.on('error', errorCallback)
stream.on('end', endCallback)
```
var dataCallback = function(record) {
//process the record
}
var errorCallback = function(error) {
//do something
}
var endCallback = function() {
//process the end of scan
}
var stream = query.execute(); // returns a stream object.
stream.on('data', dataCallback);
stream.on('error', errorCallback);
stream.on('end', endCallback);
```
<!--

@@ -215,23 +214,21 @@ ################################################################################

```js
var statement = {
aggregationUDF: {module: 'agg_module', funcname: 'agg_func'}
}
var statement = {
aggregationUDF: {module: 'agg_module', funcname: 'agg_func'}
}
var query = client.query(ns, set, statement ) // returns a query object
var query = client.query(ns, set, statement ); // returns a query object.
var dataCallback = function(result) {
//process the result of aggregation
}
var errorCallback = function(error) {
//process the error
}
var endCallback = function() {
//process the end of aggregation
}
var stream = query.execute(); // returns a stream object.
stream.on('data', dataCallback);
stream.on('error', errorCallback);
stream.on('end', endCallback);
var dataCallback = function (result) {
//process the result of aggregation
}
var errorCallback = function (error) {
//process the error
}
var endCallback = function () {
//process the end of aggregation
}
var stream = query.execute() // returns a stream object
stream.on('data', dataCallback)
stream.on('error', errorCallback)
stream.on('end', endCallback)
```

@@ -257,26 +254,26 @@

```js
// no filters should be applied during query instantiation.
// however 0 or more bins can be projected.
// And scanUDF argument must be present.
var statement = {
concurrent: true,
UDF: {module:'scanUdf', funcname: 'scanFunc'}
}
var query = client.query(ns, set, statement) // returns a query object
// no filters should be applied during query instantiation.
// however 0 or more bins can be projected.
// And scanUDF argument must be present.
var statement = { concurrent: true,
UDF: {module:'scanUdf', funcname: 'scanFunc'}
}
var query = client.query(ns, set, statement); // returns a query object.
// callback to handle the error event emitted by query stream.
var errorCallback = function(error) {
//process the error
}
// callback to handle the end event emitted by query stream.
var endCallback = function() {
//signals that the scan background job has been successfully fired.
}
// callback to handle the error event emitted by query stream
var errorCallback = function (error) {
//process the error
}
var stream = query.execute(); // returns a stream object.
stream.on('error', errorCallback);
stream.on('end', endCallback);
// callback to handle the end event emitted by query stream
var endCallback = function () {
//signals that the scan background job has been successfully fired
}
var stream = query.execute() // returns a stream object
stream.on('error', errorCallback)
stream.on('end', endCallback)
```
<!--

@@ -303,18 +300,11 @@ ################################################################################

- `recordScanned` - Total number of records in Aerospike database on which scan UDF has been applied.
- `status` - An instance [Scan Status](scanproperties.md#scanStatus) object and it contains status
of scan(in-progress, completed, aborted).
- `status` - An instance [Scan Status](scanproperties.md#scanStatus) object and it contains status
of scan(in-progress, completed, aborted).
```js
var query = client.query(namespace, set);
query.Info( scanId, function(scanInfo) {
if (scanInfo.status == scanStatus.COMPLETED)
{
// implies scan completed.
}
});
var query = client.query(namespace, set)
query.Info(scanId, function (scanInfo) {
if (scanInfo.status == scanStatus.COMPLETED) {
// implies scan completed
}
})
```

@@ -10,6 +10,6 @@ # Introduction

```js
var aerospike = require('aerospike');
var aerospike = require('aerospike')
```
Before connecting to a cluster, you must require `'aerospike'`, to get the aerospike object.
Before connecting to a cluster, you must require `aerospike`, to get the aerospike object.

@@ -21,7 +21,7 @@ You can then define a client configuration, which is used to setup a client object for connecting to and operating against as cluster.

hosts: [
{ addr: "localhost", port: 3000 }
{ addr: 'localhost', port: 3000 }
]
}
var client = aerospike.client(config);
var client = aerospike.client(config)
```

@@ -28,0 +28,0 @@

@@ -10,3 +10,3 @@ #scanProperties

```js
var aerospike = require('aerospike');
var aerospike = require('aerospike')

@@ -32,3 +32,3 @@ aerospike.scanStatus.INPROGESS

```js
var aerospike = require('aerospike');
var aerospike = require('aerospike')

@@ -35,0 +35,0 @@ aerospike.scanPriority.HIGH

@@ -8,3 +8,3 @@ # Status

```js
var aerospike = require('aerospike');
var aerospike = require('aerospike')

@@ -86,3 +86,1 @@ aerospike.status.AEROSPIKE_OK

Bin modification operation can't be done on an existing bin due to its value type

@@ -1,197 +0,185 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Perform add operation on a single record.
*
******************************************************************************/
// *****************************************************************************
// Perform add operation on a single record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Operator = aerospike.operator;
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connectt to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connectt to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var keyv = argv._.shift();
var argv = argp.argv
var keyv = argv._.shift()
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (!keyv) {
console.error("Error: Please provide a key for the operation");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a key for the operation')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client
*
******************************************************************************/
// *****************************************************************************
// Configure the client
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function run (client) {
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv
}
function run(client) {
var bins = {
i: 123
}
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv,
};
var bins = {
i: 123,
};
client.add(key, bins, function(err) {
if (isError(err)) {
process.exit(1);
} else {
!argv.quiet && console.log("OK.");
iteration.next(run, client);
}
});
client.add(key, bins, function (err) {
if (isError(err)) {
process.exit(1)
} else {
!argv.quiet && console.log('OK.')
iteration.next(run, client)
}
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error("Error: Not Found.");
return true;
default:
console.error("Error: " + err.message);
return true;
}
} else {
return false;
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error('Error: Not Found.')
return true
default:
console.error('Error: ' + err.message)
return true
}
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client);
}
});
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,198 +0,186 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Perform append operation on a single record.
*
******************************************************************************/
// *****************************************************************************
// Perform append operation on a single record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Operator = aerospike.operator;
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connectt to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connectt to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var keyv = argv._.shift();
var argv = argp.argv
var keyv = argv._.shift()
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (!keyv) {
console.error("Error: Please provide a key for the operation");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a key for the operation')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client
*
******************************************************************************/
// *****************************************************************************
// Configure the client
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function run (client) {
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv
}
function run(client) {
var bins = {
s: 'appendS'
}
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv,
};
var bins = {
s: "appendS",
};
client.append(key, bins, function(err) {
if (isError(err)) {
process.exit(1);
} else {
!argv.quiet && console.log("OK.");
iteration.next(run, client);
}
});
client.append(key, bins, function (err) {
if (isError(err)) {
process.exit(1)
} else {
!argv.quiet && console.log('OK.')
iteration.next(run, client)
}
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error("Error: Not Found.");
return true;
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error('Error: Not Found.')
return true
default:
console.error("Error: " + err.message);
return true;
}
} else {
return false;
default:
console.error('Error: ' + err.message)
return true
}
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client)
}
});
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,185 +0,175 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Read a batch of records.
*
******************************************************************************/
// *****************************************************************************
// Read a batch of records
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key [key ...]")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connectt to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key [key ...]')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connectt to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var keys = argv._.map(function(key) {
return {
ns: argv.namespace,
set: argv.set,
key: key
};
});
var argv = argp.argv
var keys = argv._.map(function (key) {
return {
ns: argv.namespace,
set: argv.set,
key: key
}
})
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (keys.length === 0) {
console.error("Error: Please provide one or more keys for the operation");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide one or more keys for the operation')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function run(client) {
client.batchExists(keys, function(err, results) {
if (isError(err)) {
process.exit(1);
} else {
!argv.quiet && console.log(JSON.stringify(results, null, ' '));
iteration.next(run, client);
}
});
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
console.error("Error: " + err.message);
return true;
function run (client) {
client.batchExists(keys, function (err, results) {
if (isError(err)) {
process.exit(1)
} else {
return false;
!argv.quiet && console.log(JSON.stringify(results, null, ' '))
iteration.next(run, client)
}
})
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client);
}
});
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
console.error('Error: ' + err.message)
return true
} else {
return false
}
}
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,191 +0,181 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Read a batch of records.
*
******************************************************************************/
// *****************************************************************************
// Read a batch of records.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key [key ...]")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connectt to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key [key ...]')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connectt to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var keys = argv._.map(function(key) {
return {
ns: argv.namespace,
set: argv.set,
key: key
};
});
var argv = argp.argv
var keys = argv._.map(function (key) {
return {
ns: argv.namespace,
set: argv.set,
key: key
}
})
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (keys.length === 0) {
console.error("Error: Please provide one or more keys for the operation");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide one or more keys for the operation')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function run(client) {
client.batchGet(keys, function(err, results) {
if (isError(err)) {
process.exit(1);
} else {
!argv.quiet && console.log(JSON.stringify(results, null, ' '));
iteration.next(run, client);
}
});
function run (client) {
client.batchGet(keys, function (err, results) {
if (isError(err)) {
process.exit(1)
} else {
!argv.quiet && console.log(JSON.stringify(results, null, ' '))
iteration.next(run, client)
}
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error("Error: Not Found.");
return true;
default:
console.error("Error: " + err.message);
return true;
}
} else {
return false;
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error('Error: Not Found.')
return true
default:
console.error('Error: ' + err.message)
return true
}
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client)
}
});
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,200 +0,187 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Read a batch of records.
*
******************************************************************************/
// *****************************************************************************
// Read a batch of records.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key [key ...] ")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
bins: {
alias: "b",
default: undefined,
describe: "Bins to select in the batch Call"
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connectt to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key [key ...] ')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
bins: {
alias: 'b',
default: undefined,
describe: 'Bins to select in the batch Call'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connectt to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var keys = argv._.map(function(key) {
return {
ns: argv.namespace,
set: argv.set,
key: key
};
});
var argv = argp.argv
var keys = argv._.map(function (key) {
return {
ns: argv.namespace,
set: argv.set,
key: key
}
})
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (keys.length === 0) {
console.error("Error: Please provide one or more keys for the operation");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide one or more keys for the operation')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation.
// *****************************************************************************
function run (client) {
var bins = ['i', 's']
/*******************************************************************************
*
* Perform the operation.
*
******************************************************************************/
function run(client) {
var bins = ['i', 's'];
client.batchSelect(keys, bins, function(err, results) {
if (isError(err)) {
process.exit(1);
} else {
!argv.quiet && console.log(JSON.stringify(result, null, ' '));
iteration.next(run, client);
}
});
client.batchSelect(keys, bins, function (err, results) {
if (isError(err)) {
process.exit(1)
}
!argv.quiet && console.log(JSON.stringify(results, null, ' '))
iteration.next(run, client)
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error("Error: Not Found.");
return true;
default:
console.error("Error: " + err.message);
return true;
}
} else {
return false;
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error('Error: Not Found.')
return true
default:
console.error('Error: ' + err.message)
return true
}
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client);
}
});
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,222 +0,209 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Get state information from the cluster or a single host.
*
******************************************************************************/
// *****************************************************************************
// Get state information from the cluster or a single host.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Language = aerospike.Language;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key module function [args ...]")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connecttt to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key module function [args ...]')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connecttt to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var keyv = argv._.shift();
var udf_module = argv._.shift();
var udf_function = argv._.shift();
var udf_args = argv._;
var argv = argp.argv
var keyv = argv._.shift()
var udf_module = argv._.shift()
var udf_function = argv._.shift()
var udf_args = argv._
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (!keyv) {
console.error("Error: Please provide a key for the operation");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a key for the operation')
console.error()
argp.showHelp()
process.exit(1)
}
if (!udf_module) {
console.error("Error: Please provide a key for the operation");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a key for the operation')
console.error()
argp.showHelp()
process.exit(1)
}
if (!udf_function) {
console.error("Error: Please provide a key for the operation");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a key for the operation')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation.
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation.
*
******************************************************************************/
function run (client) {
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv
}
function run(client) {
var udf = {
module: udf_module,
funcname: udf_function,
args: udf_args.map(function (v) {
try {
return JSON.parse(v)
} catch (exception) {
return '' + v
}
})
}
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv,
};
var udf = {
module: udf_module,
funcname: udf_function,
args: udf_args.map(function(v) {
try {
return JSON.parse(v);
} catch (exception) {
return "" + v;
}
}),
};
client.execute(key, udf, function(err, value) {
if (isError(err)) {
process.exit(1);
} else {
!argv.quiet && console.log(JSON.stringify(value, null, ' '));
iteration.next(run, client);
}
});
client.execute(key, udf, function (err, value) {
if (isError(err)) {
process.exit(1)
} else {
!argv.quiet && console.log(JSON.stringify(value, null, ' '))
iteration.next(run, client)
}
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error("Error: Not Found.");
return true;
default:
console.error("Error: " + err.message);
return true;
}
} else {
return false;
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error('Error: Not Found.')
return true
default:
console.error('Error: ' + err.message)
return true
}
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (err && err.code != Status.AEROSPIKE_OK) {
process.exit(1);
} else {
run(client);
}
});
aerospike.client(config).connect(function (err, client) {
if (err && err.code !== Status.AEROSPIKE_OK) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,206 +0,193 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Check existence of a record.
*
******************************************************************************/
// *****************************************************************************
// Check existence of a record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('../');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('../')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
'key': {
boolean: true,
default: true,
describe: "Display the record's key."
},
'metadata': {
boolean: true,
default: true,
describe: "Display the record's metadata."
},
'bins': {
boolean: true,
default: true,
describe: "Display the record's bins."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connectt to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
'key': {
boolean: true,
default: true,
describe: "Display the record's key."
},
'metadata': {
boolean: true,
default: true,
describe: "Display the record's metadata."
},
'bins': {
boolean: true,
default: true,
describe: "Display the record's bins."
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connectt to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var keyv = argv._.shift();
var argv = argp.argv
var keyv = argv._.shift()
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (!keyv) {
console.error("Error: Please provide a key for the operation");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a key for the operation')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
user: argv.user,
password: argv.password
}
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Establish a connection and execute the operation.
// *****************************************************************************
/*******************************************************************************
*
* Establish a connection and execute the opetation.
*
******************************************************************************/
function run (client) {
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv
}
function run(client) {
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv
};
client.exists(key, function(err, bins, metadata, key) {
if (isError(err)) {
process.exit(1);
} else {
!argv.quiet && console.log(JSON.stringify(result, null, ' '));
iteration.next(run, client);
}
});
client.exists(key, function (err, bins, metadata, key) {
if (isError(err)) {
process.exit(1)
}
iteration.next(run, client)
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error("Error: Not Found.");
return true;
default:
console.error("Error: " + err.message);
return true;
}
} else {
return false;
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error('Error: Not Found.')
return true
default:
console.error('Error: ' + err.message)
return true
}
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client);
}
})
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,222 +0,211 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Read a record.
*
******************************************************************************/
// *****************************************************************************
// Read a record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
'key': {
boolean: true,
default: true,
describe: "Display the record's key."
},
'metadata': {
boolean: true,
default: true,
describe: "Display the record's metadata."
},
'bins': {
boolean: true,
default: true,
describe: "Display the record's bins."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connectt to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
'key': {
boolean: true,
default: true,
describe: "Display the record's key."
},
'metadata': {
boolean: true,
default: true,
describe: "Display the record's metadata."
},
'bins': {
boolean: true,
default: true,
describe: "Display the record's bins."
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connectt to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var keyv = argv._.shift();
var argv = argp.argv
var keyv = argv._.shift()
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (!keyv) {
console.error("Error: Please provide a key for the operation");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a key for the operation')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Establish a connection and execute the opetation.
// *****************************************************************************
/*******************************************************************************
*
* Establish a connection and execute the opetation.
*
******************************************************************************/
function run (client) {
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv + iteration.current()
}
function run(client) {
client.get(key, function (err, bins, metadata, key) {
if (isError(err)) {
process.exit(1)
} else {
var record = {}
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv + iteration.current()
};
if (argv['key']) {
record.key = key
}
client.get(key, function(err, bins, metadata, key) {
if (isError(err)) {
process.exit(1);
} else {
var record = {};
if (argv['metadata']) {
record.metadata = metadata
}
if (argv['key']) {
record.key = key;
}
if (argv['bins']) {
record.bins = bins
}
if (argv['metadata']) {
record.metadata = metadata;
}
!argv.quiet && console.log(JSON.stringify(record, null, ' '))
if (argv['bins']) {
record.bins = bins;
}
!argv.quiet && console.log(JSON.stringify(record, null, ' '));
iteration.next(run, client);
}
});
iteration.next(run, client)
}
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error("Error: Not Found.");
return true;
default:
console.error("Error: " + err.message);
return true;
}
} else {
return false;
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error('Error: Not Found.')
return true
default:
console.error('Error: ' + err.message)
return true
}
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (err && err.code != Status.AEROSPIKE_OK) {
process.exit(1);
} else {
run(client);
}
aerospike.client(config).connect(function (err, client) {
if (err && err.code !== Status.AEROSPIKE_OK) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,252 +0,239 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Select bins of a record.
*
******************************************************************************/
// *****************************************************************************
// Select bins of a record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] bin index type")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
'key': {
boolean: true,
default: true,
describe: "Display the record's key."
},
'metadata': {
boolean: true,
default: true,
describe: "Display the record's metadata."
},
'bins': {
boolean: true,
default: true,
describe: "Display the record's bins."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connectt to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] bin index type')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
'key': {
boolean: true,
default: true,
describe: "Display the record's key."
},
'metadata': {
boolean: true,
default: true,
describe: "Display the record's metadata."
},
'bins': {
boolean: true,
default: true,
describe: "Display the record's bins."
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connectt to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var bin = argv._.shift();
var index = argv._.shift();
var type = argv._.shift();
var argv = argp.argv
var bin = argv._.shift()
var index = argv._.shift()
var type = argv._.shift()
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (!bin) {
console.error("Error: Please provide a bin to be indexed");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a bin to be indexed')
console.error()
argp.showHelp()
process.exit(1)
}
if (!index) {
console.error("Error: Please provide a index name");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a index name')
console.error()
argp.showHelp()
process.exit(1)
}
if (!type) {
console.error("Error: Please provide a type of index to be created");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a type of index to be created')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function run (client) {
var options = {
ns: argv.namespace,
set: argv.set,
bin: bin,
index: index
}
function run(client) {
switch (type) {
case 'integer':
client.createIntegerIndex(options, function (err) {
if (isError(err)) {
process.exit(1)
} else {
isIndexCreated(client, argv.namespace, index, 1000)
}
})
break
case 'string':
client.createStringIndex(options, function (err) {
if (isError(err)) {
process.exit(1)
} else {
isIndexCreated(client, argv.namespace, index, 1000)
}
})
break
default:
console.error('Error: Only integer and string indices are supported.')
process.exit(1)
}
}
var options = {
ns: argv.namespace,
set: argv.set,
bin: bin,
index: index,
};
switch (type) {
case "integer":
client.createIntegerIndex(options, function(err) {
if (isError(err)) {
process.exit(1);
} else {
isIndexCreated(client, argv.namespace, index, 1000);
}
});
break;
case "string":
client.createStringIndex(options, function(err) {
if (isError(err)) {
process.exit(1);
}
else {
isIndexCreated(client, argv.namespace, index, 1000);
}
});
break;
default:
console.error("Error: Only integer and string indices are supported.");
process.exit(1);
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error('Error: Not Found.')
return true
default:
console.log(err)
console.error('Error: ' + err.message)
return true
}
} else {
return false
}
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error("Error: Not Found.");
return true;
default:
console.log(err);
console.error("Error: " + err.message);
return true;
}
function isIndexCreated (client, namespace, index, pollInterval) {
client.indexCreateWait(namespace, index, pollInterval, function (err) {
if (isError(err)) {
process.exit(1)
} else {
return false;
!argv.quiet && console.log('Index Created - %s', index)
}
})
}
function isIndexCreated(client, namespace, index, pollInterval) {
client.indexCreateWait(namespace, index, pollInterval, function(err) {
if (isError(err)) {
process.exit(1);
}
else {
!argv.quiet && console.log("Index Created - %s", index);
}
});
}
aerospike.client(config).connect(function(err, client) {
if (err && err.code != Status.AEROSPIKE_OK) {
process.exit(1);
} else {
run(client);
}
});
aerospike.client(config).connect(function (err, client) {
if (err && err.code !== Status.AEROSPIKE_OK) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,201 +0,189 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Select bins of a record.
*
******************************************************************************/
// *****************************************************************************
// Select bins of a record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] index ")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
'key': {
boolean: true,
default: true,
describe: "Display the record's key."
},
'metadata': {
boolean: true,
default: true,
describe: "Display the record's metadata."
},
'bins': {
boolean: true,
default: true,
describe: "Display the record's bins."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connectt to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] index ')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
'key': {
boolean: true,
default: true,
describe: "Display the record's key."
},
'metadata': {
boolean: true,
default: true,
describe: "Display the record's metadata."
},
'bins': {
boolean: true,
default: true,
describe: "Display the record's bins."
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connectt to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var index = argv._.length === 1 ? argv._[0] : null;
var argv = argp.argv
var index = argv._.length === 1 ? argv._[0] : null
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (!index) {
console.error("Error: Please provide a index name");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a index name')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function run(client) {
client.indexRemove(argv.namespace, index, function(err) {
if (isError(err)) {
process.exit(1);
} else {
!argv.quiet && console.log("OK.");
}
});
};
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error("Error: Not Found.");
return true;
default:
console.error("Error: " + err.message);
return true;
}
function run (client) {
client.indexRemove(argv.namespace, index, function (err) {
if (isError(err)) {
process.exit(1)
} else {
return false;
!argv.quiet && console.log('OK.')
}
})
}
aerospike.client(config).connect(function(err, client) {
if (err && err.code != Status.AEROSPIKE_OK) {
process.exit(1);
} else {
run(client)
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error('Error: Not Found.')
return true
default:
console.error('Error: ' + err.message)
return true
}
});
} else {
return false
}
}
aerospike.client(config).connect(function (err, client) {
if (err && err.code !== Status.AEROSPIKE_OK) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,180 +0,169 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Get state information from the cluster or a single host.
*
******************************************************************************/
// *****************************************************************************
// Get state information from the cluster or a single host.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connectt to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connectt to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var request = argv._.length !== 0 ? argv._.shift() : "statistics";
var argv = argp.argv
var request = argv._.length !== 0 ? argv._.shift() : 'statistics'
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function run(client) {
client.info(request, {
addr: argv.host,
port: argv.port
}, function(err, response, host) {
if (isError(err)) {
process.exit(1);
} else {
var res = {
host: host,
response: response
};
!argv.quiet && console.log(JSON.stringify(res, null, ' '));
iteration.next(run, client);
}
});
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
console.error("Error: " + err.message);
return true;
function run (client) {
client.info(request, {
addr: argv.host,
port: argv.port
}, function (err, response, host) {
if (isError(err)) {
process.exit(1)
} else {
return false;
var res = {
host: host,
response: response
}
!argv.quiet && console.log(JSON.stringify(res, null, ' '))
iteration.next(run, client)
}
})
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client)
}
});
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
console.error('Error: ' + err.message)
return true
} else {
return false
}
}
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,177 +0,166 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Get state information from the cluster or a single host.
*
******************************************************************************/
// *****************************************************************************
// Get state information from the cluster or a single host.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 1000,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connectt to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 1000,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connectt to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var request = argv._.length !== 0 ? argv._.shift() : "statistics";
var argv = argp.argv
var request = argv._.length !== 0 ? argv._.shift() : 'statistics'
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function run(client) {
client.info(request, function(err, response, host) {
if (isError(err)) {
process.exit(1);
} else {
var res = {
host: host,
response: response
};
!argv.quiet && console.log(JSON.stringify(res, null, ' '));
iteration.next(run, client);
}
});
}
function isError(err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
console.error("Error: " + err.message);
return true;
function run (client) {
client.info(request, function (err, response, host) {
if (isError(err)) {
process.exit(1)
} else {
return false;
var res = {
host: host,
response: response
}
!argv.quiet && console.log(JSON.stringify(res, null, ' '))
iteration.next(run, client)
}
})
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client)
}
});
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
console.error('Error: ' + err.message)
return true
} else {
return false
}
}
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,30 +0,30 @@

var count = 0;
var limit = 1;
var count = 0
var limit = 1
function reset() {
count = 0;
};
function reset () {
count = 0
}
function setLimit(i) {
limit = i;
};
function setLimit (i) {
limit = i
}
function current() {
return count;
};
function current () {
return count
}
function next(fn, arg) {
count++;
if (count >= limit) {
process.exit(0);
} else {
fn(arg);
}
};
function next (fn, arg) {
count++
if (count >= limit) {
process.exit(0)
} else {
fn(arg)
}
}
module.exports = {
reset: reset,
setLimit: setLimit,
next: next,
current: current
};
reset: reset,
setLimit: setLimit,
next: next,
current: current
}

@@ -1,148 +0,133 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Write a record.
*
******************************************************************************/
// *****************************************************************************
// Write a record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var client = aerospike.client;
var yargs = require('yargs');
var events = require('events');
var util = require('util');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var Policy = aerospike.policy;
var Status = aerospike.status;
var filter = aerospike.filter;
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
var Status = aerospike.status
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key")
.options({
help: {
boolean: true,
describe: "Display this message."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connectt to secured cluster"
}
});
.usage('$0 [options] key')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connectt to secured cluster'
}
})
var argv = argp.argv;
var argv = argp.argv
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// modlua userpath
modlua: {
userPath: __dirname
},
//modlua userpath
modlua: {
userPath: __dirname
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
var checkError = function(err, msg) {
if (err.code != Status.AEROSPIKE_OK) {
console.log(err);
} else {
console.log(msg);
}
var checkError = function (err, msg) {
if (err.code !== Status.AEROSPIKE_OK) {
console.log(err)
} else {
console.log(msg)
}
}

@@ -152,103 +137,97 @@

if (client == null) {
console.error("Error: Client object not initialized");
process.exit(1);
console.error('Error: Client object not initialized')
process.exit(1)
}
client.connect(function(err, client) {
client.connect(function (err, client) {
if (err.code !== Status.AEROSPIKE_OK) {
console.error('Error: Aerospike server connection error. ', err.message)
process.exit(1)
}
// Get a largelist object from client.
var listkey = {
ns: argv.namespace,
set: argv.set,
key: 'ldt_list_key'
}
if (err.code != Status.AEROSPIKE_OK) {
console.error("Error: Aerospike server connection error. ", err.message);
process.exit(1);
}
var policy = {
timeout: 1000
}
var list = client.LargeList(listkey, 'ldt_list_bin', policy)
// Get a largelist object from client.
var listkey = {
ns: argv.namespace,
set: argv.set,
key: "ldt_list_key"
}
// perform all the largelist operations.
var policy = {
timeout: 1000
};
// add single value to the list.
var val = 'listvalsingle'
list.add(val, function (err, val) {
checkError(err, 'Added a single value ')
})
var list = client.LargeList(listkey, "ldt_list_bin", policy);
// update single value added to the list.
var updateVal = 'listvalupdated'
list.update(updateVal, function (err, val) {
checkError(err, 'Updated a single value ')
})
// perform all the largelist operations.
// find an entry in the list.
list.find('listvalsingle', function (err, val) {
checkError(err, 'Find function verified')
console.log('value found ', val)
})
// add single value to the list.
var val = "listvalsingle";
list.add(val, function(err, val) {
checkError(err, "Added a single value ");
});
// remove an entry in the list.
list.remove('listvalsingle', function (err, val) {
checkError(err, 'Remove an entry verified')
})
// add an array of values to the list.
val = ['listadd1', 'listadd2', 'listadd3', 'listadd4', 'listadd5']
list.add(val, function (err, retVal) {
checkError(err, 'Added an array of values')
})
// update single value added to the list.
var updateVal = "listvalupdated";
list.update(updateVal, function(err, val) {
checkError(err, "Updated a single value ");
});
// update an array of value in the list.
val = ['listupdate1', 'listupdate2', 'listupdate3', 'listupdate4', 'listupdate5']
list.update(val, function (err, val) {
checkError(err, 'Updated an array of values')
})
// find an entry in the list.
list.find("listvalsingle", function(err, val) {
checkError(err, "Find function verified");
console.log("value found ", val);
});
// find a range of entries in the list.
list.findRange('listadd1', 'listadd9', function (err, val) {
checkError(err, 'Find Range Entry Verified')
console.log(val)
})
// remove an entry in the list.
list.remove("listvalsingle", function(err, val) {
checkError(err, "Remove an entry verified");
});
// remove a range of entries in the list.
list.removeRange('listadd1', 'listadd9', function (err, val) {
checkError(err, 'Remove a range of entries verified')
})
// add an array of values to the list.
var val = ["listadd1", "listadd2", "listadd3", "listadd4", "listadd5"];
list.add(val, function(err, retVal) {
checkError(err, "Added an array of values");
});
// remove an array of values in the list.
val = ['listupdate1', 'listupdate2', 'listupdate3', 'listupdate4', 'listupdate5']
list.remove(val, function (err, val) {
checkError(err, 'Removed an array of values')
})
// update an array of value in the list.
var val = ["listupdate1", "listupdate2", "listupdate3", "listupdate4", "listupdate5"];
list.update(val, function(err, val) {
checkError(err, "Updated an array of values");
});
// scan the whole llist.
list.scan(function (err, val) {
checkError(err, 'Scan Completed')
console.log('scanned value', val)
})
// find a range of entries in the list.
list.findRange("listadd1", "listadd9", function(err, val) {
checkError(err, "Find Range Entry Verified");
console.log(val);
});
// remove a range of entries in the list.
list.removeRange("listadd1", "listadd9", function(err, val) {
checkError(err, "Remove a range of entries verified");
});
// remove an array of values in the list.
var val = ["listupdate1", "listupdate2", "listupdate3", "listupdate4", "listupdate5"];
list.remove(val, function(err, val) {
checkError(err, "Removed an array of values");
});
// scan the whole llist.
list.scan(function(err, val) {
checkError(err, "Scan Completed");
console.log("scanned value", val);
});
// Get the size of the list and destroy the list.
list.size(function(err, val) {
checkError(err, "Get size is verified");
console.log("The size of the list is ", val);
list.getConfig(function(err, val) {
console.log(val);
// destroy the llist completely.
list.destroy(function(err, val) {
checkError(err, "The list is destroyed");
});
});
});
});
// Get the size of the list and destroy the list.
list.size(function (err, val) {
checkError(err, 'Get size is verified')
console.log('The size of the list is ', val)
list.getConfig(function (err, val) {
if (err && err.code !== Status.AEROSPIKE_OK) { throw new Error(err.message) }
console.log(val)
// destroy the llist completely.
list.destroy(function (err, val) {
checkError(err, 'The list is destroyed')
})
})
})
})

@@ -1,252 +0,223 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*****************************************************************************
*
* node logging --log-file <path/to/log-file> --log-level <0-4>
*
* Demonstrates logging from the API, for PUT and GET functions.
*
* Examples:
*
* Enable Debug logging to stderr.
*
* node logging --log-level 3.
*
* Enable Detail logging to stderr.
*
* node logging --log-level 4.
*
* Redirect the log messages to a file `example.log`
*
* node logging --log-level <0-4> --log-file example.log
*
******************************************************************************/
// *****************************************************************************
//
// node logging --log-file <path/to/log-file> --log-level <0-4>
//
// Demonstrates logging from the API, for PUT and GET functions.
//
// Examples:
//
// Enable Debug logging to stderr.
//
// node logging --log-level 3.
//
// Enable Detail logging to stderr.
//
// node logging --log-level 4.
//
// Redirect the log messages to a file `example.log`
//
// node logging --log-level <0-4> --log-file example.log
//
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var policy = aerospike.policy;
var status = aerospike.status;
var status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] logfile")
.options({
help: {
boolean: true,
describe: "Display this message."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connectt to secured cluster"
}
});
.usage('$0 [options] logfile')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connectt to secured cluster'
}
})
var argv = argp.argv;
var logfile = argv._.length === 1 ? argv._[0] : null;
var argv = argp.argv
var logfile = argv._.length === 1 ? argv._[0] : null
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (logfile === null) {
console.error("Error: Please provide a logfile for the operation");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a logfile for the operation')
console.error()
argp.showHelp()
process.exit(1)
}
// *****************************************************************************
// Establish a connection to the cluster.
// *****************************************************************************
/*******************************************************************************
*
* Establish a connection to the cluster.
*
******************************************************************************/
var config = {
hosts: [{
addr: argv.host,
port: argv.port
}],
hosts: [{
addr: argv.host,
port: argv.port
}],
policies: {
timeout: argv.timeout
},
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password,
// authentication
user: argv.user,
password: argv.password
}
var client = aerospike.client(config).connect(function(err, client) {
if (err.code != status.AEROSPIKE_OK) {
console.log("Aerospike server connection Error: %j", err)
return;
}
if (client === null) {
console.error("Error: Client not initialized.");
return;
}
});
var client = aerospike.client(config).connect(function (err, client) {
if (err.code !== status.AEROSPIKE_OK) {
console.log('Aerospike server connection Error: %j', err)
return
}
if (client === null) {
console.error('Error: Client not initialized.')
return
}
})
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
// *****************************************************************************
// Perform the operation
// *****************************************************************************
Function.prototype.curry = function() {
var fn = this,
args = Array.prototype.slice.call(arguments);
return function() {
return fn.apply(this, args.concat(Array.prototype.slice.call(arguments)));
};
};
function header(message, callback) {
return function() {
console.log('');
console.log('********************************************************************************');
console.log('* ', message);
console.log('********************************************************************************');
console.log('');
if (callback) callback();
}
function header (message) {
return function (callback) {
console.log('')
console.log('********************************************************************************')
console.log('* ', message)
console.log('********************************************************************************')
console.log('')
callback()
}
}
function get(key, callback) {
return function() {
console.log('*** get')
client.get(key, function(err, record, metadata, key) {
if (callback) callback();
});
}
function get (key) {
return function (callback) {
console.log('*** get')
client.get(key, function (err, record, metadata, key) {
callback(err)
})
}
}
function put(key, rec, callback) {
return function() {
console.log('*** put')
client.put(key, rec, function(err, key) {
if (callback) callback();
});
}
function put (key, rec) {
return function (callback) {
console.log('*** put')
client.put(key, rec, function (err, key) {
callback(err)
})
}
}
function log(level, file, callback) {
return function() {
var fd;
if (file) {
if (!isNaN(parseInt(file, 10)) && isFinite(file)) {
fd = parseInt(file, 10);
} else {
fd = fs.openSync(file, "a");
}
}
console.log('*** log level=%d file=%s', level, file);
client.updateLogging({
level: level,
file: fd
});
if (callback) callback();
function log (level, file) {
return function (callback) {
var fd
if (file) {
if (!isNaN(parseInt(file, 10)) && isFinite(file)) {
fd = parseInt(file, 10)
} else {
fd = fs.openSync(file, 'a')
}
}
}
function close() {
return function() {
client.close();
}
console.log('*** log level=%d file=%s', level, file)
client.updateLogging({
level: level,
file: fd
})
callback()
}
}
var key = {
ns: argv.namespace,
set: argv.set,
key: "abc"
};
ns: argv.namespace,
set: argv.set,
key: 'abc'
}
operations = [
var operations = [
header('Log: default settings'),
put(key, { a: 1 }),
get(key),
header.curry('Log: default settings'),
put.curry(key, {
a: 1
}),
get.curry(key),
header('Log: level=4(TRACE)'),
log(5, null),
put(key, { a: 2 }),
get(key),
header.curry('Log: level=4(TRACE)'),
log.curry(5, null),
put.curry(key, {
a: 2
}),
get.curry(key),
header('Log: file=' + logfile),
log(null, logfile),
put(key, { a: 3 }),
get(key),
header.curry('Log: file=' + logfile),
log.curry(null, logfile),
put.curry(key, {
a: 3
}),
get.curry(key),
header('Log: level=3(DEBUG) file=STDERR'),
log(3, 2),
put(key, { a: 4 }),
get(key)
]
header.curry('Log: level=3(DEBUG) file=STDERR'),
log.curry(3, 2),
put.curry(key, {
a: 4
}),
get.curry(key)
];
operations.reduceRight(function(r, l) {
return l(r);
})();
operations.reduceRight(function (r, l) {
return function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
l(r)
}
}, function () {})()

@@ -1,217 +0,204 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Perform multiple operations on a single record.
*
******************************************************************************/
// *****************************************************************************
// Perform multiple operations on a single record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Operator = aerospike.operator;
var Policy = aerospike.policy;
var Status = aerospike.status;
var Operator = aerospike.operator
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var keyv = argv._.shift();
var argv = argp.argv
var keyv = argv._.shift()
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (!keyv) {
console.error("Error: Please provide a key for the operation");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a key for the operation')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Establish a connection to the cluster.
*
******************************************************************************/
// *****************************************************************************
// Establish a connection to the cluster.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
function run (client) {
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv
}
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
var ops = [
Operator.touch(1000),
Operator.incr('i', 1),
Operator.write('s', 'some_val'),
Operator.read('i'),
Operator.read('s')
]
function run(client) {
client.operate(key, ops, function (err, bins, metadata, key) {
if (isError(err)) {
process.exit(1)
} else {
var record = {}
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv
};
if (!argv['no-key']) {
record.key = key
}
var ops = [
Operator.touch(1000),
Operator.incr('i', 1),
Operator.write('s', 'some_val'),
Operator.read('i'),
Operator.read('s')
];
if (!argv['no-metadata']) {
record.metadata = metadata
}
client.operate(key, ops, function(err, bins, metadata, key) {
if (isError(err)) {
process.exit(1);
} else {
if (!argv['no-bins']) {
record.bins = bins
}
var record = {};
if (!argv['no-key']) {
record.key = key;
}
if (!argv['no-metadata']) {
record.metadata = metadata;
}
if (!argv['no-bins']) {
record.bins = bins;
}
!argv.quiet && console.log(JSON.stringify(record, null, ' '));
iteration.next(run, client);
}
});
!argv.quiet && console.log(JSON.stringify(record, null, ' '))
iteration.next(run, client)
}
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error("Error: Not Found.");
return true;
default:
console.error("Error: " + err.message);
return true;
}
} else {
return false;
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error('Error: Not Found.')
return true
default:
console.error('Error: ' + err.message)
return true
}
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client)
}
});
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -17,4 +17,5 @@ {

"aerospike": ">0",
"yargs": ">=1.2.1"
"yargs": ">=1.2.1",
"sleep": "^3.0.0"
}
}

@@ -1,201 +0,188 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Perform prepend operation on a single record.
*
******************************************************************************/
// *****************************************************************************
// Perform prepend operation on a single record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Operator = aerospike.operator;
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var keyv = argv._.shift();
var argv = argp.argv
var keyv = argv._.shift()
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (!keyv) {
console.error("Error: Please provide a key for the operation");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a key for the operation')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Establish a connection to the cluster.
*
******************************************************************************/
// *****************************************************************************
// Establish a connection to the cluster.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function run (client) {
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv
}
function run(client) {
var bins = {
s: 'prependS'
}
if (argv.profile) {
console.time('add')
}
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv
};
var bins = {
s: "prependS"
client.prepend(key, bins, function (err, bins, metadata, key) {
if (isError(err)) {
process.exit(1)
} else {
!argv.quiet && console.log('OK.')
iteration.next(run, client)
}
if (argv.profile) {
console.time("add");
}
client.prepend(key, bins, function(err, bins, metadata, key) {
if (isError(err)) {
process.exit(1);
} else {
!argv.quiet && console.log("OK.");
iteration.next(run, client);
}
});
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error("Error: Not Found.");
return true;
default:
console.error("Error: " + err.message);
return true;
}
} else {
return false;
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error('Error: Not Found.')
return true
default:
console.error('Error: ' + err.message)
return true
}
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client)
}
});
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,211 +0,201 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Write a record.
*
******************************************************************************/
// *****************************************************************************
// Write a record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Double = aerospike.Double;
var Status = aerospike.status
var Double = aerospike.Double
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var keyv = argv._.length === 1 ? argv._[0] : null;
var argv = argp.argv
var keyv = argv._.length === 1 ? argv._[0] : null
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (!keyv) {
console.error("Error: Please provide a key for the operation");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a key for the operation')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
user: argv.user,
password: argv.password
}
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function run (client) {
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv + iteration.current()
}
function run(client) {
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv + iteration.current()
};
var bins = {
i: 1152921504606846976.456,
d: 456.78,
x: Double(123.00),
s: 'abc',
l: [1, 2, 3],
m: {
s: 'g3',
i: 3,
b: new Buffer([0xa, 0xb, 0xc])
},
b: new Buffer([0xa, 0xb, 0xc]),
b2: new Uint8Array([0xa, 0xb, 0xc])
}
var bins = {
i: 1152921504606846976.456,
d: 456.78,
x: Double(123.00),
s: "abc",
l: [1, 2, 3],
m: {
s: "g3",
i: 3,
b: new Buffer([0xa, 0xb, 0xc])
},
b: new Buffer([0xa, 0xb, 0xc]),
b2: new Uint8Array([0xa, 0xb, 0xc])
};
var metadata = {
ttl: 10000,
gen: 0
}
var metadata = {
ttl: 10000,
gen: 0
};
client.put(key, bins, metadata, function(err, key) {
if (isError(err)) {
process.exit(1);
} else {
!argv.quiet && console.log("OK.");
iteration.next(run, client);
}
});
client.put(key, bins, metadata, function (err, key) {
if (isError(err)) {
process.exit(1)
} else {
!argv.quiet && console.log('OK.')
iteration.next(run, client)
}
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error("Error: Not Found.");
return true;
default:
console.error("Error: " + err.message);
return true;
}
} else {
return false;
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error('Error: Not Found.')
return true
default:
console.error('Error: ' + err.message)
return true
}
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client)
}
});
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,196 +0,181 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Write a record.
*
******************************************************************************/
// *****************************************************************************
// Write a record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var client = aerospike.client;
var yargs = require('yargs');
var events = require('events');
var util = require('util');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var filter = aerospike.filter;
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
var Status = aerospike.status
var filter = aerospike.filter
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var argv = argp.argv
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
modlua: {
userPath: __dirname
},
modlua: {
userPath: __dirname
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Establish a connection to the cluster.
// *****************************************************************************
/*******************************************************************************
*
* Establish a connection to the cluster.
*
******************************************************************************/
function run (client) {
var options = {
aggregationUDF: {
module: 'query',
funcname: 'sum_test_bin'
},
filters: [filter.range('i', 0, 10000)],
select: ['s', 'i']
}
function run(client) {
var stream = client.query(argv.namespace, argv.set, options).execute()
var count = 0;
stream.on('data', function (rec) {
!argv.quiet && console.log(JSON.stringify(rec, null, ' '))
})
var options = {
aggregationUDF: {
module: 'query',
funcname: 'sum_test_bin'
},
filters: [filter.range('i', 0, 10000)],
select: ['s', 'i'],
};
stream.on('error', function (err) {
console.error(err)
process.exit(1)
})
var stream = client.query(argv.namespace, argv.set, options).execute();
stream.on('data', function(rec) {
!argv.quiet && console.log(JSON.stringify(rec, null, ' '));
});
stream.on('error', function(err) {
console.error(err);
process.exit(1);
});
stream.on('end', function() {
iteration.next(run, client);
});
stream.on('end', function () {
iteration.next(run, client)
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
console.error("Error: " + err.message);
return true;
} else {
return false;
}
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
console.error('Error: ' + err.message)
return true
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client)
}
});
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,257 +0,248 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Write a record.
*
******************************************************************************/
// *****************************************************************************
// Write a record
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var client = aerospike.client;
var yargs = require('yargs');
var events = require('events');
var util = require('util');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var Policy = aerospike.policy;
var Status = aerospike.status;
var filter = aerospike.filter;
var GeoJSON = aerospike.GeoJSON;
var Status = aerospike.status
var filter = aerospike.filter
var GeoJSON = aerospike.GeoJSON
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key")
.options({
help: {
boolean: true,
describe: "Display this message."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connec to secured cluster"
}
});
.usage('$0 [options] key')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connec to secured cluster'
}
})
var argv = argp.argv;
var argv = argp.argv
if ( argv.help === true ) {
argp.showHelp();
process.exit(0);
if (argv.help === true) {
argp.showHelp()
process.exit(0)
}
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [
{ addr: argv.host, port: argv.port }
],
// the hosts to attempt to connect with.
hosts: [
{ addr: argv.host, port: argv.port }
],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// default policies
policies: {
timeout: argv.timeout
},
//modlua userpath
modlua: {
userPath: __dirname
}
// default policies
policies: {
timeout: argv.timeout
},
};
// modlua userpath
modlua: {
userPath: __dirname
}
if(argv.user !== null)
{
config.user = argv.user;
}
if(argv.password !== null)
{
config.password = argv.password;
if (argv.user !== null) {
config.user = argv.user
}
var g_nkeys = 20;
var g_bin = "loc";
var g_index = "points-loc-index";
if (argv.password !== null) {
config.password = argv.password
}
function execute_query(client) {
var g_nkeys = 20
var g_bin = 'loc'
var g_index = 'points-loc-index'
var count = 0;
var region = {
type: "Polygon",
coordinates: [
[[-122.500000, 37.000000],[-121.000000, 37.000000],
[-121.000000, 38.080000],[-122.500000, 38.080000],
[-122.500000, 37.000000]]
]
}
var options = { filters: [filter.geoWithin("loc", JSON.stringify(region))] }
function execute_query (client) {
var count = 0
var region = {
type: 'Polygon',
coordinates: [
[[-122.500000, 37.000000], [-121.000000, 37.000000],
[-121.000000, 38.080000], [-122.500000, 38.080000],
[-122.500000, 37.000000]]
]
}
var q = client.query(argv.namespace, argv.set, options);
var options = { filters: [filter.geoWithin('loc', JSON.stringify(region))] }
var stream = q.execute();
var q = client.query(argv.namespace, argv.set, options)
stream.on('data', function(rec) {
console.log(rec);
count++;
});
var stream = q.execute()
stream.on('error', function(err){
console.log("at error");
console.log(err);
cleanup(client, process.exit);
});
stream.on('data', function (rec) {
console.log(rec)
count++
})
stream.on('end', function() {
console.log('RECORDS FOUND:', count);
cleanup(client, process.exit);
});
stream.on('error', function (err) {
console.log('at error')
console.log(err)
cleanup(client, process.exit)
})
stream.on('end', function () {
console.log('RECORDS FOUND:', count)
cleanup(client, process.exit)
})
}
function insert_records(client, ndx, end) {
if (ndx >= end)
return execute_query(client);
function insert_records (client, ndx, end) {
if (ndx >= end) {
return execute_query(client)
}
var key = { ns: argv.namespace, set: argv.set, key: ndx }
var key = { ns: argv.namespace, set: argv.set, key: ndx }
var lng = -122 + (0.1 * ndx);
var lat = 37.5 + (0.1 * ndx);
var lng = -122 + (0.1 * ndx)
var lat = 37.5 + (0.1 * ndx)
loc = { type: "Point", coordinates: [lng, lat] }
bins = {}
bins[g_bin] = GeoJSON(JSON.stringify(loc));
client.put(key, bins, function(err, key) {
if (err.code != Status.AEROSPIKE_OK) {
console.error("insert_records: put failed: ", err.message);
process.exit(1);
}
insert_records(client, ndx + 1, end);
});
var loc = { type: 'Point', coordinates: [lng, lat] }
var bins = {}
bins[g_bin] = GeoJSON(JSON.stringify(loc))
client.put(key, bins, function (err, key) {
if (err.code !== Status.AEROSPIKE_OK) {
console.error('insert_records: put failed: ', err.message)
process.exit(1)
}
insert_records(client, ndx + 1, end)
})
}
function create_index(client) {
var options = {
ns: argv.namespace,
set: argv.set,
bin : g_bin,
index: g_index
};
client.createGeo2DSphereIndex(options, function(err) {
if (err.code != Status.AEROSPIKE_OK) {
console.log("index create failed: ", err);
process.exit(1)
}
client.indexCreateWait(options.ns, g_index, 100, function(err) {
if (err.code != aerospike.status.AEROSPIKE_OK) {
console.log("index create failed: ", err);
process.exit(1)
}
insert_records(client, 0, g_nkeys);
});
});
function create_index (client) {
var options = {
ns: argv.namespace,
set: argv.set,
bin: g_bin,
index: g_index
}
client.createGeo2DSphereIndex(options, function (err) {
if (err.code !== Status.AEROSPIKE_OK) {
console.log('index create failed: ', err)
process.exit(1)
}
client.indexCreateWait(options.ns, g_index, 100, function (err) {
if (err.code !== Status.AEROSPIKE_OK) {
console.log('index create failed: ', err)
process.exit(1)
}
insert_records(client, 0, g_nkeys)
})
})
}
function remove_index(client, complete) {
client.indexRemove(argv.namespace, g_index, function(err) {
// Ignore errors since the index may not exist.
complete(client);
});
function remove_index (client, complete) {
client.indexRemove(argv.namespace, g_index, function (err) {
if (err && !(err.code === Status.AEROSPIKE_OK || err.code === Status.AEROSPIKE_ERR_RECORD_NOT_FOUND)) {
throw new Error(err.message)
}
complete(client)
})
}
function remove_records(client, ndx, end, complete) {
if (ndx >= end)
return remove_index(client, complete);
function remove_records (client, ndx, end, complete) {
if (ndx >= end) {
return remove_index(client, complete)
}
var key = { ns: argv.namespace, set: argv.set, key: ndx }
client.remove(key, function(err, key) {
// Ignore errors since the records may not exist.
remove_records(client, ndx + 1, end, complete);
});
var key = { ns: argv.namespace, set: argv.set, key: ndx }
client.remove(key, function (err, key) {
if (err && !(err.code === Status.AEROSPIKE_OK || err.code === Status.AEROSPIKE_ERR_RECORD_NOT_FOUND)) {
throw new Error(err.message)
}
remove_records(client, ndx + 1, end, complete)
})
}
function cleanup(client, complete) {
remove_records(client, 0, g_nkeys, complete);
function cleanup (client, complete) {
remove_records(client, 0, g_nkeys, complete)
}
aerospike.client(config).connect(function(err, client) {
if (err.code == Status.AEROSPIKE_OK) {
// FIXME - when we can wait after index deletion do this instead.
// cleanup(client, create_index);
create_index(client);
}
else {
console.error("Error: Aerospike server connection error. ", err.message);
process.exit(1);
}
});
aerospike.client(config).connect(function (err, client) {
if (err.code === Status.AEROSPIKE_OK) {
// FIXME - when we can wait after index deletion do this instead.
// cleanup(client, create_index)
create_index(client)
} else {
console.error('Error: Aerospike server connection error. ', err.message)
process.exit(1)
}
})

@@ -1,190 +0,176 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Write a record.
*
******************************************************************************/
// *****************************************************************************
// Write a record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var client = aerospike.client;
var yargs = require('yargs');
var events = require('events');
var util = require('util');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var filter = aerospike.filter;
var Status = aerospike.status
var filter = aerospike.filter
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var argv = argp.argv
if (argv.help === true) {
argp.showHelp();
return;
argp.showHelp()
process.exit()
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// modlua userpath
modlua: {
userPath: __dirname
},
//modlua userpath
modlua: {
userPath: __dirname
},
user: argv.user,
password: argv.password
}
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function run (client) {
var options = {
filters: [filter.equal('i', 492)]
}
function run(client) {
var stream = client.query(argv.namespace, argv.set, options).execute()
var options = {
filters: [filter.equal("i", 492)],
};
stream.on('data', function (rec) {
!argv.quiet && console.log(JSON.stringify(rec, null, ' '))
})
var stream = client.query(argv.namespace, argv.set, options).execute();
stream.on('error', function (err) {
console.error(err)
process.exit(1)
})
stream.on('data', function(rec) {
!argv.quiet && console.log(JSON.stringify(rec, null, ' '));
});
stream.on('error', function(err) {
console.error(err);
process.exit(1);
});
stream.on('end', function() {
iteration.next(run, client);
});
stream.on('end', function () {
iteration.next(run, client)
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
console.error("Error: " + err.message);
return true;
} else {
return false;
}
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
console.error('Error: ' + err.message)
return true
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client)
}
});
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,242 +0,228 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* node range_get --start <start> --end <end> --skip <skip>
*
* Read records with given key range.
*
* Examples:
*
* Read records with keys in range 1-100
*
* node range_get -start 1 --end 100
*
* Read records with keys in range 1-100, skipping every fifth
*
* node range_get --start 1 --end 100 --skip 5
*
* Write records with keys in range 900-1000
*
* node range_put --start 900
*
******************************************************************************/
// *****************************************************************************
// node range_get --start <start> --end <end> --skip <skip>
//
// Read records with given key range.
//
// Examples:
//
// Read records with keys in range 1-100
//
// node range_get -start 1 --end 100
//
// Read records with keys in range 1-100, skipping every fifth
//
// node range_get --start 1 --end 100 --skip 5
//
// Write records with keys in range 900-1000
//
// node range_put --start 900
//
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options]")
.options({
help: {
boolean: true,
describe: "Display this message."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to secured cluster"
},
start: {
default: 1,
describe: "Start value for the key range."
},
end: {
default: 1000,
describe: "End value for the key range."
},
skip: {
default: 0,
describe: "Skip every n keys."
}
});
.usage('$0 [options]')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to secured cluster'
},
start: {
default: 1,
describe: 'Start value for the key range.'
},
end: {
default: 1000,
describe: 'End value for the key range.'
},
skip: {
default: 0,
describe: 'Skip every n keys.'
}
})
var argv = argp.argv;
var argv = argp.argv
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
aerospike.client(config).connect(function (err, client) {
if (err.code !== Status.AEROSPIKE_OK) {
console.error('Error: Aerospike server connection error. ', err.message)
process.exit(1)
}
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
//
// Perform the operation
//
aerospike.client(config).connect(function(err, client) {
function exists_done (client, start, end, skip) {
var total = end - start + 1
var done = 0
var success = 0
var notfound = 0
var failure = 0
var skipped = 0
var timeLabel = 'range_exists @ ' + total
if (err.code != Status.AEROSPIKE_OK) {
console.error("Error: Aerospike server connection error. ", err.message);
process.exit(1);
}
console.time(timeLabel)
//
// Perform the operation
//
return function (err, metadata, key, skippy) {
if (skippy === true) {
console.log('SKIP - ', key)
skipped++
} else {
switch (err.code) {
case Status.AEROSPIKE_OK:
console.log('OK - ', key, metadata)
success++
break
function exists_done(client, start, end, skip) {
var total = end - start + 1;
var done = 0;
var success = 0;
var notfound = 0;
var failure = 0;
var skipped = 0;
var timeLabel = "range_exists @ " + total;
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.log('NOT_FOUND - ', key)
notfound++
break
default:
console.log('ERR - ', err, key)
failure++
}
}
console.time(timeLabel);
return function(err, metadata, key, skippy) {
if (skippy === true) {
console.log("SKIP - ", key);
skipped++;
} else {
switch (err.code) {
case Status.AEROSPIKE_OK:
console.log("OK - ", key, metadata);
success++;
break;
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.log("NOT_FOUND - ", key);
notfound++;
break;
default:
console.log("ERR - ", err, key);
failure++;
}
}
done++;
if (done >= total) {
console.timeEnd(timeLabel);
console.log();
console.log("RANGE: start=%d end=%d skip=%d", start, end, skip);
console.log("RESULTS: (%d completed, %d success, %d failed, %d notfound, %d skipped)", done, success, failure, notfound, skipped);
console.log();
client.close();
}
}
done++
if (done >= total) {
console.timeEnd(timeLabel)
console.log()
console.log('RANGE: start=%d end=%d skip=%d', start, end, skip)
console.log('RESULTS: (%d completed, %d success, %d failed, %d notfound, %d skipped)', done, success, failure, notfound, skipped)
console.log()
client.close()
}
}
}
function exists_start(client, start, end, skip) {
var done = exists_done(client, start, end, skip);
var i = start,
s = 0;
function exists_start (client, start, end, skip) {
var done = exists_done(client, start, end, skip)
var i = start
var s = 0
for (; i <= end; i++) {
var key = {
ns: argv.namespace,
set: argv.set,
key: i
};
for (; i <= end; i++) {
var key = {
ns: argv.namespace,
set: argv.set,
key: i
}
if (skip !== 0 && ++s >= skip) {
s = 0;
done(null, null, null, key, true);
continue;
}
if (skip !== 0 && ++s >= skip) {
s = 0
done(null, null, null, key, true)
continue
}
client.exists(key, done);
}
client.exists(key, done)
}
}
exists_start(client, argv.start, argv.end, argv.skip);
});
exists_start(client, argv.start, argv.end, argv.skip)
})

@@ -1,242 +0,227 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* node range_get --start <start> --end <end> --skip <skip>
*
* Read records with given key range.
*
* Examples:
*
* Read records with keys in range 1-100
*
* node range_get -start 1 --end 100
*
* Read records with keys in range 1-100, skipping every fifth
*
* node range_get --start 1 --end 100 --skip 5
*
* Write records with keys in range 900-1000
*
* node range_put --start 900
*
******************************************************************************/
// *****************************************************************************
// node range_get --start <start> --end <end> --skip <skip>
//
// Read records with given key range.
//
// Examples:
//
// Read records with keys in range 1-100
//
// node range_get -start 1 --end 100
//
// Read records with keys in range 1-100, skipping every fifth
//
// node range_get --start 1 --end 100 --skip 5
//
// Write records with keys in range 900-1000
//
// node range_put --start 900
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options]")
.options({
help: {
boolean: true,
describe: "Display this message."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connectt to secured cluster"
},
start: {
default: 1,
describe: "Start value for the key range."
},
end: {
default: 1000,
describe: "End value for the key range."
},
skip: {
default: 0,
describe: "Skip every n keys."
}
});
.usage('$0 [options]')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connectt to secured cluster'
},
start: {
default: 1,
describe: 'Start value for the key range.'
},
end: {
default: 1000,
describe: 'End value for the key range.'
},
skip: {
default: 0,
describe: 'Skip every n keys.'
}
})
var argv = argp.argv;
var argv = argp.argv
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
aerospike.client(config).connect(function (err, client) {
if (err.code !== Status.AEROSPIKE_OK) {
console.error('Error: Aerospike server connection error. ', err.message)
process.exit(1)
}
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
//
// Perform the operation
//
aerospike.client(config).connect(function(err, client) {
function get_done (client, start, end, skip) {
var total = end - start + 1
var done = 0
var success = 0
var notfound = 0
var failure = 0
var skipped = 0
var timeLabel = 'range_get @ ' + total
if (err.code != Status.AEROSPIKE_OK) {
console.error("Error: Aerospike server connection error. ", err.message);
process.exit(1);
}
console.time(timeLabel)
//
// Perform the operation
//
return function (err, record, metadata, key, skippy) {
if (skippy === true) {
console.log('SKIP - ', key)
skipped++
} else {
switch (err.code) {
case Status.AEROSPIKE_OK:
console.log('OK - ', key, metadata, record)
success++
break
function get_done(client, start, end, skip) {
var total = end - start + 1;
var done = 0;
var success = 0;
var notfound = 0;
var failure = 0;
var skipped = 0;
var timeLabel = "range_get @ " + total;
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.log('NOT_FOUND - ', key)
notfound++
break
default:
console.log('ERR - ', err, key)
failure++
}
}
console.time(timeLabel);
return function(err, record, metadata, key, skippy) {
if (skippy === true) {
console.log("SKIP - ", key);
skipped++;
} else {
switch (err.code) {
case Status.AEROSPIKE_OK:
console.log("OK - ", key, metadata, record);
success++;
break;
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.log("NOT_FOUND - ", key);
notfound++;
break;
default:
console.log("ERR - ", err, key);
failure++;
}
}
done++;
if (done >= total) {
console.timeEnd(timeLabel);
console.log();
console.log("RANGE: start=%d end=%d skip=%d", start, end, skip);
console.log("RESULTS: (%d completed, %d success, %d failed, %d notfound, %d skipped)", done, success, failure, notfound, skipped);
console.log();
client.close();
}
}
done++
if (done >= total) {
console.timeEnd(timeLabel)
console.log()
console.log('RANGE: start=%d end=%d skip=%d', start, end, skip)
console.log('RESULTS: (%d completed, %d success, %d failed, %d notfound, %d skipped)', done, success, failure, notfound, skipped)
console.log()
client.close()
}
}
}
function get_start(client, start, end, skip) {
var done = get_done(client, start, end, skip);
var i = start,
s = 0;
function get_start (client, start, end, skip) {
var done = get_done(client, start, end, skip)
var i = start
var s = 0
for (; i <= end; i++) {
var key = {
ns: argv.namespace,
set: argv.set,
key: i
};
for (; i <= end; i++) {
var key = {
ns: argv.namespace,
set: argv.set,
key: i
}
if (skip !== 0 && ++s >= skip) {
s = 0;
done(null, null, null, key, true);
continue;
}
if (skip !== 0 && ++s >= skip) {
s = 0
done(null, null, null, key, true)
continue
}
client.get(key, done);
}
client.get(key, done)
}
}
get_start(client, argv.start, argv.end, argv.skip);
});
get_start(client, argv.start, argv.end, argv.skip)
})

@@ -1,250 +0,233 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* node range_put --start <start> --end <end> --skip <skip>
*
* Write records with given key range.
*
* Examples:
*
* Write records with keys in range 1-100
*
* node range_put --start 1 --end 100
*
* Read records with keys in range 1-100, skipping every 5th key (in sequence)
*
* node range_get --start 1 --end 100 --skip 5
*
* Write records with keys in range 900-1000
*
* node range_put --start 900
*
******************************************************************************/
// *****************************************************************************
// node range_put --start <start> --end <end> --skip <skip>
//
// Write records with given key range.
//
// Examples:
//
// Write records with keys in range 1-100
//
// node range_put --start 1 --end 100
//
// Read records with keys in range 1-100, skipping every 5th key (in sequence)
//
// node range_get --start 1 --end 100 --skip 5
//
// Write records with keys in range 900-1000
//
// node range_put --start 900
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options]")
.options({
help: {
boolean: true,
describe: "Display this message."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to secured cluster"
},
start: {
default: 1,
describe: "Start value for the key range."
},
end: {
default: 1000,
describe: "End value for the key range."
},
skip: {
default: 0,
describe: "Skip every n keys."
}
});
.usage('$0 [options]')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to secured cluster'
},
start: {
default: 1,
describe: 'Start value for the key range.'
},
end: {
default: 1000,
describe: 'End value for the key range.'
},
skip: {
default: 0,
describe: 'Skip every n keys.'
}
})
var argv = argp.argv;
var argv = argp.argv
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
aerospike.client(config).connect(function (err, client) {
if (err.code !== Status.AEROSPIKE_OK) {
console.error('Error: Aerospike server connection error. ', err.message)
process.exit(1)
}
//
// Perform the operation
//
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function put_done (client, start, end, skip) {
var total = end - start + 1
var done = 0
var success = 0
var failure = 0
var skipped = 0
var timeLabel = 'range_put @ ' + total
aerospike.client(config).connect(function(err, client) {
console.time(timeLabel)
if (err.code != Status.AEROSPIKE_OK) {
console.error("Error: Aerospike server connection error. ", err.message);
process.exit(1);
}
return function (err, key, skippy) {
if (skippy === true) {
console.log('SKIP - ', key)
skipped++
} else {
switch (err.code) {
case Status.AEROSPIKE_OK:
console.log('OK - ', key)
success++
break
default:
console.log('ERR - ', err, key)
failure++
}
}
//
// Perform the operation
//
function put_done(client, start, end, skip) {
var total = end - start + 1;
var done = 0;
var success = 0;
var failure = 0;
var skipped = 0;
var timeLabel = "range_put @ " + total;
console.time(timeLabel);
return function(err, key, skippy) {
if (skippy === true) {
console.log("SKIP - ", key);
skipped++;
} else {
switch (err.code) {
case Status.AEROSPIKE_OK:
console.log("OK - ", key);
success++;
break;
default:
console.log("ERR - ", err, key);
failure++;
}
}
done++;
if (done >= total) {
console.timeEnd(timeLabel);
console.log();
console.log("RANGE: start=%d end=%d skip=%d)", start, end, skip);
console.log("RESULTS: (%d completed, %d success, %d failed, %d skipped)", done, success, failure, skipped);
console.log();
client.close();
}
}
done++
if (done >= total) {
console.timeEnd(timeLabel)
console.log()
console.log('RANGE: start=%d end=%d skip=%d', start, end, skip)
console.log('RESULTS: (%d completed, %d success, %d failed, %d skipped)', done, success, failure, skipped)
console.log()
client.close()
}
}
}
function put_start(client, start, end, skip) {
var done = put_done(client, start, end, skip);
var i = start,
s = 0;
function put_start (client, start, end, skip) {
var done = put_done(client, start, end, skip)
var i = start
var s = 0
for (; i <= end; i++) {
for (; i <= end; i++) {
var key = {
ns: argv.namespace,
set: argv.set,
key: i
}
var key = {
ns: argv.namespace,
set: argv.set,
key: i
};
if (skip !== 0 && ++s >= skip) {
s = 0
done(null, key, true)
continue
}
if (skip !== 0 && ++s >= skip) {
s = 0;
done(null, key, true);
continue;
}
var record = {
k: i,
s: 'abc',
i: i * 1000 + 123,
b: new Buffer([0xa, 0xb, 0xc])
}
var record = {
k: i,
s: "abc",
i: i * 1000 + 123,
b: new Buffer([0xa, 0xb, 0xc])
};
var metadata = {
ttl: 10000,
gen: 0
}
var metadata = {
ttl: 10000,
gen: 0
};
client.put(key, record, metadata, done);
}
client.put(key, record, metadata, done)
}
}
put_start(client, argv.start, argv.end, argv.skip);
});
put_start(client, argv.start, argv.end, argv.skip)
})

@@ -1,241 +0,226 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* node range_get --start <start> --end <end> --skip <skip>
*
* Read records with given key range
*
* Examples:
*
* Read records with keys in range 1-100
*
* node range_get --start 1 --end 100
*
* Read records with keys in range 1-100, skipping every fifth
*
* node range_get --start 1 --end 100 --skip 5
*
* Write records with keys in range 900-1000
*
* node range_put --start 900
*
******************************************************************************/
// *****************************************************************************
// node range_get --start <start> --end <end> --skip <skip>
//
// Read records with given key range
//
// Examples:
//
// Read records with keys in range 1-100
//
// node range_get --start 1 --end 100
//
// Read records with keys in range 1-100, skipping every fifth
//
// node range_get --start 1 --end 100 --skip 5
//
// Write records with keys in range 900-1000
//
// node range_put --start 900
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options]")
.options({
help: {
boolean: true,
describe: "Display this message."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to secured cluster"
},
start: {
default: 1,
describe: "Start value for the key range."
},
end: {
default: 1000,
describe: "End value for the key range."
},
skip: {
default: 0,
describe: "Skip every n keys."
}
});
.usage('$0 [options]')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to secured cluster'
},
start: {
default: 1,
describe: 'Start value for the key range.'
},
end: {
default: 1000,
describe: 'End value for the key range.'
},
skip: {
default: 0,
describe: 'Skip every n keys.'
}
})
var argv = argp.argv;
var argv = argp.argv
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
aerospike.client(config).connect(function (err, client) {
if (err.code !== Status.AEROSPIKE_OK) {
console.error('Error: Aerospike server connection error. ', err.message)
process.exit(1)
}
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
//
// Perform the operation
//
aerospike.client(config).connect(function(err, client) {
function remove_done (client, start, end, skip) {
var total = end - start + 1
var done = 0
var success = 0
var notfound = 0
var failure = 0
var skipped = 0
var timeLabel = 'range_remove @ ' + total
if (err.code != Status.AEROSPIKE_OK) {
console.error("Error: Aerospike server connection error. ", err.message);
process.exit(1);
}
console.time(timeLabel)
//
// Perform the operation
//
return function (err, key, skippy) {
if (skippy === true) {
console.log('SKIP - ', key)
skipped++
} else {
switch (err.code) {
case Status.AEROSPIKE_OK:
console.log('OK - ', key)
success++
break
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.log('NOT_FOUND - ', key)
notfound++
break
default:
console.log('ERR - ', err, key)
failure++
}
}
function remove_done(client, start, end, skip) {
var total = end - start + 1;
var done = 0;
var success = 0;
var notfound = 0;
var failure = 0;
var skipped = 0;
var timeLabel = "range_remove @ " + total;
console.time(timeLabel);
return function(err, key, skippy) {
if (skippy === true) {
console.log("SKIP - ", key);
skipped++;
} else {
switch (err.code) {
case Status.AEROSPIKE_OK:
console.log("OK - ", key);
success++;
break;
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.log("NOT_FOUND - ", key);
notfound++;
break;
default:
console.log("ERR - ", err, key);
failure++;
}
}
done++;
if (done >= total) {
console.timeEnd(timeLabel);
console.log();
console.log("RANGE: start=%d end=%d skip=%d", start, end, skip);
console.log("RESULTS: (%d completed, %d success, %d failed, %d notfound, %d skipped)", done, success, failure, notfound, skipped);
console.log();
client.close();
}
}
done++
if (done >= total) {
console.timeEnd(timeLabel)
console.log()
console.log('RANGE: start=%d end=%d skip=%d', start, end, skip)
console.log('RESULTS: (%d completed, %d success, %d failed, %d notfound, %d skipped)', done, success, failure, notfound, skipped)
console.log()
client.close()
}
}
}
function remove_start(client, start, end, skip) {
var done = remove_done(client, start, end, skip);
var i = start,
s = 0;
function remove_start (client, start, end, skip) {
var done = remove_done(client, start, end, skip)
var i = start
var s = 0
for (; i <= end; i++) {
var key = {
ns: argv.namespace,
set: argv.set,
key: i
};
for (; i <= end; i++) {
var key = {
ns: argv.namespace,
set: argv.set,
key: i
}
if (skip !== 0 && ++s >= skip) {
s = 0;
done(null, key, true);
continue;
}
if (skip !== 0 && ++s >= skip) {
s = 0
done(null, key, true)
continue
}
client.remove(key, done);
}
client.remove(key, done)
}
}
remove_start(client, argv.start, argv.end, argv.skip);
});
remove_start(client, argv.start, argv.end, argv.skip)
})

@@ -1,275 +0,260 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* node range_validate --start <start> --end <end>
*
* Write and validate records with keys in given numeric range.
*
* Examples:
*
* Write and Validate records with keys in range 1-99:
*
* node range_validate --start 1 --end 99
*
* Write and Validate records with keys in range 900-1000
*
* node range_put --start 900
*
* Write and Validate a single record with key 99
*
* node range_validate --start 99 --end 99
*
******************************************************************************/
// *****************************************************************************
// node range_validate --start <start> --end <end>
//
// Write and validate records with keys in given numeric range.
//
// Examples:
//
// Write and Validate records with keys in range 1-99:
//
// node range_validate --start 1 --end 99
//
// Write and Validate records with keys in range 900-1000
//
// node range_put --start 900
//
// Write and Validate a single record with key 99
//
// node range_validate --start 99 --end 99
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options]")
.options({
help: {
boolean: true,
describe: "Display this message."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to secured cluster"
},
start: {
default: 1,
describe: "Start value for the key range."
},
end: {
default: 1000,
describe: "End value for the key range."
}
});
.usage('$0 [options]')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to secured cluster'
},
start: {
default: 1,
describe: 'Start value for the key range.'
},
end: {
default: 1000,
describe: 'End value for the key range.'
}
})
var argv = argp.argv;
var argv = argp.argv
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
aerospike.client(config).connect(function (err, client) {
if (err.code !== Status.AEROSPIKE_OK) {
console.error('Error: Aerospike server connection error. ', err.message)
process.exit(1)
}
//
// Perform the operation
//
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function put_done (client, start, end) {
var total = end - start + 1
var done = 0
var timeLabel = 'range_put @ ' + total
aerospike.client(config).connect(function(err, client) {
console.time(timeLabel)
if (err.code != Status.AEROSPIKE_OK) {
console.error("Error: Aerospike server connection error. ", err.message);
process.exit(1);
}
return function (err, key) {
switch (err.code) {
case Status.AEROSPIKE_OK:
console.log('OK - ', key)
break
default:
console.log('ERR - ', err, key)
}
//
// Perform the operation
//
function put_done(client, start, end) {
var total = end - start + 1;
var done = 0;
var timeLabel = "range_put @ " + total;
console.time(timeLabel);
return function(err, key) {
switch (err.code) {
case Status.AEROSPIKE_OK:
console.log("OK - ", key);
break;
default:
console.log("ERR - ", err, key);
}
done++;
if (done >= total) {
console.timeEnd(timeLabel);
console.log();
get_start(client, start, end);
}
}
done++
if (done >= total) {
console.timeEnd(timeLabel)
console.log()
get_start(client, start, end)
}
}
}
function put_start(client, start, end) {
var done = put_done(client, start, end);
var i = 0;
function put_start (client, start, end) {
var done = put_done(client, start, end)
var i = 0
for (i = start; i <= end; i++) {
var key = {
ns: argv.namespace,
set: argv.set,
key: i
};
for (i = start; i <= end; i++) {
var key = {
ns: argv.namespace,
set: argv.set,
key: i
}
var record = {
k: i,
s: "abc",
i: i * 1000 + 123,
b: new Buffer([0xa, 0xb, 0xc])
};
var record = {
k: i,
s: 'abc',
i: i * 1000 + 123,
b: new Buffer([0xa, 0xb, 0xc])
}
var metadata = {
ttl: 10000,
gen: 0
};
var metadata = {
ttl: 10000,
gen: 0
}
client.put(key, record, metadata, done);
}
client.put(key, record, metadata, done)
}
}
function get_done(client, start, end) {
var total = end - start + 1;
var done = 0;
var timeLabel = "range_get @ " + total;
function get_done (client, start, end) {
var total = end - start + 1
var done = 0
var timeLabel = 'range_get @ ' + total
console.time(timeLabel);
console.time(timeLabel)
return function(err, record, metadata, key) {
switch (err.code) {
case Status.AEROSPIKE_OK:
if (record.k != key.key) {
console.log("INVALID - ", key, metadata, record);
console.log(" - record.k != key.key");
} else if (record.i != record.k * 1000 + 123) {
console.log("INVALID - ", key, metadata, record);
console.log(" - record.i != record.k * 1000 + 123");
} else if (record.b[0] == 0xa && record.b[0] == 0xb && record.b[0] == 0xc) {
console.log("INVALID - ", key, metadata, record);
console.log(" - record.b != [0xa,0xb,0xc]");
} else {
console.log("VALID - ", key, metadata, record);
}
break;
default:
console.log("ERR - ", err, key);
}
return function (err, record, metadata, key) {
switch (err.code) {
case Status.AEROSPIKE_OK:
if (record.k !== key.key) {
console.log('INVALID - ', key, metadata, record)
console.log(' - record.k != key.key')
} else if (record.i !== record.k * 1000 + 123) {
console.log('INVALID - ', key, metadata, record)
console.log(' - record.i != record.k * 1000 + 123')
} else if (record.b[0] === 0xa && record.b[0] === 0xb && record.b[0] === 0xc) {
console.log('INVALID - ', key, metadata, record)
console.log(' - record.b != [0xa,0xb,0xc]')
} else {
console.log('VALID - ', key, metadata, record)
}
break
default:
console.log('ERR - ', err, key)
}
done++;
if (done >= total) {
console.timeEnd(timeLabel);
console.log();
client.close();
}
};
done++
if (done >= total) {
console.timeEnd(timeLabel)
console.log()
client.close()
}
}
}
function get_start(client, start, end) {
var done = get_done(client, start, end);
var i = 0;
function get_start (client, start, end) {
var done = get_done(client, start, end)
var i = 0
for (i = start; i <= end; i++) {
var key = {
ns: argv.namespace,
set: argv.set,
key: i
};
for (i = start; i <= end; i++) {
var key = {
ns: argv.namespace,
set: argv.set,
key: i
}
client.get(key, done);
}
client.get(key, done)
}
}
put_start(client, argv.start, argv.end);
});
put_start(client, argv.start, argv.end)
})

@@ -1,192 +0,181 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Remove a record.
*
******************************************************************************/
// *****************************************************************************
// Remove a record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var keyv = argv._.shift();
var argv = argp.argv
var keyv = argv._.shift()
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (!keyv) {
console.error("Error: Please provide a key for the operation");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a key for the operation')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Establish a connection to the cluster.
*
******************************************************************************/
// *****************************************************************************
// Establish a connection to the cluster.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function run (client) {
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv + iteration.current
}
function run(client) {
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv + iteration.current,
};
client.remove(key, function(err) {
if (isError(err)) {
process.exit(1);
} else {
!argv.quiet && console.log("OK.");
iteration.next(run, client);
}
});
client.remove(key, function (err) {
if (isError(err)) {
process.exit(1)
} else {
!argv.quiet && console.log('OK.')
iteration.next(run, client)
}
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error("Error: Not Found.");
return true;
default:
console.error("Error: " + err.message);
return true;
}
} else {
return false;
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error('Error: Not Found.')
return true
default:
console.error('Error: ' + err.message)
return true
}
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client);
}
});
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,195 +0,179 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Write a record.
*
******************************************************************************/
// *****************************************************************************
// Write a record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var client = aerospike.client;
var yargs = require('yargs');
var events = require('events');
var util = require('util');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var filter = aerospike.filter;
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
var Status = aerospike.status
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var argv = argp.argv
if (argv.help === true) {
argp.showHelp();
return;
argp.showHelp()
process.exit()
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
modlua: {
userPath: __dirname
},
modlua: {
userPath: __dirname
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Establish a connection to the cluster.
// *****************************************************************************
function run (client) {
var options = {
aggregationUDF: {
module: 'query',
funcname: 'sum_test_bin'
},
select: ['s', 'i']
}
var stream = client.query(argv.namespace, argv.set, options).execute()
/*******************************************************************************
*
* Establish a connection to the cluster.
*
******************************************************************************/
stream.on('data', function (rec) {
!argv.quiet && console.log(JSON.stringify(rec, null, ' '))
})
function run(client) {
stream.on('error', function (err) {
console.error(err)
process.exit(1)
})
var options = {
aggregationUDF: {
module: 'query',
funcname: 'sum_test_bin'
},
select: ['s', 'i'],
};
var stream = client.query(argv.namespace, argv.set, options).execute();
stream.on('data', function(rec) {
!argv.quiet && console.log(JSON.stringify(rec, null, ' '));
});
stream.on('error', function(err) {
console.error(err);
process.exit(1);
});
stream.on('end', function() {
iteration.next(run, client);
});
stream.on('end', function () {
iteration.next(run, client)
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
console.error("Error: " + err.message);
return true;
} else {
return false;
}
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
console.error('Error: ' + err.message)
return true
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client);
}
});
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,203 +0,183 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Write a record.
*
******************************************************************************/
// *****************************************************************************
// Write a record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var client = aerospike.client;
var yargs = require('yargs');
var events = require('events');
var util = require('util');
var sleep = require('sleep');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var sleep = require('sleep')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var filter = aerospike.filter;
var scanStatus = aerospike.scanStatus;
var Status = aerospike.status
var scanStatus = aerospike.scanStatus
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to secured cluster"
}
});
.usage('$0 [options]')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to secured cluster'
}
})
var argv = argp.argv;
var argv = argp.argv
if (argv.help === true) {
argp.showHelp();
return;
argp.showHelp()
process.exit()
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
modllua: {
userPath: __dirname
},
modllua: {
userPath: __dirname
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Establish a connection to the cluster.
// *****************************************************************************
aerospike.client(config).connect(function (err, client) {
if (err.code !== Status.AEROSPIKE_OK) {
console.error('Error: Aerospike server connection error. ', err.message)
process.exit(1)
}
//
// Perform the operation
// Fire up a background scan command and check the status of the scan
// every 1 second
//
/*******************************************************************************
*
* Establish a connection to the cluster.
*
******************************************************************************/
aerospike.client(config).connect(function(err, client) {
if (err.code != Status.AEROSPIKE_OK) {
console.error("Error: Aerospike server connection error. ", err.message);
process.exit(1);
var options = {
UDF: {
module: 'scan',
funcname: 'updateRecord'
}
}
//
// Perform the operation
// Fire up a background scan command and check the status of the scan
// every 1 second
//
var scanBackground = client.query(argv.namespace, argv.set, options)
var count = 0;
var scanStream = scanBackground.execute()
var options = {
UDF: {
module: 'scan',
funcname: 'updateRecord'
}
}
scanStream.on('error', function (err) {
console.log(err)
})
var scanBackground = client.query(argv.namespace, argv.set, options);
var scanStream = scanBackground.execute();
scanStream.on('error', function(err) {
console.log(err);
});
var checkStatus = function(scanJobStats) {
console.log(scanJobStats);
if (scanJobStats.status != scanStatus.COMPLETED) {
return false;
} else {
return true;
}
var checkStatus = function (scanJobStats) {
console.log(scanJobStats)
if (scanJobStats.status !== scanStatus.COMPLETED) {
return false
} else {
return true
}
}
var infoCallback = function(scanJobStats, scanId) {
if (!checkStatus(scanJobStats)) {
sleep.sleep(1)
scanBackground.Info(scanId, infoCallback);
}
var infoCallback = function (scanJobStats, scanId) {
if (!checkStatus(scanJobStats)) {
sleep.sleep(1)
scanBackground.Info(scanId, infoCallback)
}
}
var info = function(scanId) {
scanBackground.Info(scanId, infoCallback);
}
scanStream.on('end', info);
});
var info = function (scanId) {
scanBackground.Info(scanId, infoCallback)
}
scanStream.on('end', info)
})

@@ -1,168 +0,155 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Write a record.
*
******************************************************************************/
// *****************************************************************************
// Write a record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var client = aerospike.client;
var yargs = require('yargs');
var events = require('events');
var util = require('util');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var filter = aerospike.filter;
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
var Status = aerospike.status
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] scanId")
.options({
help: {
boolean: true,
describe: "Display this message."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to secured cluster"
}
});
.usage('$0 [options] scanId')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to secured cluster'
}
})
var argv = argp.argv;
var argv = argp.argv
if (argv.help === true) {
argp.showHelp();
return;
argp.showHelp()
process.exit()
}
var scanId = argv._.length === 1 ? argv._[0] : null;
var scanId = argv._.length === 1 ? argv._[0] : null
if (!scanId) {
console.error("Error: Please provide the scan Id to get the status of scan")
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide the scan Id to get the status of scan')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function run(client) {
client.query(argv.namespace, argv.set).Info(scanId, function(res) {
!argv.quiet && console.log(JSON.stringify(res, null, ' '));
});
function run (client) {
client.query(argv.namespace, argv.set).Info(scanId, function (res) {
!argv.quiet && console.log(JSON.stringify(res, null, ' '))
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
console.error("Error: " + err.message);
return true;
} else {
return false;
}
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
console.error('Error: ' + err.message)
return true
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client);
}
});
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,187 +0,172 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Write a record.
*
******************************************************************************/
// *****************************************************************************
// Write a record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var client = aerospike.client;
var yargs = require('yargs');
var events = require('events');
var util = require('util');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var scanPriority = aerospike.scanPriority;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var argv = argp.argv
if (argv.help === true) {
argp.showHelp();
return;
argp.showHelp()
process.exit()
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function run (client) {
var options = {
nobins: false,
concurrent: true
}
function run(client) {
var stream = client.query(argv.namespace, argv.set, options).execute()
var options = {
nobins: false,
concurrent: true
};
stream.on('data', function (rec) {
!argv.quiet && console.log(JSON.stringify(rec, null, ' '))
})
var stream = client.query(argv.namespace, argv.set, options).execute();
stream.on('error', function (err) {
console.error(err)
process.exit(1)
})
stream.on('data', function(rec) {
!argv.quiet && console.log(JSON.stringify(rec, null, ' '));
});
stream.on('error', function(err) {
console.error(err);
process.exit(1);
});
stream.on('end', function() {
iteration.next(run, client);
});
stream.on('end', function () {
iteration.next(run, client)
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
console.error("Error: " + err.message);
return true;
} else {
return false;
}
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
console.error('Error: ' + err.message)
return true
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client);
}
});
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,231 +0,219 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Select bins of a record.
*
******************************************************************************/
// *****************************************************************************
// Select bins of a record.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] key bin [bin ...]")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
'key': {
boolean: true,
default: true,
describe: "Display the record's key."
},
'metadata': {
boolean: true,
default: true,
describe: "Display the record's metadata."
},
'bins': {
boolean: true,
default: true,
describe: "Display the record's bins."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] key bin [bin ...]')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
'key': {
boolean: true,
default: true,
describe: "Display the record's key."
},
'metadata': {
boolean: true,
default: true,
describe: "Display the record's metadata."
},
'bins': {
boolean: true,
default: true,
describe: "Display the record's bins."
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var keyv = argv._.shift();
var bins = argv._;
var argv = argp.argv
var keyv = argv._.shift()
var bins = argv._
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (!keyv) {
console.error("Error: Please provide a key for the operation");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a key for the operation')
console.error()
argp.showHelp()
process.exit(1)
}
if (bins.length === 0) {
console.error("Error: Please provide one or more bins to select.");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide one or more bins to select.')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// authentication
user: argv.user,
password: argv.password
}
// authentication
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
function run (client) {
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv
}
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
client.select(key, bins, function (err, bins, metadata, key) {
if (isError(err)) {
process.exit(1)
} else {
var record = {}
function run(client) {
if (argv['key']) {
record.key = key
}
var key = {
ns: argv.namespace,
set: argv.set,
key: keyv,
};
if (argv['metadata']) {
record.metadata = metadata
}
client.select(key, bins, function(err, bins, metadata, key) {
if (isError(err)) {
process.exit(1);
} else {
var record = {};
if (argv['bins']) {
record.bins = bins
}
if (argv['key']) {
record.key = key;
}
!argv.quiet && console.log(JSON.stringify(record, null, ' '))
if (argv['metadata']) {
record.metadata = metadata;
}
if (argv['bins']) {
record.bins = bins;
}
!argv.quiet && console.log(JSON.stringify(record, null, ' '));
iteration.next(run, client);
}
});
iteration.next(run, client)
}
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error("Error: Not Found.");
return true;
default:
console.error("Error: " + err.message);
return true;
}
} else {
return false;
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
switch (err.code) {
case Status.AEROSPIKE_ERR_RECORD_NOT_FOUND:
console.error('Error: Not Found.')
return true
default:
console.error('Error: ' + err.message)
return true
}
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (isError(err)) {
process.exit(1);
} else {
run(client);
}
});
aerospike.client(config).connect(function (err, client) {
if (isError(err)) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,189 +0,178 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Get state information from the cluster or a single host.
*
******************************************************************************/
// *****************************************************************************
// Get state information from the cluster or a single host.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Language = aerospike.language;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] filepath")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] filepath')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var file = argv._.shift();
var argv = argp.argv
var file = argv._.shift()
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (!file) {
console.error("Error: Please provide a file to register.");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a file to register.')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// modlua userpath
modlua: {
userPath: __dirname
},
//modlua userpath
modlua: {
userPath: __dirname
},
user: argv.user,
password: argv.password
}
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function run(client) {
client.udfRegister(file, function(err) {
function run (client) {
client.udfRegister(file, function (err) {
if (isError(err)) {
process.exit(1)
} else {
client.udfRegisterWait(file, 1000, function (err) {
if (isError(err)) {
process.exit(1);
process.exit(1)
} else {
client.udfRegisterWait(file, 1000, function(err) {
if(isError(err)) {
process.exit(1);
} else {
!argv.quiet && console.log("UDF Registration Successful - %s", file);
}
});
!argv.quiet && console.log('UDF Registration Successful - %s', file)
}
});
})
}
})
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
console.error("Error: " + err.message);
return true;
} else {
return false;
}
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
console.error('Error: ' + err.message)
return true
} else {
return false
}
}
aerospike.client(config).connect(function(err, client) {
if (err && err.code != Status.AEROSPIKE_OK) {
process.exit(1);
} else {
run(client)
}
});
aerospike.client(config).connect(function (err, client) {
if (err && err.code !== Status.AEROSPIKE_OK) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,184 +0,173 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/*******************************************************************************
*
* Get state information from the cluster or a single host.
*
******************************************************************************/
// *****************************************************************************
// Get state information from the cluster or a single host.
// *****************************************************************************
var fs = require('fs');
var aerospike = require('aerospike');
var yargs = require('yargs');
var iteration = require('./iteration');
var fs = require('fs')
var aerospike = require('aerospike')
var yargs = require('yargs')
var iteration = require('./iteration')
var Policy = aerospike.policy;
var Status = aerospike.status;
var Language = aerospike.language;
var Status = aerospike.status
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var argp = yargs
.usage("$0 [options] module")
.options({
help: {
boolean: true,
describe: "Display this message."
},
quiet: {
alias: "q",
boolean: true,
describe: "Do not display content."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 10,
describe: "Timeout in milliseconds."
},
'log-level': {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
'log-file': {
default: undefined,
describe: "Path to a file send log messages to."
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default: null,
describe: "Username to connect to secured cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to secured cluster"
},
iterations: {
alias: "I",
default: 1,
describe: "Number of iterations"
},
});
.usage('$0 [options] module')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
quiet: {
alias: 'q',
boolean: true,
describe: 'Do not display content.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 10,
describe: 'Timeout in milliseconds.'
},
'log-level': {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
'log-file': {
default: undefined,
describe: 'Path to a file send log messages to.'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to secured cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to secured cluster'
},
iterations: {
alias: 'I',
default: 1,
describe: 'Number of iterations'
}
})
var argv = argp.argv;
var module = argv._.shift();
var argv = argp.argv
var module = argv._.shift()
if (argv.help === true) {
argp.showHelp();
process.exit(0);
argp.showHelp()
process.exit(0)
}
if (!module) {
console.error("Error: Please provide a UDF module name to remove.");
console.error();
argp.showHelp();
process.exit(1);
console.error('Error: Please provide a UDF module name to remove.')
console.error()
argp.showHelp()
process.exit(1)
}
iteration.setLimit(argv.iterations);
iteration.setLimit(argv.iterations)
/*******************************************************************************
*
* Configure the client.
*
******************************************************************************/
// *****************************************************************************
// Configure the client.
// *****************************************************************************
config = {
var config = {
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// the hosts to attempt to connect with.
hosts: [{
addr: argv.host,
port: argv.port
}],
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], 'a') : 2
},
// log configuration
log: {
level: argv['log-level'],
file: argv['log-file'] ? fs.openSync(argv['log-file'], "a") : 2
},
// default policies
policies: {
timeout: argv.timeout
},
// default policies
policies: {
timeout: argv.timeout
},
// modlua userpath
modlua: {
userPath: __dirname
},
//modlua userpath
modlua: {
userPath: __dirname
},
user: argv.user,
password: argv.password
}
user: argv.user,
password: argv.password,
};
// *****************************************************************************
// Perform the operation
// *****************************************************************************
/*******************************************************************************
*
* Perform the operation
*
******************************************************************************/
function run(client) {
client.udfRemove(module, function(err) {
if (isError(err)) {
process.exit(1);
} else {
!argv.quiet && console.log("OK.");
iteration.next(run, client);
}
});
}
function isError(err) {
if (err && err.code != Status.AEROSPIKE_OK) {
console.error("Error: " + err.message);
return true;
function run (client) {
client.udfRemove(module, function (err) {
if (isError(err)) {
process.exit(1)
} else {
return false;
!argv.quiet && console.log('OK.')
iteration.next(run, client)
}
})
}
aerospike.client(config).connect(function(err, client) {
if (err && err.code != Status.AEROSPIKE_OK) {
process.exit(1);
} else {
run(client)
}
});
function isError (err) {
if (err && err.code !== Status.AEROSPIKE_OK) {
console.error('Error: ' + err.message)
return true
} else {
return false
}
}
aerospike.client(config).connect(function (err, client) {
if (err && err.code !== Status.AEROSPIKE_OK) {
process.exit(1)
} else {
run(client)
}
})

@@ -1,23 +0,40 @@

var as = require('../build/Release/aerospike.node');
var LargeList = require('./llist.js');
var stream = require('stream');
var inherits = require('util').inherits;
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/******************************************************************************
* RecordStream - used for Scan and Query operations
*****************************************************************************/
'use strict'
function RecordStream() {}
var as = require('../build/Release/aerospike.node')
var LargeList = require('./llist.js')
var stream = require('stream')
var inherits = require('util').inherits
inherits(RecordStream, stream);
// ****************************************************************************
// RecordStream - used for Scan and Query operations
// ****************************************************************************
RecordStream.prototype.writable = false;
RecordStream.prototype.readable = true;
RecordStream.prototype._read = function() {};
function RecordStream () {}
/******************************************************************************
* Streaming Scan Operation
*****************************************************************************/
inherits(RecordStream, stream)
RecordStream.prototype.writable = false
RecordStream.prototype.readable = true
RecordStream.prototype._read = function () {}
// ****************************************************************************
// Streaming Scan Operation
// ****************************************************************************
// wrapper function around query_foreach function.

@@ -28,450 +45,439 @@ // This wrapper receives results from V8 layer and emits 'data' event

// When all the results are consumed it emits 'end' event.
execute = function() {
var execute = function execute () {
var self = this
var rs = new RecordStream()
var rs = new RecordStream();
var onResult = function onResult (res, key) {
rs.emit('data', res)
}
var self = this;
var onError = function onError (error) {
rs.emit('error', error)
}
var onEnd = function onEnd (end) {
if (!self.isQuery && self.hasUDF) {
self.scanId = end
rs.emit('end', end)
} else {
rs.emit('end')
}
}
var onResult = function(res, key) {
rs.emit('data', res);
};
if (self.isQuery) {
// it is a query request.
if (self.hasUDF) {
// query UDF is not supported currently.
throw new Error('Query UDF feature not supported')
} else {
// normal query and query aggregation is invoked here.
self.foreach(onResult, onError, onEnd)
}
} else {
// it is a scan request
if (self.hasUDF) {
// scan with a UDF - so background scan.
// background scan does not return records. callback for record is NULL.
self.foreach(null, onError, onEnd)
} else {
// it is a foreground scan or scan aggregation.
self.foreach(onResult, onError, onEnd)
}
}
return rs
}
var onError = function(error) {
rs.emit('error', error);
};
var Info = function info (scanId, callback) {
var self = this
self.queryInfo(scanId, callback)
}
var onEnd = function(end) {
if (!self.isQuery && self.hasUDF) {
self.scanId = end;
rs.emit('end', end);
} else {
rs.emit('end');
}
};
var query = function query (ns, set, options) {
if (typeof set !== 'string') {
set = ''
}
if (self.isQuery) // it is a query request.
{
if (self.hasUDF) {
// query UDF is not supported currently.
throw new Error("Query UDF feature not supported");
} else {
// normal query and query aggregation is invoked here.
self.foreach(onResult, onError, onEnd);
}
if (!options) {
options = null
}
} else // it is a scan request
{
if (self.hasUDF) // scan with a UDF - so background scan.
{
// background scan does not return records. So callback for record is NULL.
self.foreach(null, onError, onEnd);
} else // it is a foreground scan or scan aggregation.
{
self.foreach(onResult, onError, onEnd);
}
var queryObj = this.createQuery(ns, set, options)
var queryProto = Object.getPrototypeOf(queryObj)
}
return rs;
if (!queryProto.execute) {
queryProto.execute = execute
}
};
if (!queryProto.Info) {
queryProto.Info = Info
}
return queryObj
}
Info = function(scanId, callback) {
var self = this;
self.queryInfo(scanId, callback);
};
query = function(ns, set, options) {
if (typeof(set) != "string") {
set = '';
}
if(!options) {
options = null;
var createIntegerIndex = function createIntegerIndex (options, callback) {
var policy
var set
if (options && options.policy) {
policy = options.policy
}
if (options && options.set) {
set = options.set
}
this.indexCreate(
options.ns
, set
, options.bin
, options.index
, as.indexType.NUMERIC
, policy
, callback
)
}
var queryObj = this.createQuery(ns, set, options);
var queryProto = Object.getPrototypeOf(queryObj);
if( !queryProto.execute)
{
queryProto.execute = execute;
var createStringIndex = function createStringIndex (options, callback) {
var policy
var set
if (options && options.policy) {
policy = options.policy
}
if (options && options.set) {
set = options.set
}
this.indexCreate(
options.ns
, set
, options.bin
, options.index
, as.indexType.STRING
, policy
, callback
)
}
if( !queryProto.Info)
{
queryProto.Info = Info;
var createGeo2DSphereIndex =
function createGeo2DSphereIndex (options, callback) {
var policy
var set
if (options && options.policy) {
policy = options.policy
}
if (options && options.set) {
set = options.set
}
this.indexCreate(
options.ns
, set
, options.bin
, options.index
, as.indexType.GEO2DSPHERE
, policy
, callback
)
}
return queryObj;
};
var parseOperateArgs = function parseOperateArgs (args) {
var arglength = args.length
var options = {}
options.callback = args[arglength - 1]
if (arglength === 3) {
options.policy = undefined
options.metadata = undefined
} else if (arglength === 4) {
options.metadata = args[arglength - 2]
options.policy = undefined
} else if (arglength === 5) {
options.policy = args[arglength - 2]
options.metadata = args[arglength - 3]
}
createIntegerIndex = function(options, callback) {
var policy;
var set;
if (options && options.policy) {
policy = options.policy;
}
if (options && options.set) {
set = options.set;
}
this.indexCreate(
options.ns,
set,
options.bin,
options.index,
as.indexType.NUMERIC,
policy,
callback
);
};
return options
}
createStringIndex = function(options, callback) {
var policy;
var set;
if (options && options.policy) {
policy = options.policy;
}
if (options && options.set) {
set = options.set;
}
this.indexCreate(
options.ns,
set,
options.bin,
options.index,
as.indexType.STRING,
policy,
callback
);
};
var add = function add (key, bins, metadata, policy, callback) {
var options = parseOperateArgs(arguments)
// populate ops from bins argument here
var ops = []
var prop
createGeo2DSphereIndex = function(options, callback) {
var policy;
var set;
if (options && options.policy) {
policy = options.policy;
}
if (options && options.set) {
set = options.set;
}
this.indexCreate(
options.ns,
set,
options.bin,
options.index,
as.indexType.GEO2DSPHERE,
policy,
callback
);
};
for (prop in bins) {
ops.push(aerospike.operator.incr(prop, bins[prop]))
}
this.operate(key, ops, options.metadata, options.policy, options.callback)
}
parseOperateArgs = function(args) {
var arglength = args.length;
var append = function append (key, bins, metadata, policy, callback) {
var options = parseOperateArgs(arguments)
// populate ops from bins argument here
var ops = []
var prop
var options = {};
options.callback = args[arglength - 1];
for (prop in bins) {
ops.push(aerospike.operator.append(prop, bins[prop]))
}
this.operate(key, ops, options.metadata, options.policy, options.callback)
}
if (arglength == 3) {
options.policy = undefined;
options.metadata = undefined;
} else if (arglength == 4) {
options.metadata = args[arglength - 2];
options.policy = undefined;
} else if (arglength == 5) {
options.policy = args[arglength - 2];
options.metadata = args[arglength - 3];
}
var prepend = function prepend (key, bins, metadata, policy, callback) {
var options = parseOperateArgs(arguments)
// populate ops from bins argument here
var ops = []
var prop
return options;
};
for (prop in bins) {
ops.push(aerospike.operator.prepend(prop, bins[prop]))
}
add = function(key, bins, metadata, policy, callback) {
var options = parseOperateArgs(arguments);
this.operate(key, ops, options.metadata, options.policy, options.callback)
}
// populate ops from bins argument here
var ops = [];
// ****************************************************************************
// `aerospike` shim
// ****************************************************************************
for (var prop in bins) {
ops.push(aerospike.operator.incr(prop, bins[prop]));
}
this.operate(key, ops, options.metadata, options.policy, options.callback);
};
append = function(key, bins, metadata, policy, callback) {
var options = parseOperateArgs(arguments);
// populate ops from bins argument here
var ops = [];
for (var prop in bins) {
ops.push(aerospike.operator.append(prop, bins[prop]));
}
this.operate(key, ops, options.metadata, options.policy, options.callback);
};
prepend = function(key, bins, metadata, policy, callback) {
var options = parseOperateArgs(arguments);
// populate ops from bins argument here
var ops = [];
for (var prop in bins) {
ops.push(aerospike.operator.prepend(prop, bins[prop]));
}
this.operate(key, ops, options.metadata, options.policy, options.callback);
};
/******************************************************************************
* `aerospike` shim
*****************************************************************************/
var aerospike = {
// client: as.client,
key: as.key,
status: as.status,
policy: as.policy,
operations: as.operations,
cdt_operations: as.cdt_operations,
language: as.language,
log: as.log,
scanPriority: as.scanPriority,
predicates: as.predicates,
indexType: as.indexType,
scanStatus: as.scanStatus,
Double : as.Double
};
key: as.key,
status: as.status,
policy: as.policy,
language: as.language,
log: as.log,
scanPriority: as.scanPriority,
predicates: as.predicates,
indexType: as.indexType,
scanStatus: as.scanStatus,
Double: as.Double
}
aerospike.client = function(config) {
var client = as.client(config);
if (client === null) {
throw new Error("client object creation failed - null value returned");
}
var proto = Object.getPrototypeOf(client);
aerospike.client = function client (config) {
var client = as.client(config)
if (client === null) {
throw new Error('Client object creation failed - null value returned')
}
if (!proto.createQuery) {
proto.createQuery = proto.query;
proto.query = query;
}
var proto = Object.getPrototypeOf(client)
if (!proto.createQuery) {
proto.createQuery = proto.query
proto.query = query
}
if (!proto.createIntegerIndex) {
proto.createIntegerIndex = createIntegerIndex;
}
if (!proto.createIntegerIndex) {
proto.createIntegerIndex = createIntegerIndex
}
if (!proto.createStringIndex) {
proto.createStringIndex = createStringIndex;
}
if (!proto.createStringIndex) {
proto.createStringIndex = createStringIndex
}
if (!proto.createGeo2DSphereIndex) {
proto.createGeo2DSphereIndex = createGeo2DSphereIndex;
}
if (!proto.createGeo2DSphereIndex) {
proto.createGeo2DSphereIndex = createGeo2DSphereIndex
}
if (!proto.LargeList) {
proto.LargeList = LargeList;
}
if (!proto.LargeList) {
proto.LargeList = LargeList
}
if (!proto.add) {
proto.add = add;
}
if (!proto.add) {
proto.add = add
}
if (!proto.append) {
proto.append = append;
}
if (!proto.append) {
proto.append = append
}
if (!proto.prepend) {
proto.prepend = prepend;
}
if (!proto.prepend) {
proto.prepend = prepend
}
return client;
};
return client
}
var populate_op = function(op, bin, value) {
var obj = {};
obj.operation = op;
obj.bin = bin;
obj.value = value;
return obj;
};
var populateOp = function populateOp (op, bin, props) {
var obj = {}
obj.operation = op
obj.bin = bin
for (var prop in props) {
obj[prop] = props[prop]
}
return obj
}
var populate_cdt_op = function(op, bin, props) {
var obj = {};
obj.cdt_operation = op;
obj.bin = bin;
var populateCdtOp = function populateCdtOp (op, bin, props) {
var obj = {}
obj.cdtOperation = op
obj.bin = bin
for (var prop in props) {
obj[prop] = props[prop];
};
return obj;
obj[prop] = props[prop]
}
return obj
}
var read_op = function(args) {
return populate_op(as.operations.READ, arguments[0]);
};
var readOp = function read (bin) {
return populateOp(as.operations.READ, bin)
}
var write_op = function(args) {
return populate_op(as.operations.WRITE, arguments[0], arguments[1]);
};
var writeOp = function write (bin, value) {
return populateOp(as.operations.WRITE, bin, {value: value})
}
var incr_op = function(args) {
return populate_op(as.operations.INCR, arguments[0], arguments[1]);
};
var incrOp = function incr (bin, value) {
return populateOp(as.operations.INCR, bin, {value: value})
}
var append_op = function(args) {
return populate_op(as.operations.APPEND, arguments[0], arguments[1]);
};
var appendOp = function append (bin, value) {
return populateOp(as.operations.APPEND, bin, {value: value})
}
var prepend_op = function(args) {
return populate_op(as.operations.PREPEND, arguments[0], arguments[1]);
};
var prependOp = function prepend (bin, value) {
return populateOp(as.operations.PREPEND, bin, {value: value})
}
var touch_op = function(args) {
var obj = {};
obj.operation = as.operations.TOUCH;
obj.ttl = arguments[0];
return obj;
};
var touchOp = function touch (bin, ttl) {
return populateOp(as.operations.TOUCH, bin, {ttl: ttl})
}
var list_append_op = function(bin, value) {
return populate_cdt_op(as.cdt_operations.LIST_APPEND, bin, {value: value});
};
var listAppendOp = function listAppend (bin, value) {
return populateCdtOp(as.cdt_operations.LIST_APPEND, bin, {value: value})
}
var list_append_items_op = function(bin, list) {
return populate_cdt_op(as.cdt_operations.LIST_APPEND_ITEMS, bin, {list: list});
};
var listAppendItemsOp = function listAppendItems (bin, list) {
return populateCdtOp(as.cdt_operations.LIST_APPEND_ITEMS, bin,
{list: list})
}
var list_insert_op = function(bin, index, value) {
return populate_cdt_op(as.cdt_operations.LIST_INSERT, bin, {index: index, value: value});
};
var listInsertOp = function listInsert (bin, index, value) {
return populateCdtOp(as.cdt_operations.LIST_INSERT, bin,
{index: index, value: value})
}
var list_insert_items_op = function(args) {
return { cdt_operation: as.cdt_operations.LIST_INSERT_ITEMS, bin: arguments[0], index: arguments[1], list: arguments[2] };
};
var listInsertItemsOp = function listInsertItems (bin, index, list) {
return populateCdtOp(as.cdt_operations.LIST_INSERT_ITEMS, bin,
{index: index, list: list})
}
var list_pop_op = function(args) {
return { cdt_operation: as.cdt_operations.LIST_POP, bin: arguments[0], index: arguments[1] };
};
var listPopOp = function listPop (bin, index) {
return populateCdtOp(as.cdt_operations.LIST_POP, bin, {index: index})
}
var list_pop_range_op = function(args) {
return { cdt_operation: as.cdt_operations.LIST_POP_RANGE, bin: arguments[0], index: arguments[1], count: arguments[2] };
};
var listPopRangeOp = function listPopRange (bin, index, count) {
return populateCdtOp(as.cdt_operations.LIST_POP_RANGE, bin,
{index: index, count: count})
}
var list_remove_op = function(bin, index) {
return populate_cdt_op(as.cdt_operations.LIST_REMOVE, bin, {index: index});
};
var listRemoveOp = function listRemove (bin, index) {
return populateCdtOp(as.cdt_operations.LIST_REMOVE, bin, {index: index})
}
var list_remove_range_op = function(args) {
return { cdt_operation: as.cdt_operations.LIST_REMOVE_RANGE, bin: arguments[0], index: arguments[1], count: arguments[2] };
};
var listRemoveRangeOp = function listRemoveRange (bin, index, count) {
return populateCdtOp(as.cdt_operations.LIST_REMOVE_RANGE, bin,
{index: index, count: count})
}
var list_clear_op = function(args) {
return { cdt_operation: as.cdt_operations.LIST_CLEAR, bin: arguments[0] };
};
var listClearOp = function listClear (bin) {
return populateCdtOp(as.cdt_operations.LIST_CLEAR, bin)
}
var list_set_op = function(bin, index, value) {
return populate_cdt_op(as.cdt_operations.LIST_SET, bin, {index: index, value: value});
};
var listSetOp = function listSet (bin, index, value) {
return populateCdtOp(as.cdt_operations.LIST_SET, bin,
{index: index, value: value})
}
var list_trim_op = function(args) {
return { cdt_operation: as.cdt_operations.LIST_TRIM, bin: arguments[0], index: arguments[1], count: arguments[2] };
};
var listTrimOp = function listTrim (bin, index, count) {
return populateCdtOp(as.cdt_operations.LIST_TRIM, bin,
{index: index, count: count})
}
var list_get_op = function(bin, index) {
return populate_cdt_op(as.cdt_operations.LIST_GET, bin, {index: index});
};
var listGetOp = function listGet (bin, index) {
return populateCdtOp(as.cdt_operations.LIST_GET, bin, {index: index})
}
var list_get_range_op = function(args) {
return { cdt_operation: as.cdt_operations.LIST_GET_RANGE, bin: arguments[0], index: arguments[1], count: arguments[2] };
};
var listGetRangeOp = function listGetRange (bin, index, count) {
return populateCdtOp(as.cdt_operations.LIST_GET_RANGE, bin,
{index: index, count: count})
}
var list_size_op = function(args) {
return { cdt_operation: as.cdt_operations.LIST_SIZE, bin: arguments[0] };
};
var listSizeOp = function listSize (bin) {
return populateCdtOp(as.cdt_operations.LIST_SIZE, bin)
}
aerospike.operator = {
read: read_op,
write: write_op,
incr: incr_op,
append: append_op,
prepend: prepend_op,
touch: touch_op,
listAppend: list_append_op,
listAppendItems: list_append_items_op,
listInsert: list_insert_op,
listInsertItems: list_insert_items_op,
listPop: list_pop_op,
listPopRange: list_pop_range_op,
listRemove: list_remove_op,
listRemoveRange: list_remove_range_op,
listClear: list_clear_op,
listSet: list_set_op,
listTrim: list_trim_op,
listGet: list_get_op,
listGetRange: list_get_range_op,
listSize: list_size_op
};
read: readOp,
write: writeOp,
incr: incrOp,
append: appendOp,
prepend: prependOp,
touch: touchOp,
listAppend: listAppendOp,
listAppendItems: listAppendItemsOp,
listInsert: listInsertOp,
listInsertItems: listInsertItemsOp,
listPop: listPopOp,
listPopRange: listPopRangeOp,
listRemove: listRemoveOp,
listRemoveRange: listRemoveRangeOp,
listClear: listClearOp,
listSet: listSetOp,
listTrim: listTrimOp,
listGet: listGetOp,
listGetRange: listGetRangeOp,
listSize: listSizeOp
}
var equal_filter = function(args) {
var obj = {};
obj.predicate = as.predicates.EQUAL;
if (typeof(arguments[1]) == "number") {
obj.type = as.indexType.NUMERIC;
} else if (typeof(arguments[1]) == "string") {
obj.type = as.indexType.STRING;
}
obj.bin = arguments[0];
obj.val = arguments[1];
return obj;
};
var equalFilter = function equalFilter (args) {
var obj = {}
obj.predicate = as.predicates.EQUAL
if (typeof arguments[1] === 'number') {
obj.type = as.indexType.NUMERIC
} else if (typeof arguments[1] === 'string') {
obj.type = as.indexType.STRING
}
obj.bin = arguments[0]
obj.val = arguments[1]
return obj
}
var range_filter = function(args) {
var obj = {};
obj.predicate = as.predicates.RANGE;
obj.type = as.indexType.NUMERIC;
obj.bin = arguments[0];
obj.min = arguments[1];
obj.max = arguments[2];
return obj;
};
var rangeFilter = function rangeFilter (args) {
var obj = {}
obj.predicate = as.predicates.RANGE
obj.type = as.indexType.NUMERIC
obj.bin = arguments[0]
obj.min = arguments[1]
obj.max = arguments[2]
return obj
}
var geo_within_filter = function(args) {
var obj = {};
obj.predicate = as.predicates.RANGE;
obj.type = as.indexType.GEO2DSPHERE;
obj.bin = arguments[0];
obj.val = arguments[1];
return obj;
};
var geoWithinFilter = function geoWithinFilter (args) {
var obj = {}
obj.predicate = as.predicates.RANGE
obj.type = as.indexType.GEO2DSPHERE
obj.bin = arguments[0]
obj.val = arguments[1]
return obj
}
var geo_contains_filter = function(args) {
var obj = {};
obj.predicate = as.predicates.RANGE;
obj.type = as.indexType.GEO2DSPHERE;
obj.bin = arguments[0];
obj.val = arguments[1];
return obj;
};
var geoContainsFilter = function geoContainsFilter (args) {
var obj = {}
obj.predicate = as.predicates.RANGE
obj.type = as.indexType.GEO2DSPHERE
obj.bin = arguments[0]
obj.val = arguments[1]
return obj
}
aerospike.filter = {
equal: equal_filter,
range: range_filter,
geoWithin: geo_within_filter,
geoContains: geo_contains_filter
};
equal: equalFilter,
range: rangeFilter,
geoWithin: geoWithinFilter,
geoContains: geoContainsFilter
}
function GeoJSON(strval) {
if (this instanceof GeoJSON) {
this.str = strval
} else {
return new GeoJSON(strval);
}
};
aerospike.GeoJSON = GeoJSON;
function GeoJSON (strval) {
if (this instanceof GeoJSON) {
this.str = strval
} else {
return new GeoJSON(strval)
}
}
aerospike.GeoJSON = GeoJSON
module.exports = aerospike;
module.exports = aerospike

@@ -1,35 +0,67 @@

function checkArgs(args, expArgLength) {
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
// number of arguments passed to the given function.
var arglength = args.length;
const STRACE_RE = /at ([\w.]+) \((.*):(\d+):(\d+)\)/ // pattern for parsing a line of a stack trace
//last argument must always be a callback.
//error if it is not callback type.
if (typeof args[arglength - 1] != "function") {
throw new Error("Callback function must be passed for this async API");
}
// Creates a new aerospike.error object with the given error code and message.
// The function name, file name and line number for the error are set
// automatically by inspecting the current stack trace and looking for the last
// LargeList function call on it.
function llistError (code, message) {
var error = { code: code, message: message }
var strace = new Error().stack.split('\n')
while (strace.length > 0) {
var line = strace.shift()
if (line.match(/LargeList\.instance/)) {
var match = line.match(STRACE_RE)
if (match) {
error.func = match[1].split('.').pop()
error.file = match[2]
error.line = match[3]
}
break
}
}
return error
}
//for functions requiring fixed number of arguments
//this check is performed.
//If function does not have fixed number of arguments
//this check is skipped.
if (typeof expArgLength != "undefined") {
if (arglength != expArgLength) {
var err = (new Error()).stack.split("\n")[3];
var error = {};
error.func = err.split(".")[2].split("(")[0];
error.file = err.split("(")[1].split(":")[0];
error.line = err.split(":")[1];
error.code = 2;
error.message = "Number of arguments passed - Invalid";
var callback = args[arglength - 1];
callback(error, undefined);
return -1;
}
}
function checkArgs (args, expArgLength) {
// number of arguments passed to the given function.
var arglength = args.length
return 0;
// last argument must always be a callback.
// error if it is not callback type.
if (typeof args[arglength - 1] !== 'function') {
throw new Error('Callback function must be passed for this async API')
}
// for functions requiring fixed number of arguments
// this check is performed.
// If function does not have fixed number of arguments
// this check is skipped.
if (typeof expArgLength !== 'undefined') {
if (arglength !== expArgLength) {
var error = llistError(2, 'Invalid number of arguments')
var callback = args[arglength - 1]
callback(error, undefined)
return -1
}
}
return 0
}
// Generic function to execute any LDT function.

@@ -43,129 +75,123 @@ // Invokes udf execute with the corresponding LDT

// Position of the UDF arguments is passed to parse effectively.
var executeLDTFunction = function(ldtFunc, ldtargs, arglength, udfPosition) {
if (typeof udfPosition == 'undefined') {
udfPosition = -1;
}
var executeLDTFunction = function (ldtFunc, ldtargs, arglength, udfPosition) {
if (typeof udfPosition === 'undefined') {
udfPosition = -1
}
if (checkArgs(ldtargs, arglength) !== 0) {
return -1;
}
var udfargs = [this.binName];
for (var i = 0; i < arglength - 1; i++) {
if (udfPosition == i) {
udfargs.push(ldtargs[i].module);
udfargs.push(ldtargs[i].funcname);
udfargs.push(ldtargs[i].args);
} else {
udfargs.push(ldtargs[i]);
}
}
udfargs.push(this.createModule);
var udf = {
module: this.module,
funcname: ldtFunc,
args: udfargs
};
this.client.execute(this.key, udf, this.writePolicy, ldtargs[arglength - 1]);
};
if (checkArgs(ldtargs, arglength) !== 0) {
return -1
}
var udfargs = [this.binName]
for (var i = 0; i < arglength - 1; i++) {
if (udfPosition === i) {
udfargs.push(ldtargs[i].module)
udfargs.push(ldtargs[i].funcname)
udfargs.push(ldtargs[i].args)
} else {
udfargs.push(ldtargs[i])
}
}
udfargs.push(this.createModule)
var udf = {
module: this.module,
funcname: ldtFunc,
args: udfargs
}
this.client.execute(this.key, udf, this.writePolicy, ldtargs[arglength - 1])
}
var LargeList = function LargeList (key, binName, writePolicy, createModule) {
var instance = {}
instance.client = this
instance.key = key
instance.writePolicy = writePolicy
instance.binName = binName
instance.module = 'llist'
instance.createModule = createModule
instance.executeLDTFunction = executeLDTFunction
LargeList = function(key, binName, writePolicy, createModule) {
// Handle all the variations of add function.
// 1. val can be a single value
// 2. val can be an array of values
instance.add = function (val, callback) {
if (Array.isArray(arguments[0])) {
this.executeLDTFunction('add_all', arguments, 2)
} else {
this.executeLDTFunction('add', arguments, 2)
}
}
LargeList.client = this;
LargeList.key = key;
LargeList.writePolicy = writePolicy;
LargeList.binName = binName;
LargeList.module = "llist";
LargeList.createModule = createModule;
LargeList.executeLDTFunction = executeLDTFunction;
// Handle all the variations of update.
// same as add variations
instance.update = function (val, callback) {
if (Array.isArray(arguments[0])) {
this.executeLDTFunction('update_all', arguments, 2)
} else {
this.executeLDTFunction('update', arguments, 2)
}
}
// Handle all the variations of add function.
// 1. val can be a single value
// 2. val can be an array of values
LargeList.add = function(val, callback) {
if (Array.isArray(arguments[0])) {
this.executeLDTFunction("add_all", arguments, 2);
} else {
this.executeLDTFunction("add", arguments, 2);
}
// Handle all the variations of remove.
// Same as add variations and the following
instance.remove = function (val, callback) {
if (Array.isArray(val)) {
this.executeLDTFunction('remove_all', arguments, 2)
} else {
this.executeLDTFunction('remove', arguments, 2)
}
}
};
// Can pass a range to remove the values within the range (inclusive).
instance.removeRange = function (valBegin, valEnd, callback) {
this.executeLDTFunction('remove_range', arguments, 3)
}
// Handle all the variations of update.
// same as add variations
LargeList.update = function(val, callback) {
if (Array.isArray(arguments[0])) {
this.executeLDTFunction("update_all", arguments, 2);
} else {
this.executeLDTFunction("update", arguments, 2);
}
};
instance.find = function find (val, filterArgs, callback) {
var arglength = arguments.length
if (arglength === 2) {
this.executeLDTFunction('find', arguments, 2)
} else if (arglength === 3) {
this.executeLDTFunction('find', arguments, 3, 1)
} else {
return
}
}
// Handle all the variations of remove.
// Same as add variations and the following
LargeList.remove = function(val, callback) {
// apply filter - pass all elements through a filter and return all that qualify.
instance.filter = function (filterArgs, callback) {
this.executeLDTFunction('filter', arguments, 1, 0)
}
instance.findRange = function (valBegin, valEnd, filterArgs, callback) {
var arglength = arguments.length
if (Array.isArray(val)) {
this.executeLDTFunction("remove_all", arguments, 2);
} else {
this.executeLDTFunction("remove", arguments, 2);
}
};
if (arglength === 3) {
this.executeLDTFunction('range', arguments, 3)
} else if (arglength === 4) {
this.executeLDTFunction('range', arguments, 4, 2)
} else {
return
}
}
// Can pass a range to remove the values within the range (inclusive).
LargeList.removeRange = function(valBegin, valEnd, callback) {
instance.scan = function (callback) {
this.executeLDTFunction('scan', arguments, 1)
}
this.executeLDTFunction("remove_range", arguments, 3);
};
instance.destroy = function (callback) {
this.executeLDTFunction('destroy', arguments, 1)
}
LargeList.find = function(val, filterArgs, callback) {
var arglength = arguments.length;
instance.size = function (callback) {
this.executeLDTFunction('size', arguments, 1)
}
if (arglength == 2) {
this.executeLDTFunction("find", arguments, 2);
} else if (arglength == 3) {
this.executeLDTFunction("find", arguments, 3, 1);
} else {
return;
}
instance.getConfig = function (callback) {
this.executeLDTFunction('config', arguments, 1)
}
};
return instance
}
// apply filter - pass all elements through a filter and return all that qualify.
LargeList.filter = function(filterArgs, callback) {
this.executeLDTFunction("filter", arguments, 1, 0);
};
LargeList.findRange = function(valBegin, valEnd, filterArgs, callback) {
var arglength = arguments.length;
if (arglength == 3) {
this.executeLDTFunction("range", arguments, 3);
} else if (arglength == 4) {
this.executeLDTFunction("range", arguments, 4, 2);
} else {
return;
}
};
LargeList.scan = function(callback) {
this.executeLDTFunction("scan", arguments, 1);
};
LargeList.destroy = function(callback) {
this.executeLDTFunction("destroy", arguments, 1);
};
LargeList.size = function(callback) {
this.executeLDTFunction("size", arguments, 1);
};
LargeList.getConfig = function(callback) {
this.executeLDTFunction("config", arguments, 1);
};
return LargeList;
};
module.exports = LargeList;
module.exports = LargeList
{
"name": "aerospike",
"version": "1.0.54",
"version": "1.0.55",
"description": "Aerospike Client Library",

@@ -28,3 +28,3 @@ "tags": [

"scripts": {
"test": "node_modules/mocha/bin/mocha -R spec"
"test": "standard && mocha"
},

@@ -35,7 +35,8 @@ "dependencies": {

"devDependencies": {
"expect.js": "0.2.x",
"mocha": ">0",
"expect.js": "0.2.x",
"superagent": "0.15.x",
"yargs": "1.2.1"
"yargs": "1.2.1",
"standard": "^5.4.1"
}
}

@@ -0,1 +1,3 @@

[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
# Aerospike Node.js Client

@@ -5,3 +7,3 @@

This module is compatible with Node.js v0.10.x, v0.12.x, Iojs, v4.*, v5.x and supports the following operating systems:
This module is compatible with Node.js v0.10.x, v0.12.x, io.js, v4.x, v5.x and supports the following operating systems:
CentOS/RHEL 6.x, Debian 6+, Ubuntu 12.04+, Fedora20, Fedora21, Fedora 22, Linuxmint and Mac OS X.

@@ -13,3 +15,3 @@

- [Primer on Node.js Modules](#Primer-on-Node.js-Modules)
- [Installing via NPM Registry](#Installing-via-NPM-Registry)
- [Installing via npm Registry](#Installing-via-npm-Registry)
- [Installing via Git Repository](#Installing-via-Git-Repository)

@@ -204,6 +206,6 @@ - [C Client Resolution](#C-Client-Resolution)

<a name="Installing-via-NPM-Registry"></a>
### Installing via NPM Registry
<a name="Installing-via-npm-Registry"></a>
### Installing via npm Registry
Installing via NPM Registry is pretty simple and most common install method, as
Installing via npm Registry is pretty simple and most common install method, as
it only involves a single step.

@@ -232,3 +234,3 @@

Installing via Git Repository is slightly different from installing via NPM
Installing via Git Repository is slightly different from installing via npm
registry, in that you will be referencing the module by path, rather than name.

@@ -287,3 +289,3 @@

Aerospike. To install with Aggregation enabled:
$ USELUA=1 npm install

@@ -290,0 +292,0 @@

@@ -1,168 +0,159 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before, after */
// we want to test the built aerospike module
var aerospike = require('../build/Release/aerospike');
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var aerospike = require('../build/Release/aerospike')
var options = require('./util/options')
var expect = require('expect.js')
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var valgen = require('./generators/value');
var keygen = require('./generators/key')
var metagen = require('./generators/metadata')
var recgen = require('./generators/record')
var putgen = require('./generators/put')
var valgen = require('./generators/value')
var status = aerospike.status;
var policy = aerospike.policy;
var status = aerospike.status
describe('client.batchExists()', function() {
describe('client.batchExists()', function () {
var config = options.getConfig()
var client = aerospike.client(config)
var config = options.getConfig();
var client = aerospike.client(config);
before(function (done) {
client.connect(function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
before(function(done) {
client.connect(function(err){
done();
});
});
after(function (done) {
client.close()
client = null
done()
})
after(function(done) {
client.close();
client = null;
done();
});
it('should successfully find 10 records', function (done) {
this.timeout(3000)
// number of records
var nrecords = 10
it('should successfully find 10 records', function(done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/batch_exists/10/', random: false})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()})
this.timeout(3000);
// number of records
var nrecords = 10;
// writer using generators
// callback provides an array of written keys
putgen.put(client, nrecords, kgen, rgen, mgen, function (written) {
var keys = Object.keys(written).map(function (key) {
return written[key].key
})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/batch_exists/10/", random: false});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()});
var len = keys.length
expect(len).to.equal(nrecords)
// writer using generators
// callback provides an array of written keys
putgen.put(client, nrecords, kgen, rgen, mgen, function(written) {
client.batchExists(keys, function (err, results) {
var result
var j
var keys = Object.keys(written).map(function(key){
return written[key].key;
});
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(results.length).to.equal(len)
var len = keys.length;
expect(len).to.equal(nrecords);
for (j = 0; j < results.length; j++) {
result = results[j]
expect(result.status).to.equal(status.AEROSPIKE_OK)
if (j === nrecords - 1) {
done()
}
}
})
})
})
client.batchExists(keys, function(err, results) {
it('should fail finding 10 records', function (done) {
this.timeout(3000)
// number of records
var nrecords = 10
var result;
var j;
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/batch_exists/fail/', random: false})
var keys = keygen.range(kgen, nrecords)
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(results.length).to.equal(len);
client.batchExists(keys, function (err, results) {
var result
var j
for ( j = 0; j < results.length; j++) {
result = results[j];
expect(result.status).to.equal(status.AEROSPIKE_OK);
if( j == nrecords-1) {
done();
}
}
});
});
});
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(results.length).to.equal(nrecords)
it('should fail finding 10 records', function(done) {
for (j = 0; j < results.length; j++) {
result = results[j]
// This if-else check is introduced to handle test failures
// in backward compatibility issues. Should be removed when an official release
// of C client is done, with error code changes.
if (result.status !== 602) {
expect(result.status).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND)
} else {
expect(result.status).to.equal(602)
}
}
this.timeout(3000);
// number of records
var nrecords = 10;
done()
})
})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/batch_exists/fail/", random: false});
var keys = keygen.range(kgen, nrecords);
it('should successfully find 1000 records', function (done) {
this.timeout(5000)
// number of records
var nrecords = 1000
client.batchExists(keys, function(err, results) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/batch_exists/1000/', random: false})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()})
var result;
var j;
// writer using generators
// callback provides an object of written records, where the
// keys of the object are the record's keys.
putgen.put(client, nrecords, kgen, rgen, mgen, function (written) {
var keys = Object.keys(written).map(function (key) {
return written[key].key
})
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(results.length).to.equal(nrecords);
var len = keys.length
expect(len).to.equal(nrecords)
for ( j = 0; j < results.length; j++) {
result = results[j];
// This if-else check is introduced to handle test failures
// in backward compatibility issues. Should be removed when an official release
// of C client is done, with error code changes.
if(result.status != 602) {
expect(result.status).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND);
} else {
expect(result.status).to.equal(602);
}
}
client.batchExists(keys, function (err, results) {
var result
var j
done();
});
});
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(results.length).to.equal(len)
it('should successfully find 1000 records', function(done) {
for (j = 0; j < results.length; j++) {
result = results[j]
expect(result.status).to.equal(status.AEROSPIKE_OK)
}
this.timeout(5000);
// number of records
var nrecords = 1000;
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/batch_exists/1000/", random: false});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()});
// writer using generators
// callback provides an object of written records, where the
// keys of the object are the record's keys.
putgen.put(client, nrecords, kgen, rgen, mgen, function(written) {
var keys = Object.keys(written).map(function(key){
return written[key].key;
});
var len = keys.length;
expect(len).to.equal(nrecords);
client.batchExists(keys, function(err, results) {
var result;
var j;
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(results.length).to.equal(len);
for ( j = 0; j < results.length; j++) {
result = results[j];
expect(result.status).to.equal(status.AEROSPIKE_OK);
}
done();
});
});
});
});
done()
})
})
})
})

@@ -1,180 +0,170 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before, after */
// we want to test the built aerospike module
var aerospike = require('../build/Release/aerospike');
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var aerospike = require('../build/Release/aerospike')
var options = require('./util/options')
var expect = require('expect.js')
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var valgen = require('./generators/value');
var keygen = require('./generators/key')
var metagen = require('./generators/metadata')
var recgen = require('./generators/record')
var putgen = require('./generators/put')
var valgen = require('./generators/value')
var status = aerospike.status;
var policy = aerospike.policy;
var status = aerospike.status
describe('client.batchGet()', function() {
describe('client.batchGet()', function () {
var config = options.getConfig()
var client = aerospike.client(config)
var config = options.getConfig();
var client = aerospike.client(config);
before(function (done) {
client.connect(function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
before(function(done) {
client.connect(function(err) {
done();
});
});
after(function (done) {
client.close()
client = null
done()
})
after(function(done) {
client.close();
client = null;
done();
});
it('should successfully read 10 records', function (done) {
// number of records
var nrecords = 10
it('should successfully read 10 records', function(done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/batch_get/' + nrecords + '/', random: false})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()})
// number of records
var nrecords = 10;
// writer using generators
// callback provides an object of written records, where the
// keys of the object are the record's keys.
putgen.put(client, nrecords, kgen, rgen, mgen, function (written) {
var keys = Object.keys(written).map(function (key) {
return written[key].key
})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/batch_get/10/", random: false});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()});
var len = keys.length
expect(len).to.equal(nrecords)
// writer using generators
// callback provides an object of written records, where the
// keys of the object are the record's keys.
putgen.put(client, 10, kgen, rgen, mgen, function(written) {
client.batchGet(keys, function (err, results) {
var result
var j
var keys = Object.keys(written).map(function(key) {
return written[key].key;
});
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(results.length).to.equal(len)
var len = keys.length;
expect(len).to.equal(nrecords);
for (j = 0; j < results.length; j++) {
result = results[j]
client.batchGet(keys, function(err, results) {
expect(result.status).to.equal(status.AEROSPIKE_OK)
var result;
var j;
var record = result.record
var _record = written[result.key.key].record
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(results.length).to.equal(len);
expect(record).to.eql(_record)
}
for ( j = 0; j < results.length; j++) {
result = results[j];
done()
})
})
})
expect(result.status).to.equal(status.AEROSPIKE_OK);
it('should fail reading 10 records', function (done) {
// number of records
var nrecords = 10
var record = result.record;
var _record = written[result.key.key].record;
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/batch_get/fail/', random: false})
expect(record).to.eql(_record);
}
// values
var keys = keygen.range(kgen, nrecords)
done();
});
});
});
// writer using generators
// callback provides an object of written records, where the
// keys of the object are the record's keys.
client.batchGet(keys, function (err, results) {
var result
var j
it('should fail reading 10 records', function(done) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(results.length).to.equal(nrecords)
// number of records
var nrecords = 10;
for (j = 0; j < results.length; j++) {
result = results[j]
if (result.status !== 602) {
expect(result.status).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND)
} else {
expect(result.status).to.equal(602)
}
}
done()
})
})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/batch_get/fail/", random: false});
it('should successfully read 1000 records', function (done) {
// this high for low-end hosts
this.timeout(5000)
// values
var keys = keygen.range(kgen, 10);
// number of records
var nrecords = 1000
// writer using generators
// callback provides an object of written records, where the
// keys of the object are the record's keys.
client.batchGet(keys, function(err, results) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/batch_get/1000/', random: false})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()})
var result;
var j;
// writer using generators
// callback provides an object of written records, where the
// keys of the object are the record's keys.
putgen.put(client, nrecords, kgen, rgen, mgen, function (written) {
var keys = Object.keys(written).map(function (key) {
return written[key].key
})
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(results.length).to.equal(10);
var len = keys.length
expect(len).to.equal(nrecords)
for ( j = 0; j < results.length; j++) {
result = results[j];
if(result.status != 602) {
expect(result.status).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND);
}
else {
expect(result.status).to.equal(602);
}
}
done();
});
});
client.batchGet(keys, function (err, results) {
var result
var j
it('should successfully read 1000 records', function(done) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(results.length).to.equal(len)
// this high for low-end hosts
this.timeout(5000);
for (j = 0; j < results.length; j++) {
result = results[j]
expect(result.status).to.equal(status.AEROSPIKE_OK)
// number of records
var nrecords = 1000;
var record = result.record
var _record = written[result.key.key].record
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/batch_get/1000/", random: false});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()});
// writer using generators
// callback provides an object of written records, where the
// keys of the object are the record's keys.
putgen.put(client, nrecords, kgen, rgen, mgen, function(written) {
var keys = Object.keys(written).map(function(key) {
return written[key].key;
});
var len = keys.length;
expect(len).to.equal(nrecords);
client.batchGet(keys, function(err, results) {
var result;
var j;
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(results.length).to.equal(len);
for ( j = 0; j < results.length; j++) {
result = results[j];
expect(result.status).to.equal(status.AEROSPIKE_OK);
var record = result.record;
var _record = written[result.key.key].record;
expect(record).to.eql(_record);
}
done();
});
});
});
});
expect(record).to.eql(_record)
}
done()
})
})
})
})

@@ -1,189 +0,176 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before, after */
// we want to test the built aerospike module
var aerospike = require('../build/Release/aerospike');
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var aerospike = require('../build/Release/aerospike')
var options = require('./util/options')
var expect = require('expect.js')
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var valgen = require('./generators/value');
var keygen = require('./generators/key')
var metagen = require('./generators/metadata')
var recgen = require('./generators/record')
var putgen = require('./generators/put')
var valgen = require('./generators/value')
var status = aerospike.status;
var policy = aerospike.policy;
var status = aerospike.status
describe('client.batchSelect()', function() {
describe('client.batchSelect()', function () {
var config = options.getConfig()
var client = aerospike.client(config)
var config = options.getConfig();
var client = aerospike.client(config);
before(function (done) {
client.connect(function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
before(function(done) {
client.connect(function(err){
done();
});
});
after(function (done) {
client.close()
client = null
done()
})
after(function(done) {
client.close();
client = null;
done();
});
it('should successfully read bins from 10 records', function (done) {
// number of records
var nrecords = 10
it('should successfully read bins from 10 records', function(done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/batch_get/10/', random: false})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()})
// number of records
var nrecords = 10;
// writer using generators
// callback provides an object of written records, where the
// keys of the object are the record's keys.
putgen.put(client, 10, kgen, rgen, mgen, function (written) {
var keys = Object.keys(written).map(function (key) {
return written[key].key
})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/batch_get/10/", random: false});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()});
var bins = ['i', 's']
var len = keys.length
expect(len).to.equal(nrecords)
// writer using generators
// callback provides an object of written records, where the
// keys of the object are the record's keys.
putgen.put(client, 10, kgen, rgen, mgen, function(written) {
client.batchSelect(keys, bins, function (err, results) {
var result
var j
var keys = Object.keys(written).map(function(key){
return written[key].key;
});
var bins = [ 'i' , 's'];
var len = keys.length;
expect(len).to.equal(nrecords);
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(results.length).to.equal(len)
client.batchSelect(keys, bins, function(err, results) {
for (j = 0; j < results.length; j++) {
result = results[j]
var result;
var j;
expect(result.status).to.equal(status.AEROSPIKE_OK)
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(results.length).to.equal(len);
var record = result.record
var _record = written[result.key.key].record
expect(record.i).to.eql(_record.i)
expect(record.s).to.eql(_record.s)
}
for ( j = 0; j < results.length; j++) {
result = results[j];
done()
})
})
})
expect(result.status).to.equal(status.AEROSPIKE_OK);
it('should fail reading bins from non-existent records', function (done) {
// number of records
var nrecords = 10
var record = result.record;
var _record = written[result.key.key].record;
expect(record.i).to.eql(_record.i);
expect(record.s).to.eql(_record.s);
}
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/batch_get/fail/', random: false})
done();
});
});
});
// values
var keys = keygen.range(kgen, nrecords)
it('should fail reading bins from non-existent records', function(done) {
var bins = ['i', 's']
// writer using generators
// callback provides an object of written records, where the
// keys of the object are the record's keys.
client.batchSelect(keys, bins, function (err, results) {
var result
var j
// number of records
var nrecords = 10;
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(results.length).to.equal(nrecords)
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/batch_get/fail/", random: false});
for (j = 0; j < results.length; j++) {
result = results[j]
if (result.status !== 602) {
expect(result.status).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND)
} else {
expect(result.status).to.equal(602)
}
}
// values
var keys = keygen.range(kgen, 10);
done()
})
})
var bins = ['i', 's'];
// writer using generators
// callback provides an object of written records, where the
// keys of the object are the record's keys.
client.batchSelect(keys, bins, function(err, results) {
it('should successfully read bins of 1000 records', function (done) {
// this high for low-end hosts
this.timeout(6000)
var result;
var j;
// number of records
var nrecords = 1000
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(results.length).to.equal(10);
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/batch_get/1000/', random: false})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()})
for ( j = 0; j < results.length; j++) {
result = results[j];
if(result.status != 602)
{
expect(result.status).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND);
}
else
{
expect(result.status).to.equal(602);
}
}
// writer using generators
// callback provides an object of written records, where the
// keys of the object are the record's keys.
putgen.put(client, nrecords, kgen, rgen, mgen, function (written) {
var keys = Object.keys(written).map(function (key) {
return written[key].key
})
done();
});
});
var bins = ['i', 's']
var len = keys.length
expect(len).to.equal(nrecords)
it('should successfully read bins of 1000 records', function(done) {
client.batchSelect(keys, bins, function (err, results) {
var result
var j
// this high for low-end hosts
this.timeout(6000);
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(results.length).to.equal(len)
// number of records
var nrecords = 1000;
for (j = 0; j < results.length; j++) {
result = results[j]
expect(result.status).to.equal(status.AEROSPIKE_OK)
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/batch_get/1000/", random: false});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()});
var record = result.record
var _record = written[result.key.key].record
// writer using generators
// callback provides an object of written records, where the
// keys of the object are the record's keys.
putgen.put(client, nrecords, kgen, rgen, mgen, function(written) {
expect(record.i).to.eql(_record.i)
expect(record.s).to.eql(_record.s)
}
var keys = Object.keys(written).map(function(key){
return written[key].key;
});
var bins = ['i', 's'];
var len = keys.length;
expect(len).to.equal(nrecords);
client.batchSelect(keys, bins, function(err, results) {
var result;
var j;
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(results.length).to.equal(len);
for ( j = 0; j < results.length; j++) {
result = results[j];
expect(result.status).to.equal(status.AEROSPIKE_OK);
var record = result.record;
var _record = written[result.key.key].record;
expect(record.i).to.eql(_record.i);
expect(record.s).to.eql(_record.s);
}
done();
});
});
});
});
done()
})
})
})
})

@@ -1,745 +0,687 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before, after */
// we want to test the built aerospike module
var aerospike = require('../lib/aerospike');
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var aerospike = require('../lib/aerospike')
var options = require('./util/options')
var expect = require('expect.js')
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var keygen = require('./generators/key')
var metagen = require('./generators/metadata')
var recgen = require('./generators/record')
var status = aerospike.status;
var policy = aerospike.policy;
var op = aerospike.operator;
var status = aerospike.status
var op = aerospike.operator
describe('client.operate()', function() {
describe('client.operate()', function () {
var config = options.getConfig()
var client = aerospike.client(config)
var config = options.getConfig();
var client = aerospike.client(config);
before(function (done) {
client.connect(function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
before(function(done) {
client.connect(function(err){
done();
});
});
after(function (done) {
client.close()
client = null
done()
})
after(function(done) {
client.close();
client = null;
done();
});
describe('operator.listAppend', function () {
it('should append the given item at the end of the list', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/append/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
describe('operator.listAppend', function() {
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
it('should append the given item at the end of the list', function(done) {
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listAppend('list', 99)
]
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/append/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record2.list).to.eql([1, 2, 3, 4, 5, 99])
// write the record then check
client.put(key, record, meta, function(err, key) {
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
})
var ops = [
op.listAppend('list', 99)
];
describe('operator.listAppendItems', function () {
it('should append the given items at the end of the list', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/append_items/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listAppendItems('list', [99, 100])
]
expect(record2.list).to.eql([1, 2, 3, 4, 5, 99]);
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
client.remove(key1, function(err, key){
done();
});
});
});
});
});
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record2.list).to.eql([1, 2, 3, 4, 5, 99, 100])
});
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
})
describe('operator.listAppendItems', function() {
describe('operator.listInsert', function () {
it('should insert the given item at the specified index of the list', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/insert/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
it('should append the given items at the end of the list', function(done) {
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/append_items/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listInsert('list', 2, 99)
]
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// write the record then check
client.put(key, record, meta, function(err, key) {
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record2.list).to.eql([1, 2, 99, 3, 4, 5])
var ops = [
op.listAppendItems('list', [99, 100])
];
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
})
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
describe('operator.listInsertItems', function () {
it('should insert the given items at the specified index of the list', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/insert_items/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
expect(record2.list).to.eql([1, 2, 3, 4, 5, 99, 100]);
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listInsertItems('list', 2, [99, 100])
]
client.remove(key1, function(err, key){
done();
});
});
});
});
});
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
});
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record2.list).to.eql([1, 2, 99, 100, 3, 4, 5])
describe('operator.listInsert', function() {
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
})
it('should insert the given item at the specified index of the list', function(done) {
describe('operator.listPop', function () {
it('should remove the item at the specified index and return it', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/pop/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/insert/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listPop('list', 2)
]
// write the record then check
client.put(key, record, meta, function(err, key) {
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(record1.list).to.eql(3)
var ops = [
op.listInsert('list', 2, 99)
];
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record2.list).to.eql([1, 2, 4, 5])
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
})
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
describe('operator.listPopRange', function () {
it('should remove the items at the specified range and return them', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/pop_range/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
expect(record2.list).to.eql([1, 2, 99, 3, 4, 5]);
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
client.remove(key1, function(err, key){
done();
});
});
});
});
});
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listPopRange('list', 2, 2)
]
});
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(record1.list).to.eql([3, 4])
describe('operator.listInsertItems', function() {
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record2.list).to.eql([1, 2, 5])
it('should insert the given items at the specified index of the list', function(done) {
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/insert_items/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
it('should remove and return all items from the specified index if count is not specified', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/pop_range_from/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// write the record then check
client.put(key, record, meta, function(err, key) {
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listPopRange('list', 2)
]
var ops = [
op.listInsertItems('list', 2, [99, 100])
];
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(record1.list).to.eql([3, 4, 5])
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record2.list).to.eql([1, 2])
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
})
expect(record2.list).to.eql([1, 2, 99, 100, 3, 4, 5]);
describe('operator.listRemove', function () {
it('should remove the item at the specified index', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/remove/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
client.remove(key1, function(err, key){
done();
});
});
});
});
});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
});
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listRemove('list', 2)
]
describe('operator.listPop', function() {
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
it('should remove the item at the specified index and return it', function(done) {
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record2.list).to.eql([1, 2, 4, 5])
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/pop/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
})
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
describe('operator.listRemoveRange', function () {
it('should remove the items at the specified range', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/remove_range/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
// write the record then check
client.put(key, record, meta, function(err, key) {
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
var ops = [
op.listPop('list', 2)
];
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listRemoveRange('list', 2, 2)
]
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(record1.list).to.eql(3);
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record2.list).to.eql([1, 2, 5])
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
expect(record2.list).to.eql([1, 2, 4, 5]);
it('should remove all items from the specified index if count is not specified', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/remove_range_from/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
client.remove(key1, function(err, key){
done();
});
});
});
});
});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
});
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listRemoveRange('list', 2)
]
describe('operator.listPopRange', function() {
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
it('should remove the items at the specified range and return them', function(done) {
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record2.list).to.eql([1, 2])
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/pop_range/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
})
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
describe('operator.listClear', function () {
it('should remove all elements from the list', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/clear/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
// write the record then check
client.put(key, record, meta, function(err, key) {
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
var ops = [
op.listPopRange('list', 2, 2)
];
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listClear('list')
]
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(record1.list).to.eql([3, 4]);
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record2.list).to.eql([])
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
})
expect(record2.list).to.eql([1, 2, 5]);
describe('operator.listSet', function () {
it('should set the item at the specified index', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/set/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
client.remove(key1, function(err, key){
done();
});
});
});
});
});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
it('should remove and return all items from the specified index if count is not specified', function(done) {
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listSet('list', 2, 99)
]
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/pop_range_from/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record2.list).to.eql([1, 2, 99, 4, 5])
// write the record then check
client.put(key, record, meta, function(err, key) {
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
})
var ops = [
op.listPopRange('list', 2)
];
describe('operator.listTrim', function () {
it('should remove all elements not within the specified range', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/trim/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
expect(record1.list).to.eql([3, 4, 5]);
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listTrim('list', 1, 3)
]
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(record2.list).to.eql([1, 2]);
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record2.list).to.eql([2, 3, 4])
client.remove(key1, function(err, key){
done();
});
});
});
});
});
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
})
});
describe('operator.listGet', function () {
it('should get the item at the specified index', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
describe('operator.listRemove', function() {
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
it('should remove the item at the specified index', function(done) {
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listGet('list', 2)
]
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/remove/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(record1.list).to.equal(3)
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
// write the record then check
client.put(key, record, meta, function(err, key) {
it('should return an error if the index is out of bounds', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/get/oob/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
var ops = [
op.listRemove('list', 2)
];
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listGet('list', 99)
]
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR_REQUEST_INVALID)
expect(record2.list).to.eql([1, 2, 4, 5]);
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
client.remove(key1, function(err, key){
done();
});
});
});
});
});
describe('operator.listGetRange', function () {
it('should get the items at the specified range', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/get_range/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
describe('operator.listRemoveRange', function() {
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listGetRange('list', 1, 3)
]
it('should remove the items at the specified range', function(done) {
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(record1.list).to.eql([2, 3, 4])
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/remove_range/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
it('should get all the items from the specified index if count is not specified', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/get_range_from/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
// write the record then check
client.put(key, record, meta, function(err, key) {
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
var ops = [
op.listRemoveRange('list', 2, 2)
];
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listGetRange('list', 1)
]
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(record1.list).to.eql([2, 3, 4, 5])
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
expect(record2.list).to.eql([1, 2, 5]);
describe('operator.listSize', function () {
it('should get the lement count of the list', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/cdt/size/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]})
client.remove(key1, function(err, key){
done();
});
});
});
});
});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
it('should remove all items from the specified index if count is not specified', function(done) {
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.listSize('list')
]
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/remove_range_from/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(record1.list).to.equal(5)
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function(err, key) {
var ops = [
op.listRemoveRange('list', 2)
];
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record2.list).to.eql([1, 2]);
client.remove(key1, function(err, key){
done();
});
});
});
});
});
});
describe('operator.listClear', function() {
it('should remove all elements from the list', function(done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/clear/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function(err, key) {
var ops = [
op.listClear('list')
];
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record2.list).to.eql([]);
client.remove(key1, function(err, key){
done();
});
});
});
});
});
});
describe('operator.listSet', function() {
it('should set the item at the specified index', function(done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/set/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function(err, key) {
var ops = [
op.listSet('list', 2, 99)
];
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record2.list).to.eql([1, 2, 99, 4, 5]);
client.remove(key1, function(err, key){
done();
});
});
});
});
});
});
describe('operator.listTrim', function() {
it('should remove all elements not within the specified range', function(done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/trim/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function(err, key) {
var ops = [
op.listTrim('list', 1, 3)
];
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record2.list).to.eql([2, 3, 4]);
client.remove(key1, function(err, key){
done();
});
});
});
});
});
});
describe('operator.listGet', function() {
it('should get the item at the specified index', function(done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function(err, key) {
var ops = [
op.listGet('list', 2)
];
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record1.list).to.equal(3);
client.remove(key1, function(err, key){
done();
});
});
});
});
it('should return an error if the index is out of bounds', function(done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/get/oob/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function(err, key) {
var ops = [
op.listGet('list', 99)
];
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_ERR_REQUEST_INVALID);
client.remove(key1, function(err, key){
done();
});
});
});
});
});
describe('operator.listGetRange', function() {
it('should get the items at the specified range', function(done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/get_range/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function(err, key) {
var ops = [
op.listGetRange('list', 1, 3)
];
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record1.list).to.eql([2, 3, 4]);
client.remove(key1, function(err, key){
done();
});
});
});
});
it('should get all the items from the specified index if count is not specified', function(done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/get_range_from/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function(err, key) {
var ops = [
op.listGetRange('list', 1)
];
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record1.list).to.eql([2, 3, 4, 5]);
client.remove(key1, function(err, key){
done();
});
});
});
});
});
describe('operator.listSize', function() {
it('should get the lement count of the list', function(done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/cdt/size/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({list: [1, 2, 3, 4, 5]});
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function(err, key) {
var ops = [
op.listSize('list')
];
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record1.list).to.equal(5);
client.remove(key1, function(err, key){
done();
});
});
});
});
});
});
client.remove(key1, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
})

@@ -1,108 +0,108 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before, after */
// we want to test the built aerospike module
var aerospike = require('../build/Release/aerospike');
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var aerospike = require('../build/Release/aerospike')
var options = require('./util/options')
var expect = require('expect.js')
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var keygen = require('./generators/key')
var status = aerospike.status;
var policy = aerospike.policy;
var language = aerospike.language;
var status = aerospike.status
describe('client.Execute()', function(done) {
describe('client.execute()', function (done) {
var config = options.getConfig()
var client = aerospike.client(config)
var config = options.getConfig();
var client = aerospike.client(config);
before(function (done) {
client.connect(function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
client.udfRegister(__dirname + '/udf_test.lua', function (err) {
expect(err.code).to.equal(status.AEROSPIKE_OK)
done()
})
})
})
before(function(done) {
client.connect(function(err){
client.udfRegister(__dirname+"/udf_test.lua", function(err) {
expect(err.code).to.equal(status.AEROSPIKE_OK);
done();
});
});
});
after(function (done) {
client.close()
client = null
done()
})
after(function(done) {
client.close()
client = null;
done();
});
it('should invoke an UDF to without any args', function (done) {
var udfArgs = { module: 'udf_test', funcname: 'rec_create' }
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/udfExecute/'})
var key = kgen()
client.execute(key, udfArgs, function (err, res) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(res).to.equal(0)
client.remove(key, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
it('should invoke an UDF to without any args', function(done) {
var udfArgs = { module: "udf_test", funcname: "rec_create" }
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/udfExecute/"});
var key = kgen();
client.execute(key, udfArgs, function(err, res) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(res).to.equal(0);
client.remove(key, function(err, key){
done();
});
});
});
it('should invoke an UDF with arguments', function(done) {
var udfArgs = { module: "udf_test", funcname: "rec_update", args: [123, "str"] }
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/udfExecute/"});
var key = kgen();
client.execute(key, udfArgs, function( err, res) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(res).to.equal(0);
client.remove(key, function(err, key) {
done();
});
});
});
it('should invoke an UDF with apply policy', function(done) {
var udfArgs = { module: "udf_test", funcname: "rec_update" , args: [345, "bar"]}
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/udfExecute/"});
var key = kgen();
var applypolicy = { timeout : 1500}
client.execute(key, udfArgs, applypolicy, function( err, res) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(res).to.equal(0);
client.remove(key, function(err, key){
done();
});
});
});
it('should invoke an UDF function which does not exist - expected to fail', function(done) {
var udfArgs = { module: "udf_test", funcname: "rec_nofunc" }
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/udfExecute/"});
var key = kgen();
client.execute(key, udfArgs, function( err, res, key) {
expect(err).to.be.ok();
if(err.code != 1300) {
expect(err.code).to.equal(status.AEROSPIKE_ERR_UDF);
}
else {
expect(err.code).to.equal(1300);
}
done();
});
});
it('should invoke an UDF with arguments', function (done) {
var udfArgs = { module: 'udf_test', funcname: 'rec_update', args: [123, 'str'] }
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/udfExecute/'})
var key = kgen()
client.execute(key, udfArgs, function (err, res) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(res).to.equal(0)
client.remove(key, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
});
it('should invoke an UDF with apply policy', function (done) {
var udfArgs = {module: 'udf_test', funcname: 'rec_update', args: [345, 'bar']}
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/udfExecute/'})
var key = kgen()
var applypolicy = {timeout: 1500}
client.execute(key, udfArgs, applypolicy, function (err, res) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(res).to.equal(0)
client.remove(key, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
it('should invoke an UDF function which does not exist - expected to fail', function (done) {
var udfArgs = { module: 'udf_test', funcname: 'rec_nofunc' }
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/udfExecute/'})
var key = kgen()
client.execute(key, udfArgs, function (err, res, key) {
expect(err).to.be.ok()
if (err.code !== 1300) {
expect(err.code).to.equal(status.AEROSPIKE_ERR_UDF)
} else {
expect(err.code).to.equal(1300)
}
done()
})
})
})

@@ -1,96 +0,91 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before, after */
// we want to test the built aerospike module
var aerospike = require('../build/Release/aerospike');
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var aerospike = require('../build/Release/aerospike')
var options = require('./util/options')
var expect = require('expect.js')
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var valgen = require('./generators/value');
var keygen = require('./generators/key')
var metagen = require('./generators/metadata')
var recgen = require('./generators/record')
var valgen = require('./generators/value')
var status = aerospike.status;
var policy = aerospike.policy;
var status = aerospike.status
describe('client.exists()', function() {
describe('client.exists()', function () {
var config = options.getConfig()
var client = aerospike.client(config)
var config = options.getConfig();
var client = aerospike.client(config);
before(function (done) {
client.connect(function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
before(function(done) {
client.connect(function(err){
done();
});
});
after(function (done) {
client.close()
client = null
done()
})
after(function(done) {
client.close();
client = null;
done();
});
it('should find the record', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/exists/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()})
it('should find the record', function(done) {
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/exists/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()});
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
client.exists(key, function (err, metadata, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
client.remove(key, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key,meta);
it('should not find the record', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/exists/fail/'})
// write the record then check
client.put(key, record, meta, function(err, key) {
client.exists(key, function(err, metadata, key) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.remove(key, function(err, key){
done();
});
});
});
});
// values
var key = kgen()
it('should not find the record', function(done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/exists/fail/"});
// values
var key = kgen();
// write the record then check
client.exists(key, function(err, metadata, key) {
expect(err).to.be.ok();
if(err.code != 602) {
expect(err.code).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND);
}
else {
expect(err.code).to.equal(602);
}
done();
});
});
});
// write the record then check
client.exists(key, function (err, metadata, key) {
expect(err).to.be.ok()
if (err.code !== 602) {
expect(err.code).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND)
} else {
expect(err.code).to.equal(602)
}
done()
})
})
})

@@ -1,65 +0,64 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
var valgen = require('./value');
var valgen = require('./value')
/**
* Returns a generator for bytes keys.
*/
function bytes(namespace, set, options) {
var bgen = valgen.bytes(options);
return function() {
return { ns: namespace, set: set, key: bgen()};
};
//
// Returns a generator for bytes keys.
//
function bytes (namespace, set, options) {
var bgen = valgen.bytes(options)
return function () {
return {ns: namespace, set: set, key: bgen()}
}
}
/**
* Returns a generator for string keys.
*/
function string(namespace, set, options) {
var sgen = valgen.string(options);
return function() {
return { ns: namespace, set: set, key: sgen()};
};
//
// Returns a generator for string keys.
//
function string (namespace, set, options) {
var sgen = valgen.string(options)
return function () {
return {ns: namespace, set: set, key: sgen()}
}
}
/**
* Returns a generator for integer keys.
*/
function integer(namespace, set, options) {
var igen = valgen.integer(options);
return function() {
return { ns: namespace, set: set, key: igen()};
};
//
// Returns a generator for integer keys.
//
function integer (namespace, set, options) {
var igen = valgen.integer(options)
return function () {
return {ns: namespace, set: set, key: igen()}
}
}
function range(keygen, end, start) {
start = start ? start : 0;
end = end ? end : start + 1;
var a = []
for (var i = 0; i < end; i++) {
a.push(keygen());
}
return a;
function range (keygen, end, start) {
start = start || 0
end = end || start + 1
var a = []
for (var i = 0; i < end; i++) {
a.push(keygen())
}
return a
}
module.exports = {
bytes: bytes,
integer: integer,
string: string,
range: range
};
bytes: bytes,
integer: integer,
string: string,
range: range
}

@@ -1,29 +0,28 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/**
* Returns a static record.
*/
function constant(metadata) {
return function(key) {
return metadata;
};
//
// Returns a static record.
//
function constant (metadata) {
return function (key) {
return metadata
}
}
module.exports = {
constant: constant
};
constant: constant
}

@@ -1,67 +0,62 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
var aerospike = require('../../build/Release/aerospike')
var status = aerospike.status
var aerospike = require('../../build/Release/aerospike');
var expect = require('expect.js');
var status = aerospike.status;
function put_done (total, done) {
var entries = {}
var count = 0
function put_done(total, done) {
return function (_key, record, metadata) {
return function (err, key, skippy) {
switch (err.code) {
case status.AEROSPIKE_OK:
entries[key.key] = {
status: err.code,
key: key,
record: record,
metadata: metadata
}
break
default:
console.error('Error: ', err, key)
}
var entries = {};
var count = 0;
return function(_key, record, metadata) {
return function(err, key, skippy) {
switch ( err.code ) {
case status.AEROSPIKE_OK:
entries[key.key] = {
status: err.code,
key: key,
record: record,
metadata: metadata
};
break;
default:
console.error("Error: ", err, key);
}
count++;
if ( count >= total ) {
done(entries);
}
};
};
count++
if (count >= total) {
done(entries)
}
}
}
}
function put(client, n, keygen, recgen, metagen, done) {
function put (client, n, keygen, recgen, metagen, done) {
var d = put_done(n, done)
var i
var d = put_done(n, done);
var i;
for ( i = 0; i < n; i++ ) {
var key = keygen();
var metadata = metagen(key);
var record = recgen(key, metadata);
var callback = d(key, record, metadata);
client.put(key, record, metadata, callback);
}
for (i = 0; i < n; i++) {
var key = keygen()
var metadata = metagen(key)
var record = recgen(key, metadata)
var callback = d(key, record, metadata)
client.put(key, record, metadata, callback)
}
}
module.exports = {
put: put
};
put: put
}

@@ -1,43 +0,42 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/**
* Returns a static record.
*/
function constant(bins) {
return function(key, metadata) {
return bins
};
//
// Returns a static record.
//
function constant (bins) {
return function (key, metadata) {
return bins
}
}
/**
* Returns a record from bins spec'd using generators record.
*/
function record(bins) {
return function(key, metadata) {
var out = {};
for ( var bin in bins ) {
out[bin] = bins[bin]()
}
return out;
};
//
// Returns a record from bins spec'd using generators record.
//
function record (bins) {
return function (key, metadata) {
var out = {}
for (var bin in bins) {
out[bin] = bins[bin]()
}
return out
}
}
module.exports = {
constant: constant,
record: record
};
constant: constant,
record: record
}

@@ -1,31 +0,30 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
function range(end, start) {
start = start ? start : 0;
end = end ? end : start + 1;
var i, j;
var a = Array(end-start+1);
for ( i = 0, j = start; j < end; i++, j++ ) {
a[i] = j;
}
return a;
function range (end, start) {
start = start || 0
end = end || start + 1
var i, j
var a = Array(end - start + 1)
for (i = 0, j = start; j < end; i++, j++) {
a[i] = j
}
return a
}
module.exports = {
range: range
}
range: range
}

@@ -1,166 +0,162 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
// *****************************************************************************
// HELPERS
// ****************************************************************************
/*******************************************************************************
* HELPERS
******************************************************************************/
function random(min,max) {
var rand = Math.floor(Math.random() * 0x100000000) % max;
return rand < min ? min : rand;
function random (min, max) {
var rand = Math.floor(Math.random() * 0x100000000) % max
return rand < min ? min : rand
}
function merge(o1, o2) {
var o3 = {};
var k;
if ( o1 ) {
for ( k in o1 ) {
o3[k] = o1[k];
}
function merge (o1, o2) {
var o3 = {}
var k
if (o1) {
for (k in o1) {
o3[k] = o1[k]
}
if ( o2 ) {
for ( k in o2 ) {
o3[k] = o2[k];
}
}
if (o2) {
for (k in o2) {
o3[k] = o2[k]
}
return o3;
}
return o3
}
/*******************************************************************************
* GENERATORS
******************************************************************************/
// *****************************************************************************
// GENERATORS
// *****************************************************************************
function constant(value) {
return function() {
return value;
}
function constant (value) {
return function () {
return value
}
}
function string(options) {
var opt = merge(string.defaults, options);
var seq = 0;
return function() {
if ( opt.random === true ) {
var len = random(opt.length.min, opt.length.max);
var arr = new Array(len);
for (var i = 0; i < len; i++) {
arr[i] = opt.charset[random(0, opt.charset.length)];
}
return opt.prefix + arr.join('') + opt.suffix;
}
else {
return opt.prefix + (seq++) + opt.suffix;
}
function string (options) {
var opt = merge(string.defaults, options)
var seq = 0
return function () {
if (opt.random === true) {
var len = random(opt.length.min, opt.length.max)
var arr = new Array(len)
for (var i = 0; i < len; i++) {
arr[i] = opt.charset[random(0, opt.charset.length)]
}
return opt.prefix + arr.join('') + opt.suffix
} else {
return opt.prefix + (seq++) + opt.suffix
}
}
}
string.defaults = {
random: true,
length: {
min: 1,
max: 128
},
prefix: '',
suffix: '',
charset: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'
};
random: true,
length: {
min: 1,
max: 128
},
prefix: '',
suffix: '',
charset: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'
}
function bytes(options) {
var opt = merge(bytes.defaults, options);
return function() {
var len = random(opt.length.min, opt.length.max);
var buf = new Buffer(len);
for (var i = 0; i < len; i++) {
buf[i] = random(opt.byte.min, opt.byte.max);
}
return buf;
function bytes (options) {
var opt = merge(bytes.defaults, options)
return function () {
var len = random(opt.length.min, opt.length.max)
var buf = new Buffer(len)
for (var i = 0; i < len; i++) {
buf[i] = random(opt.byte.min, opt.byte.max)
}
return buf
}
}
bytes.defaults = {
length: {
min: 1,
max: 1024
},
byte: {
min: 0,
max: 255
}
};
length: {
min: 1,
max: 1024
},
byte: {
min: 0,
max: 255
}
}
function integer(options) {
var opt = merge(integer.defaults, options);
var seq = opt.min;
return function() {
return opt.random === true ? random(opt.min, opt.max) : seq++;
}
function integer (options) {
var opt = merge(integer.defaults, options)
var seq = opt.min
return function () {
return opt.random === true ? random(opt.min, opt.max) : seq++
}
}
integer.defaults = {
random: true,
min: 0,
max: 0xffffff
};
random: true,
min: 0,
max: 0xffffff
}
function array() {
return function() {
var itype = integer();
var stype = string();
var btype = bytes();
var arr = [itype(), stype(), btype()];
return arr;
}
function array () {
return function () {
var itype = integer()
var stype = string()
var btype = bytes()
var arr = [itype(), stype(), btype()]
return arr
}
}
function map() {
return function() {
var num = integer();
var str = string();
var uint = bytes();
var map = { itype: num(), stype: str(), btyte: uint()} ;
return map;
}
function map () {
return function () {
var num = integer()
var str = string()
var uint = bytes()
var map = {itype: num(), stype: str(), btyte: uint()}
return map
}
}
function array_of_array(){
return function(){
var arr = array();
var obj = map();
var list = [ arr(), obj() ];
return list;
}
function array_of_array () {
return function () {
var arr = array()
var obj = map()
var list = [ arr(), obj() ]
return list
}
}
function map_of_map() {
return function() {
var arr = array();
var obj = map();
var map_of_list = {inner_list: arr(), inner_map: obj() };
return map_of_list;
}
function map_of_map () {
return function () {
var arr = array()
var obj = map()
var map_of_list = {inner_list: arr(), inner_map: obj()}
return map_of_list
}
}
module.exports = {
bytes: bytes,
constant: constant,
integer: integer,
string: string,
array: array,
map: map,
array_of_array: array_of_array,
map_of_map: map_of_map
};
bytes: bytes,
constant: constant,
integer: integer,
string: string,
array: array,
map: map,
array_of_array: array_of_array,
map_of_map: map_of_map
}

@@ -1,116 +0,117 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before, after */
// we want to test the built aerospike module
var aerospike = require('../build/Release/aerospike');
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var aerospike = require('../build/Release/aerospike')
var options = require('./util/options')
var expect = require('expect.js')
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var keygen = require('./generators/key')
var metagen = require('./generators/metadata')
var recgen = require('./generators/record')
var status = aerospike.status;
var policy = aerospike.policy;
describe('client.get()', function() {
var status = aerospike.status
var policy = aerospike.policy
var config = options.getConfig();
var client = aerospike.client(config);
describe('client.get()', function () {
var config = options.getConfig()
var client = aerospike.client(config)
before(function(done) {
client.connect(function(err){
done();
});
});
before(function (done) {
client.connect(function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
after(function(done) {
client.close();
client = null;
done();
});
after(function (done) {
client.close()
client = null
done()
})
it('should read the record', function(done) {
it('should read the record', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({i: 123, s: 'abc'})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({i: 123, s: "abc"});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
client.get(key, function (err, record, metadata, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
client.remove(key, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
// write the record then check
client.put(key, record, meta, function(err, key) {
client.get(key, function(err, record, metadata, key) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.remove(key, function(err, key) {
done();
});
});
});
});
it('should not find the record', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/not_found/'})
it('should not find the record', function(done) {
// values
var key = kgen()
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/not_found/"});
// write the record then check
client.get(key, function (err, record, metadata, key) {
expect(err).to.be.ok()
if (err.code !== 602) {
expect(err.code).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND)
} else {
expect(err.code).to.equal(602)
}
done()
})
})
// values
var key = kgen();
it('should read the record w/ a key send policy', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({i: 123, s: 'abc'})
// write the record then check
client.get(key, function(err, record, metadata, key) {
expect(err).to.be.ok();
if(err.code != 602) {
expect(err.code).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND);
}
else {
expect(err.code).to.equal(602);
}
done();
});
});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
var pol = { key: policy.key.SEND }
it('should read the record w/ a key send policy', function(done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({i: 123, s: "abc"});
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
var pol = { key: policy.key.SEND };
// write the record then check
client.put(key, record, meta, function(err, key) {
client.get(key, pol, function(err, record, metadata, key) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.remove(key, function(err, key){
done();
});
});
});
});
});
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
client.get(key, pol, function (err, record, metadata, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
client.remove(key, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})

@@ -1,115 +0,109 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before, after */
// we want to test the built aerospike module
var aerospike = require('../lib/aerospike');
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var aerospike = require('../lib/aerospike')
var options = require('./util/options')
var expect = require('expect.js')
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var status = aerospike.status
var status = aerospike.status;
var policy = aerospike.policy;
describe('client.index()', function () {
var config = options.getConfig()
var client = aerospike.client(config)
describe('client.index()', function() {
before(function (done) {
client.connect(function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
var config = options.getConfig();
var client = aerospike.client(config);
after(function (done) {
client.close()
client = null
done()
})
before(function(done) {
client.connect(function(err){
done();
});
});
after(function(done) {
client.close();
client = null;
done();
});
it('should create an integer index', function(done) {
var args = { ns: options.namespace,
set: options.set,
bin : "integer_bin",
index: "integer_index" }
client.createIntegerIndex(args, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
done();
});
});
it('should create an string index', function(done) {
var args = { ns: options.namespace, set: options.set, bin : "string_bin",
index: "string_index" }
client.createStringIndex(args, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
done();
});
});
it('should create an integer index with info policy', function(done) {
var args = { ns: options.namespace, set: options.set, bin : "policy_bin",
index: "policy_index", policy:{ timeout : 1000, send_as_is: true, check_bounds: false }}
client.createIntegerIndex(args, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
done();
});
});
it('should drop an index', function(done) {
client.indexRemove(options.namespace, "string_integer", function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
done();
});
});
it('should create an integer index and wait until index creation is done', function(done) {
var args = { ns: options.namespace,
set: options.set,
bin : "integer_done",
index: "integer_index_done" }
client.createIntegerIndex(args, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.indexCreateWait(options.namespace, "integer_index_done", 1000, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
done();
});
});
});
it('should create a string index and wait until index creation is done', function(done) {
var args = { ns: options.namespace,
set: options.set,
bin : "string_done",
index: "string_index_done" }
client.createStringIndex(args, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.indexCreateWait(options.namespace, "string_index_done", 1000, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
done();
});
});
});
});
it('should create an integer index', function (done) {
var args = { ns: options.namespace,
set: options.set,
bin: 'integer_bin',
index: 'integer_index' }
client.createIntegerIndex(args, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
done()
})
})
it('should create an string index', function (done) {
var args = { ns: options.namespace, set: options.set, bin: 'string_bin',
index: 'string_index' }
client.createStringIndex(args, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
done()
})
})
it('should create an integer index with info policy', function (done) {
var args = { ns: options.namespace, set: options.set, bin: 'policy_bin',
index: 'policy_index', policy: { timeout: 1000, send_as_is: true, check_bounds: false }}
client.createIntegerIndex(args, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
done()
})
})
it('should drop an index', function (done) {
client.indexRemove(options.namespace, 'string_integer', function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
done()
})
})
it('should create an integer index and wait until index creation is done', function (done) {
var args = { ns: options.namespace,
set: options.set,
bin: 'integer_done',
index: 'integer_index_done' }
client.createIntegerIndex(args, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
client.indexCreateWait(options.namespace, 'integer_index_done', 1000, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
done()
})
})
})
it('should create a string index and wait until index creation is done', function (done) {
var args = { ns: options.namespace,
set: options.set,
bin: 'string_done',
index: 'string_index_done' }
client.createStringIndex(args, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
client.indexCreateWait(options.namespace, 'string_index_done', 1000, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
done()
})
})
})
})

@@ -1,56 +0,51 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before, after */
// we want to test the built aerospike module
var aerospike = require('../build/Release/aerospike');
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var aerospike = require('../build/Release/aerospike')
var options = require('./util/options')
var expect = require('expect.js')
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var status = aerospike.status
var status = aerospike.status;
var policy = aerospike.policy;
describe('client.info()', function () {
var config = options.getConfig()
var client = aerospike.client(config)
describe('client.info()', function() {
before(function (done) {
client.connect(function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
var config = options.getConfig();
var client = aerospike.client(config);
after(function (done) {
client.close()
client = null
done()
})
before(function(done) {
client.connect(function(err){
done();
});
});
after(function(done) {
client.close();
client = null;
done();
});
it('should get "objects" from entire cluster', function(done) {
var host = {addr: options.host, port: options.port};
client.info("objects", host, function(err, response, host) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
done();
});
});
});
it('should get "objects" from entire cluster', function (done) {
var host = {addr: options.host, port: options.port}
client.info('objects', host, function (err, response, host) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
done()
})
})
})

@@ -1,579 +0,442 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before, after */
// we want to test the built aerospike module
var aerospike = require('../lib/aerospike');
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var aerospike = require('../lib/aerospike')
var options = require('./util/options')
var expect = require('expect.js')
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var valgen = require('./generators/value');
var valgen = require('./generators/value')
var status = aerospike.status;
var policy = aerospike.policy;
var language = aerospike.language;
var status = aerospike.status
var policy = aerospike.policy
describe('client.LargeList()', function (done) {
var config = options.getConfig()
var client = aerospike.client(config)
describe('client.LargeList()', function(done) {
// A single LList is created. All LList operations are done in this single list to demonstrate the
// usage of LList API.
// The operations include adding an element, udpating an element, searching for an element
// and removing an element.
// Get a largelist object from client.
var listkey = {ns: options.namespace, set: options.set, key: 'ldt_list_key'}
var writepolicy = {timeout: 1000, key: policy.key.SEND, commitLevel: policy.commitLevel.ALL}
var LList = client.LargeList(listkey, 'ldt_list_bin', writepolicy)
var ldtEnabled = true
var config = options.getConfig()
var client = aerospike.client(config);
before(function (done) {
client.connect(function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
var ns = 'namespace/' + options.namespace.toString()
client.info(ns, {addr: options.host, port: options.port},
function (err, response, host) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var nsConfig = response.split(';')
for (var i = 0; i < nsConfig.length; i++) {
if (nsConfig[i].search('ldt-enabled=false') >= 0) {
ldtEnabled = false
console.log('Skipping LDT test cases')
break
}
}
done()
})
})
})
// A single LList is created. All LList operations are done in this single list to demonstrate the
// usage of LList API.
// The operations include adding an element, udpating an element, searching for an element
// and removing an element.
// Get a largelist object from client.
var listkey = {ns: options.namespace, set: options.set, key: "ldt_list_key"}
var writepolicy = { timeout: 1000, key: policy.key.SEND, commitLevel: policy.commitLevel.ALL};
var LList = client.LargeList(listkey, "ldt_list_bin", writepolicy);
var ldtEnabled = true;
before(function(done) {
client.connect(function(err){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
var ns = "namespace/" + options.namespace.toString();
client.info( ns, {addr:options.host, port: options.port},
function(err, response, host){
var nsConfig = response.split(";")
for (var i = 0; i < nsConfig.length; i++)
{
if(nsConfig[i].search("ldt-enabled=false") >= 0)
{
ldtEnabled = false;
console.log("Skipping LDT test cases");
break;
}
}
done();
});
});
});
after(function (done) {
LList.destroy(function (err, val) {
if (ldtEnabled) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
client.close()
client = null
}
done()
})
})
after(function(done) {
// LList used in this test case is destructed here. The list will not be available after destroying
// the list.
LList.destroy(function(err, val) {
if(ldtEnabled)
{
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.close();
client = null;
done();
}
else
{
done();
}
});
it('should add an element of type integer to the LList ', function (done) {
if (!ldtEnabled) { this.skip() }
var igen = valgen.integer()
var listval = igen()
var intval = {'key': 'intvalue', 'value': listval}
// insert an integer value into the list.
LList.add(intval, function (err, retVal) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// verify the inserted element in the list.
LList.find({'key': 'intvalue'}, function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(val[0].value).to.equal(listval)
done()
})
})
})
});
it('should add an element of type string to the LList ', function (done) {
if (!ldtEnabled) { this.skip() }
var sgen = valgen.string()
var listval = sgen()
var strval = {'key': 'stringvalue', 'value': listval}
// insert an string value into the list.
LList.add(strval, function (err, retVal) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// verify the inserted element in the list.
LList.find({'key': 'stringvalue'}, function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(val[0].value).to.equal(listval)
done()
})
})
})
it('should add an element of type integer to the LList ', function(done) {
if(ldtEnabled)
{
var igen = valgen.integer();
var listval = igen();
var intval = {"key":"intvalue", "value": listval}
// insert an integer value into the list.
LList.add(intval, function(err, retVal){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
//verify the inserted element in the list.
LList.find({"key":"intvalue"}, function(err, val) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(val[0].value).to.equal(listval);
done();
});
});
}
else
{
done();
}
});
it('should add an element of type string to the LList ', function(done) {
if(ldtEnabled)
{
var sgen = valgen.string();
var listval = sgen();
var strval = {"key": "stringvalue", "value" : listval};
// insert an string value into the list.
LList.add(strval, function(err, retVal){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
//verify the inserted element in the list.
LList.find({"key":"stringvalue"}, function(err, val) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(val[0].value).to.equal(listval);
done();
});
});
}
else
{
done();
}
});
it('should add an element of type bytes to the LList ', function(done) {
if(ldtEnabled)
{
var bgen = valgen.bytes();
var listval = bgen();
var bytesval = {"key": "bytesvalue", "value" : listval};
// insert a byte value into the list.
LList.add(bytesval, function(err, retVal){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
//verify the inserted element in the list.
LList.find({"key":"bytesvalue"}, function(err, val) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(val[0].value).to.eql(listval);
done();
});
});
}
else
{
done();
}
});
it('should add an element of type array to the LList ', function(done) {
if(ldtEnabled)
{
var agen = valgen.array();
var listval = agen();
var bytesval = {"key": "arrayvalue", "value" : listval};
// insert an array element into the list.
LList.add(bytesval, function(err, retVal){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
//verify the inserted element in the list.
LList.find({"key":"arrayvalue"}, function(err, val) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(val[0].value).to.eql(listval);
done();
});
});
}
else
{
done();
}
});
it('should add an element of type map to the LList ', function(done) {
if(ldtEnabled)
{
var mgen = valgen.map();
var listval = mgen();
var mapval = {"key": "mapvalue", "value" : listval};
// insert a map element into the list.
LList.add(mapval, function(err, retVal){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
//verify the inserted element in the list.
LList.find({"key":"mapvalue"}, function(err, val) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(val[0].value).to.eql(listval);
done();
});
});
}
else
{
done();
}
});
it('should add an array of values to LList ', function(done) {
if(ldtEnabled)
{
var mgen = valgen.map();
var agen = valgen.array();
var igen = valgen.integer();
var sgen = valgen.string();
var bgen = valgen.bytes();
it('should add an element of type bytes to the LList ', function (done) {
if (!ldtEnabled) { this.skip() }
var bgen = valgen.bytes()
var listval = bgen()
var bytesval = {'key': 'bytesvalue', 'value': listval}
// insert a byte value into the list.
LList.add(bytesval, function (err, retVal) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// verify the inserted element in the list.
LList.find({'key': 'bytesvalue'}, function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(val[0].value).to.eql(listval)
done()
})
})
})
// array of values to be inserted into the LList.
var valList = [ bgen(), igen(), agen(), mgen(), sgen()]
it('should add an element of type array to the LList ', function (done) {
if (!ldtEnabled) { this.skip() }
var agen = valgen.array()
var listval = agen()
var bytesval = {'key': 'arrayvalue', 'value': listval}
// insert an array element into the list.
LList.add(bytesval, function (err, retVal) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// verify the inserted element in the list.
LList.find({'key': 'arrayvalue'}, function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(val[0].value).to.eql(listval)
done()
})
})
})
var bytesval = {"key": "arraybytesvalue", "value" : valList[0]}
var integerval = {"key":"arrayintvalue", "value" : valList[1]}
var arrayval = {"key": "arraylistvalue", "value" : valList[2]}
var mapval = {"key": "arraymapvalue", "value" : valList[3]}
var stringval = {"key": "arraystrvalue", "value" : valList[4]}
// array of values with key to be inserted into the LList.
var arrayList = [ mapval, arrayval, bytesval, stringval, integerval];
LList.add(arrayList, function(err, retVal){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
//verify the inserted element in the list.
LList.findRange("arraybytesvalue", "arraystrvalue", function(err, val) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(val[0].value).to.eql(valList[0]);
expect(val[1].value).to.equal(valList[1]);
expect(val[2].value).to.eql(valList[2]);
expect(val[3].value).to.eql(valList[3]);
expect(val[4].value).to.equal(valList[4]);
done();
});
});
}
else
{
done();
}
});
it('should verify that passing wrong number of arguments to add API fails gracefully', function(done) {
if(ldtEnabled)
{
var igen = valgen.integer();
var listval = igen();
var intval = {"key":"intvalue", "value": listval}
LList.add(intval, undefined, function(err, retVal){
expect(err).to.be.ok();
expect(err.func).to.equal('add ');
done();
});
}
else
{
done();
}
});
it('should add an element of type map to the LList ', function (done) {
if (!ldtEnabled) { this.skip() }
var mgen = valgen.map()
var listval = mgen()
var mapval = {'key': 'mapvalue', 'value': listval}
// insert a map element into the list.
LList.add(mapval, function (err, retVal) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// verify the inserted element in the list.
LList.find({'key': 'mapvalue'}, function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(val[0].value).to.eql(listval)
done()
})
})
})
it('should update an element in the LList ', function(done) {
if(ldtEnabled)
{
var igen = valgen.integer();
var listval = igen();
var intval = {"key":"intvalue", "value": listval}
// update an integer value in the list.
LList.update(intval, function(err, retVal){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
//verify the updated element in the list.
LList.find({"key":"intvalue"}, function(err, val) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(val[0].value).to.equal(listval);
done();
});
});
}
else
{
done();
}
});
it('should update an array of values in the LList ', function(done) {
if(ldtEnabled)
{
var mgen = valgen.map();
var agen = valgen.array();
var igen = valgen.integer();
var sgen = valgen.string();
var bgen = valgen.bytes();
var valList = [ bgen(), igen(), agen(), mgen(), sgen()]
it('should add an array of values to LList ', function (done) {
if (!ldtEnabled) { this.skip() }
var mgen = valgen.map()
var agen = valgen.array()
var igen = valgen.integer()
var sgen = valgen.string()
var bgen = valgen.bytes()
var bytesval = {"key": "arraybytesvalue", "value" : valList[0]}
var integerval = {"key":"arrayintvalue", "value" : valList[1]}
var arrayval = {"key": "arraylistvalue", "value" : valList[2]}
var mapval = {"key": "arraymapvalue", "value" : valList[3]}
var stringval = {"key": "arraystrvalue", "value" : valList[4]}
var arrayList = [ mapval, arrayval, bytesval, stringval, integerval];
// array of values to be inserted into the LList.
var valList = [bgen(), igen(), agen(), mgen(), sgen()]
//update an array of elements in the list.
LList.update(arrayList, function(err, retVal){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
//verify the updated elements in the list.
LList.findRange("arraybytesvalue", "arraystrvalue", function(err, val) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(val[0].value).to.eql(valList[0]);
expect(val[1].value).to.equal(valList[1]);
expect(val[2].value).to.eql(valList[2]);
expect(val[3].value).to.eql(valList[3]);
expect(val[4].value).to.equal(valList[4]);
done();
});
});
}
else
{
done();
}
});
it('should verify that passing wrong number of arguments to update API fails gracefully', function(done) {
if(ldtEnabled)
{
var igen = valgen.integer();
var listval = igen();
var intval = {"key":"intvalue", "value": listval}
LList.update(intval, undefined, function(err, retVal){
expect(err).to.be.ok();
expect(err.func).to.equal('update ');
done();
});
}
else
{
done();
}
});
var bytesval = {key: 'arraybytesvalue', value: valList[0]}
var integerval = {key: 'arrayintvalue', value: valList[1]}
var arrayval = {key: 'arraylistvalue', value: valList[2]}
var mapval = {key: 'arraymapvalue', value: valList[3]}
var stringval = {key: 'arraystrvalue', value: valList[4]}
it('should verify the find API of LList -finds an existing element', function(done) {
if(ldtEnabled)
{
//find an element in the list.
LList.find({"key":"intvalue"}, function(err, val) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(val[0]).to.have.property('value');
done();
});
}
else
{
done();
}
});
it('should verify the find API of LList -finds a non-existing element and fails', function(done) {
if(ldtEnabled)
{
//find an element in the list.
LList.find({"key":"novalue"}, function(err, val) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_ERR_LARGE_ITEM_NOT_FOUND);
done();
});
}
else
{
done();
}
})
// array of values with key to be inserted into the LList.
var arrayList = [mapval, arrayval, bytesval, stringval, integerval]
LList.add(arrayList, function (err, retVal) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// verify the inserted element in the list.
LList.findRange('arraybytesvalue', 'arraystrvalue', function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(val[0].value).to.eql(valList[0])
expect(val[1].value).to.equal(valList[1])
expect(val[2].value).to.eql(valList[2])
expect(val[3].value).to.eql(valList[3])
expect(val[4].value).to.equal(valList[4])
done()
})
})
})
it('should verify the range API of LList- expected to find existing elements', function(done) {
if(ldtEnabled)
{
LList.findRange("arraybytesvalue", "arraystrvalue", function(err, val) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(val.length).to.equal(5);
done();
});
}
else
{
done();
}
});
it('should verify the range API of LList- expected to not find any elements', function(done) {
if(ldtEnabled)
{
LList.findRange("zbytesvalue", "zstrvalue", function(err, val) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(val.length).to.eql(0);
done();
});
}
else
{
done();
}
});
it('should verify the size API of LList ', function(done) {
if(ldtEnabled)
{
LList.size(function(err, val) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(val).to.equal(10);
done();
});
}
else
{
done();
}
});
it('should verify that size API fails gracefully when passing wrong number of arguments', function(done) {
if(ldtEnabled)
{
LList.size(2, function(err, val) {
expect(err).to.be.ok();
expect(err.func).to.equal('size ');
done();
});
}
else
{
done();
}
});
it('should verify the scan API of LList ', function(done) {
if(ldtEnabled)
{
LList.scan(function(err, val) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(val.length).to.equal(10);
done();
});
}
else
{
done();
}
});
it('should verify the scan API fails gracefully when wrong number of arguments are passed', function(done) {
if(ldtEnabled)
{
LList.scan("scan", function(err, val) {
expect(err).to.be.ok();
expect(err.func).to.equal('scan ');
done();
});
}
else
{
done();
}
});
it('should verify that passing wrong number of arguments to add API fails gracefully', function (done) {
if (!ldtEnabled) { this.skip() }
var igen = valgen.integer()
var listval = igen()
var intval = {'key': 'intvalue', 'value': listval}
LList.add(intval, undefined, function (err, retVal) {
expect(err).to.be.ok()
expect(err.func).to.equal('add')
done()
})
})
it('should remove an element from the LList ', function(done) {
if(ldtEnabled)
{
var intval = {"key":"intvalue"}
// remove the integer value into the list.
LList.remove(intval, function(err, retVal){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
//verify the removed element in the list.
LList.find({"key":"intvalue"}, function(err, val) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_ERR_LARGE_ITEM_NOT_FOUND);
LList.size(function(err, val){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(val).to.equal(9);
done();
});
});
});
}
else
{
done();
}
});
it('should remove an array of elements from LList ', function(done) {
if(ldtEnabled)
{
var bytesval = {"key": "bytesvalue"}
var stringval = {"key":"stringvalue"}
var arrayval = {"key": "arrayvalue"}
var mapval = {"key": "mapvalue" }
// remove an array of elements from the list.
var arrayList = [ mapval, arrayval, bytesval, stringval ];
LList.remove(arrayList, function(err, retVal){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
LList.size(function(err, val){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(val).to.equal(5);
done();
})
});
}
else
{
done();
}
});
it('should verify remove API fails when invalid number of arguments are passed', function(done) {
if(ldtEnabled)
{
// remove an array of elements from the list.
LList.remove("list", 123, function(err, retVal){
expect(err).to.be.ok();
expect(err.func).to.equal('remove ');
done();
});
}
else
{
done();
}
});
it('should update an element in the LList ', function (done) {
if (!ldtEnabled) { this.skip() }
var igen = valgen.integer()
var listval = igen()
var intval = {'key': 'intvalue', 'value': listval}
// update an integer value in the list.
LList.update(intval, function (err, retVal) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// verify the updated element in the list.
LList.find({'key': 'intvalue'}, function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(val[0].value).to.equal(listval)
done()
})
})
})
it('should verify removing a range of values in LList ', function(done) {
if(ldtEnabled)
{
LList.removeRange("arraybytesvalue", "arraystrvalue", function(err, retVal){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
LList.findRange("arraybytesvalue", "arraystrvalue", function(err, val) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(val.length).to.equal(0);
LList.size(function(err, val){
expect(err).to.be.ok();
expect(err.code).to.be.equal(status.AEROSPIKE_OK);
expect(val).to.equal(0);
done();
});
});
});
}
else
{
done();
}
});
it('should verify removeRange API fails when invalid number of arguments are passed', function(done) {
if(ldtEnabled)
{
LList.removeRange("list", 123, 345, function(err, retVal){
expect(err).to.be.ok();
expect(err.func).to.equal('removeRange ');
done();
});
}
else
{
done();
}
});
});
it('should update an array of values in the LList ', function (done) {
if (!ldtEnabled) { this.skip() }
var mgen = valgen.map()
var agen = valgen.array()
var igen = valgen.integer()
var sgen = valgen.string()
var bgen = valgen.bytes()
var valList = [bgen(), igen(), agen(), mgen(), sgen()]
var bytesval = {key: 'arraybytesvalue', value: valList[0]}
var integerval = {key: 'arrayintvalue', value: valList[1]}
var arrayval = {key: 'arraylistvalue', value: valList[2]}
var mapval = {key: 'arraymapvalue', value: valList[3]}
var stringval = {key: 'arraystrvalue', value: valList[4]}
var arrayList = [mapval, arrayval, bytesval, stringval, integerval]
// update an array of elements in the list.
LList.update(arrayList, function (err, retVal) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// verify the updated elements in the list.
LList.findRange('arraybytesvalue', 'arraystrvalue', function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(val[0].value).to.eql(valList[0])
expect(val[1].value).to.equal(valList[1])
expect(val[2].value).to.eql(valList[2])
expect(val[3].value).to.eql(valList[3])
expect(val[4].value).to.equal(valList[4])
done()
})
})
})
it('should verify that passing wrong number of arguments to update API fails gracefully', function (done) {
if (!ldtEnabled) { this.skip() }
var igen = valgen.integer()
var listval = igen()
var intval = {'key': 'intvalue', 'value': listval}
LList.update(intval, undefined, function (err, retVal) {
expect(err).to.be.ok()
expect(err.func).to.equal('update')
done()
})
})
it('should verify the find API of LList -finds an existing element', function (done) {
if (!ldtEnabled) { this.skip() }
// find an element in the list.
LList.find({'key': 'intvalue'}, function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(val[0]).to.have.property('value')
done()
})
})
it('should verify the find API of LList -finds a non-existing element and fails', function (done) {
if (!ldtEnabled) { this.skip() }
// find an element in the list.
LList.find({'key': 'novalue'}, function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR_LARGE_ITEM_NOT_FOUND)
done()
})
})
it('should verify the range API of LList- expected to find existing elements', function (done) {
if (!ldtEnabled) { this.skip() }
LList.findRange('arraybytesvalue', 'arraystrvalue', function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(val.length).to.equal(5)
done()
})
})
it('should verify the range API of LList- expected to not find any elements', function (done) {
if (!ldtEnabled) { this.skip() }
LList.findRange('zbytesvalue', 'zstrvalue', function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(val.length).to.eql(0)
done()
})
})
it('should verify the size API of LList ', function (done) {
if (!ldtEnabled) { this.skip() }
LList.size(function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(val).to.equal(10)
done()
})
})
it('should verify that size API fails gracefully when passing wrong number of arguments', function (done) {
if (!ldtEnabled) { this.skip() }
LList.size(2, function (err, val) {
expect(err).to.be.ok()
expect(err.func).to.equal('size')
done()
})
})
it('should verify the scan API of LList ', function (done) {
if (!ldtEnabled) { this.skip() }
LList.scan(function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(val.length).to.equal(10)
done()
})
})
it('should verify the scan API fails gracefully when wrong number of arguments are passed', function (done) {
if (!ldtEnabled) { this.skip() }
LList.scan('scan', function (err, val) {
expect(err).to.be.ok()
expect(err.func).to.equal('scan')
done()
})
})
it('should remove an element from the LList ', function (done) {
if (!ldtEnabled) { this.skip() }
var intval = {'key': 'intvalue'}
// remove the integer value into the list.
LList.remove(intval, function (err, retVal) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// verify the removed element in the list.
LList.find({'key': 'intvalue'}, function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR_LARGE_ITEM_NOT_FOUND)
LList.size(function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(val).to.equal(9)
done()
})
})
})
})
it('should remove an array of elements from LList ', function (done) {
if (!ldtEnabled) { this.skip() }
var bytesval = {key: 'bytesvalue'}
var stringval = {key: 'stringvalue'}
var arrayval = {key: 'arrayvalue'}
var mapval = {key: 'mapvalue'}
// remove an array of elements from the list.
var arrayList = [ mapval, arrayval, bytesval, stringval ]
LList.remove(arrayList, function (err, retVal) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
LList.size(function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(val).to.equal(5)
done()
})
})
})
it('should verify remove API fails when invalid number of arguments are passed', function (done) {
if (!ldtEnabled) { this.skip() }
// remove an array of elements from the list.
LList.remove('list', 123, function (err, retVal) {
expect(err).to.be.ok()
expect(err.func).to.equal('remove')
done()
})
})
it('should verify removing a range of values in LList ', function (done) {
if (!ldtEnabled) { this.skip() }
LList.removeRange('arraybytesvalue', 'arraystrvalue', function (err, retVal) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
LList.findRange('arraybytesvalue', 'arraystrvalue', function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(val.length).to.equal(0)
LList.size(function (err, val) {
expect(err).to.be.ok()
expect(err.code).to.be.equal(status.AEROSPIKE_OK)
expect(val).to.equal(0)
done()
})
})
})
})
it('should verify removeRange API fails when invalid number of arguments are passed', function (done) {
if (!ldtEnabled) { this.skip() }
LList.removeRange('list', 123, 345, function (err, retVal) {
expect(err).to.be.ok()
expect(err.func).to.equal('removeRange')
done()
})
})
})

@@ -1,67 +0,52 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it */
// we want to test the built aerospike module
var aerospike = require('../build/Release/aerospike');
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var fs = require('fs');
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var aerospike = require('../build/Release/aerospike')
var options = require('./util/options')
var expect = require('expect.js')
var fs = require('fs')
var status = aerospike.status;
var policy = aerospike.policy;
var status = aerospike.status
describe('client.updateLogging()', function() {
describe('client.updateLogging()', function () {
var config = options.getConfig()
config.log.file = null
var fd = null;
beforeEach(function(done) {
done();
});
after(function(done) {
done();
});
var config = options.getConfig();
config.log.file = null;
it('should log the messages to test.log', function(done) {
var host = {addr: options.host, port: options.port};
var count = 0;
fs.open('test.log','a', function(err, fd) {
config.log.file = fd;
aerospike.client(config).connect(function(err, client) {
client.info("objects", host, function(err, response, host) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
count++;
var buffer = new Buffer(100);
fs.readFile( 'test.log', function(err, data) {
expect(data).to.be.ok();
done();
});
});
});
});
});
});
it('should log the messages to test.log', function (done) {
var host = {addr: options.host, port: options.port}
var count = 0
fs.open('test.log', 'a', function (err, fd) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
config.log.file = fd
aerospike.client(config).connect(function (err, client) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
client.info('objects', host, function (err, response, host) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
count++
fs.readFile('test.log', function (err, data) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(data).to.be.ok()
done()
})
})
})
})
})
})

@@ -1,530 +0,530 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before, after */
// we want to test the built aerospike module
var aerospike = require('../lib/aerospike');
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var aerospike = require('../lib/aerospike')
var options = require('./util/options')
var expect = require('expect.js')
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var keygen = require('./generators/key')
var metagen = require('./generators/metadata')
var recgen = require('./generators/record')
var status = aerospike.status;
var policy = aerospike.policy;
var op = aerospike.operator;
var status = aerospike.status
var op = aerospike.operator
describe('client.operate()', function() {
describe('client.operate()', function () {
var config = options.getConfig()
var client = aerospike.client(config)
var config = options.getConfig();
var client = aerospike.client(config);
before(function (done) {
client.connect(function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
before(function(done) {
client.connect(function(err){
done();
});
});
after(function (done) {
client.close()
client = null
done()
})
after(function(done) {
client.close();
client = null;
done();
});
it('should increment a bin', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({i: 123, s: 'abc'})
it('should increment a bin', function(done) {
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({i: 123, s: "abc"});
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.incr('i', 432)
]
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// write the record then check
client.put(key, record, meta, function(err, key) {
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record['i'] + 432).to.equal(record2['i'])
expect(record['s']).to.equal(record2['s'])
var ops = [
op.incr('i', 432)
];
client.remove(key2, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
it('should append a bin', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({i: 123, s: 'abc'})
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record['i'] + 432).to.equal(record2['i']);
expect(record['s']).to.equal(record2['s']);
client.remove(key2, function(err, key){
done();
});
});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
});
});
});
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.append('s', 'def')
]
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
it('should append a bin', function(done) {
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record['i']).to.equal(record2['i'])
expect(record['s'] + 'def').to.equal(record2['s'])
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({i: 123, s: "abc"});
client.remove(key2, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
it('should prepend and read a bin', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({i: 123, s: 'abc'})
// write the record then check
client.put(key, record, meta, function(err, key) {
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
var ops = [
op.append('s', 'def')
];
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.prepend('s', 'def'),
op.read('s')
]
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(record1['i']).to.equal(undefined)
expect('def' + record['s']).to.equal(record1['s'])
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record['i']).to.equal(record2['i']);
expect(record['s'] + 'def').to.equal(record2['s']);
client.remove(key2, function(err, key){
done();
});
});
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record['i']).to.equal(record2['i'])
expect('def' + record['s']).to.equal(record2['s'])
});
});
});
client.remove(key2, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
it('should prepend and read a bin', function(done) {
it('should touch a record(refresh ttl) ', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({i: 123, s: 'abc'})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({i: 123, s: "abc"});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// TEST LOGIC
// 1.Write a record to an aerospike server.
// 2.Read the record, to get the ttl and calculate
// the difference in the ttl written and the ttl returned by server.
// 3.Touch the record with a definite ttl.
// 4.Read the record and calculate the difference in the ttl between the
// touch ttl value and read ttl value.
// 5.Compare the difference with the earlier difference calculated.
// 6.This is to account for the clock asynchronicity between
// the client and the server machines.
// 7.Server returns a number, at which the record expires according the server clock.
// 8.The client calculates the time in seconds, and gives back ttl. In the case , where
// clocks are not synchronous between server and client, the ttl client calculates may not
// be accurate to the user. Nevertheless server expires the record in the correct time.
// write the record then check
client.put(key, record, meta, function(err, key) {
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.touch(2592000)
]
var ops = [
op.prepend('s', 'def'),
op.read('s'),
];
client.get(key, function (err, record3, metadata3, key3) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ttl_diff = metadata3.ttl - meta.ttl
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record1['i']).to.equal(undefined);
expect('def' + record['s']).to.equal(record1['s']);
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record['i']).to.equal(record2['i']);
expect('def'+record['s'] ).to.equal(record2['s']);
client.remove(key2, function(err, key){
done();
});
});
client.get(key1, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record['i']).to.equal(record2['i'])
expect(record['s']).to.equal(record2['s'])
expect(2592000 + ttl_diff + 10).to.be.above(metadata2.ttl)
expect(2592000 + ttl_diff - 10).to.be.below(metadata2.ttl)
});
});
});
it('should touch a record(refresh ttl) ', function(done) {
client.remove(key2, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({i: 123, s: "abc"});
it('should prepend using prepend API and verify the bin', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({i: 123, s: 'abc'})
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// TEST LOGIC
// 1.Write a record to an aerospike server.
// 2.Read the record, to get the ttl and calculate
// the difference in the ttl written and the ttl returned by server.
// 3.Touch the record with a definite ttl.
// 4.Read the record and calculate the difference in the ttl between the
// touch ttl value and read ttl value.
// 5.Compare the difference with the earlier difference calculated.
// 6.This is to account for the clock asynchronicity between
// the client and the server machines.
// 7.Server returns a number, at which the record expires according the server clock.
// 8.The client calculates the time in seconds, and gives back ttl. In the case , where
// clocks are not synchronous between server and client, the ttl client calculates may not
// be accurate to the user. Nevertheless server expires the record in the correct time.
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var bin = {s: 'def'}
// write the record then check
client.put(key, record, meta, function(err, key) {
var ops = [
op.touch(2592000)
];
client.get(key, function(err, record3, metadata3, key3){
expect(err).to.be.ok();
ttl_diff = metadata3.ttl - meta.ttl;
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.get(key1, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record['i']).to.equal(record2['i']);
expect(record['s']).to.equal(record2['s']);
expect(2592000 + ttl_diff+10).to.be.above(metadata2.ttl);
expect(2592000 + ttl_diff-10).to.be.below(metadata2.ttl);
client.remove(key2, function(err, key){
done();
});
});
client.prepend(key, bin, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
});
});
});
});
it('should prepend using prepend API and verify the bin', function(done) {
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record['i']).to.equal(record2['i'])
expect('def' + record['s']).to.equal(record2['s'])
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({i: 123, s: "abc"});
client.remove(key2, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
it('should prepend using prepend API and verify the bin with metadata', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({i: 123, s: 'abc'})
// write the record then check
client.put(key, record, meta, function(err, key) {
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
var bin = { s: 'def'}
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var bin = {s: 'def'}
client.prepend(key, bin, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.prepend(key, bin, meta, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record['i']).to.equal(record2['i']);
expect('def'+record['s'] ).to.equal(record2['s']);
client.remove(key2, function(err, key){
done();
});
});
client.get(key, function (err, record2, metadata2, key2) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(record['i']).to.equal(record2['i'])
expect('def' + record['s']).to.equal(record2['s'])
});
});
});
it('should prepend using prepend API and verify the bin with metadata', function(done) {
client.remove(key2, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({i: 123, s: "abc"});
it('should append a bin using append API and verify the bin', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({i: 123, s: 'abc'})
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// write the record then check
client.put(key, record, meta, function(err, key) {
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var bin = {s: 'def'}
var bin = { s: 'def'}
client.append(key, bin, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
client.prepend(key, bin, meta, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record['i']).to.equal(record2['i'])
expect(record['s'] + 'def').to.equal(record2['s'])
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record['i']).to.equal(record2['i']);
expect('def'+record['s'] ).to.equal(record2['s']);
client.remove(key2, function(err, key){
done();
});
});
client.remove(key2, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
});
});
});
it('should append a bin using append API and verify the bin with metadata', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({i: 123, s: 'abc'})
it('should append a bin using append API and verify the bin', function(done) {
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({i: 123, s: "abc"});
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var bin = {s: 'def'}
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
client.append(key, bin, meta, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// write the record then check
client.put(key, record, meta, function(err, key) {
var bin = { s: 'def'};
client.append(key, bin, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record['i']).to.equal(record2['i'])
expect(record['s'] + 'def').to.equal(record2['s'])
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record['i']).to.equal(record2['i']);
expect(record['s'] + 'def').to.equal(record2['s']);
client.remove(key2, function(err, key){
done();
});
});
client.remove(key2, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
});
});
});
it('should append a bin using append API and verify the bin with metadata', function(done) {
it('should add a value to a bin and verify', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({i: 123, s: 'abc'})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({i: 123, s: "abc"});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var bin = {i: 432}
// write the record then check
client.put(key, record, meta, function(err, key) {
var bin = { s: 'def'};
client.append(key, bin, meta, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.add(key, bin, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record['i']).to.equal(record2['i']);
expect(record['s'] + 'def').to.equal(record2['s']);
client.remove(key2, function(err, key){
done();
});
});
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record['i'] + 432).to.equal(record2['i'])
expect(record['s']).to.equal(record2['s'])
});
});
});
client.remove(key2, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
it('should add a value to a bin and verify', function(done) {
it('should add a value to a bin with metadata and verify', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({i: 123, s: 'abc'})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({i: 123, s: "abc"});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var bin = {i: 432}
// write the record then check
client.put(key, record, meta, function(err, key) {
client.add(key, bin, meta, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
var bin = { i : 432}
client.add(key, bin, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record['i'] + 432).to.equal(record2['i'])
expect(record['s']).to.equal(record2['s'])
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record['i'] + 432).to.equal(record2['i']);
expect(record['s']).to.equal(record2['s']);
client.remove(key2, function(err, key){
done();
});
});
client.remove(key2, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
});
});
});
it('should add a value to a bin with metadata and verify', function(done) {
it('should add a string value to a bin and expected fail', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({i: 123, s: 'abc'})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({i: 123, s: "abc"});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var bin = {i: 'str'}
// write the record then check
client.put(key, record, meta, function(err, key) {
client.add(key, bin, meta, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR_PARAM)
done()
})
})
})
var bin = { i : 432}
client.add(key, bin, meta, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
it('should append a bin of type integer using append API and expected to fail', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({i: 123, s: 'abc'})
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record['i'] + 432).to.equal(record2['i']);
expect(record['s']).to.equal(record2['s']);
client.remove(key2, function(err, key){
done();
});
});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
});
});
});
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var bin = {s: 123}
it('should add a string value to a bin and expected fail', function(done) {
client.append(key, bin, meta, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR_PARAM)
done()
})
})
})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({i: 123, s: "abc"});
it('should prepend an integer using prepend API and expect to fail', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({i: 123, s: 'abc'})
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// write the record then check
client.put(key, record, meta, function(err, key) {
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var bin = {s: 123}
var bin = { i : "str"}
client.add(key, bin, meta, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_ERR_PARAM);
done();
client.prepend(key, bin, meta, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR_PARAM)
done()
})
})
})
});
});
});
it('should return a client error if any of the operations are invalid', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.constant({i: 123, s: 'abc'})
it('should append a bin of type integer using append API and expected to fail', function(done) {
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({i: 123, s: "abc"});
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var ops = [
op.incr('i', 432),
op.incr('i', 'str') // invalid increment with string value
]
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
client.operate(key, ops, function (err, record1, metadata1, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR_PARAM)
// write the record then check
client.put(key, record, meta, function(err, key) {
var bin = { s: 123};
client.append(key, bin, meta, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_ERR_PARAM);
done();
client.get(key, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record2['i']).to.equal(123)
expect(record2['s']).to.equal('abc')
});
});
});
it('should prepend an integer using prepend API and expect to fail', function(done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({i: 123, s: "abc"});
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function(err, key) {
var bin = { s: 123}
client.prepend(key, bin, meta, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_ERR_PARAM);
done();
});
});
});
it('should return a client error if any of the operations are invalid', function(done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.constant({i: 123, s: "abc"});
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function(err, key) {
var ops = [
op.incr('i', 432),
op.incr('i', "str") // invalid increment with string value
];
client.operate(key, ops, function(err, record1, metadata1, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_ERR_PARAM);
client.get(key, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record2['i']).to.equal(123);
expect(record2['s']).to.equal('abc');
client.remove(key2, function(err, key){
done();
});
});
});
});
});
});
client.remove(key2, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
})

@@ -1,561 +0,578 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before, after */
// we want to test the built aerospike module
var aerospike = require('../build/Release/aerospike');
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var aerospike = require('../build/Release/aerospike')
var options = require('./util/options')
var expect = require('expect.js')
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var valgen = require('./generators/value');
var keygen = require('./generators/key')
var metagen = require('./generators/metadata')
var recgen = require('./generators/record')
var valgen = require('./generators/value')
var status = aerospike.status;
var policy = aerospike.policy;
var Double = aerospike.Double;
var status = aerospike.status
var Double = aerospike.Double
describe('client.put()', function() {
describe('client.put()', function () {
var config = options.getConfig()
var client = aerospike.client(config)
var config = options.getConfig();
var client = aerospike.client(config);
before(function (done) {
client.connect(function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
before(function(done) {
client.connect(function(err){
done();
});
});
after(function (done) {
client.close()
client = null
done()
})
after(function(done) {
client.close();
client = null;
done();
});
it('should write and validate 100 records', function (done) {
// counters
var total = 100
var count = 0
it('should write and validate 100 records', function(done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/put/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()})
// counters
var total = 100;
var count = 0;
function iteration () {
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/put/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()});
// write the record then check
client.put(key, record, meta, function (err, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
function iteration() {
client.get(key, function (err, _record, _metadata, _key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(_record).to.eql(record)
count++
if (count >= total) {
done()
}
})
})
}
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
for (var i = 0; i < total; i++) {
iteration()
}
})
// write the record then check
client.put(key, record, meta, function(err, key) {
client.get(key, function(err, _record, _metadata, _key) {
it('should write the record w/ string key', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/put/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string()})
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(_record).to.eql(record);
count++;
if ( count >= total ) {
done();
}
});
});
}
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
for ( var i = 0; i < total; i++ ) {
iteration();
}
});
// write the record then check
client.put(key, record, meta, function (err, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
it('should write the record w/ string key', function(done) {
client.get(key, function (err, record, metadata, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/put/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string()});
client.remove(key, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
it('should write the record w/ int key', function (done) {
// generators
var kgen = keygen.integer(options.namespace, options.set)
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string()})
// write the record then check
client.put(key, record, meta, function(err, key) {
client.get(key, function(err, record, metadata, key) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.remove(key, function(err, key){
done();
});
});
});
});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
it('should write the record w/ int key', function(done) {
// write the record then check
client.put(key, record, meta, function (err, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// generators
var kgen = keygen.integer(options.namespace, options.set);
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string()});
client.get(key, function (err, record, metadata, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
client.remove(key, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
// write the record then check
client.put(key, record, meta, function(err, key) {
client.get(key, function(err, record, metadata, key) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.remove(key, function(err, key){
done();
});
it('should write the record w/ bytes key', function (done) {
// generators
var kgen = keygen.bytes(options.namespace, options.set)
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string()})
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// write the record then check
client.put(key, record, meta, function (err, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
});
});
});
client.get(key, function (err, record, metadata, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
it('should write the record w/ bytes key', function(done) {
client.remove(key, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
// generators
var kgen = keygen.bytes(options.namespace, options.set);
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string()});
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function(err, key) {
client.get(key, function(err, record, metadata, key) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.remove(key, function(err, key){
done();
});
});
});
});
it('shoule write an array, map type of bin and read', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/put/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({list: valgen.array(), map: valgen.map()})
it('shoule write an array, map type of bin and read', function(done) {
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/put/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({list: valgen.array(), map: valgen.map()});
// write the record and then check
client.put(key, record, meta, function (err, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
//values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
client.get(key, function (err, record1, metadata, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record1).to.eql(record)
//write the record and then check
client.put(key, record, meta, function(err, key) {
client.get(key, function(err, record1, metadata, key){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record1).to.eql(record);
client.remove(key, function(err, key){
done();
});
});
});
});
it('shoule write a bin with double value', function(done) {
client.remove(key, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/put/"});
var mgen = metagen.constant({ttl: 1000});
it('shoule write a bin with double value', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/put/'})
var mgen = metagen.constant({ttl: 1000})
//values
var key = kgen();
var meta = mgen(key);
var record = {
val : 123.45,
dval: Double(456.00)
}
//write the record and then check
client.put(key, record, meta, function(err, key) {
client.get(key, function(err, record1, metadata, key){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record1.val).to.equal(record.val);
expect(record1.dval).to.equal(record.dval.Double);
client.remove(key, function(err, key){
done();
});
});
});
});
// values
var key = kgen()
var meta = mgen(key)
var record = {
val: 123.45,
dval: Double(456.00)
}
// write the record and then check
client.put(key, record, meta, function (err, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
it('should write an array of map and array, map of array and map, then read', function(done){
client.get(key, function (err, record1, metadata, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record1.val).to.equal(record.val)
expect(record1.dval).to.equal(record.dval.Double)
//generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/put/"});
var mgen = metagen.constant({ttl:1000});
var rgen = recgen.record({list_of_list: valgen.array_of_array(), map_of_list: valgen.map_of_map()});
client.remove(key, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
//values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
it('should write an array of map and array, map of array and map, then read', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/put/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({list_of_list: valgen.array_of_array(), map_of_list: valgen.map_of_map()})
//write the record and then check
client.put(key, record, meta, function(err, key) {
client.get(key, function(err, record1, metadata, key){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(record1).to.eql(record);
client.remove(key, function(err, key){
done();
});
});
});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
});
// write the record and then check
client.put(key, record, meta, function (err, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
it('should write, read, write, and check gen', function(done) {
client.get(key, function (err, record1, metadata, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(record1).to.eql(record)
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/put/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string()});
client.remove(key, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
it('should write, read, write, and check gen', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/put/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string()})
// write the record then check
client.put(key, record, meta, function(err, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(key1).to.have.property('ns', key.ns);
expect(key1).to.have.property('set', key.set);
expect(key1).to.have.property('key', key.key);
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
client.get(key1, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(key2).to.have.property('ns', key.ns);
expect(key2).to.have.property('set', key.set);
expect(key2).to.have.property('key', key.key);
expect(record2).to.eql(record);
// write the record then check
client.put(key, record, meta, function (err, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(key1).to.have.property('ns', key.ns)
expect(key1).to.have.property('set', key.set)
expect(key1).to.have.property('key', key.key)
var key3 = key2;
var record3 = record2;
client.get(key1, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(key2).to.have.property('ns', key.ns)
expect(key2).to.have.property('set', key.set)
expect(key2).to.have.property('key', key.key)
expect(record2).to.eql(record)
record3.i++;
var key3 = key2
var record3 = record2
client.put(key3, record3, meta, function(err, key4) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(key4).to.have.property('ns', key.ns);
expect(key4).to.have.property('set', key.set);
expect(key4).to.have.property('key', key.key);
record3.i++
client.get(key4, function(err, record5, metadata5, key5) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(key5).to.have.property('ns', key.ns);
expect(key5).to.have.property('set', key.set);
expect(key5).to.have.property('key', key.key);
expect(record5).to.eql(record3);
expect(metadata5.gen).to.equal(metadata2.gen+1);
expect(record5.i).to.equal(record3.i);
client.remove(key5, function(err, key){
done();
});
});
});
});
});
});
client.put(key3, record3, meta, function (err, key4) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(key4).to.have.property('ns', key.ns)
expect(key4).to.have.property('set', key.set)
expect(key4).to.have.property('key', key.key)
it('should write, read, remove, read, write, and check gen', function(done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/put/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string()});
client.get(key4, function (err, record5, metadata5, key5) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(key5).to.have.property('ns', key.ns)
expect(key5).to.have.property('set', key.set)
expect(key5).to.have.property('key', key.key)
expect(record5).to.eql(record3)
expect(metadata5.gen).to.equal(metadata2.gen + 1)
expect(record5.i).to.equal(record3.i)
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
client.remove(key5, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
})
// write the record then check
client.put(key, record, meta, function(err, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(key1).to.have.property('ns', key.ns);
expect(key1).to.have.property('set', key.set);
expect(key1).to.have.property('key', key.key);
it('should write, read, remove, read, write, and check gen', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/put/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string()})
client.get(key1, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(key2).to.have.property('ns', key.ns);
expect(key2).to.have.property('set', key.set);
expect(key2).to.have.property('key', key.key);
expect(record2).to.eql(record);
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
client.remove(key2, function(err, key3) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(key3).to.have.property('ns', key.ns);
expect(key3).to.have.property('set', key.set);
expect(key3).to.have.property('key', key.key);
// write the record then check
client.put(key, record, meta, function (err, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(key1).to.have.property('ns', key.ns)
expect(key1).to.have.property('set', key.set)
expect(key1).to.have.property('key', key.key)
client.get(key3, function(err, record4, metadata4, key4) {
expect(err).to.be.ok();
if(err.code != 602) {
expect(err.code).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND);
} else {
expect(err.code).to.equal(602);
}
client.get(key1, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(key2).to.have.property('ns', key.ns)
expect(key2).to.have.property('set', key.set)
expect(key2).to.have.property('key', key.key)
expect(record2).to.eql(record)
client.put(key, record, meta, function(err, key5) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(key5).to.have.property('ns', key.ns);
expect(key5).to.have.property('set', key.set);
expect(key5).to.have.property('key', key.key);
client.remove(key2, function (err, key3) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(key3).to.have.property('ns', key.ns)
expect(key3).to.have.property('set', key.set)
expect(key3).to.have.property('key', key.key)
client.get(key5, function(err, record6, metadata6, key6) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(key6).to.have.property('ns', key.ns);
expect(key6).to.have.property('set', key.set);
expect(key6).to.have.property('key', key.key);
expect(record6).to.eql(record);
expect(metadata6.gen).to.equal(1);
client.remove(key6, function(err, key){
done();
});
});
});
});
});
});
});
});
client.get(key3, function (err, record4, metadata4, key4) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND)
it('should write null for bins with empty list and map', function(done) {
client.put(key, record, meta, function (err, key5) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(key5).to.have.property('ns', key.ns)
expect(key5).to.have.property('set', key.set)
expect(key5).to.have.property('key', key.key)
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/put/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({
l: valgen.constant([1,2,3]),
le: valgen.constant([]),
m: valgen.constant({a: 1, b: 2}),
me: valgen.constant({})
});
client.get(key5, function (err, record6, metadata6, key6) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(key6).to.have.property('ns', key.ns)
expect(key6).to.have.property('set', key.set)
expect(key6).to.have.property('key', key.key)
expect(record6).to.eql(record)
expect(metadata6.gen).to.equal(1)
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
client.remove(key6, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
})
})
})
// write the record then check
client.put(key, record, meta, function(err, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
it('should write null for bins with empty list and map', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/put/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({
l: valgen.constant([1, 2, 3]),
le: valgen.constant([]),
m: valgen.constant({a: 1, b: 2}),
me: valgen.constant({})
})
expect(key1).to.have.property('ns', key.ns);
expect(key1).to.have.property('set', key.set);
expect(key1).to.have.property('key', key.key);
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
client.get(key1, function(err, record2, metadata2, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
// write the record then check
client.put(key, record, meta, function (err, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(key1).to.have.property('ns', key.ns)
expect(key1).to.have.property('set', key.set)
expect(key1).to.have.property('key', key.key)
expect(key2).to.have.property('ns', key.ns);
expect(key2).to.have.property('set', key.set);
expect(key2).to.have.property('key', key.key);
expect(record2).to.eql(record);
expect(record2.m).to.eql({a: 1, b: 2});
expect(record2.me).to.be.eql({});
expect(record2.l).to.eql([1,2,3]);
expect(record2.le).to.be.eql([]);
client.remove(key, function(err, key) {
done();
});
});
});
});
it('should write a bin of type undefined and write should not fail', function(done) {
client.get(key1, function (err, record2, metadata2, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(key2).to.have.property('ns', key.ns)
expect(key2).to.have.property('set', key.set)
expect(key2).to.have.property('key', key.key)
expect(record2).to.eql(record)
expect(record2.m).to.eql({a: 1, b: 2})
expect(record2.me).to.be.eql({})
expect(record2.l).to.eql([1, 2, 3])
expect(record2.le).to.be.eql([])
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/put/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({
l : valgen.constant([1,2,3]),
m : valgen.constant({a: 1, b: 2}),
});
client.remove(key, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
record.bin_un = undefined;
// write the record then check
client.put(key, record, meta, function(err, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_ERR_PARAM);
client.remove(key, function(err,key){
done();
});
});
});
it('should write a set with empty string and write should pass', function(done) {
it('should write a bin of type undefined and write should not fail', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/put/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({
l: valgen.constant([1, 2, 3]),
m: valgen.constant({a: 1, b: 2})
})
// generators
var kgen = keygen.string(options.namespace, "", {prefix: "test/put/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({
l : valgen.constant([1,2,3]),
m : valgen.constant({a: 1, b: 2}),
});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
record.bin_un = undefined
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function(err, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.get(key1, function(err, bins, meta, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(bins.m).to.eql({a: 1, b: 2});
expect(bins.l).to.eql([1,2,3]);
client.remove(key2, function(err, key3){
done();
});
});
});
});
it('should write a map with undefined entry and verify the record', function(done) {
// write the record then check
client.put(key, record, meta, function (err, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR_PARAM)
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/put/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({
l : valgen.constant([1,2,3, undefined]),
m : valgen.constant({a: 1, b: 2, c:undefined}),
});
client.remove(key, function (err, key) {
expect(err.code).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND)
done()
})
})
})
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// write the record then check
client.put(key, record, meta, function(err, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.get(key1, function(err, bins, meta, key2) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(bins.m).to.eql({a: 1, b: 2, c:null});
expect(bins.l).to.eql([1,2,3,null]);
client.remove(key2, function(err, key3){
done();
});
});
});
});
it('should write an object with boolean value and should fail', function(done) {
it('should write a set with empty string and write should pass', function (done) {
// generators
var kgen = keygen.string(options.namespace, '', {prefix: 'test/put/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({
l: valgen.constant([1, 2, 3]),
m: valgen.constant({a: 1, b: 2})
})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/put/"});
var mgen = metagen.constant({ttl: 1000});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// write the record then check
client.put(key, record, meta, function (err, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// values
var key = kgen();
var meta = mgen(key);
var record = { boolbin: true}
// write the record then check
client.put(key, record, meta, function(err, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_ERR_PARAM);
done();
});
});
it('should write a key with undefined value and it should fail gracefully', function(done) {
client.get(key1, function (err, bins, meta, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(bins.m).to.eql({a: 1, b: 2})
expect(bins.l).to.eql([1, 2, 3])
// generators
var kgen = keygen.string(options.namespace, options.set, undefined);
var mgen = metagen.constant({ttl: 1000});
// values
var key = aerospike.key(options.namespace, options.set, undefined);
var meta = mgen(key);
var record = { }
// write the record then check
client.put(key, record, meta, function(err, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_ERR_PARAM);
done();
});
});
client.remove(key2, function (err, key3) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
it('should check generation and then update record only if generation is equal (CAS)', function(done) {
it('should write a map with undefined entry and verify the record', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/put/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({
l: valgen.constant([1, 2, 3, undefined]),
m: valgen.constant({a: 1, b: 2, c: undefined})
})
// generators
var kgen = keygen.integer(options.namespace, options.set);
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string()});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// write the record then check
client.put(key, record, meta, function (err, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
client.get(key1, function (err, bins, meta, key2) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(bins.m).to.eql({a: 1, b: 2, c: null})
expect(bins.l).to.eql([1, 2, 3, null])
// write the record then check
client.put(key, record, meta, function(err, key) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
// check the content of the record
client.get(key, function(err, record, metadata, key) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
var mgen = metagen.constant({gen:1})
var meta = mgen(key);
var writePolicy = { gen: aerospike.policy.gen.EQ};
client.put(key, record, meta, writePolicy, function(err, key){
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.get(key, function( err, record, metadata, key) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(metadata.gen).to.equal(2);
client.remove(key, function(err, key){
done();
});
});
});
});
});
});
client.remove(key2, function (err, key3) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
});
it('should write an object with boolean value and should fail', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/put/'})
var mgen = metagen.constant({ttl: 1000})
// values
var key = kgen()
var meta = mgen(key)
var record = {boolbin: true}
// write the record then check
client.put(key, record, meta, function (err, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR_PARAM)
done()
})
})
it('should write a key with undefined value and it should fail gracefully', function (done) {
// generators
var mgen = metagen.constant({ttl: 1000})
// values
var key = aerospike.key(options.namespace, options.set, undefined)
var meta = mgen(key)
var record = { }
// write the record then check
client.put(key, record, meta, function (err, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR_PARAM)
done()
})
})
it('should check generation and then update record only if generation is equal (CAS)', function (done) {
// generators
var kgen = keygen.integer(options.namespace, options.set)
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string()})
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// write the record then check
client.put(key, record, meta, function (err, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// check the content of the record
client.get(key, function (err, record, metadata, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var mgen = metagen.constant({gen: 1})
var meta = mgen(key)
var writePolicy = {gen: aerospike.policy.gen.EQ}
client.put(key, record, meta, writePolicy, function (err, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
client.get(key, function (err, record, metadata, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
expect(metadata.gen).to.equal(2)
client.remove(key, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})
})
})

@@ -1,258 +0,238 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before, after */
// we want to test the built aerospike module
var aerospike = require('../lib/aerospike')
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var options = require('./util/options')
var expect = require('expect.js')
var status = aerospike.status
var filter = aerospike.filter
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var valgen = require('./generators/value');
describe('client.query()', function () {
var config = options.getConfig()
config.modlua = {}
config.modlua.userPath = __dirname
var client = aerospike.client(config)
var status = aerospike.status;
var policy = aerospike.policy;
var scanStatus = aerospike.scanStatus;
var filter = aerospike.filter;
before(function (done) {
client.connect(function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var indexCreationCallback = function (err) {
expect(err.code).to.equal(status.AEROSPIKE_OK)
}
// create integer and string index.
var indexObj = {
ns: options.namespace,
set: options.set,
bin: 'queryBinInt',
index: 'queryIndexInt'
}
client.createIntegerIndex(indexObj, indexCreationCallback)
describe('client.query()', function() {
indexObj = {
ns: options.namespace,
set: options.set,
bin: 'queryBinString',
index: 'queryIndexString'
}
client.createStringIndex(indexObj, indexCreationCallback)
var config = options.getConfig();
config.modlua = {};
config.modlua.userPath = __dirname;
var client = aerospike.client(config);
// Register the UDFs to be used in aggregation.
before(function(done) {
client.connect(function(err){
var dir = __dirname
var filename = dir + '/aggregate.lua'
client.udfRegister(filename, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
})
var indexCreationCallback = function(err){
expect(err.code).to.equal(status.AEROSPIKE_OK);
}
// create integer and string index.
var indexObj = {
ns: options.namespace,
set: options.set,
bin: 'queryBinInt',
index: 'queryIndexInt'
}
client.createIntegerIndex(indexObj, indexCreationCallback);
// load objects - to be queried in test case.
var total = 100
var count = 0
indexObj = {
ns: options.namespace,
set: options.set,
bin: 'queryBinString',
index: 'queryIndexString'
}
client.createStringIndex(indexObj, indexCreationCallback);
function iteration (i) {
// values
var key = {ns: options.namespace, set: options.set, key: 'test/query' + i.toString()}
var meta = {ttl: 10000, gen: 1}
var record = {queryBinInt: i, queryBinString: 'querystringvalue'}
// Register the UDFs to be used in aggregation.
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var dir = __dirname;
var filename = dir + "/aggregate.lua"
client.udfRegister(filename, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
});
// load objects - to be queried in test case.
var total = 100;
var count = 0;
function iteration(i) {
// values
var key = { ns: options.namespace, set: options.set, key: "test/query" + i.toString()}
var meta = { ttl: 10000, gen: 1}
var record = { queryBinInt: i, queryBinString: 'querystringvalue'}
// write the record then check
client.put(key, record, meta, function(err, key) {
client.get(key, function(err, _record, _metadata, _key) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
count++;
if ( count >= total ) {
done();
}
});
});
client.get(key, function (err, _record, _metadata, _key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
count++
if (count >= total) {
done()
}
})
})
}
for ( var i = 1; i <= total; i++ ) {
iteration(i);
}
for (var i = 1; i <= total; i++) {
iteration(i)
}
})
})
});
after(function (done) {
client.close()
client = null
done()
})
});
it('should query on an integer index - filter by equality of bin value', function (done) {
// counters
var count = 0
var err = 0
after(function(done) {
client.close();
client = null;
done();
});
var args = { filters: [filter.equal('queryBinInt', 100)] }
var query = client.query(options.namespace, options.set, args)
it('should query on an integer index - filter by equality of bin value', function(done) {
var stream = query.execute()
stream.on('data', function (rec) {
expect(rec.bins).to.have.property('queryBinInt')
expect(rec.bins).to.have.property('queryBinString')
expect(rec.bins['queryBinInt']).to.equal(100)
count++
})
stream.on('error', function (error) { // eslint-disable-line handle-callback-err
err++
})
stream.on('end', function (end) {
expect(count).to.be.equal(1)
expect(err).to.equal(0)
done()
})
})
// counters
var total = 100;
var count = 0;
var err = 0;
it('should query on an integer index - filter by range of bin values', function (done) {
// counters
var total = 100
var count = 0
var err = 0
var args = { filters: [filter.equal('queryBinInt', 100)] }
var query = client.query(options.namespace, options.set, args);
var args = { filters: [filter.range('queryBinInt', 1, 100)] }
var query = client.query(options.namespace, options.set, args)
var stream = query.execute();
stream.on('data', function(rec){
expect(rec.bins).to.have.property('queryBinInt');
expect(rec.bins).to.have.property('queryBinString');
expect(rec.bins['queryBinInt']).to.equal(100);
count++;
});
stream.on('error', function(error){
err++;
});
stream.on('end', function(end){
expect(count).to.be.equal(1);
expect(err).to.equal(0);
done();
});
});
it('should query on an integer index - filter by range of bin values', function(done) {
var stream = query.execute()
stream.on('data', function (rec) {
expect(rec.bins).to.have.property('queryBinInt')
expect(rec.bins).to.have.property('queryBinString')
expect(rec.bins['queryBinInt']).to.be.lessThan(101)
count++
})
stream.on('error', function (error) { // eslint-disable-line handle-callback-err
err++
})
stream.on('end', function (end) {
expect(count).to.be.greaterThan(total - 1)
expect(err).to.equal(0)
done()
})
})
// counters
var total = 100;
var count = 0;
var err = 0;
it('should query on a string index - filter by equality of bin value', function (done) {
// counters
var total = 100
var count = 0
var err = 0
var args = { filters: [filter.range('queryBinInt', 1, 100)] }
var query = client.query(options.namespace, options.set, args);
var args = { filters: [filter.equal('queryBinString', 'querystringvalue')] }
var query = client.query(options.namespace, options.set, args)
var stream = query.execute();
stream.on('data', function(rec){
expect(rec.bins).to.have.property('queryBinInt');
expect(rec.bins).to.have.property('queryBinString');
expect(rec.bins['queryBinInt']).to.be.lessThan(101);
count++;
});
stream.on('error', function(error){
err++;
});
stream.on('end', function(end){
expect(count).to.be.greaterThan(total-1);
expect(err).to.equal(0);
done();
});
});
it('should query on a string index - filter by equality of bin value', function(done) {
var stream = query.execute()
stream.on('data', function (rec) {
expect(rec.bins).to.have.property('queryBinInt')
expect(rec.bins).to.have.property('queryBinString')
expect(rec.bins['queryBinString']).to.equal('querystringvalue')
count++
})
stream.on('error', function (error) { // eslint-disable-line handle-callback-err
err++
})
stream.on('end', function (end) {
expect(count).to.be.greaterThan(total - 1)
expect(err).to.equal(0)
// counters
var total = 100;
var count = 0;
var err = 0;
done()
})
})
var args = { filters: [filter.equal('queryBinString', 'querystringvalue')] }
var query = client.query(options.namespace, options.set, args);
it('should query on an index and apply aggregation user defined function', function (done) {
if (!options.run_aggregation) {
done()
} else {
// counters
var count = 0
var err = 0
var stream = query.execute();
stream.on('data', function(rec){
expect(rec.bins).to.have.property('queryBinInt');
expect(rec.bins).to.have.property('queryBinString');
expect(rec.bins['queryBinString']).to.equal('querystringvalue');
count++;
});
stream.on('error', function(error){
err++;
});
stream.on('end', function(end){
expect(count).to.be.greaterThan(total-1);
expect(err).to.equal(0);
var args = { filters: [filter.equal('queryBinString', 'querystringvalue')],
aggregationUDF: {module: 'aggregate', funcname: 'sum_test_bin'}}
var query = client.query(options.namespace, options.set, args)
done();
});
});
var stream = query.execute()
stream.on('data', function (result) {
expect(result).to.be.ok()
count++
})
stream.on('error', function (error) {
expect(error).to.be.ok()
expect(error.code).to.equal(status.AEROSPIKE_OK)
err++
})
stream.on('end', function (end) {
expect(count).to.be.equal(1)
expect(err).to.equal(0)
done()
})
}
})
it('should query on an index and apply aggregation user defined function', function(done) {
it('should scan aerospike database and apply aggregation user defined function', function (done) {
if (!options.run_aggregation) {
done()
} else {
// counters
var count = 0
var err = 0
if( !options.run_aggregation ) {
done();
}
else {
// counters
var total = 100;
var count = 0;
var err = 0;
var args = {aggregationUDF: {module: 'aggregate', funcname: 'sum_test_bin'}}
var query = client.query(options.namespace, options.set, args)
var args = { filters: [filter.equal('queryBinString', 'querystringvalue')],
aggregationUDF: {module:'aggregate', funcname:'sum_test_bin'}}
var query = client.query(options.namespace, options.set, args);
var stream = query.execute();
stream.on('data', function(result){
expect(result).to.be.ok();
count++;
});
stream.on('error', function(error){
expect(error).to.be.ok();
expect(error.code).to.equal(status.AEROSPIKE_OK);
err++;
});
stream.on('end', function(end){
expect(count).to.be.equal(1);
expect(err).to.equal(0);
done();
});
}
});
it('should scan aerospike database and apply aggregation user defined function', function(done) {
if( !options.run_aggregation ) {
done();
}
else {
// counters
var total = 100;
var count = 0;
var err = 0;
var args = { aggregationUDF: {module:'aggregate', funcname:'sum_test_bin'}}
var query = client.query(options.namespace, options.set, args);
var stream = query.execute();
stream.on('data', function(result){
expect(result).to.be.ok();
count++;
});
stream.on('error', function(error){
expect(error).to.be.ok();
expect(error.code).to.equal(status.AEROSPIKE_OK);
err++;
});
stream.on('end', function(end){
expect(count).to.be.equal(1);
expect(err).to.equal(0);
done();
});
}
});
});
var stream = query.execute()
stream.on('data', function (result) {
expect(result).to.be.ok()
count++
})
stream.on('error', function (error) {
expect(error).to.be.ok()
expect(error.code).to.equal(status.AEROSPIKE_OK)
err++
})
stream.on('end', function (end) {
expect(count).to.be.equal(1)
expect(err).to.equal(0)
done()
})
}
})
})

@@ -1,136 +0,125 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before, after */
// we want to test the built aerospike module
var aerospike = require('../build/Release/aerospike');
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var aerospike = require('../build/Release/aerospike')
var options = require('./util/options')
var expect = require('expect.js')
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var valgen = require('./generators/value');
var keygen = require('./generators/key')
var metagen = require('./generators/metadata')
var recgen = require('./generators/record')
var valgen = require('./generators/value')
var status = aerospike.status;
var policy = aerospike.policy;
var status = aerospike.status
describe('client.remove()', function() {
describe('client.remove()', function () {
var config = options.getConfig()
var client = aerospike.client(config)
var config = options.getConfig();
var client = aerospike.client(config);
before(function (done) {
client.connect(function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
before(function(done) {
client.connect(function(err){
done();
});
});
after(function (done) {
client.close()
client = null
done()
})
after(function(done) {
client.close();
client = null;
done();
});
it('should remove a record w/ string key', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()})
it('should remove a record w/ string key', function(done) {
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()});
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
client.get(key, function (err, record, metadata, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
// write the record then check
client.put(key, record, meta, function(err, key) {
client.get(key, function(err, record, metadata, key) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.remove(key, function(err, key) {
client.get(key, function(err, record, metadata, key) {
expect(err).to.be.ok();
if(err.code != 602) {
expect(err.code).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND);
}
else {
expect(err.code).to.equal(602);
}
done();
});
});
});
});
});
client.remove(key, function (err, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
it('should remove a record w/ integer key', function(done) {
client.get(key, function (err, record, metadata, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND)
done()
})
})
})
})
})
// generators
var kgen = keygen.integer(options.namespace, options.set);
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()});
it('should remove a record w/ integer key', function (done) {
// generators
var kgen = keygen.integer(options.namespace, options.set)
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()})
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
// write the record then check
client.put(key, record, meta, function(err, key) {
client.get(key, function(err, record, metadata, key) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.remove(key, function(err, key) {
client.get(key, function(err, record, metadata, key) {
expect(err).to.be.ok();
if(err.code != 602) {
expect(err.code).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND);
}
else {
expect(err.code).to.equal(602);
}
done();
});
});
});
});
});
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
it('should not remove a non-existent key', function(done) {
client.get(key, function (err, record, metadata, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/not_found/"});
client.remove(key, function (err, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
// values
var key = kgen();
client.get(key, function (err, record, metadata, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND)
done()
})
})
})
})
})
// write the record then check
client.remove(key, function(err, key) {
expect(err).to.be.ok();
if(err.code != 602) {
expect(err.code).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND);
}
else {
expect(err.code).to.equal(602);
}
done();
});
});
it('should not remove a non-existent key', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/not_found/'})
});
// values
var key = kgen()
client.remove(key, function (err, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND)
done()
})
})
})

@@ -1,187 +0,177 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before, after */
// we want to test the built aerospike module
var aerospike = require('../lib/aerospike')
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var options = require('./util/options')
var expect = require('expect.js')
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var valgen = require('./generators/value');
var metagen = require('./generators/metadata')
var recgen = require('./generators/record')
var valgen = require('./generators/value')
var status = aerospike.status;
var policy = aerospike.policy;
var queryStatus = aerospike.scanStatus;
describe('client.query() - without where clause(Scan)', function() {
var status = aerospike.status
var config = options.getConfig();
var client = aerospike.client(config);
describe('client.query() - without where clause(Scan)', function () {
var config = options.getConfig()
var client = aerospike.client(config)
before(function(done) {
client.connect(function(err){
// counters
before(function (done) {
client.connect(function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var total = 100;
var count = 0;
// counters
var total = 100
var count = 0
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/query/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()});
// generators
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()})
function iteration(i) {
function iteration (i) {
// values
var key = {ns: options.namespace, set: options.set, key: 'test/query' + i.toString()}
var meta = mgen(key)
var record = rgen(key, meta)
// values
var key = { ns: options.namespace, set: options.set, key: "test/query" + i.toString()}
var meta = mgen(key);
var record = rgen(key, meta);
// register the UDF used in scan background.
var dir = __dirname
var filename = dir + '/scan.lua'
client.udfRegister(filename, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
})
//register the UDF used in scan background.
var dir = __dirname;
var filename = dir + "/scan.lua";
client.udfRegister(filename, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
});
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
// write the record then check
client.put(key, record, meta, function(err, key) {
client.get(key, function(err, _record, _metadata, _key) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
count++;
if ( count >= total ) {
done();
}
});
});
client.get(key, function (err, _record, _metadata, _key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
count++
if (count >= total) {
done()
}
})
})
}
for ( var i = 0; i < total; i++ ) {
iteration(i);
}
});
for (var i = 0; i < total; i++) {
iteration(i)
}
})
})
});
after(function (done) {
client.close()
client = null
done()
})
after(function(done) {
var total = 100;
client.close();
client = null;
done();
});
it('should query all the records', function (done) {
this.timeout(5000)
// counters
var count = 0
var err = 0
it('should query all the records', function(done) {
var query = client.query(options.namespace, options.set)
this.timeout(5000);
// counters
var total = 100;
var count = 0;
var err = 0;
var stream = query.execute()
var query = client.query(options.namespace, options.set);
stream.on('data', function (rec) {
count++
})
stream.on('error', function (error) { // eslint-disable-line handle-callback-err
err++
})
stream.on('end', function (end) {
// derive it as a percentage.
expect(count).to.be.greaterThan(99)
expect(err).to.equal(0)
var stream = query.execute();
done()
})
})
stream.on('data', function(rec){
count++;
});
stream.on('error', function(error){
err++;
});
stream.on('end', function(end){
// derive it as a percentage.
expect(count).to.be.greaterThan(99);
expect(err).to.equal(0);
it('should query and select no bins', function (done) {
this.timeout(5000)
var total = 100
var count = 0
var err = 0
done();
});
});
var args = {nobins: true}
var query = client.query(options.namespace, options.set, args)
it('should query and select no bins', function(done) {
var stream = query.execute()
this.timeout(5000);
var total = 100;
var count = 0;
var err = 0;
stream.on('data', function (rec) {
count++
})
stream.on('error', function (error) { // eslint-disable-line handle-callback-err
err++
})
stream.on('end', function (end) {
expect(count).to.be.greaterThan(total)
expect(err).to.equal(0)
done()
})
})
var args = { nobins : true}
var query = client.query(options.namespace, options.set, args);
it('should query and select only few bins in the record', function (done) {
this.timeout(5000)
var total = 99
var count = 0
var err = 0
var stream = query.execute();
var args = {select: ['i', 's']}
var query = client.query(options.namespace, options.set, args)
stream.on('data', function(rec) {
count++;
});
stream.on('error', function(error){
err++;
});
stream.on('end', function(end) {
expect(count).to.be.greaterThan(total);
expect(err).to.equal(0);
done();
});
});
it('should query and select only few bins in the record', function(done) {
var stream = query.execute()
this.timeout(5000);
var total = 99;
var count = 0;
var err = 0;
stream.on('data', function (rec) {
count++
})
stream.on('error', function (error) { // eslint-disable-line handle-callback-err
err++
})
stream.on('end', function (end) {
expect(count).to.be.greaterThan(total)
expect(err).to.equal(0)
done()
})
})
var args = { select : ['i', 's']}
var query = client.query(options.namespace, options.set, args);
it('should do a scan background and check for the status of scan job ', function (done) {
var args = {UDF: {module: 'scan', funcname: 'updateRecord'}}
var scanBackground = client.query(options.namespace, options.set, args)
var stream = query.execute();
var err = 0
var stream = scanBackground.execute()
stream.on('data', function(rec) {
count++;
});
stream.on('error', function(error){
err++;
});
stream.on('end', function(end) {
expect(count).to.be.greaterThan(total);
expect(err).to.equal(0);
done();
});
});
it('should do a scan background and check for the status of scan job ', function(done) {
var args = { UDF: {module: 'scan', funcname: 'updateRecord'}}
var scanBackground = client.query( options.namespace, options.set, args);
var err = 0;
var scanStream = scanBackground.execute();
var infoCallback = function( scanJobStats, scanId) {
done();
}
scanStream.on('error', function(error) {
err++;
});
scanStream.on('end', function(scanId) {
scanBackground.Info(scanId, infoCallback);
});
});
});
var infoCallback = function (scanJobStats, scanId) {
done()
}
stream.on('error', function (error) { // eslint-disable-line handle-callback-err
err++
})
stream.on('end', function (scanId) {
scanBackground.Info(scanId, infoCallback)
})
})
})

@@ -1,161 +0,164 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before, after */
// we want to test the built aerospike module
var aerospike = require('../build/Release/aerospike');
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var aerospike = require('../build/Release/aerospike')
var options = require('./util/options')
var expect = require('expect.js')
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var valgen = require('./generators/value');
var keygen = require('./generators/key')
var metagen = require('./generators/metadata')
var recgen = require('./generators/record')
var valgen = require('./generators/value')
var status = aerospike.status;
var policy = aerospike.policy;
var status = aerospike.status
var policy = aerospike.policy
describe('client.select()', function() {
describe('client.select()', function () {
var config = options.getConfig()
var client = aerospike.client(config)
var config = options.getConfig();
var client = aerospike.client(config);
before(function (done) {
client.connect(function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
before(function(done) {
client.connect(function(err){
done();
});
});
after(function (done) {
client.close()
client = null
done()
})
after(function(done) {
client.close();
client = null;
done();
});
it('should read the record', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/select/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()})
it('should read the record', function(done) {
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
var bins = Object.keys(record).slice(0, 1)
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/select/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()});
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
var bins = Object.keys(record).slice(0,1);
client.select(key, bins, function (err, _record, metadata, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(_record).to.only.have.keys(bins)
// write the record then check
client.put(key, record, meta, function(err, key) {
client.select(key, bins, function(err, _record, metadata, key) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(_record).to.only.have.keys(bins);
for (var bin in _record) {
expect(_record[bin]).to.be(record[bin])
}
for ( var bin in _record ) {
expect(_record[bin]).to.be(record[bin]);
}
client.remove(key, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
client.remove(key, function(err, key){
done();
});
});
});
});
it('should fail - when a select is called without key ', function(done) {
it('should fail - when a select is called without key ', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/select/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/select/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
var bins = Object.keys(record).slice(0, 1)
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
var bins = Object.keys(record).slice(0,1);
// write the record then check
client.put(key, record, meta, function (err, key1) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
var select_key = {ns: options.namespace, set: options.set}
// write the record then check
client.put(key, record, meta, function(err, key1) {
var select_key = { ns:options.namespace, set: options.set}
client.select(select_key, bins, function(err, _record, metadata, key1) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_ERR_PARAM);
client.remove(key, function(err, key){
done();
});
});
});
});
client.select(select_key, bins, function (err, _record, metadata, key1) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR_PARAM)
it('should not find the record', function(done) {
client.remove(key, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/not_found/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()});
it('should not find the record', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/not_found/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()})
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
var bins = Object.keys(record).slice(0,1);
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
var bins = Object.keys(record).slice(0, 1)
// write the record then check
client.select(key, bins, function(err, record, metadata, key) {
expect(err).to.be.ok();
if(err.code != 602) {
expect(err.code).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND);
}
else {
expect(err.code).to.equal(602);
}
done();
});
});
// write the record then check
client.select(key, bins, function (err, record, metadata, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR_RECORD_NOT_FOUND)
done()
})
})
it('should read the record w/ a key send policy', function(done) {
it('should read the record w/ a key send policy', function (done) {
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: 'test/get/'})
var mgen = metagen.constant({ttl: 1000})
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()})
// generators
var kgen = keygen.string(options.namespace, options.set, {prefix: "test/get/"});
var mgen = metagen.constant({ttl: 1000});
var rgen = recgen.record({i: valgen.integer(), s: valgen.string(), b: valgen.bytes()});
// values
var key = kgen()
var meta = mgen(key)
var record = rgen(key, meta)
var bins = Object.keys(record).slice(0, 1)
var pol = {key: policy.key.SEND}
// values
var key = kgen();
var meta = mgen(key);
var record = rgen(key, meta);
var bins = Object.keys(record).slice(0,1);
var pol = { key: policy.key.SEND };
// write the record then check
client.put(key, record, meta, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
// write the record then check
client.put(key, record, meta, function(err, key) {
client.select(key, bins, pol, function(err, _record, metadata, key) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
expect(_record).to.only.have.keys(bins);
client.select(key, bins, pol, function (err, _record, metadata, key) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
expect(_record).to.only.have.keys(bins)
for ( var bin in _record ) {
expect(_record[bin]).to.be(record[bin]);
}
client.remove(key, function(err, key){
done();
});
});
});
});
});
for (var bin in _record) {
expect(_record[bin]).to.be(record[bin])
}
client.remove(key, function (err, key) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
})
})
})

@@ -1,117 +0,108 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before, after */
// we want to test the built aerospike module
var aerospike = require('../build/Release/aerospike');
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var aerospike = require('../build/Release/aerospike')
var options = require('./util/options')
var expect = require('expect.js')
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var status = aerospike.status
var language = aerospike.language
var status = aerospike.status;
var policy = aerospike.policy;
var language = aerospike.language;
describe('client.udfRegister()', function (done) {
var config = options.getConfig()
var client = aerospike.client(config)
describe('client.udfRegister()', function(done) {
before(function (done) {
client.connect(function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
var config = options.getConfig();
var client = aerospike.client(config);
after(function (done) {
client.close()
client = null
done()
})
before(function(done) {
client.connect(function(err){
done();
});
});
it('should register an UDF file to aerospike cluster', function (done) {
var dir = __dirname
var filename = dir + '/udf_test.lua'
client.udfRegister(filename, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
done()
})
})
after(function(done) {
client.close()
client = null;
done();
});
it('should register an UDF file to aerospike cluster', function(done) {
var dir = __dirname;
var filename = dir + "/udf_test.lua"
client.udfRegister(filename, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
done();
});
});
it('should register an UDF file with a LUA type to aerospike cluster', function (done) {
var dir = __dirname
var filename = dir + '/udf_test.lua'
client.udfRegister(filename, language.LUA, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
done()
})
})
it('should register an UDF file with a LUA type to aerospike cluster', function(done) {
var dir = __dirname;
var filename = dir + "/udf_test.lua"
client.udfRegister(filename, language.LUA, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
done();
});
});
it('should register an UDF file with a info policy to aerospike cluster', function(done) {
var dir = __dirname;
var filename = dir + "/udf_test.lua"
var infopolicy = { timeout : 1000, send_as_is: true, check_bounds: false }
client.udfRegister(filename, infopolicy, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
done();
});
});
it('should register an UDF file with a info policy to aerospike cluster', function (done) {
var dir = __dirname
var filename = dir + '/udf_test.lua'
var infopolicy = { timeout: 1000, send_as_is: true, check_bounds: false }
client.udfRegister(filename, infopolicy, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
done()
})
})
it('should register an UDF file with a info policy and LUA type to aerospike cluster', function (done) {
var dir = __dirname
var filename = dir + '/udf_test.lua'
var infopolicy = { timeout: 1000, send_as_is: true, check_bounds: false }
client.udfRegister(filename, language.LUA, infopolicy, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
done()
})
})
it('should register an UDF file with a info policy and LUA type to aerospike cluster', function(done) {
var dir = __dirname;
var filename = dir + "/udf_test.lua"
var infopolicy = { timeout : 1000, send_as_is: true, check_bounds: false }
client.udfRegister(filename, language.LUA, infopolicy, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
done();
});
});
it('registering a non-existent UDF file to aerospike cluster - should fail', function (done) {
var filename = 'test.lua'
client.udfRegister(filename, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR)
done()
})
})
it('registering a non-existent UDF file to aerospike cluster - should fail',function(done) {
var filename = "test.lua"
client.udfRegister(filename, function(err) {
expect(err).to.be.ok();
if(err.code != 100) {
expect(err.code).to.equal(status.AEROSPIKE_ERR);
}
else {
expect(err.code).to.equal(100);
}
done();
});
});
it('should register an UDF file to aerospike cluster and wait until all registration is done across all nodes in Aerospike cluster', function(done) {
var dir = __dirname;
var filename = dir + "/udf_test.lua"
client.udfRegister(filename, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.udfRegisterWait("udf_test.lua", 1000, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
done();
});
});
});
});
it('should register an UDF file to aerospike cluster and wait until all registration is done across all nodes in Aerospike cluster', function (done) {
var dir = __dirname
var filename = dir + '/udf_test.lua'
client.udfRegister(filename, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
client.udfRegisterWait('udf_test.lua', 1000, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
done()
})
})
})
})

@@ -1,70 +0,60 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
/* global describe, it, before */
// we want to test the built aerospike module
var aerospike = require('../build/Release/aerospike');
var options = require('./util/options');
var assert = require('assert');
var expect = require('expect.js');
var aerospike = require('../build/Release/aerospike')
var options = require('./util/options')
var expect = require('expect.js')
var keygen = require('./generators/key');
var metagen = require('./generators/metadata');
var recgen = require('./generators/record');
var putgen = require('./generators/put');
var status = aerospike.status
var status = aerospike.status;
var policy = aerospike.policy;
var language = aerospike.language;
describe('client.udfRemove()', function (done) {
var config = options.getConfig()
var client = aerospike.client(config)
describe('client.udfRemove()', function(done) {
before(function (done) {
client.connect(function (err) {
if (err && err.code !== status.AEROSPIKE_OK) { throw new Error(err.message) }
done()
})
})
var config = options.getConfig();
var client = aerospike.client(config);
it('should remove an UDF module with a info policy from aerospike cluster', function (done) {
var dir = __dirname
var filename = dir + '/udf_test.lua'
var infopolicy = { timeout: 1000, send_as_is: true, check_bounds: false }
client.udfRegister(filename, infopolicy, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
client.udfRemove('udf_test.lua', infopolicy, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_OK)
done()
})
})
})
before(function(done) {
client.connect(function(err){
done();
});
});
after(function(done) {
done();
});
it('should remove an UDF module with a info policy from aerospike cluster', function(done) {
var dir = __dirname;
var filename = dir + "/udf_test.lua"
var infopolicy = { timeout : 1000, send_as_is: true, check_bounds: false }
client.udfRegister(filename, infopolicy, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
client.udfRemove("udf_test.lua", infopolicy, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_OK);
done();
});
});
});
it('remove non-existent UDF module from aerospike cluster - should fail',function(done) {
var filename = "noudf.lua"
client.udfRemove(filename, function(err) {
expect(err).to.be.ok();
expect(err.code).to.equal(status.AEROSPIKE_ERR_UDF);
done();
});
});
});
it('remove non-existent UDF module from aerospike cluster - should fail', function (done) {
var filename = 'noudf.lua'
client.udfRemove(filename, function (err) {
expect(err).to.be.ok()
expect(err.code).to.equal(status.AEROSPIKE_ERR_UDF)
done()
})
})
})

@@ -1,107 +0,105 @@

/*******************************************************************************
* Copyright 2013-2014 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
// *****************************************************************************
// Copyright 2013-2016 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************
var aerospike = require('../../build/Release/aerospike')
var yargs = require('yargs')
var fs = require('fs')
var aerospike = require('../../build/Release/aerospike');
var yargs = require('yargs');
var fs = require('fs');
/*******************************************************************************
*
* Options parsing
*
******************************************************************************/
// *****************************************************************************
// Options parsing
// *****************************************************************************
var parser = yargs
.usage("$0 [options]")
.options({
help: {
boolean: true,
describe: "Display this message."
},
host: {
alias: "h",
default: "127.0.0.1",
describe: "Aerospike database address."
},
port: {
alias: "p",
default: 3000,
describe: "Aerospike database port."
},
timeout: {
alias: "t",
default: 100,
describe: "Timeout in milliseconds."
},
log: {
alias: "l",
default: aerospike.log.INFO,
describe: "Log level [0-5]"
},
log_file: {
alias: "f",
default: fs.openSync("test.log", "a"),
describe: "Log file to redirect the log messages"
},
namespace: {
alias: "n",
default: "test",
describe: "Namespace for the keys."
},
set: {
alias: "s",
default: "demo",
describe: "Set for the keys."
},
user: {
alias: "U",
default:null,
describe: "Username to connect to a secure cluster"
},
password: {
alias: "P",
default: null,
describe: "Password to connect to a secure cluster"
},
run_aggregation: {
default: false,
describe: "Set this to true to run aggregation tests"
}
});
.usage('$0 [options]')
.options({
help: {
boolean: true,
describe: 'Display this message.'
},
host: {
alias: 'h',
default: '127.0.0.1',
describe: 'Aerospike database address.'
},
port: {
alias: 'p',
default: 3000,
describe: 'Aerospike database port.'
},
timeout: {
alias: 't',
default: 100,
describe: 'Timeout in milliseconds.'
},
log: {
alias: 'l',
default: aerospike.log.INFO,
describe: 'Log level [0-5]'
},
log_file: {
alias: 'f',
default: fs.openSync('test.log', 'a'),
describe: 'Log file to redirect the log messages'
},
namespace: {
alias: 'n',
default: 'test',
describe: 'Namespace for the keys.'
},
set: {
alias: 's',
default: 'demo',
describe: 'Set for the keys.'
},
user: {
alias: 'U',
default: null,
describe: 'Username to connect to a secure cluster'
},
password: {
alias: 'P',
default: null,
describe: 'Password to connect to a secure cluster'
},
run_aggregation: {
default: false,
describe: 'Set this to true to run aggregation tests'
}
})
var options = process.env['OPTIONS'] ? parser.parse(process.env['OPTIONS'].trim().split(' ')) : parser.argv;
var options = process.env['OPTIONS'] ? parser.parse(process.env['OPTIONS'].trim().split(' ')) : parser.argv
options.getConfig = function() {
var config = {};
config = {
hosts: [ {addr:options.host, port: options.port} ],
log: { level: options.log, file: options.log_file},
policies: { timeout: options.timeout}
}
if(options.user !== null) {
config.user = options.user;
}
if(options.password !== null) {
config.password = options.password;
}
return config;
options.getConfig = function () {
var config = {}
config = {
hosts: [{addr: options.host, port: options.port}],
log: {level: options.log, file: options.log_file},
policies: {timeout: options.timeout}
}
if (options.user !== null) {
config.user = options.user
}
if (options.password !== null) {
config.password = options.password
}
return config
}
if ( options.help === true ) {
parser.showHelp();
process.exit(0);
if (options.help === true) {
parser.showHelp()
process.exit(0)
}
module.exports = options;
module.exports = options

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc