From ddfdbf0e40aa2a9ac7f48520829dc6b30ff3c02b Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Thu, 2 Sep 2010 23:52:25 +0100 Subject: Add test for unknown consolidation function error --- jarmon/jarmon.js | 19 +++---------------- jarmon/jarmon.test.js | 27 +++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js index 32e0283..3f63b3e 100644 --- a/jarmon/jarmon.js +++ b/jarmon/jarmon.js @@ -127,20 +127,6 @@ jarmon.localTimeFormatter = function (v, axis) { }; -jarmon.TimeRangeError = function(message) { - /** - * Raised when an invalid timerange is encountered. - * - * @class jarmon.TimeRangeError - * @constructor - * @param message {String} A description of the error reason - **/ - this.name = "TimeRangeError"; - this.message = (message || ""); -} -jarmon.TimeRangeError.prototype = Error.prototype; - - /** * A wrapper around an instance of javascriptrrd.RRDFile which provides a * convenient way to query the RRDFile based on time range, RRD data source (DS) @@ -173,7 +159,7 @@ jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs, dsId, cfNam **/ if (startTimeJs >= endTimeJs) { - throw new jarmon.TimeRangeError( + throw RangeError( ['starttime must be less than endtime. ', 'starttime: ', startTimeJs, 'endtime: ', endTimeJs].join('')); @@ -182,6 +168,7 @@ jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs, dsId, cfNam // The startTime, endTime and lastupdate time are not necessarily on a step // boundaries. Here we divide, round and then multiply by the step size to // find the nearest "Primary Data Point" (PDP) time. + console.log('RRD: ', this.rrd); var minStep = this.rrd.getMinStep(); var startTime = Math.round(startTimeJs/1000/minStep) * minStep; var lastUpdated = this.rrd.getLastUpdate(); @@ -229,7 +216,7 @@ jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs, dsId, cfNam // If we got to the end of the loop without ever defining step, it means // that the CF check never succeded. if(!step) { - throw new Error('Unrecognised consolidation function: ' + cfName); + throw TypeError('Unrecognised consolidation function: ' + cfName); } var startRowTime = Math.floor(startTime/step)*step + step; diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 7bffb1b..9e8eaca 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -171,19 +171,42 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { this.d.addCallback( function(self, rrd) { self.resume(function() { - var rq = new jarmon.RrdQuery(self.rrd, ''); + var rq = new jarmon.RrdQuery(rrd, ''); var error = null; try { rq.getData(1, 0); } catch(e) { error = e; } - Y.Assert.isInstanceOf(jarmon.TimeRangeError, error); + Y.Assert.isInstanceOf(RangeError, error); }); }, this); this.wait(); }, + + test_getDataUnknownCfError: function () { + /** + * Error is raised if the rrd file doesn't contain an RRA with the + * requested consolidation function (CF) + **/ + this.d.addCallback( + function(self, rrd) { + self.resume(function() { + var rq = new jarmon.RrdQuery(rrd, ''); + var error = null; + try { + rq.getData(RRD_STARTTIME, RRD_ENDTIME, 0, 'FOO'); + } catch(e) { + error = e; + } + Y.Assert.isInstanceOf(TypeError, error); + }); + }, this); + this.wait(); + }, + + test_getData: function () { /** * The generated rrd file should have values 0-9 at 300s intervals -- cgit v1.2.3-2-g168b