Search in sources :

Example 11 with MeasurementRowsBuilder

use of org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder in project newts by OpenNMS.

the class ComputeTest method test.

@Test
public void test() {
    Iterator<Row<Measurement>> testData = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("in", 2).element("out", 2).row(600).element("in", 6).element("out", 4).build();
    ResultDescriptor rDescriptor = new ResultDescriptor().datasource("in", AVERAGE).datasource("out", AVERAGE).calculate("total", PLUS, "in", "out");
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("in", 2).element("out", 2).element("total", 4).row(600).element("in", 6).element("out", 4).element("total", 10).build();
    Compute compute = new Compute(rDescriptor, testData);
    assertRowsEqual(expected, compute);
}
Also used : MeasurementRowsBuilder(org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder) Resource(org.opennms.newts.api.Resource) ResultDescriptor(org.opennms.newts.api.query.ResultDescriptor) Row(org.opennms.newts.api.Results.Row) Test(org.junit.Test)

Example 12 with MeasurementRowsBuilder

use of org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder in project newts by OpenNMS.

the class PrimaryDataTest method testShortSamples.

@Test
public void testShortSamples() {
    // Samples occur prior to the nearest step interval boundary.
    Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(000).element("m0", 0).element("m1", 1).row(250).element("m0", 1).element("m1", 2).row(550).element("m0", 2).element("m1", 3).row(850).element("m0", 3).element("m1", 4).build();
    // Minimal result descriptor
    ResultDescriptor rDescriptor = new ResultDescriptor().step(Duration.seconds(300)).datasource("m0", "m0", Duration.seconds(600), null).datasource("m1", "m1", Duration.seconds(600), null);
    // Expected results
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("m0", 1.16666667).element("m1", 2.16666667).row(600).element("m0", 2.16666667).element("m1", 3.16666667).row(900).element("m0", 3.0).element("m1", 4.0).build();
    PrimaryData primaryData = new PrimaryData(new Resource("localhost"), Timestamp.fromEpochSeconds(300), Timestamp.fromEpochSeconds(900), rDescriptor, testData);
    assertRowsEqual(expected, primaryData);
}
Also used : MeasurementRowsBuilder(org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder) Resource(org.opennms.newts.api.Resource) ResultDescriptor(org.opennms.newts.api.query.ResultDescriptor) Row(org.opennms.newts.api.Results.Row) SampleRowsBuilder(org.opennms.newts.aggregate.Utils.SampleRowsBuilder) Test(org.junit.Test)

Example 13 with MeasurementRowsBuilder

use of org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder in project newts by OpenNMS.

the class PrimaryDataTest method testOneToOneSamples.

@Test
public void testOneToOneSamples() {
    // Samples perfectly correlate to step interval boundaries.
    Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(0).element("m0", 0).element("m1", 1).row(300).element("m0", 1).element("m1", 2).row(600).element("m0", 2).element("m1", 3).row(900).element("m0", 3).element("m1", 4).build();
    // Minimal result descriptor
    ResultDescriptor rDescriptor = new ResultDescriptor().step(Duration.seconds(300)).datasource("m0", "m0", Duration.seconds(600), null).datasource("m1", "m1", Duration.seconds(600), null);
    // Expected results
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("m0", 1).element("m1", 2).row(600).element("m0", 2).element("m1", 3).row(900).element("m0", 3).element("m1", 4).build();
    PrimaryData primaryData = new PrimaryData(new Resource("localhost"), Timestamp.fromEpochSeconds(300), Timestamp.fromEpochSeconds(900), rDescriptor, testData);
    assertRowsEqual(expected, primaryData);
}
Also used : MeasurementRowsBuilder(org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder) Resource(org.opennms.newts.api.Resource) ResultDescriptor(org.opennms.newts.api.query.ResultDescriptor) Row(org.opennms.newts.api.Results.Row) SampleRowsBuilder(org.opennms.newts.aggregate.Utils.SampleRowsBuilder) Test(org.junit.Test)

Example 14 with MeasurementRowsBuilder

use of org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder in project newts by OpenNMS.

the class PrimaryDataTest method testHeartbeatTwoSamples.

@Test
public void testHeartbeatTwoSamples() {
    // Sample interval of 600 seconds (m1) exceeds heartbeat of 601
    Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(0).element("m0", 0).element("m1", 1).row(300).element("m0", 1).element("m1", 2).row(600).element("m0", 2).row(900).element("m0", 3).element("m1", 4).build();
    // Minimal result descriptor
    ResultDescriptor rDescriptor = new ResultDescriptor().step(Duration.seconds(300)).datasource("m0", "m0", Duration.seconds(601), null).datasource("m1", "m1", Duration.seconds(601), null);
    // Expected results
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("m0", 1).element("m1", 2).row(600).element("m0", 2).element("m1", 4).row(900).element("m0", 3).element("m1", 4).build();
    PrimaryData primaryData = new PrimaryData(new Resource("localhost"), Timestamp.fromEpochSeconds(300), Timestamp.fromEpochSeconds(900), rDescriptor, testData);
    assertRowsEqual(expected, primaryData);
}
Also used : MeasurementRowsBuilder(org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder) Resource(org.opennms.newts.api.Resource) ResultDescriptor(org.opennms.newts.api.query.ResultDescriptor) Row(org.opennms.newts.api.Results.Row) SampleRowsBuilder(org.opennms.newts.aggregate.Utils.SampleRowsBuilder) Test(org.junit.Test)

Example 15 with MeasurementRowsBuilder

use of org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder in project newts by OpenNMS.

the class PrimaryDataTest method testHeartbeatOneSample.

@Test
public void testHeartbeatOneSample() {
    // Sample interval of 600 seconds (m1) exceeds heartbeat of 601
    Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(0).element("m1", 1).row(300).element("m1", 2).row(900).element("m1", 4).build();
    // Minimal result descriptor
    ResultDescriptor rDescriptor = new ResultDescriptor().step(Duration.seconds(300)).datasource("m1", "m1", Duration.seconds(601), null);
    // Expected results
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("m1", 2).row(600).element("m1", 4).row(900).element("m1", 4).build();
    PrimaryData primaryData = new PrimaryData(new Resource("localhost"), Timestamp.fromEpochSeconds(300), Timestamp.fromEpochSeconds(900), rDescriptor, testData);
    assertRowsEqual(expected, primaryData);
}
Also used : MeasurementRowsBuilder(org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder) Resource(org.opennms.newts.api.Resource) ResultDescriptor(org.opennms.newts.api.query.ResultDescriptor) Row(org.opennms.newts.api.Results.Row) SampleRowsBuilder(org.opennms.newts.aggregate.Utils.SampleRowsBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 MeasurementRowsBuilder (org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder)20 Resource (org.opennms.newts.api.Resource)20 Row (org.opennms.newts.api.Results.Row)20 ResultDescriptor (org.opennms.newts.api.query.ResultDescriptor)20 SampleRowsBuilder (org.opennms.newts.aggregate.Utils.SampleRowsBuilder)14 Measurement (org.opennms.newts.api.Measurement)1 BinaryFunction (org.opennms.newts.api.query.ResultDescriptor.BinaryFunction)1