Permalink
Browse files

added tests and fixed a deserialization issue in row

  • Loading branch information...
devdazed committed Jan 6, 2012
1 parent ca11b76 commit e5c3b821ef3eb4d2e74a2ccbfcc0e2ae9b293f41
Showing with 116 additions and 51 deletions.
  1. +6 −2 Makefile
  2. +58 −0 examples/bench_helenus.js
  3. +7 −2 lib/pool.js
  4. +3 −2 lib/row.js
  5. +8 −2 package.json
  6. +34 −0 test/suite.js
  7. +0 −43 test/test.js
View
@@ -1,5 +1,9 @@
+NODE_PATH="./node_modules/whiskey/bin/"
test:
- @echo "populate me"
+ whiskey --real-time --scope-leaks --tests test/suite.js
-.PHONY: test
+cov:
+ node_modules/whiskey/bin/whiskey --coverage --tests test/suite.js
+
+.PHONY: test cov
View
@@ -0,0 +1,58 @@
+/**
+ * Basically here we are benchmarking helenus
+ */
+var Helenus = require('../');
+
+/**
+ * Some information about our tests
+ * create column family bench_test with comparator=UTF8Type and default_validation_class=UTF8Type and key_validation_class=UTF8Type;
+ */
+var times = 100000, completed = 0, i = 0, vals,
+ cqlInsert = "UPDATE bench_test USING CONSISTENCY ANY SET '%s'='%s' WHERE key='%s'";
+
+/**
+ * Create our helenus connection
+ */
+var conn = new Helenus.Connection({
+ host:'localhost:9160',
+ keyspace:'helenus_test'
+ });
+
+/**
+ * First bench helenus
+ */
+function bench(callback){
+ conn.connect(function(err, keyspace){
+ if(err){
+ throw(err);
+ }
+
+ console.time('Helenus ' + times + ' writes');
+
+ function cb(err, results){
+ if(err){
+ console.log('Error encountered at: ' + completed);
+ throw(err);
+ }
+ completed += 1;
+
+ if(completed === times){
+ console.timeEnd('Helenus ' + times + ' writes') ;
+ conn.close();
+ callback();
+ }
+ }
+
+ /**
+ * lets run a test for writes
+ */
+ for(; i < times; i += 1){
+ vals = ['Column'+i, i.toString(16), (i % 100).toString(16)];
+ conn.cql(cqlInsert, vals, { gzip:true }, cb);
+ }
+ });
+}
+
+bench(function(){
+ console.log('Done');
+});
View
@@ -20,13 +20,18 @@ var Connection = require('./connection'),
* @constructor
*/
var Pool = function(options){
- this.clients = [];
- this.hosts = options.hosts;
+ this.clients = [];
this.keyspace = options.keyspace;
this.user = options.user;
this.password = options.password;
this.timeout = options.timeout;
+ if(!options.hosts && options.host){
+ this.hosts = [options.hosts];
+ } else {
+ this.hosts = options.hosts;
+ }
+
if(!Array.isArray(this.hosts)){
throw(new Error('HelenusError: Invalid hosts supplied for connection pool'));
}
View
@@ -12,6 +12,7 @@ var Row = function(data, schema){
this._nameMarshaller = new Marshal(schema.default_name_type || 'BytesType');
this._map = {};
this._schema = schema;
+ this._humanColumnNames = [];
for(; i < len; i += 1){
item = data.columns[i];
@@ -34,6 +35,7 @@ var Row = function(data, schema){
ttl:item.ttl
});
this._map[item.name] = i;
+ this._humanColumnNames.push(name);
}
}
@@ -69,8 +71,7 @@ Row.prototype.get = function(name){
* Inspect method for columns
*/
Row.prototype.inspect = function(){
- var cols = Object.keys(this._map).join('\', \'');
- return util.format("<Row: Key: '%s', ColumnCount: %s, Columns: [ '%s' ]>", this.key, this.length, cols);
+ return util.format("<Row: Key: '%s', ColumnCount: %s, Columns: [ '%s' ]>", this.key, this.length, this._humanColumnNames);
};
/**
View
@@ -6,8 +6,14 @@
, "author": "Russell Bradberry <rbradberry@gmail.com>"
, "dependencies": {
"helenus-thrift":"0.7.1",
- "uuid-js":">0.5.2"
- }
+ "uuid-js":">0.5.2"
+ }
+ , "devDependencies": {
+ "whiskey": "*"
+ }
+ , "scripts": {
+ "test": "make test"
+ }
, "main": "index"
, "engines": { "node": "0.6.x" }
}
View
@@ -0,0 +1,34 @@
+var config = {
+ host : 'localhost:9160',
+ keyspace : 'system',
+ user : 'test',
+ password : 'test1233',
+ timeout : 3000
+};
+
+var helenus, pool;
+
+/**
+ * Tests connecting to the server using the system keyspace
+ * also ensures the connection is available for the other tests
+ */
+exports.setUp = function(test, assert) {
+ helenus = require('../');
+ pool = new helenus.ConnectionPool(config);
+
+ //connect to the local machine
+ pool.connect(function(err, keyspace){
+ assert.ifError(err, 'askdhgdfsj');
+ test.finish();
+ });
+};
+
+//exports['test create keyspace']
+
+/**
+ * Closes the connection and tests it doesn't throw.
+ */
+exports.tearDown = function(test, assert){
+ assert.doesNotThrow(function(){ pool.close(); });
+ test.finish();
+};
View
@@ -1,43 +0,0 @@
-var helenus = require('../'),
- pool = new helenus.ConnectionPool({
- hosts : ['localhost:9160'],
- keyspace : 'helenus_test',
- user : 'test',
- password : 'test1233',
- timeout : 3000
- });
-
-pool.on('error', function(err){
- throw(err);
-});
-
-//connect to the local machine
-pool.connect(function(err, keyspace){
- if(err){
- throw(err);
- } else {
- //test standard
-
- keyspace.standard_test.insert('foo-bar', { 'one':'1', 'two':2, 'three':3, 'four':4 }, {}, function(err){
- if(err){
- throw(err);
- }
- var cql = "SELECT %s FROM '%s' WHERE key='%s'",
- fields = "*",
- options = [fields, 'standard_test', 'key1'];
-
- pool.cql(cql, options, { gzip:true }, function(err, results){
- if(err){
- throw(err);
- }
-
- console.log(results)
- //results[0].forEach(function(name, value, timestamp, ttl){
- // console.log(name, value, timestamp, ttl);
- //});
-
- pool.close();
- });
- });
- }
-});

0 comments on commit e5c3b82

Please sign in to comment.