Permalink
Browse files

Move microtime to optionalDependencies.

This way if you have trouble installing/building microtime on Windows, you
can still use helenus (albeit without microsecond precision timestamps).
  • Loading branch information...
1 parent a4f2942 commit 21230b7477d60c9da6d18b9fb7c9c52070a465e4 Muir Manders committed Oct 25, 2013
Showing with 35 additions and 5 deletions.
  1. +2 −2 lib/column.js
  2. +2 −2 lib/column_family.js
  3. +12 −0 lib/time.js
  4. +3 −1 package.json
  5. +16 −0 test/thrift.js
View
4 lib/column.js
@@ -1,6 +1,6 @@
var util = require('util'),
ttypes = require('./cassandra/cassandra_types'),
- microtime = require('microtime');
+ time = require('./time');
/**
* Cassandra Column object representation
@@ -26,7 +26,7 @@ var Column = function(name, value, timestamp, ttl){
* The timestamp in microseconds of the value
* @default {Number} current time in microseconds
*/
- this.timestamp_micro = microtime.now();
+ this.timestamp_micro = time.microtime();
} else if (this.timestamp instanceof Date) {
this.timestamp_micro = timestamp.getTime() * 1000;
} else {
View
4 lib/column_family.js
@@ -4,7 +4,7 @@ var util = require('util'),
CounterColumn = require('./counter_column'),
Row = require('./row'),
ttype = require('./cassandra/cassandra_types'),
- microtime = require('microtime');
+ time = require('./time');
/**
* NO-Operation for deault callbacks
@@ -288,7 +288,7 @@ ColumnFamily.prototype.remove = function() {
var timestamp;
if (args.options.timestamp == null) {
- timestamp = microtime.now();
+ timestamp = time.microtime();
} else if (args.options.timestamp instanceof Date) {
timestamp = args.options.timestamp.getTime() * 1000;
} else {
View
12 lib/time.js
@@ -0,0 +1,12 @@
+var time = {};
+
+try {
+ var microtime = require('microtime');
+ time.microtime = microtime.now;
+} catch (e) {
+ time.microtime = function() {
+ return Date.now() * 1000;
+ };
+}
+
+module.exports = time;
View
4 package.json
@@ -15,7 +15,9 @@
, "dependencies": {
"helenus-thrift": "0.7.3"
, "node-uuid": "1.3.3"
- , "microtime": "0.4.0"
+ }
+ , "optionalDependencies": {
+ "microtime": "0.4.0"
}
, "devDependencies": {
"whiskey": "git://github.com/cloudkick/whiskey.git#b3c5bc23e30c95e46083bc7628c2557c1c15ec95"
View
16 test/thrift.js
@@ -4,6 +4,12 @@ var config = require('./helpers/thrift'),
Helenus, conn, ks, cf_standard, row_standard, cf_composite, cf_counter,
cf_reversed, cf_composite_nested_reversed;
+var has_microtime = false;
+try {
+ require('microtime');
+ has_microtime = true;
+} catch(e) { }
+
module.exports = {
'setUp':function(test, assert){
Helenus = require('helenus');
@@ -207,6 +213,11 @@ module.exports = {
},
'test cf.insert default microsecond timestamp':function(test, assert){
+ if (!has_microtime) {
+ test.finish();
+ return;
+ }
+
//try to tease out same-ms collision with 50 attempts
var finished = 0, ok = true;
var callback = function() {
@@ -700,6 +711,11 @@ module.exports = {
},
'test standard cf remove default microsecond timestamp':function(test, assert) {
+ if (!has_microtime) {
+ test.finish();
+ return;
+ }
+
//try to tease out same-ms collision with 50 attempts
var finished = 0, ok = true;
var callback = function() {

0 comments on commit 21230b7

Please sign in to comment.