Search in sources :

Example 56 with Resource

use of org.opennms.newts.api.Resource 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)

Example 57 with Resource

use of org.opennms.newts.api.Resource in project newts by OpenNMS.

the class PrimaryDataTest method testLongSamples.

@Test
public void testLongSamples() {
    // Samples occur later-than (after) the step interval.
    Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(0).element("m0", 0).element("m1", 1).row(350).element("m0", 1).element("m1", 2).row(650).element("m0", 2).element("m1", 3).row(950).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.0).element("m1", 2.0).row(600).element("m0", 1.83333333).element("m1", 2.83333333).row(900).element("m0", 2.83333333).element("m1", 3.83333333).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 58 with Resource

use of org.opennms.newts.api.Resource in project newts by OpenNMS.

the class PrimaryDataTest method testSkippedSample.

@Test
public void testSkippedSample() {
    // Sample m0 is missing at timestamp 550, (but interval does not exceed heartbeat).
    Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(0).element("m0", 0).element("m1", 1).row(250).element("m0", 1).element("m1", 2).row(550).element("m1", 3).row(840).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.33333333).element("m1", 2.16666667).row(600).element("m0", 3.00000000).element("m1", 3.16666667).row(900).element("m0", 3.00000000).element("m1", 4.00000000).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 59 with Resource

use of org.opennms.newts.api.Resource in project newts by OpenNMS.

the class PrimaryDataTest method testLeadingSamplesMiss.

@Test
public void testLeadingSamplesMiss() {
    // Missing a couple leading samples
    Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(900000300).element("m0", 0).row(900000600).element("m0", 1).row(900000900).element("m0", 2).row(900001200).element("m0", 3).build();
    ResultDescriptor rDescriptor = new ResultDescriptor(Duration.seconds(300)).datasource("m0", "m0", Duration.seconds(600), null);
    // Expected results
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(900000000).element("m0", Double.NaN).row(900000300).element("m0", Double.NaN).row(900000600).element("m0", 1).row(900000900).element("m0", 2).row(900001200).element("m0", 3).build();
    PrimaryData primaryData = new PrimaryData(new Resource("localhost"), Timestamp.fromEpochSeconds(900000000), Timestamp.fromEpochSeconds(900001200), 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 60 with Resource

use of org.opennms.newts.api.Resource in project newts by OpenNMS.

the class PrimaryDataTest method testOneToManySamples.

@Test
public void testOneToManySamples() {
    // Actual sample interval is smaller than step size; One sample is mapped to many measurements
    Iterator<Row<Sample>> testData = new SampleRowsBuilder(new Resource("localhost"), MetricType.GAUGE).row(0).element("m0", 0).element("m1", 1).row(900).element("m0", 1).element("m1", 2).row(1800).element("m0", 2).element("m1", 3).build();
    // Minimal result descriptor
    ResultDescriptor rDescriptor = new ResultDescriptor().step(Duration.seconds(300)).datasource("m0", "m0", Duration.seconds(1000), null).datasource("m1", "m1", Duration.seconds(1000), null);
    // Expected results
    Iterator<Row<Measurement>> expected = new MeasurementRowsBuilder(new Resource("localhost")).row(300).element("m0", 1).element("m1", 2).row(600).element("m0", 1).element("m1", 2).row(900).element("m0", 1).element("m1", 2).row(1200).element("m0", 2).element("m1", 3).row(1500).element("m0", 2).element("m1", 3).row(1800).element("m0", 2).element("m1", 3).build();
    PrimaryData primaryData = new PrimaryData(new Resource("localhost"), Timestamp.fromEpochSeconds(300), Timestamp.fromEpochSeconds(1800), 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

Resource (org.opennms.newts.api.Resource)67 Test (org.junit.Test)50 Row (org.opennms.newts.api.Results.Row)35 ResultDescriptor (org.opennms.newts.api.query.ResultDescriptor)31 MeasurementRowsBuilder (org.opennms.newts.aggregate.Utils.MeasurementRowsBuilder)20 SampleRowsBuilder (org.opennms.newts.aggregate.Utils.SampleRowsBuilder)20 Sample (org.opennms.newts.api.Sample)19 Measurement (org.opennms.newts.api.Measurement)14 Context (org.opennms.newts.api.Context)12 MetricRegistry (com.codahale.metrics.MetricRegistry)9 SearchResults (org.opennms.newts.api.search.SearchResults)8 Timestamp (org.opennms.newts.api.Timestamp)7 ResourcePath (org.opennms.netmgt.model.ResourcePath)6 ContextConfigurations (org.opennms.newts.cassandra.ContextConfigurations)6 Map (java.util.Map)5 Results (org.opennms.newts.api.Results)5 CassandraSession (org.opennms.newts.cassandra.CassandraSession)5 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)4 List (java.util.List)4 Result (org.opennms.newts.api.search.SearchResults.Result)4