/** * @return the p */ public Period getPeriod() { if(period.getScale() != 0) period = new Period(period.getScale()); return period; }
@Test(expected = ParseException.class) public void invaliddate() throws ParseException { @SuppressWarnings("unused") Period p = new Period("2007-14-42 00:15:31", "2007-12-31 23:59:50"); }
static public Period getPeriod(Probe<?, ?> p, long endSec) { Date end = org.rrd4j.core.Util.getDate(endSec); Calendar calBegin = Calendar.getInstance(); calBegin.setTime(end); calBegin.add(Calendar.MONTH, -1); Date begin = calBegin.getTime(); end = jrds.Util.normalize(end, p.getStep()); Period pr = null; try { pr = new Period(Long.toString(begin.getTime()), Long.toString(end.getTime())); } catch (ParseException e) { } return pr; }
public Graph(GraphNode node) { this.node = node; addACL(node.getACL()); Period p = new Period(); setStart(p.getBegin()); setEnd(p.getEnd()); }
@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()); }
@Test public void previousScale() throws ParseException { Period p = new Period().previous(); 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()); }
@Test public void mixedFormat() throws ParseException { begin = fullISOFORMAT.parse("2007-01-01T00:00:00"); end = fullISOFORMAT.parse("2007-12-31T23:59:59"); Period p = new Period("2007-01-01T00:00", "2007-12-31T23:59"); Assert.assertEquals(p.getBegin(), begin); Assert.assertEquals(p.getEnd(), end); Assert.assertEquals(0, p.getScale()); }
@Test public void fullIsoFormat() throws ParseException { begin = fullISOFORMAT.parse("2007-01-01T00:00:00"); end = fullISOFORMAT.parse("2007-12-31T23:59:59"); Period p = new Period("2007-01-01T00:00:00", "2007-12-31T23:59:59"); Assert.assertEquals(begin, p.getBegin()); Assert.assertEquals(end, p.getEnd()); Assert.assertEquals(0, p.getScale()); }
@Test public void spaceSeparator() throws ParseException { begin = fullISOFORMAT.parse("2007-02-01T00:15:31"); end = fullISOFORMAT.parse("2007-12-31T23:59:50"); Period p = new Period("2007-02-01 00:15:31", "2007-12-31 23:59:50"); Assert.assertEquals(begin, p.getBegin()); Assert.assertEquals(end, p.getEnd()); Assert.assertEquals(0, p.getScale()); }
@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 shortFormat() throws ParseException { begin = fullISOFORMAT.parse("2007-01-01T00:00:00"); end = fullISOFORMAT.parse("2007-12-31T23:59:59"); Period p = new Period("2007-01-01", "2007-12-31"); Assert.assertEquals(p.getBegin(), begin); Assert.assertEquals(p.getEnd(), end); Assert.assertEquals(0, p.getScale()); }
@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()); }
@Test public void fromLong() throws ParseException { begin = new Date(1000); end = new Date(100000); Period p = new Period("1000", "100000"); Assert.assertEquals(begin, p.getBegin()); Assert.assertEquals(end, p.getEnd()); Assert.assertEquals(0, p.getScale()); }
@Test public void getBytes() throws Exception { GraphNode gn = new GraphNode(p, GetMoke.getGraphDesc()); Period pr = new Period(); Graph g = new Graph(gn); g.setPeriod(pr); ByteArrayOutputStream out = new ByteArrayOutputStream(); g.writePng(out); Assert.assertTrue(out.size() > 0); }
@Test public void StrictIsoFormat() throws ParseException { begin = strictISOFORMAT.parse("20070101T00:00:00+0000"); end = strictISOFORMAT.parse("20071231T23:59:59+0000"); Period p = new Period("20070101T00:00:00Z", "20071231T23:59:59Z"); Assert.assertEquals(end, p.getEnd()); Assert.assertEquals(begin, p.getBegin()); Assert.assertEquals(0, p.getScale()); }
@Test public void previousFull() throws ParseException { begin = fullISOFORMAT.parse("2007-03-01T00:00:00"); end = fullISOFORMAT.parse("2007-03-01T23:59:59"); Period p = new Period("2007-03-02 00:00:00", "2007-03-02 23:59:59").previous(); logger.trace(p.getBegin()); logger.trace(p.getEnd()); Assert.assertEquals(begin, p.getBegin()); Assert.assertEquals(end, p.getEnd()); Assert.assertEquals(0, p.getScale()); }
@Test(expected = ParseException.class) public void invalid1() throws ParseException { Period p = new Period("a1", "2007-01"); Assert.assertNull(p.getBegin()); Assert.assertNull(p.getEnd()); Assert.assertEquals(0, p.getScale()); }
@Test(expected = ParseException.class) public void invalid2() throws ParseException { Period p = new Period(" ", ""); Assert.assertNull(p.getBegin()); Assert.assertNull(p.getEnd()); Assert.assertEquals(0, p.getScale()); }
@Test(expected = ParseException.class) public void nullargs() throws ParseException { Period p = new Period(null, null); Assert.assertNull(p.getBegin()); Assert.assertNull(p.getEnd()); Assert.assertEquals(0, p.getScale()); }
@Test public void compare() throws IOException, InvocationTargetException { GraphNode gn = new GraphNode(p, GetMoke.getGraphDesc()); Period pr = new Period(); Graph g1 = new Graph(gn); g1.setPeriod(pr); Graph g2 = new Graph(gn); g2.setPeriod(pr); Assert.assertEquals(g1.hashCode(), g2.hashCode()); Assert.assertEquals(g1, g2); }