From 333dfba10d99e5a2eec391c2481156329e2949dc Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Sat, 28 Aug 2010 22:34:26 +0100 Subject: the start of a builder of simple, testable rrd files --- jarmon/jarmon.js | 2 +- jarmon/jarmon.test.js | 53 ++++++++++++++++++++++++++++++++++++++++--------- jarmonbuild/commands.py | 21 ++++++++++++++++++++ 3 files changed, 66 insertions(+), 10 deletions(-) diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js index 6296fc5..24f967d 100644 --- a/jarmon/jarmon.js +++ b/jarmon/jarmon.js @@ -263,7 +263,7 @@ jarmon.RrdQuery.prototype.getData = function(startTime, endTime, dsId, cfName) { jarmon.RrdQueryRemote = function(url, unit, downloader) { this.url = url; this.unit = unit; - this.downloader = downloader; + this.downloader = downloader || jarmon.downloadBinary; this.lastUpdate = 0; this._download = null; }; diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js index 86243b4..229b9a8 100644 --- a/jarmon/jarmon.test.js +++ b/jarmon/jarmon.test.js @@ -48,19 +48,54 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) { Y.Test.Runner.add(new Y.Test.Case({ name: "jarmon.RrdQuery", + setUp: function() { + this.d = new jarmon.downloadBinary('simple.rrd') + .addCallback( + function(self, binary) { + try { + return new RRDFile(binary); + } catch(e) { + console.log(e); + } + }, this) + .addErrback( + function(ret) { + console.log(ret); + }); + }, + test_getDataTimeRangeOverlapError: function () { /** * The starttime must be less than the endtime **/ - var rq = new jarmon.RrdQuery({}, ''); - var error = null; - try { - rq.getData(1, 0); - } catch(e) { - error = e; - } - Y.Assert.isInstanceOf(jarmon.TimeRangeError, error); - } + this.d.addCallback( + function(self, rrd) { + self.resume(function() { + var rq = new jarmon.RrdQuery(self.rrd, ''); + var error = null; + try { + rq.getData(1, 0); + } catch(e) { + error = e; + } + Y.Assert.isInstanceOf(jarmon.TimeRangeError, error); + }); + }, this); + this.wait(); + }, + + test_getDataSimple: function () { + /** + * The starttime must be less than the endtime + **/ + this.d.addCallback( + function(self, rrd) { + self.resume(function() { + Y.Assert.areEqual(1, rrd.getLastUpdate()); + }); + }, this); + this.wait(); + }, })); diff --git a/jarmonbuild/commands.py b/jarmonbuild/commands.py index 5071a46..91b266a 100644 --- a/jarmonbuild/commands.py +++ b/jarmonbuild/commands.py @@ -185,10 +185,31 @@ class BuildReleaseCommand(BuildCommand): z.close() +class BuildTestDataCommand(object): + def __init__(self, buildversion): + self.log = logging.getLogger( + '%s.%s' % (__name__, self.__class__.__name__)) + + def main(self, argv): + from pyrrd.rrd import DataSource, RRA, RRD + + dss = [] + rras = [] + filename = '/tmp/test.rrd' + dss.append(DataSource(dsName='speed', dsType='COUNTER', heartbeat=600)) + rras.append(RRA(cf='AVERAGE', xff=0.5, steps=1, rows=24)) + rras.append(RRA(cf='AVERAGE', xff=0.5, steps=6, rows=10)) + my_rrd = RRD(filename, ds=dss, rra=rras, start=0) + my_rrd.create() + my_rrd.bufferValue(1, '12363') + my_rrd.bufferValue(2, '12363') + my_rrd.update() + # The available sub commands build_commands = { 'apidocs': BuildApidocsCommand, 'release': BuildReleaseCommand, + 'testdata': BuildTestDataCommand, } -- cgit v1.2.3