Search in sources :

Example 21 with RRDv3

use of org.opennms.netmgt.rrd.model.v3.RRDv3 in project opennms by OpenNMS.

the class RrdMergeIT method testRrdMerge.

/**
 * Test RRD merge.
 * <p>Both test XML contains data from different range of times, and the value is always increasing.</p>
 *
 * @throws Exception the exception
 */
@Test
public void testRrdMerge() throws Exception {
    RRDv3 tempA = JaxbUtils.unmarshal(RRDv3.class, new File("src/test/resources/rrd-tempA-rrd.xml"));
    RRDv3 tempB = JaxbUtils.unmarshal(RRDv3.class, new File("src/test/resources/rrd-tempB-rrd.xml"));
    // Retrieve a list of the time stamps of the rows with data from tempA.rrd
    // Verify the max value
    Double value = Double.NEGATIVE_INFINITY;
    List<Long> timestampsA = new ArrayList<>();
    for (RRA rra : tempA.getRras()) {
        for (Row row : rra.getRows()) {
            if (!row.isNan()) {
                timestampsA.add(tempA.findTimestampByRow(rra, row));
                Double current = row.getValues().get(0);
                if (current > value) {
                    value = current;
                }
            }
        }
    }
    Assert.assertEquals(new Double(3.0), value);
    // Retrieve a list of the time stamps of the rows with data from tempB.rrd
    value = Double.NEGATIVE_INFINITY;
    List<Long> timestampsB = new ArrayList<>();
    for (RRA rra : tempB.getRras()) {
        for (Row row : rra.getRows()) {
            if (!row.isNan()) {
                timestampsB.add(tempB.findTimestampByRow(rra, row));
                Double current = row.getValues().get(0);
                if (current > value) {
                    value = current;
                }
            }
        }
    }
    Assert.assertEquals(new Double(18.0), value);
    // Verify that all the timestamps on timestampsA are different than the timestamps from timestampsB
    for (Long l : timestampsA) {
        if (timestampsB.contains(l)) {
            Assert.fail("The timestampsB should not contain any timestamp from timestampsA");
        }
    }
    for (Long l : timestampsB) {
        if (timestampsA.contains(l)) {
            Assert.fail("The timestampsA should not contain any timestamp from timestampsB");
        }
    }
    // Perform the Merge Operation, merging the data from tempA.rrd to tempB.rrd
    tempB.merge(tempA);
    // Retrieve the list of the non NaN rows from the updated tempB.rrd
    value = Double.NEGATIVE_INFINITY;
    List<Long> timestampsFinal = new ArrayList<>();
    for (RRA rra : tempB.getRras()) {
        for (Row row : rra.getRows()) {
            if (!row.isNan()) {
                timestampsFinal.add(tempB.findTimestampByRow(rra, row));
                Double current = row.getValues().get(0);
                if (current > value) {
                    value = current;
                }
            }
        }
    }
    Assert.assertEquals(new Double(18.0), value);
    // Verify that timestampsFinal contains timestampsA and timestampsB
    Assert.assertTrue(timestampsFinal.containsAll(timestampsA));
    Assert.assertTrue(timestampsFinal.containsAll(timestampsB));
}
Also used : RRA(org.opennms.netmgt.rrd.model.v3.RRA) RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3) ArrayList(java.util.ArrayList) Row(org.opennms.netmgt.rrd.model.Row) File(java.io.File) Test(org.junit.Test)

Aggregations

RRDv3 (org.opennms.netmgt.rrd.model.v3.RRDv3)21 File (java.io.File)15 Test (org.junit.Test)14 RRDv1 (org.opennms.netmgt.rrd.model.v1.RRDv1)8 ArrayList (java.util.ArrayList)5 Row (org.opennms.netmgt.rrd.model.Row)4 List (java.util.List)3 RRA (org.opennms.netmgt.rrd.model.v3.RRA)3 FileWriter (java.io.FileWriter)2 Map (java.util.Map)2 NavigableMap (java.util.NavigableMap)2 SortedMap (java.util.SortedMap)2 AbstractRRD (org.opennms.netmgt.rrd.model.AbstractRRD)2 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 SAXSource (javax.xml.transform.sax.SAXSource)1 FileUtils (org.apache.commons.io.FileUtils)1 RrdException (org.jrobin.core.RrdException)1