private Period makePeriod() { Period p = null; try { String scaleStr = getValue("scale"); // Changed name for this attribute if(scaleStr == null) scaleStr = getValue("autoperiod"); int scale = jrds.Util.parseStringNumber(scaleStr, -1); String end = getValue("end"); String begin = getValue("begin"); if(scale > 0) p = new Period(scale); else if(end != null && begin != null) p = new Period(begin, end); else p = new Period(); if(params.containsKey("periodnext")) p = p.next(); else if(params.containsKey("periodprevious")) p = p.previous(); } catch (NumberFormatException | ParseException e) { logger.error("Period cannot be parsed: " + e.getMessage()); } return p; }
@Test public void nextScale() throws ParseException { Period p = new Period().next(); logger.trace(p.getBegin()); logger.trace(p.getEnd()); long offsetDay = 86400 * 1000 - (p.getEnd().getTime() - p.getBegin().getTime()); Assert.assertTrue("offset to large: " + offsetDay, Math.abs(offsetDay) < 1100); Assert.assertEquals(0, p.getScale()); }
public void setScale(int s) { period = new Period(s); }
/** * @return Returns the scale. */ public int getScale() { return period.getScale(); }
/** * @return Returns the end. */ public long getEnd() { if(period != null) return period.getEnd().getTime(); return Long.MIN_VALUE; }
/** * @return Returns the begin. */ public long getBegin() { if(period != null) return period.getBegin().getTime(); return Long.MIN_VALUE; }
public Period(String begin, String end) throws ParseException { this(Scale.MANUAL, string2Date(begin, true), string2Date(end, false)); }
public List<String> getPeriodNames() { logger.trace("Knonw period names: " + Period.getPeriodNames()); return Period.getPeriodNames(); }
@Test public void nextFull() throws ParseException { begin = fullISOFORMAT.parse("2007-03-03T00:00:00"); end = fullISOFORMAT.parse("2007-03-03T23:59:59"); Period p = new Period("2007-03-02 00:00:00", "2007-03-02 23:59:59").next(); logger.trace(p.getBegin()); logger.trace(p.getEnd()); Assert.assertEquals(begin, p.getBegin()); Assert.assertEquals(end, p.getEnd()); Assert.assertEquals(0, p.getScale()); }
public Period next() { return new Period(Scale.MANUAL, begin.plus(period), end.plus(period)); }
if(p.period.getScale() != 0 || !cache) { res.addDateHeader("Expires", new Date().getTime() + graphStep * 1000);
@Test public void nextFullWithOneSecond() throws ParseException { begin = fullISOFORMAT.parse("2007-03-03T00:00:00"); end = fullISOFORMAT.parse("2007-03-03T23:59:59"); Period p = new Period("2007-03-02 00:00:00", "2007-03-03T00:00:00").next(); logger.trace(p.getBegin()); logger.trace(p.getEnd()); Assert.assertEquals(begin, p.getBegin()); Assert.assertEquals(end, p.getEnd()); Assert.assertEquals(0, p.getScale()); }
@Test public void readDatasourcesNames() throws Exception { GenerateProbe.ChainedMap<Object> factoryArgs = GenerateProbe.ChainedMap.start(1).set("rrdfile", rrdfile.getCanonicalPath()); GenerateProbe.ChainedMap<Object> args = GenerateProbe.ChainedMap.start(2) .set(StoreFactory.class, new RRDToolStoreFactory()) .set(GenerateProbe.FACTORYCONFIG, factoryArgs); Probe<?,?> p = GenerateProbe.fillProbe(new GenerateProbe.EmptyProbe(), testFolder, args); p.getPd().add("speed", DsType.GAUGE); p.getPd().add("weight", DsType.GAUGE); Assert.assertTrue(p.checkStore()); Period period = new Period("1999-03-07T13:00:00", "1999-03-07T13:15:00"); DataProcessor dp = p.extract(ExtractInfo.get().make(period.getBegin(), period.getEnd())); String[] dsNames = dp.getSourceNames(); Assert.assertEquals("data source weight not found", "weight", dsNames[0]); Assert.assertEquals("data source speed not found", "speed", dsNames[1]); Assert.assertEquals("Missing last values", 2, p.getMainStore().getLastValues().size()); }