Search in sources :

Example 1 with Archive

use of org.jrobin.core.Archive in project opennms by OpenNMS.

the class JRobinConverterTest method testCombine.

@Test
public void testCombine() throws Exception {
    createMockSineRrds(null);
    final File newFile = m_converter.createTempRrd(m_sineFull);
    try {
        m_converter.consolidateRrdFile(m_sineFull, newFile);
        RrdDb newRrd = new RrdDb(newFile.getPath(), true);
        TimeSeriesDataSource rrdDatabase = new RrdDatabase(newRrd);
        assertEquals(m_baseTime, newRrd.getLastArchiveUpdateTime());
        Archive archive = newRrd.getArchive(0);
        Robin robin = archive.getRobin(newRrd.getDsIndex("a"));
        assertEquals(4032, robin.getSize());
        assertEquals(Double.NaN, rrdDatabase.getDataAt(1293195600).getValue("a"), ACCEPTABLE_DOUBLE_DELTA);
        assertEquals(0.049584469635D, rrdDatabase.getDataAt(1293210000).getValue("a"), ACCEPTABLE_DOUBLE_DELTA);
        assertEquals(0.023333333333D, rrdDatabase.getDataAt(1298046000).getValue("a"), ACCEPTABLE_DOUBLE_DELTA);
    } finally {
        newFile.delete();
    }
}
Also used : Archive(org.jrobin.core.Archive) RrdDb(org.jrobin.core.RrdDb) File(java.io.File) Robin(org.jrobin.core.Robin) Test(org.junit.Test)

Example 2 with Archive

use of org.jrobin.core.Archive in project opennms by OpenNMS.

the class JRobinConverterTest method checkArchive.

protected void checkArchive(final RrdDb rrd, final Integer nanSample, final Integer numberSample, final Double numberValue, final Integer archiveIndex, final Integer numDses, final Integer dsIndex, String dsName) throws RrdException, IOException {
    LogUtils.debugf(this, "checking archive %s for consistency", rrd);
    final Archive archive = rrd.getArchive(archiveIndex);
    final Map<String, Integer> indexes = m_converter.getDsIndexes(rrd);
    assertEquals(numDses, Integer.valueOf(indexes.size()));
    final Robin robin = archive.getRobin(dsIndex);
    if (nanSample == null) {
        for (final double value : robin.getValues()) {
            assertTrue(!Double.isNaN(value));
        }
    } else {
        assertTrue(Double.isNaN(robin.getValue(nanSample)));
    }
    assertEquals(numberValue, Double.valueOf(robin.getValue(numberSample)));
    // Make sure FetchData matches
    final FetchData data = rrd.createFetchRequest("AVERAGE", archive.getStartTime(), archive.getEndTime()).fetchData();
    final double[] values = data.getValues(dsName);
    if (nanSample == null) {
        for (final double value : values) {
            assertTrue(!Double.isNaN(value));
        }
    } else {
        assertTrue(Double.isNaN(values[nanSample]));
    }
    assertEquals(numberValue, Double.valueOf(values[numberSample]));
}
Also used : Archive(org.jrobin.core.Archive) Robin(org.jrobin.core.Robin) FetchData(org.jrobin.core.FetchData)

Aggregations

Archive (org.jrobin.core.Archive)2 Robin (org.jrobin.core.Robin)2 File (java.io.File)1 FetchData (org.jrobin.core.FetchData)1 RrdDb (org.jrobin.core.RrdDb)1 Test (org.junit.Test)1