summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Wall <richard@largo>2010-12-30 12:56:10 +0000
committerRichard Wall <richard@largo>2010-12-30 12:56:10 +0000
commitb3b166f6455b8556b5f14f35f8f755f26d5d87e1 (patch)
treee8d2374005eb48f389ebb8eeaff12a6547e63f18
parentc71886f059b6d2ad68f55a37c891f26898a5c7be (diff)
Unit tests for RrdQueryRemote
-rw-r--r--jarmon/jarmon.js4
-rw-r--r--jarmon/jarmon.test.js99
2 files changed, 101 insertions, 2 deletions
diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js
index a66a93b..6e1d1f8 100644
--- a/jarmon/jarmon.js
+++ b/jarmon/jarmon.js
@@ -316,7 +316,7 @@ jarmon.RrdQueryRemote.prototype._callRemote = function(methodName, args) {
};
-jarmon.RrdQueryRemote.prototype.getData = function(startTime, endTime, dsId) {
+jarmon.RrdQueryRemote.prototype.getData = function(startTime, endTime, dsId, cfName) {
/**
* Return a Flot compatible data series asynchronously.
*
@@ -329,7 +329,7 @@ jarmon.RrdQueryRemote.prototype.getData = function(startTime, endTime, dsId) {
if(this.lastUpdate < endTime/1000) {
this._download = null;
}
- return this._callRemote('getData', [startTime, endTime, dsId]);
+ return this._callRemote('getData', [startTime, endTime, dsId, cfName]);
};
/**
diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js
index fda076f..2b4465d 100644
--- a/jarmon/jarmon.test.js
+++ b/jarmon/jarmon.test.js
@@ -277,6 +277,105 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) {
Y.Test.Runner.add(new Y.Test.Case({
+ name: "jarmon.RrdQueryRemote",
+
+ setUp: function() {
+ this.rq = new jarmon.RrdQueryRemote('build/test.rrd', '')
+ },
+
+ test_getDataTimeRangeOverlapError: function () {
+ /**
+ * The starttime must be less than the endtime
+ **/
+ this.rq.getData(1, 0).addBoth(
+ function(self, res) {
+ self.resume(function() {
+ Y.Assert.isInstanceOf(RangeError, res);
+ });
+ }, 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.rq.getData(RRD_STARTTIME, RRD_ENDTIME, 0, 'FOO').addBoth(
+ function(self, res) {
+ self.resume(function() {
+ Y.Assert.isInstanceOf(TypeError, res);
+ });
+ }, this);
+ this.wait();
+ },
+
+
+ test_getData: function () {
+ /**
+ * The generated rrd file should have values 0-9 at 300s intervals
+ * starting at 1980-01-01 00:00:00
+ * Result should include a data points with times > starttime and
+ * <= endTime
+ **/
+ this.rq.getData(RRD_STARTTIME + (RRD_STEP+1) * 1000,
+ RRD_ENDTIME - (RRD_STEP-1) * 1000).addBoth(
+ function(self, data) {
+ self.resume(function() {
+ // We request data starting 1 STEP +1s after the RRD file
+ // first val and ending 1 STEP -1s before the RRD last val
+ // ie one step within the RRD file, but 1s away from the
+ // step boundary to test the quantisation of the
+ // requested time range.
+
+ // so we expect two less rows than the total rows in the
+ // file.
+ Y.Assert.areEqual(RRD_RRAROWS-2, data.data.length);
+
+ // The value of the first returned row should be the
+ // second value in the RRD file (starts at value 0)
+ Y.Assert.areEqual(1, data.data[0][1]);
+
+ // The value of the last returned row should be the
+ // 10 value in the RRD file (starts at value 0)
+ Y.Assert.areEqual(10, data.data[data.data.length-1][1]);
+
+ // The timestamp of the first returned row should be
+ // exactly one step after the start of the RRD file
+ Y.Assert.areEqual(
+ RRD_STARTTIME+RRD_STEP*1000, data.data[0][0]);
+
+ // RRD_ENDTIME is on a step boundary and is therfore
+ // actually the start time of a new row
+ // So when we ask for endTime = RRD_ENDTIME-STEP-1 we
+ // actually get data up to the 2nd to last RRD row.
+ Y.Assert.areEqual(
+ RRD_ENDTIME-RRD_STEP*1000*2,
+ data.data[data.data.length-1][0]);
+ });
+ }, this);
+ this.wait();
+ },
+
+ test_getDataUnknownValues: function () {
+ /**
+ * If the requested time range is outside the range of the RRD file
+ * we should not get any values back
+ **/
+ this.rq.getData(RRD_ENDTIME, RRD_ENDTIME+1000).addBoth(
+ function(self, data) {
+ self.resume(function() {
+ Y.Assert.areEqual(0, data.data.length);
+ });
+ }, this);
+ this.wait();
+ }
+
+ }));
+
+
+ Y.Test.Runner.add(new Y.Test.Case({
name: "jarmon.Chart",
test_draw: function () {