Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use strict mode everywhere

  • Loading branch information...
commit 402f68b9cbe2a0fb332343788df6fae5682e1401 1 parent e592724
Philip (flip) Kromer authored
Showing with 372 additions and 295 deletions.
  1. +2 −0  bin/collector.js
  2. +2 −0  bin/evaluator.js
  3. +2 −0  bin/warmer.js
  4. +4 −2 lib/cube/authentication.js
  5. +2 −0  lib/cube/bisect.js
  6. +2 −0  lib/cube/collectd.js
  7. +2 −0  lib/cube/collector.js
  8. +2 −0  lib/cube/emitter-http.js
  9. +2 −0  lib/cube/emitter-udp.js
  10. +2 −0  lib/cube/emitter-ws.js
  11. +2 −0  lib/cube/emitter.js
  12. +3 −0  lib/cube/endpoint.js
  13. +2 −0  lib/cube/evaluator.js
  14. +7 −4 lib/cube/event.js
  15. +2 −0  lib/cube/index.js
  16. +4 −3 lib/cube/metalog.js
  17. +5 −3 lib/cube/metric.js
  18. +9 −0 lib/cube/models.js
  19. +3 −1 lib/cube/reduces.js
  20. +22 −21 lib/cube/server.js
  21. +2 −0  lib/cube/tiers.js
  22. +2 −0  lib/cube/types.js
  23. +2 −0  lib/cube/visualizer.js
  24. +11 −9 lib/cube/warmer.js
  25. +2 −0  test/authentication-test.js
  26. +2 −0  test/collector-test.js
  27. +3 −1 test/evaluator-test.js
  28. +2 −0  test/event-expression-test.js
  29. +3 −1 test/metalog-test.js
  30. +2 −0  test/metric-expression-test.js
  31. +112 −114 test/metric-test.js
  32. +2 −0  test/reduces-test.js
  33. +2 −0  test/server-test.js
  34. +3 −1 test/test_helper.js
  35. +137 −135 test/tiers-test.js
  36. +2 −0  test/types-test.js
  37. +2 −0  test/visualizer-test.js
View
2  bin/collector.js
@@ -1,3 +1,5 @@
+'use strict';
+
var options = require("../config/cube").include("collector"),
cube = require("../"),
server = cube.server(options);
View
2  bin/evaluator.js
@@ -1,3 +1,5 @@
+'use strict';
+
var options = require("../config/cube").include('evaluator'),
cube = require("../"),
server = cube.server(options);
View
2  bin/warmer.js
@@ -1,3 +1,5 @@
+'use strict';
+
var options = require("../config/cube").include('warmer'),
cube = require("../"),
warmer = cube.warmer(options);
View
6 lib/cube/authentication.js
@@ -1,3 +1,5 @@
+'use strict';
+
//
// authentication -- authenticate user identities and authorize their action
//
@@ -106,8 +108,8 @@ authentication.mongo_cookie = function(db, options){
// base-64 encode a uid and bcrypted secret
authentication.gen_cookie = function(session_name, uid, secret){
- encoded_uid = new Buffer(uid, 'utf8').toString('base64');
- encoded_sec = new Buffer(secret, 'utf8').toString('base64');
+ var encoded_uid = new Buffer(uid, 'utf8').toString('base64');
+ var encoded_sec = new Buffer(secret, 'utf8').toString('base64');
return (session_name+"="+encoded_uid+"--"+encoded_sec+";");
};
View
2  lib/cube/bisect.js
@@ -1,3 +1,5 @@
+'use strict';
+
module.exports = bisect;
function bisect(a, x) {
View
2  lib/cube/collectd.js
@@ -1,3 +1,5 @@
+'use strict';
+
exports.putter = function(putter) {
var valuesByKey = {};
View
2  lib/cube/collector.js
@@ -1,3 +1,5 @@
+'use strict';
+
//
// collector -- listen for incoming metrics
//
View
2  lib/cube/emitter-http.js
@@ -1,3 +1,5 @@
+'use strict';
+
var util = require("util"),
http = require("http");
View
2  lib/cube/emitter-udp.js
@@ -1,3 +1,5 @@
+'use strict';
+
var util = require("util"),
dgram = require("dgram");
View
2  lib/cube/emitter-ws.js
@@ -1,3 +1,5 @@
+'use strict';
+
var util = require("util"),
websocket = require("websocket");
View
2  lib/cube/emitter.js
@@ -1,3 +1,5 @@
+'use strict';
+
//
// emitter - writes events to the collector.
//
View
3  lib/cube/endpoint.js
@@ -1,3 +1,5 @@
+'use strict';
+
//
// endpoint -- router for requests.
//
@@ -8,6 +10,7 @@
//
module.exports = function(method, path, dispatch) {
+ var match;
if (method instanceof RegExp) {
dispatch = path, path = method;
match = function(p, m) { return path.test(p); };
View
2  lib/cube/evaluator.js
@@ -1,3 +1,5 @@
+'use strict';
+
var endpoint = require("./endpoint"),
url = require("url");
View
11 lib/cube/event.js
@@ -1,3 +1,5 @@
+'use strict';
+
// TODO include the event._id (and define a JSON encoding for ObjectId?)
// TODO allow the event time to change when updating (fix invalidation)
@@ -53,7 +55,7 @@ exports.putter = function(db){
// Validate the date and type.
if (!type_re.test(type)) return callback({error: "invalid type"}), -1;
if (isNaN(time)) return callback({error: "invalid time"}), -1;
-
+
// Drop events from before invalidation horizon
if(time < new Date(new Date() - options.horizons.invalidation)) return callback({error: "event before invalidation horizon"}), -1;
@@ -80,6 +82,7 @@ exports.putter = function(db){
// that if you want to customize the size of the capped metrics collection,
// or add custom indexes, you can still do all that by hand.
db.collectionNames(type + "_events", function(error, names) {
+ handle(error);
var events = collection(type).events;
if (names.length) return saveEvents();
@@ -88,7 +91,7 @@ exports.putter = function(db){
db.createCollection(type + "_events", event_options, function(error, events){
handle(error);
events.ensureIndex({"t": 1}, handle);
-
+
// Create a collection for metrics. Three indexes are required: one
// for finding metrics, one (_id) for updating, and one for invalidation.
db.createCollection(type + "_metrics", metric_options, function(error, metrics) {
@@ -159,7 +162,6 @@ exports.putter = function(db){
"_id.t": {$in: timesToInvalidateByTier[tier]}
}, invalidate, multi);
}
- flushed = true;
}
timesToInvalidateByTierByType = {}; // copy-on-write
}, invalidateInterval));
@@ -199,7 +201,7 @@ exports.getter = function(db) {
try {
expression = parser.parse(request.expression);
} catch (error) {
- var resp = { is: "invalid expression", expression: request.expression, error: error }
+ var resp = { is: "invalid expression", expression: request.expression, error: error };
metalog.info('cube_getter', resp);
return callback(resp), -1;
}
@@ -305,6 +307,7 @@ exports.getter = function(db) {
};
function handle(error) {
+ metalog.info('cube_request', {is: 'event error', error: error });
if (error) throw error;
}
View
2  lib/cube/index.js
@@ -1,3 +1,5 @@
+'use strict';
+
exports.authentication = require("./authentication");
exports.metalog = require("./metalog");
exports.emitter = require("./emitter");
View
7 lib/cube/metalog.js
@@ -1,3 +1,5 @@
+'use strict';
+
var util = require("util");
var metalog = {
@@ -39,9 +41,8 @@ metalog.minor = function(name, hsh){
// Dump the 'util.inspect' view of each argument to the console.
metalog.inspectify = function(args){
- var whence = metalog.inspectify.caller.name || '(anon)';
- for (idx in arguments) {
- if (whence){ util.print(whence + ' ' + idx + ": "); }
+ for (var idx in arguments) {
+ util.print(idx + ": ");
util.print(util.inspect(arguments[idx])+"\n");
};
};
View
8 lib/cube/metric.js
@@ -1,3 +1,5 @@
+'use strict';
+
// TODO use expression ids or hashes for more compact storage
var parser = require("./metric-expression"),
@@ -114,9 +116,8 @@ exports.getter = function(db) {
reduce = reduces[expression.reduce],
filter = {t: {}},
fields = {t: 1};
-
+
if (!reduce) return callback({error: "invalid reduce operation"}), -1;
-
// Copy any expression filters into the query object.
expression.filter(filter);
@@ -175,7 +176,7 @@ exports.getter = function(db) {
// the order in which rows are returned from the database. Thus, we know
// when we've seen all of the events for a given time interval.
function computeFlat(start, stop) {
- if(tier.floor(start) < new Date(new Date() - options.horizons.calculation)){
+ if (tier.floor(start) < new Date(new Date() - options.horizons.calculation)){
metalog.info('cube_compute', {is: 'past_horizon', metric: metric });
start = tier.step(tier.floor(new Date(new Date() - options.horizons.calculation)))
}
@@ -248,5 +249,6 @@ exports.getter = function(db) {
};
function handle(error) {
+ metalog.info('cube_request', {is: 'event error', error: error });
if (error) throw error;
}
View
9 lib/cube/models.js
@@ -0,0 +1,9 @@
+
+exports.units = {
+ second: 1e3,
+ second10: 10e3,
+ minute: 60e3,
+ minute5: 300e3,
+ hour: 3600e3,
+ day: 86400e3
+};
View
4 lib/cube/reduces.js
@@ -1,3 +1,5 @@
+'use strict';
+
var reduces = module.exports = {
sum: function(values) {
@@ -23,7 +25,7 @@ var reduces = module.exports = {
// while (++i < n) if (!((value = values[i]) in map)) map[value] = ++count;
// return count;
// },
- //
+ //
// median: function(values) {
// return quantile(values.sort(ascending), .5);
// }
View
43 lib/cube/server.js
@@ -1,3 +1,5 @@
+'use strict';
+
// Server -- generic HTTP, UDP and websockets server
//
// Used by the collector to accept new events via HTTP or websockets
@@ -17,7 +19,7 @@ var util = require("util"),
dgram = require("dgram"),
websocket = require("websocket"),
websprocket = require("websocket-server"),
- static = require("node-static"),
+ file_server = require("node-static"),
mongodb = require("mongodb"),
authentication = require("./authentication"),
event = require("./event"),
@@ -52,7 +54,7 @@ module.exports = function(options) {
var server = {},
primary = http.createServer(),
secondary = websprocket.createServer(),
- file = new static.Server("static"),
+ file = new file_server.Server("static"),
udp,
endpoints = {ws: [], http: []},
server_options = options["mongo-server_options"],
@@ -108,26 +110,26 @@ module.exports = function(options) {
// save auth from connection requesta
var authorization = request.authorized;
+ function connection_callback(response) {
+ connection.sendUTF(JSON.stringify(response));
+ }
+
// Forward messages to the appropriate endpoint, or close the connection.
for (var i = -1, n = endpoints.ws.length, e; ++i < n;) {
if ((e = endpoints.ws[i]).match(request.url)) {
- function callback(response) {
- connection.sendUTF(JSON.stringify(response));
- }
-
- callback.id = ++id;
+ connection_callback.id = ++id;
// Listen for socket disconnect.
if (e.dispatch.close) connection.socket.on("end", function() {
- e.dispatch.close(callback);
+ e.dispatch.close(connection_callback);
});
connection.on("message", function(message) {
// staple the authorization back on
var payload = JSON.parse(message.utf8Data || message);
payload.authorized = authorization;
- e.dispatch(payload, callback);
+ e.dispatch(payload, connection_callback);
});
metalog.event('cube_request', { is: 'ws', method: "WebSocket", ip: connection.remoteAddress, path: request.url}, 'minor');
@@ -141,20 +143,19 @@ module.exports = function(options) {
primary.on("request", function(request, response) {
var u = url.parse(request.url);
+ function auth_ok(perms) {
+ metalog.event('cube_request', { is: 'auth_ok', method: request.method, ip: request.connection.remoteAddress, path: u.pathname, auth: true, user: perms });
+ e.dispatch(request, response);
+ }
+ function auth_no(reason) {
+ metalog.event('cube_request', { is: 'auth_no', method: request.method, ip: request.connection.remoteAddress, path: u.pathname, auth: false });
+ response.writeHead(403, {"Content-Type": "text/plain"});
+ response.end("403 Forbidden");
+ }
+
// Forward messages to the appropriate endpoint, or 404.
for (var i = -1, n = endpoints.http.length, e; ++i < n;) {
if ((e = endpoints.http[i]).match(u.pathname, request.method)) {
-
- function auth_ok(perms) {
- metalog.event('cube_request', { is: 'auth_ok', method: request.method, ip: request.connection.remoteAddress, path: u.pathname, auth: true, user: perms });
- e.dispatch(request, response);
- }
- function auth_no(reason) {
- metalog.event('cube_request', { is: 'auth_no', method: request.method, ip: request.connection.remoteAddress, path: u.pathname, auth: false });
- response.writeHead(403, {"Content-Type": "text/plain"});
- response.end("403 Forbidden");
- }
-
return authenticator.check(request, auth_ok, auth_no);
}
}
@@ -178,7 +179,7 @@ module.exports = function(options) {
server.start = function(server_start_cb) {
// Connect to mongodb.
- mongo_password = options["mongo-password"]; delete options["mongo-password"];
+ var mongo_password = options["mongo-password"]; delete options["mongo-password"];
metalog.info('cube_life', {is: 'mongo_connect', options: options });
db.open(function(error) {
if (error) throw error;
View
2  lib/cube/tiers.js
@@ -1,3 +1,5 @@
+'use strict';
+
var tiers = module.exports = {};
var second = 1000,
View
2  lib/cube/types.js
@@ -1,3 +1,5 @@
+'use strict';
+
// Much like db.collection, but caches the result for both events and metrics.
// Also, this is synchronous, since we are opening a collection unsafely.
var types = module.exports = function(db) {
View
2  lib/cube/visualizer.js
@@ -1,3 +1,5 @@
+'use strict';
+
var url = require("url"),
path = require("path"),
endpoint = require("./endpoint"),
View
20 lib/cube/warmer.js
@@ -1,3 +1,5 @@
+'use strict';
+
var cluster = require('cluster'),
mongodb = require('mongodb'),
metric = require('./metric'),
@@ -6,15 +8,15 @@ var cluster = require('cluster'),
module.exports = function(options){
var db, mongo, calculate_metric, boards, tier;
-
+
function fetch_metrics(callback){
var expressions = [];
-
+
if(!boards){
db.collection("boards", function(error, collection) { boards = collection; fetch_metrics(callback); });
return;
}
-
+
boards.find({}, {pieces: 1}, function(error, cursor) {
if (error) throw error;
cursor.each(function(error, row) {
@@ -30,20 +32,20 @@ module.exports = function(options){
});
});
}
-
+
function process_metrics(expressions){
expressions.forEach(function(expression){
var stop = new Date(),
start = tier.step(tier.floor(new Date(stop - options.horizons.calculation)));
-
+
metalog.info('cube_warm', {is: 'warm_metric', metric: {query: expressions}, start: start, stop: stop });
-
+
// fake metrics request
calculate_metric({ step: tier.key, expression: expression, start: start, stop: stop }, function(){});
});
setTimeout(function(){ fetch_metrics(process_metrics); }, options['warmer-interval']);
}
-
+
return {
start: function(){
mongo = new mongodb.Server(options['mongo-host'], options['mongo-port']);
@@ -54,11 +56,11 @@ module.exports = function(options){
metalog.event("cube_life", { is: 'start_warmer', options: options });
- db.open(function(error) {
+ db.open(function(error) {
if (error) throw error;
calculate_metric = metric.getter(db);
fetch_metrics(process_metrics);
});
}
};
-}
+}
View
2  test/authentication-test.js
@@ -1,3 +1,5 @@
+'use strict';
+
var vows = require("vows"),
assert = require("assert"),
test_helper = require('./test_helper'),
View
2  test/collector-test.js
@@ -1,3 +1,5 @@
+'use strict';
+
var vows = require("vows"),
assert = require("assert"),
test_helper = require("./test_helper"),
View
4 test/evaluator-test.js
@@ -1,3 +1,5 @@
+'use strict';
+
var vows = require("vows"),
assert = require("assert"),
test_helper = require("./test_helper"),
@@ -13,7 +15,7 @@ function frontend_components() {
// suite.addBatch(
// test_helper.with_server(server_options, frontend_components, {
-//
+//
// "POST /event/put with invalid JSON": {
// topic: test_helper.request({method: "POST", path: "/1.0/event/put"}, "This ain't JSON.\n"),
// "responds with status 400": function(response) {
View
2  test/event-expression-test.js
@@ -1,3 +1,5 @@
+'use strict';
+
var vows = require("vows"),
assert = require("assert"),
parser = require("../lib/cube/event-expression");
View
4 test/metalog-test.js
@@ -1,3 +1,5 @@
+'use strict';
+
var vows = require("vows"),
assert = require("assert"),
test_helper = require('./test_helper');
@@ -56,7 +58,7 @@ suite.with_log({
assert.equal(this.logged.infoed.pop(), 'reactor_level\t{"criticality":9,"hemiconducers":"relucting"}');
},
'writes an event to cube itself': function(metalog){
- event = this.logged.putted.pop();
+ var event = this.logged.putted.pop();
event.time = 'whatever';
assert.deepEqual(event, {
data: { hemiconducers: 'relucting', criticality: 9 },
View
2  test/metric-expression-test.js
@@ -1,3 +1,5 @@
+'use strict';
+
var vows = require("vows"),
assert = require("assert"),
parser = require("../lib/cube/metric-expression");
View
226 test/metric-test.js
@@ -1,6 +1,9 @@
+'use strict'
+
var vows = require("vows"),
assert = require("assert"),
test_helper = require("./test_helper"),
+ models = require("../lib/cube/models"), units = models.units,
event = require("../lib/cube/event"),
metric = require("../lib/cube/metric");
@@ -11,25 +14,26 @@ var step_testing_delay = 250,
var suite = vows.describe("metric");
+var nowish = Date.now(), nowish10 = (10e3 * Math.floor(nowish/10e3));
var steps = {
- 1e4: function(date, n) { return new Date((Math.floor(date / 1e4) + n) * 1e4); },
- 6e4: function(date, n) { return new Date((Math.floor(date / 6e4) + n) * 6e4); },
- 3e5: function(date, n) { return new Date((Math.floor(date / 3e5) + n) * 3e5); },
- 36e5: function(date, n) { return new Date((Math.floor(date / 36e5) + n) * 36e5); },
- 864e5: function(date, n) { return new Date((Math.floor(date / 864e5) + n) * 864e5); }
+ 10e3: function(date, n) { return new Date((Math.floor(date / units.second10) + n) * units.second10); },
+ 60e3: function(date, n) { return new Date((Math.floor(date / units.minute) + n) * units.minute); },
+ 300e3: function(date, n) { return new Date((Math.floor(date / units.minute5) + n) * units.minute5); },
+ 3600e3: function(date, n) { return new Date((Math.floor(date / units.hour) + n) * units.hour); },
+ 86400e3: function(date, n) { return new Date((Math.floor(date / units.day) + n) * units.day); }
};
-steps[1e4].description = "10-second";
-steps[6e4].description = "1-minute";
-steps[3e5].description = "5-minute";
-steps[36e5].description = "1-hour";
-steps[864e5].description = "1-day";
+steps[units.second10].description = "10-second";
+steps[units.minute ].description = "1-minute";
+steps[units.minute5 ].description = "5-minute";
+steps[units.hour ].description = "1-hour";
+steps[units.day ].description = "1-day";
suite.addBatch(test_helper.batch({
topic: function(test_db) {
var putter = event.putter(test_db.db),
- getter = metric.getter(test_db.db),
- callback = this.callback;
+ getter = metric.getter(test_db.db),
+ callback = this.callback;
// Seed the events table with a simple event: a value going from 0 to 2499
for (var i = 0; i < 2500; i++) {
@@ -45,85 +49,77 @@ suite.addBatch(test_helper.batch({
},
"unary expression": metricTest({
- expression: "sum(test)",
- start: "2011-07-17T23:47:00.000Z",
- stop: "2011-07-18T00:50:00.000Z",
- }, {
- 6e4: [0, 0, 0, 1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 39, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
- 3e5: [0, 17, 65, 143, 175, 225, 275, 325, 375, 425, 475, 0, 0],
- 36e5: [82, 2418],
- 864e5: [82, 2418]
- }
- ),
+ expression: "sum(test)",
+ start: "2011-07-17T23:47:00.000Z",
+ stop: "2011-07-18T00:50:00.000Z",
+ }, {
+ 60e3: [0, 0, 0, 1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 39, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ 300e3: [0, 17, 65, 143, 175, 225, 275, 325, 375, 425, 475, 0, 0],
+ 3600e3: [82, 2418],
+ 86400e3: [82, 2418]
+ }),
"unary expression with data accessor": metricTest({
- expression: "sum(test(i))",
- start: "2011-07-17T23:47:00.000Z",
- stop: "2011-07-18T00:50:00.000Z"
- }, {
- 3e5: [0, 136, 3185, 21879, 54600, 115200, 209550, 345150, 529500, 770100, 1074450, 0, 0],
- 36e5: [3321, 3120429],
- 864e5: [3321, 3120429]
- }
- ),
+ expression: "sum(test(i))",
+ start: "2011-07-17T23:47:00.000Z",
+ stop: "2011-07-18T00:50:00.000Z"
+ }, {
+ 300e3: [0, 136, 3185, 21879, 54600, 115200, 209550, 345150, 529500, 770100, 1074450, 0, 0],
+ 3600e3: [3321, 3120429],
+ 86400e3: [3321, 3120429]
+ }),
"unary expression with compound data accessor": metricTest({
- expression: "sum(test(i / 100))",
- start: "2011-07-17T23:47:00.000Z",
- stop: "2011-07-18T00:50:00.000Z"
- }, {
- 3e5: [0, 1.36, 31.85, 218.79, 546, 1152, 2095.5, 3451.5, 5295, 7701, 10744.5, 0, 0],
- 36e5: [33.21, 31204.29],
- 864e5: [33.21, 31204.29]
- }
- ),
+ expression: "sum(test(i / 100))",
+ start: "2011-07-17T23:47:00.000Z",
+ stop: "2011-07-18T00:50:00.000Z"
+ }, {
+ 300e3: [0, 1.36, 31.85, 218.79, 546, 1152, 2095.5, 3451.5, 5295, 7701, 10744.5, 0, 0],
+ 3600e3: [33.21, 31204.29],
+ 86400e3: [33.21, 31204.29]
+ }),
"compound expression (sometimes fails due to race condition?)": metricTest({
- expression: "max(test(i)) - min(test(i))",
- start: "2011-07-17T23:47:00.000Z",
- stop: "2011-07-18T00:50:00.000Z",
- }, {
- 3e5: [NaN, 16, 64, 142, 174, 224, 274, 324, 374, 424, 474, NaN, NaN],
- 36e5: [81, 2417],
- 864e5: [81, 2417]
- }
- ),
+ expression: "max(test(i)) - min(test(i))",
+ start: "2011-07-17T23:47:00.000Z",
+ stop: "2011-07-18T00:50:00.000Z",
+ }, {
+ 300e3: [NaN, 16, 64, 142, 174, 224, 274, 324, 374, 424, 474, NaN, NaN],
+ 3600e3: [81, 2417],
+ 86400e3: [81, 2417]
+ }),
"non-pyramidal expression": metricTest({
- expression: "distinct(test(i))",
- start: "2011-07-17T23:47:00.000Z",
- stop: "2011-07-18T00:50:00.000Z",
- }, {
- 3e5: [0, 17, 65, 143, 175, 225, 275, 325, 375, 425, 475, 0, 0],
- 36e5: [82, 2418],
- 864e5: [82, 2418]
- }
- ),
+ expression: "distinct(test(i))",
+ start: "2011-07-17T23:47:00.000Z",
+ stop: "2011-07-18T00:50:00.000Z",
+ }, {
+ 300e3: [0, 17, 65, 143, 175, 225, 275, 325, 375, 425, 475, 0, 0],
+ 3600e3: [82, 2418],
+ 86400e3: [82, 2418]
+ }),
"compound pyramidal and non-pyramidal expression": metricTest({
- expression: "sum(test(i)) - median(test(i))",
- start: "2011-07-17T23:47:00.000Z",
- stop: "2011-07-18T00:50:00.000Z",
- }, {
- 3e5: [NaN, 128, 3136, 21726, 54288, 114688, 208788, 344088, 528088, 768288, 1072188, NaN, NaN],
- 36e5: [3280.5, 3119138.5],
- 864e5: [3280.5, 3119138.5]
- }
- ),
+ expression: "sum(test(i)) - median(test(i))",
+ start: "2011-07-17T23:47:00.000Z",
+ stop: "2011-07-18T00:50:00.000Z",
+ }, {
+ 300e3: [NaN, 128, 3136, 21726, 54288, 114688, 208788, 344088, 528088, 768288, 1072188, NaN, NaN],
+ 3600e3: [3280.5, 3119138.5],
+ 86400e3: [3280.5, 3119138.5]
+ }),
"compound with constant expression": metricTest({
- expression: "-1 + sum(test)",
- start: "2011-07-17T23:47:00.000Z",
- stop: "2011-07-18T00:50:00.000Z",
- }, {
- 3e5: [-1, 16, 64, 142, 174, 224, 274, 324, 374, 424, 474, -1, -1],
- 36e5: [81, 2417],
- 864e5: [81, 2417]
- }
- )
-}));
+ expression: "-1 + sum(test)",
+ start: "2011-07-17T23:47:00.000Z",
+ stop: "2011-07-18T00:50:00.000Z",
+ }, {
+ 300e3: [-1, 16, 64, 142, 174, 224, 274, 324, 374, 424, 474, -1, -1],
+ 3600e3: [81, 2417],
+ 86400e3: [81, 2417]
+ })
-suite.export(module);
+}));
// metricTest -- generates test tree for metrics.
//
@@ -151,7 +147,7 @@ suite.export(module);
function metricTest(request, expected) {
// { 'at 1-minute intervals': { }, 'at 1-day intervals': { } }
var tree = {}, k;
- for (step in expected) tree["at " + steps[step].description + " intervals"] = testStep(step, expected[step]);
+ for (var step in expected) tree["at " + steps[step].description + " intervals"] = testStep(step, expected[step]);
return tree;
//
@@ -174,7 +170,7 @@ function metricTest(request, expected) {
//
function testStep(step, expected) {
var start = new Date(request.start),
- stop = new Date(request.stop);
+ stop = new Date(request.stop);
var subtree = {
topic: get_metrics_with_delay(0),
@@ -187,11 +183,11 @@ function metricTest(request, expected) {
function get_metrics_with_delay(depth){ return function(){
var actual = [],
- timeout = setTimeout(function() { cb("Time's up!"); }, 10000),
- cb = this.callback,
- req = Object.create(request),
- getter = arguments[depth];
- req.step = step;
+ timeout = setTimeout(function() { cb("Time's up!"); }, 10000),
+ cb = this.callback,
+ req = Object.create(request),
+ getter = arguments[depth];
+ req.step = step;
// Wait long enough for the events to have settled in the db. The
// non-cached (depth=0) round can all start in parallel, making this an
// effective `nextTick`. On the secon
@@ -211,55 +207,57 @@ function metricTest(request, expected) {
function metrics_assertions(){ return {
'rounds down the start time (inclusive)': function(actual) {
- var floor = steps[step](start, 0);
- assert.deepEqual(actual[0].time, floor);
+ var floor = steps[step](start, 0);
+ assert.deepEqual(actual[0].time, floor);
},
'rounds up the stop time (exclusive)': function(actual){
- var ceil = steps[step](stop, 0);
- if (!(ceil - stop)) ceil = steps[step](stop, -1);
- assert.deepEqual(actual[actual.length - 1].time, ceil);
+ var ceil = steps[step](stop, 0);
+ if (!(ceil - stop)) ceil = steps[step](stop, -1);
+ assert.deepEqual(actual[actual.length - 1].time, ceil);
},
'formats UTC time in ISO 8601': function(actual){
- actual.forEach(function(d) {
- assert.instanceOf(d.time, Date);
- assert.match(JSON.stringify(d.time), /[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:00.000Z/);
- });
+ actual.forEach(function(d) {
+ assert.instanceOf(d.time, Date);
+ assert.match(JSON.stringify(d.time), /[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:00.000Z/);
+ });
},
'returns exactly one value per time': function(actual){
- var i = 0, n = actual.length, t = actual[0].time;
- while (++i < n) assert.isTrue(t < (t = actual[i].time));
+ var i = 0, n = actual.length, t = actual[0].time;
+ while (++i < n) assert.isTrue(t < (t = actual[i].time));
},
'each metric defines only time and value properties': function(actual){
- actual.forEach(function(d) {
- assert.deepEqual(Object.keys(d), ["time", "value"]);
- });
+ actual.forEach(function(d) {
+ assert.deepEqual(Object.keys(d), ["time", "value"]);
+ });
},
'returns the expected times': function(actual){
- var floor = steps[step],
- time = floor(start, 0),
- times = [];
- while (time < stop) {
- times.push(time);
- time = floor(time, 1);
- }
- assert.deepEqual(actual.map(function(d) { return d.time; }), times);
+ var floor = steps[step],
+ time = floor(start, 0),
+ times = [];
+ while (time < stop) {
+ times.push(time);
+ time = floor(time, 1);
+ }
+ assert.deepEqual(actual.map(function(d) { return d.time; }), times);
},
'returns the expected values': function(actual){
- var actualValues = actual.map(function(d) { return d.value; });
- assert.equal(expected.length, actual.length, "expected " + expected + ", got " + actualValues);
- expected.forEach(function(value, i) {
- if (Math.abs(actual[i].value - value) > 1e-6) {
- assert.fail(actual.map(function(d) { return d.value; }), expected, "expected {expected}, got {actual} at " + actual[i].time.toISOString());
- }
- });
+ var actualValues = actual.map(function(d) { return d.value; });
+ assert.equal(expected.length, actual.length, "expected " + expected + ", got " + actualValues);
+ expected.forEach(function(value, i) {
+ if (Math.abs(actual[i].value - value) > 1e-6) {
+ assert.fail(actual.map(function(d) { return d.value; }), expected, "expected {expected}, got {actual} at " + actual[i].time.toISOString());
+ }
+ });
}
}}; // metric assertions
} // subtree
} // tree
+
+suite.export(module);
View
2  test/reduces-test.js
@@ -1,3 +1,5 @@
+'use strict';
+
var vows = require("vows"),
assert = require("assert"),
reduces = require("../lib/cube/reduces");
View
2  test/server-test.js
@@ -1,3 +1,5 @@
+'use strict';
+
var vows = require("vows"),
assert = require("assert"),
test_helper = require("./test_helper"),
View
4 test/test_helper.js
@@ -1,3 +1,5 @@
+'use strict';
+
var assert = require("assert"),
http = require("http"),
dgram = require('dgram'),
@@ -108,7 +110,7 @@ test_helper.delaying_topic = delaying_topic;
function delayed_callback(context){
return function(){
var callback_delay = 100;
- args = arguments;
+ var args = arguments;
setTimeout(function(){ context.callback.apply(context, args) }, callback_delay)
};
}
View
272 test/tiers-test.js
@@ -1,3 +1,5 @@
+'use strict';
+
var vows = require("vows"),
assert = require("assert"),
tiers = require("../lib/cube/tiers");
@@ -31,51 +33,51 @@ suite.addBatch({
"floor": {
"rounds down to 10-seconds": function(tier) {
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 00, 20)), utc(2011, 08, 02, 12, 00, 20));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 00, 21)), utc(2011, 08, 02, 12, 00, 20));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 00, 23)), utc(2011, 08, 02, 12, 00, 20));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 00, 39)), utc(2011, 08, 02, 12, 00, 30));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 00, 40)), utc(2011, 08, 02, 12, 00, 40));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 0, 20)), utc(2011, 8, 2, 12, 0, 20));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 0, 21)), utc(2011, 8, 2, 12, 0, 20));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 0, 23)), utc(2011, 8, 2, 12, 0, 20));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 0, 39)), utc(2011, 8, 2, 12, 0, 30));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 0, 40)), utc(2011, 8, 2, 12, 0, 40));
},
"does not modify the passed-in date": function(tier) {
- var date = utc(2011, 08, 02, 12, 00, 21);
- assert.deepEqual(tier.floor(date), utc(2011, 08, 02, 12, 00, 20));
- assert.deepEqual(date, utc(2011, 08, 02, 12, 00, 21));
+ var date = utc(2011, 8, 2, 12, 0, 21);
+ assert.deepEqual(tier.floor(date), utc(2011, 8, 2, 12, 0, 20));
+ assert.deepEqual(date, utc(2011, 8, 2, 12, 0, 21));
}
},
"ceil": {
"rounds up to 10-seconds": function(tier) {
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 00, 20)), utc(2011, 08, 02, 12, 00, 20));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 00, 21)), utc(2011, 08, 02, 12, 00, 30));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 00, 23)), utc(2011, 08, 02, 12, 00, 30));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 00, 39)), utc(2011, 08, 02, 12, 00, 40));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 00, 40)), utc(2011, 08, 02, 12, 00, 40));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 0, 20)), utc(2011, 8, 2, 12, 0, 20));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 0, 21)), utc(2011, 8, 2, 12, 0, 30));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 0, 23)), utc(2011, 8, 2, 12, 0, 30));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 0, 39)), utc(2011, 8, 2, 12, 0, 40));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 0, 40)), utc(2011, 8, 2, 12, 0, 40));
},
"does not modified the specified date": function(tier) {
- var date = utc(2011, 08, 02, 12, 00, 21);
- assert.deepEqual(tier.ceil(date), utc(2011, 08, 02, 12, 00, 30));
- assert.deepEqual(date, utc(2011, 08, 02, 12, 00, 21));
+ var date = utc(2011, 8, 2, 12, 0, 21);
+ assert.deepEqual(tier.ceil(date), utc(2011, 8, 2, 12, 0, 30));
+ assert.deepEqual(date, utc(2011, 8, 2, 12, 0, 21));
}
},
"step": {
"increments time by ten seconds": function(tier) {
- var date = utc(2011, 08, 02, 23, 59, 20);
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 02, 23, 59, 30));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 02, 23, 59, 40));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 02, 23, 59, 50));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 03, 00, 00, 00));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 03, 00, 00, 10));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 03, 00, 00, 20));
+ var date = utc(2011, 8, 2, 23, 59, 20);
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 2, 23, 59, 30));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 2, 23, 59, 40));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 2, 23, 59, 50));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 3, 0, 0, 0));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 3, 0, 0, 10));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 3, 0, 0, 20));
},
"does not round the specified date": function(tier) {
- assert.deepEqual(tier.step(utc(2011, 08, 02, 12, 21, 23)), utc(2011, 08, 02, 12, 21, 33));
+ assert.deepEqual(tier.step(utc(2011, 8, 2, 12, 21, 23)), utc(2011, 8, 2, 12, 21, 33));
},
"does not modify the specified date": function(tier) {
- var date = utc(2011, 08, 02, 12, 20, 00);
- assert.deepEqual(tier.step(date), utc(2011, 08, 02, 12, 20, 10));
- assert.deepEqual(date, utc(2011, 08, 02, 12, 20, 00));
+ var date = utc(2011, 8, 2, 12, 20, 0);
+ assert.deepEqual(tier.step(date), utc(2011, 8, 2, 12, 20, 10));
+ assert.deepEqual(date, utc(2011, 8, 2, 12, 20, 0));
}
}
},
@@ -94,52 +96,52 @@ suite.addBatch({
"floor": {
"rounds down to minutes": function(tier) {
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 20, 00)), utc(2011, 08, 02, 12, 20));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 20, 01)), utc(2011, 08, 02, 12, 20));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 21, 00)), utc(2011, 08, 02, 12, 21));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 23, 00)), utc(2011, 08, 02, 12, 23));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 24, 59)), utc(2011, 08, 02, 12, 24));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 25, 00)), utc(2011, 08, 02, 12, 25));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 20, 0)), utc(2011, 8, 2, 12, 20));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 20, 1)), utc(2011, 8, 2, 12, 20));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 21, 0)), utc(2011, 8, 2, 12, 21));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 23, 0)), utc(2011, 8, 2, 12, 23));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 24, 59)), utc(2011, 8, 2, 12, 24));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 25, 0)), utc(2011, 8, 2, 12, 25));
},
"does not modify the passed-in date": function(tier) {
- var date = utc(2011, 08, 02, 12, 21, 20);
- assert.deepEqual(tier.floor(date), utc(2011, 08, 02, 12, 21));
- assert.deepEqual(date, utc(2011, 08, 02, 12, 21, 20));
+ var date = utc(2011, 8, 2, 12, 21, 20);
+ assert.deepEqual(tier.floor(date), utc(2011, 8, 2, 12, 21));
+ assert.deepEqual(date, utc(2011, 8, 2, 12, 21, 20));
}
},
"ceil": {
"rounds up to minutes": function(tier) {
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 20, 00)), utc(2011, 08, 02, 12, 20));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 20, 01)), utc(2011, 08, 02, 12, 21));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 21, 00)), utc(2011, 08, 02, 12, 21));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 23, 00)), utc(2011, 08, 02, 12, 23));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 24, 59)), utc(2011, 08, 02, 12, 25));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 25, 00)), utc(2011, 08, 02, 12, 25));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 20, 0)), utc(2011, 8, 2, 12, 20));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 20, 1)), utc(2011, 8, 2, 12, 21));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 21, 0)), utc(2011, 8, 2, 12, 21));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 23, 0)), utc(2011, 8, 2, 12, 23));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 24, 59)), utc(2011, 8, 2, 12, 25));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 25, 0)), utc(2011, 8, 2, 12, 25));
},
"does not modified the specified date": function(tier) {
- var date = utc(2011, 08, 02, 12, 21, 20);
- assert.deepEqual(tier.ceil(date), utc(2011, 08, 02, 12, 22));
- assert.deepEqual(date, utc(2011, 08, 02, 12, 21, 20));
+ var date = utc(2011, 8, 2, 12, 21, 20);
+ assert.deepEqual(tier.ceil(date), utc(2011, 8, 2, 12, 22));
+ assert.deepEqual(date, utc(2011, 8, 2, 12, 21, 20));
}
},
"step": {
"increments time by one minute": function(tier) {
- var date = utc(2011, 08, 02, 23, 45, 00);
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 02, 23, 46));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 02, 23, 47));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 02, 23, 48));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 02, 23, 49));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 02, 23, 50));
+ var date = utc(2011, 8, 2, 23, 45, 0);
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 2, 23, 46));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 2, 23, 47));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 2, 23, 48));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 2, 23, 49));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 2, 23, 50));
},
"does not round the specified date": function(tier) {
- assert.deepEqual(tier.step(utc(2011, 08, 02, 12, 21, 23)), utc(2011, 08, 02, 12, 22, 23));
+ assert.deepEqual(tier.step(utc(2011, 8, 2, 12, 21, 23)), utc(2011, 8, 2, 12, 22, 23));
},
"does not modify the specified date": function(tier) {
- var date = utc(2011, 08, 02, 12, 20);
- assert.deepEqual(tier.step(date), utc(2011, 08, 02, 12, 21));
- assert.deepEqual(date, utc(2011, 08, 02, 12, 20));
+ var date = utc(2011, 8, 2, 12, 20);
+ assert.deepEqual(tier.step(date), utc(2011, 8, 2, 12, 21));
+ assert.deepEqual(date, utc(2011, 8, 2, 12, 20));
}
}
},
@@ -158,52 +160,52 @@ suite.addBatch({
"floor": {
"rounds down to 5-minutes": function(tier) {
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 20, 00)), utc(2011, 08, 02, 12, 20));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 20, 01)), utc(2011, 08, 02, 12, 20));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 21, 00)), utc(2011, 08, 02, 12, 20));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 23, 00)), utc(2011, 08, 02, 12, 20));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 24, 59)), utc(2011, 08, 02, 12, 20));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 25, 00)), utc(2011, 08, 02, 12, 25));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 20, 0)), utc(2011, 8, 2, 12, 20));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 20, 1)), utc(2011, 8, 2, 12, 20));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 21, 0)), utc(2011, 8, 2, 12, 20));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 23, 0)), utc(2011, 8, 2, 12, 20));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 24, 59)), utc(2011, 8, 2, 12, 20));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 25, 0)), utc(2011, 8, 2, 12, 25));
},
"does not modify the passed-in date": function(tier) {
- var date = utc(2011, 08, 02, 12, 21);
- assert.deepEqual(tier.floor(date), utc(2011, 08, 02, 12, 20));
- assert.deepEqual(date, utc(2011, 08, 02, 12, 21));
+ var date = utc(2011, 8, 2, 12, 21);
+ assert.deepEqual(tier.floor(date), utc(2011, 8, 2, 12, 20));
+ assert.deepEqual(date, utc(2011, 8, 2, 12, 21));
}
},
"ceil": {
"rounds up to 5-minutes": function(tier) {
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 20, 00)), utc(2011, 08, 02, 12, 20));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 20, 01)), utc(2011, 08, 02, 12, 25));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 21, 00)), utc(2011, 08, 02, 12, 25));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 23, 00)), utc(2011, 08, 02, 12, 25));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 24, 59)), utc(2011, 08, 02, 12, 25));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 25, 00)), utc(2011, 08, 02, 12, 25));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 20, 0)), utc(2011, 8, 2, 12, 20));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 20, 1)), utc(2011, 8, 2, 12, 25));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 21, 0)), utc(2011, 8, 2, 12, 25));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 23, 0)), utc(2011, 8, 2, 12, 25));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 24, 59)), utc(2011, 8, 2, 12, 25));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 25, 0)), utc(2011, 8, 2, 12, 25));
},
"does not modified the specified date": function(tier) {
- var date = utc(2011, 08, 02, 12, 21, 00);
- assert.deepEqual(tier.ceil(date), utc(2011, 08, 02, 12, 25));
- assert.deepEqual(date, utc(2011, 08, 02, 12, 21));
+ var date = utc(2011, 8, 2, 12, 21, 0);
+ assert.deepEqual(tier.ceil(date), utc(2011, 8, 2, 12, 25));
+ assert.deepEqual(date, utc(2011, 8, 2, 12, 21));
}
},
"step": {
"increments time by five minutes": function(tier) {
- var date = utc(2011, 08, 02, 23, 45, 00);
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 02, 23, 50));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 02, 23, 55));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 03, 00, 00));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 03, 00, 05));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 03, 00, 10));
+ var date = utc(2011, 8, 2, 23, 45, 0);
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 2, 23, 50));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 2, 23, 55));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 3, 0, 0));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 3, 0, 5));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 3, 0, 10));
},
"does not round the specified date": function(tier) {
- assert.deepEqual(tier.step(utc(2011, 08, 02, 12, 21, 23)), utc(2011, 08, 02, 12, 26, 23));
+ assert.deepEqual(tier.step(utc(2011, 8, 2, 12, 21, 23)), utc(2011, 8, 2, 12, 26, 23));
},
"does not modify the specified date": function(tier) {
- var date = utc(2011, 08, 02, 12, 20, 00);
- assert.deepEqual(tier.step(date), utc(2011, 08, 02, 12, 25));
- assert.deepEqual(date, utc(2011, 08, 02, 12, 20));
+ var date = utc(2011, 8, 2, 12, 20, 0);
+ assert.deepEqual(tier.step(date), utc(2011, 8, 2, 12, 25));
+ assert.deepEqual(date, utc(2011, 8, 2, 12, 20));
}
}
},
@@ -222,50 +224,50 @@ suite.addBatch({
"floor": {
"rounds down to hours": function(tier) {
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 00, 00)), utc(2011, 08, 02, 12, 00));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 00, 01)), utc(2011, 08, 02, 12, 00));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 21, 00)), utc(2011, 08, 02, 12, 00));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 59, 59)), utc(2011, 08, 02, 12, 00));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 13, 00, 00)), utc(2011, 08, 02, 13, 00));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 0, 0)), utc(2011, 8, 2, 12, 0));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 0, 1)), utc(2011, 8, 2, 12, 0));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 21, 0)), utc(2011, 8, 2, 12, 0));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 59, 59)), utc(2011, 8, 2, 12, 0));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 13, 0, 0)), utc(2011, 8, 2, 13, 0));
},
"does not modify the passed-in date": function(tier) {
- var date = utc(2011, 08, 02, 12, 21);
- assert.deepEqual(tier.floor(date), utc(2011, 08, 02, 12, 00));
- assert.deepEqual(date, utc(2011, 08, 02, 12, 21));
+ var date = utc(2011, 8, 2, 12, 21);
+ assert.deepEqual(tier.floor(date), utc(2011, 8, 2, 12, 0));
+ assert.deepEqual(date, utc(2011, 8, 2, 12, 21));
}
},
"ceil": {
"rounds up to hours": function(tier) {
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 00, 00)), utc(2011, 08, 02, 12, 00));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 00, 01)), utc(2011, 08, 02, 13, 00));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 21, 00)), utc(2011, 08, 02, 13, 00));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 59, 59)), utc(2011, 08, 02, 13, 00));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 13, 00, 00)), utc(2011, 08, 02, 13, 00));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 0, 0)), utc(2011, 8, 2, 12, 0));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 0, 1)), utc(2011, 8, 2, 13, 0));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 21, 0)), utc(2011, 8, 2, 13, 0));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 59, 59)), utc(2011, 8, 2, 13, 0));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 13, 0, 0)), utc(2011, 8, 2, 13, 0));
},
"does not modified the specified date": function(tier) {
- var date = utc(2011, 08, 02, 12, 21, 00);
- assert.deepEqual(tier.ceil(date), utc(2011, 08, 02, 13, 00));
- assert.deepEqual(date, utc(2011, 08, 02, 12, 21));
+ var date = utc(2011, 8, 2, 12, 21, 0);
+ assert.deepEqual(tier.ceil(date), utc(2011, 8, 2, 13, 0));
+ assert.deepEqual(date, utc(2011, 8, 2, 12, 21));
}
},
"step": {
"increments time by one hour": function(tier) {
- var date = utc(2011, 08, 02, 22, 00, 00);
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 02, 23, 00));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 03, 00, 00));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 03, 01, 00));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 03, 02, 00));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 03, 03, 00));
+ var date = utc(2011, 8, 2, 22, 0, 0);
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 2, 23, 0));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 3, 0, 0));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 3, 1, 0));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 3, 2, 0));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 3, 3, 0));
},
"does not round the specified date": function(tier) {
- assert.deepEqual(tier.step(utc(2011, 08, 02, 12, 21, 23)), utc(2011, 08, 02, 13, 21, 23));
+ assert.deepEqual(tier.step(utc(2011, 8, 2, 12, 21, 23)), utc(2011, 8, 2, 13, 21, 23));
},
"does not modify the specified date": function(tier) {
- var date = utc(2011, 08, 02, 12, 00, 00);
- assert.deepEqual(tier.step(date), utc(2011, 08, 02, 13, 00));
- assert.deepEqual(date, utc(2011, 08, 02, 12, 00));
+ var date = utc(2011, 8, 2, 12, 0, 0);
+ assert.deepEqual(tier.step(date), utc(2011, 8, 2, 13, 0));
+ assert.deepEqual(date, utc(2011, 8, 2, 12, 0));
}
}
},
@@ -284,50 +286,50 @@ suite.addBatch({
"floor": {
"rounds down to days": function(tier) {
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 00, 00, 00)), utc(2011, 08, 02, 00, 00));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 00, 00, 01)), utc(2011, 08, 02, 00, 00));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 12, 21, 00)), utc(2011, 08, 02, 00, 00));
- assert.deepEqual(tier.floor(utc(2011, 08, 02, 23, 59, 59)), utc(2011, 08, 02, 00, 00));
- assert.deepEqual(tier.floor(utc(2011, 08, 03, 00, 00, 00)), utc(2011, 08, 03, 00, 00));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 0, 0, 0)), utc(2011, 8, 2, 0, 0));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 0, 0, 1)), utc(2011, 8, 2, 0, 0));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 12, 21, 0)), utc(2011, 8, 2, 0, 0));
+ assert.deepEqual(tier.floor(utc(2011, 8, 2, 23, 59, 59)), utc(2011, 8, 2, 0, 0));
+ assert.deepEqual(tier.floor(utc(2011, 8, 3, 0, 0, 0)), utc(2011, 8, 3, 0, 0));
},
"does not modify the passed-in date": function(tier) {
- var date = utc(2011, 08, 02, 12, 21);
- assert.deepEqual(tier.floor(date), utc(2011, 08, 02, 00, 00));
- assert.deepEqual(date, utc(2011, 08, 02, 12, 21));
+ var date = utc(2011, 8, 2, 12, 21);
+ assert.deepEqual(tier.floor(date), utc(2011, 8, 2, 0, 0));
+ assert.deepEqual(date, utc(2011, 8, 2, 12, 21));
}
},
"ceil": {
"rounds up to days": function(tier) {
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 00, 00, 00)), utc(2011, 08, 02, 00, 00));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 00, 00, 01)), utc(2011, 08, 03, 00, 00));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 12, 21, 00)), utc(2011, 08, 03, 00, 00));
- assert.deepEqual(tier.ceil(utc(2011, 08, 02, 23, 59, 59)), utc(2011, 08, 03, 00, 00));
- assert.deepEqual(tier.ceil(utc(2011, 08, 03, 00, 00, 00)), utc(2011, 08, 03, 00, 00));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 0, 0, 0)), utc(2011, 8, 2, 0, 0));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 0, 0, 1)), utc(2011, 8, 3, 0, 0));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 12, 21, 0)), utc(2011, 8, 3, 0, 0));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 2, 23, 59, 59)), utc(2011, 8, 3, 0, 0));
+ assert.deepEqual(tier.ceil(utc(2011, 8, 3, 0, 0, 0)), utc(2011, 8, 3, 0, 0));
},
"does not modified the specified date": function(tier) {
- var date = utc(2011, 08, 02, 12, 21, 00);
- assert.deepEqual(tier.ceil(date), utc(2011, 08, 03, 00, 00));
- assert.deepEqual(date, utc(2011, 08, 02, 12, 21));
+ var date = utc(2011, 8, 2, 12, 21, 0);
+ assert.deepEqual(tier.ceil(date), utc(2011, 8, 3, 0, 0));
+ assert.deepEqual(date, utc(2011, 8, 2, 12, 21));
}
},
"step": {
"increments time by one day": function(tier) {
- var date = utc(2011, 08, 02, 00, 00, 00);
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 03, 00, 00));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 04, 00, 00));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 05, 00, 00));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 06, 00, 00));
- assert.deepEqual(date = tier.step(date), utc(2011, 08, 07, 00, 00));
+ var date = utc(2011, 8, 2, 0, 0, 0);
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 3, 0, 0));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 4, 0, 0));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 5, 0, 0));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 6, 0, 0));
+ assert.deepEqual(date = tier.step(date), utc(2011, 8, 7, 0, 0));
},
"does not round the specified date": function(tier) {
- assert.deepEqual(tier.step(utc(2011, 08, 02, 12, 21, 23)), utc(2011, 08, 03, 12, 21, 23));
+ assert.deepEqual(tier.step(utc(2011, 8, 2, 12, 21, 23)), utc(2011, 8, 3, 12, 21, 23));
},
"does not modify the specified date": function(tier) {
- var date = utc(2011, 08, 02, 00, 00, 00);
- assert.deepEqual(tier.step(date), utc(2011, 08, 03, 00, 00));
- assert.deepEqual(date, utc(2011, 08, 02, 00, 00));
+ var date = utc(2011, 8, 2, 0, 0, 0);
+ assert.deepEqual(tier.step(date), utc(2011, 8, 3, 0, 0));
+ assert.deepEqual(date, utc(2011, 8, 2, 0, 0));
}
}
}
View
2  test/types-test.js
@@ -1,3 +1,5 @@
+'use strict';
+
var vows = require("vows"),
assert = require("assert"),
mongodb = require("mongodb"),
View
2  test/visualizer-test.js
@@ -1,3 +1,5 @@
+'use strict';
+
var vows = require("vows"),
assert = require("assert"),
cube = require("../"),
Please sign in to comment.
Something went wrong with that request. Please try again.