Search in sources :

Example 51 with DataPoints

use of net.opentsdb.core.DataPoints in project opentsdb by OpenTSDB.

the class TestMovingAverage method evaluateWindow1dps.

@Test
public void evaluateWindow1dps() throws Exception {
    params.add("1");
    final DataPoints[] results = func.evaluate(data_query, query_results, params);
    assertEquals(1, results.length);
    assertEquals(METRIC, results[0].metricName());
    long ts = START_TIME;
    double v = 1;
    for (DataPoint dp : results[0]) {
        assertEquals(ts, dp.timestamp());
        assertFalse(dp.isInteger());
        assertEquals(v, dp.doubleValue(), 0.001);
        ts += INTERVAL;
        v += 1;
    }
}
Also used : DataPoint(net.opentsdb.core.DataPoint) DataPoints(net.opentsdb.core.DataPoints) Test(org.junit.Test) SeekableViewsForTest(net.opentsdb.core.SeekableViewsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 52 with DataPoints

use of net.opentsdb.core.DataPoints in project opentsdb by OpenTSDB.

the class TestMovingAverage method evaluateWindow5min.

@Test
public void evaluateWindow5min() throws Exception {
    params.add("'5min'");
    final DataPoints[] results = func.evaluate(data_query, query_results, params);
    assertEquals(1, results.length);
    assertEquals(METRIC, results[0].metricName());
    long ts = START_TIME;
    double v = 0;
    for (DataPoint dp : results[0]) {
        assertEquals(ts, dp.timestamp());
        assertFalse(dp.isInteger());
        assertEquals(v, dp.doubleValue(), 0.001);
        ts += INTERVAL;
    }
}
Also used : DataPoint(net.opentsdb.core.DataPoint) DataPoints(net.opentsdb.core.DataPoints) Test(org.junit.Test) SeekableViewsForTest(net.opentsdb.core.SeekableViewsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 53 with DataPoints

use of net.opentsdb.core.DataPoints in project opentsdb by OpenTSDB.

the class TestMovingAverage method evaluateWindow5dps.

@Test
public void evaluateWindow5dps() throws Exception {
    params.add("5");
    final DataPoints[] results = func.evaluate(data_query, query_results, params);
    assertEquals(1, results.length);
    assertEquals(METRIC, results[0].metricName());
    long ts = START_TIME;
    double v = 0;
    for (DataPoint dp : results[0]) {
        assertEquals(ts, dp.timestamp());
        assertFalse(dp.isInteger());
        assertEquals(v, dp.doubleValue(), 0.001);
        ts += INTERVAL;
        if (ts == 1356998640000L) {
            v = 3.0;
        }
    }
}
Also used : DataPoint(net.opentsdb.core.DataPoint) DataPoints(net.opentsdb.core.DataPoints) Test(org.junit.Test) SeekableViewsForTest(net.opentsdb.core.SeekableViewsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 54 with DataPoints

use of net.opentsdb.core.DataPoints in project opentsdb by OpenTSDB.

the class TestMultiplySeries method multiplyTooManyResultSets.

@Test(expected = IllegalArgumentException.class)
public void multiplyTooManyResultSets() throws Exception {
    SeekableView view2 = SeekableViewsForTest.generator(START_TIME, INTERVAL, NUM_POINTS, true, 10, 1);
    DataPoints dps2 = PowerMockito.mock(DataPoints.class);
    when(dps2.iterator()).thenReturn(view2);
    when(dps2.metricName()).thenReturn("sys.mem");
    when(dps2.metricUID()).thenReturn(new byte[] { 0, 0, 2 });
    group_bys = new DataPoints[] { dps2 };
    // doesn't matter what they are
    for (int i = 0; i < 100; i++) {
        query_results.add(group_bys);
    }
    func.evaluate(data_query, query_results, params);
}
Also used : SeekableView(net.opentsdb.core.SeekableView) DataPoints(net.opentsdb.core.DataPoints) DataPoint(net.opentsdb.core.DataPoint) Test(org.junit.Test) SeekableViewsForTest(net.opentsdb.core.SeekableViewsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 55 with DataPoints

use of net.opentsdb.core.DataPoints in project opentsdb by OpenTSDB.

the class TestMultiplySeries method multiplyMultipleSeriesEach.

@Test
public void multiplyMultipleSeriesEach() throws Exception {
    oneExtraSameE();
    queryAB_Dstar();
    query_results.clear();
    query_results.add(results.get("1").getValue());
    query_results.add(results.get("0").getValue());
    final DataPoints[] results = func.evaluate(data_query, query_results, params);
    assertEquals(3, results.length);
    double[][] vals = new double[2][];
    vals[0] = new double[] { 11, 24, 39 };
    vals[1] = new double[] { 56, 75, 96 };
    for (int i = 0; i < results.length; i++) {
        long ts = 1431561600000l;
        final SeekableView it = results[i].iterator();
        int x = 0;
        while (it.hasNext()) {
            final DataPoint dp = it.next();
            assertEquals(ts, dp.timestamp());
            if (i < 2) {
                assertEquals(vals[i][x++], dp.toDouble(), 0.0001);
            } else {
                assertEquals(0, dp.toDouble(), 0.0001);
            }
            ts += INTERVAL;
        }
    }
}
Also used : DataPoint(net.opentsdb.core.DataPoint) SeekableView(net.opentsdb.core.SeekableView) DataPoints(net.opentsdb.core.DataPoints) DataPoint(net.opentsdb.core.DataPoint) Test(org.junit.Test) SeekableViewsForTest(net.opentsdb.core.SeekableViewsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

DataPoints (net.opentsdb.core.DataPoints)82 Test (org.junit.Test)67 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)67 DataPoint (net.opentsdb.core.DataPoint)64 SeekableViewsForTest (net.opentsdb.core.SeekableViewsForTest)54 SeekableView (net.opentsdb.core.SeekableView)50 ArrayList (java.util.ArrayList)24 TSQuery (net.opentsdb.core.TSQuery)18 Annotation (net.opentsdb.meta.Annotation)17 MockDataPoints (net.opentsdb.storage.MockDataPoints)13 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)11 Matchers.anyString (org.mockito.Matchers.anyString)9 IOException (java.io.IOException)6 MutableDataPoint (net.opentsdb.core.MutableDataPoint)6 Callback (com.stumbleupon.async.Callback)5 Query (net.opentsdb.core.Query)5 TSSubQuery (net.opentsdb.core.TSSubQuery)5 Deferred (com.stumbleupon.async.Deferred)4 Map (java.util.Map)4 List (java.util.List)3