Search in sources :

Example 36 with SeekableView

use of net.opentsdb.core.SeekableView 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)

Example 37 with SeekableView

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

the class TestMultiplySeries method multiplyOneSeriesEach.

@Test
public void multiplyOneSeriesEach() 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 };
    query_results.add(group_bys);
    final DataPoints[] results = func.evaluate(data_query, query_results, params);
    assertEquals(1, results.length);
    assertEquals(METRIC_STRING, results[0].metricName());
    final int[] vals = new int[] { 10, 22, 36, 52, 70 };
    int i = 0;
    long ts = START_TIME;
    for (DataPoint dp : results[0]) {
        assertEquals(ts, dp.timestamp());
        assertEquals(vals[i++], dp.toDouble(), 0.001);
        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)

Example 38 with SeekableView

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

the class TestPostAggregatedDataPoints method emptyPoints.

@Test
public void emptyPoints() throws Exception {
    points = new MutableDataPoint[0];
    final PostAggregatedDataPoints dps = new PostAggregatedDataPoints(base_data_points, points);
    assertEquals(METRIC_NAME, dps.metricName());
    assertEquals(METRIC_NAME, dps.metricNameAsync().join());
    assertSame(tags, dps.getTags());
    assertSame(tags, dps.getTagsAsync().join());
    assertSame(agg_tags, dps.getAggregatedTags());
    assertSame(agg_tags, dps.getAggregatedTagsAsync().join());
    assertSame(tsuids, dps.getTSUIDs());
    assertSame(annotations, dps.getAnnotations());
    assertSame(tag_uids, dps.getTagUids());
    assertEquals(42, dps.getQueryIndex());
    assertEquals(0, dps.size());
    assertEquals(0, dps.aggregatedSize());
    // values
    final SeekableView iterator = dps.iterator();
    assertFalse(iterator.hasNext());
    try {
        iterator.next();
        fail("Expected a NoSuchElementException");
    } catch (NoSuchElementException e) {
    }
}
Also used : SeekableView(net.opentsdb.core.SeekableView) NoSuchElementException(java.util.NoSuchElementException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 39 with SeekableView

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

the class TestPostAggregatedDataPoints method ctorDefaults.

@Test
public void ctorDefaults() throws Exception {
    final PostAggregatedDataPoints dps = new PostAggregatedDataPoints(base_data_points, points);
    assertEquals(METRIC_NAME, dps.metricName());
    assertEquals(METRIC_NAME, dps.metricNameAsync().join());
    assertSame(tags, dps.getTags());
    assertSame(tags, dps.getTagsAsync().join());
    assertSame(agg_tags, dps.getAggregatedTags());
    assertSame(agg_tags, dps.getAggregatedTagsAsync().join());
    assertSame(tsuids, dps.getTSUIDs());
    assertSame(annotations, dps.getAnnotations());
    assertSame(tag_uids, dps.getTagUids());
    assertEquals(42, dps.getQueryIndex());
    assertEquals(5, dps.size());
    assertEquals(5, dps.aggregatedSize());
    // values
    final SeekableView iterator = dps.iterator();
    int values = 0;
    long value = 0;
    long ts = BASE_TIME;
    while (iterator.hasNext()) {
        final DataPoint dp = iterator.next();
        assertEquals(value++, dp.longValue());
        assertEquals(ts, dp.timestamp());
        ts += TIME_INTERVAL;
        values++;
    }
    assertEquals(5, values);
    assertFalse(iterator.hasNext());
    try {
        iterator.next();
        fail("Expected a NoSuchElementException");
    } catch (NoSuchElementException e) {
    }
    assertEquals(BASE_TIME + (4 * TIME_INTERVAL), dps.timestamp(4));
    assertEquals(4, dps.longValue(4));
    assertTrue(dps.isInteger(4));
    try {
        assertEquals(4, dps.doubleValue(4), 0.00);
        fail("Expected a ClassCastException");
    } catch (ClassCastException e) {
    }
    try {
        dps.timestamp(5);
        fail("Expected a ArrayIndexOutOfBoundsException");
    } catch (ArrayIndexOutOfBoundsException e) {
    }
    try {
        dps.isInteger(5);
        fail("Expected a ArrayIndexOutOfBoundsException");
    } catch (ArrayIndexOutOfBoundsException e) {
    }
    try {
        dps.longValue(5);
        fail("Expected a ArrayIndexOutOfBoundsException");
    } catch (ArrayIndexOutOfBoundsException e) {
    }
    try {
        dps.doubleValue(5);
        fail("Expected a ArrayIndexOutOfBoundsException");
    } catch (ArrayIndexOutOfBoundsException e) {
    }
}
Also used : MutableDataPoint(net.opentsdb.core.MutableDataPoint) DataPoint(net.opentsdb.core.DataPoint) SeekableView(net.opentsdb.core.SeekableView) MutableDataPoint(net.opentsdb.core.MutableDataPoint) DataPoint(net.opentsdb.core.DataPoint) NoSuchElementException(java.util.NoSuchElementException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 40 with SeekableView

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

the class TestScale method evaluateFactor1point5GroupBy.

@Test
public void evaluateFactor1point5GroupBy() throws Exception {
    params.add("1.5");
    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.metricNameAsync()).thenReturn(Deferred.fromResult("sys.mem"));
    group_bys = new DataPoints[] { dps, dps2 };
    query_results.clear();
    query_results.add(group_bys);
    final DataPoints[] results = func.evaluate(data_query, query_results, params);
    assertEquals(2, results.length);
    assertEquals(METRIC, results[0].metricName());
    assertEquals("sys.mem", results[1].metricName());
    long ts = START_TIME;
    double v = 1.5;
    for (DataPoint dp : results[0]) {
        System.out.println(dp.timestamp() + " : " + dp.toDouble());
        assertEquals(ts, dp.timestamp());
        assertFalse(dp.isInteger());
        assertEquals(v, dp.doubleValue(), 0.001);
        ts += INTERVAL;
        v += 1.5;
    }
    ts = START_TIME;
    v = 15;
    for (DataPoint dp : results[1]) {
        assertEquals(ts, dp.timestamp());
        assertFalse(dp.isInteger());
        assertEquals(v, dp.doubleValue(), 0.001);
        ts += INTERVAL;
        v += 1.5;
    }
}
Also used : DataPoint(net.opentsdb.core.DataPoint) SeekableView(net.opentsdb.core.SeekableView) DataPoints(net.opentsdb.core.DataPoints) Test(org.junit.Test) SeekableViewsForTest(net.opentsdb.core.SeekableViewsForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SeekableView (net.opentsdb.core.SeekableView)54 DataPoint (net.opentsdb.core.DataPoint)50 DataPoints (net.opentsdb.core.DataPoints)50 Test (org.junit.Test)47 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)47 SeekableViewsForTest (net.opentsdb.core.SeekableViewsForTest)45 ArrayList (java.util.ArrayList)7 MutableDataPoint (net.opentsdb.core.MutableDataPoint)7 AggregationIterator (net.opentsdb.core.AggregationIterator)3 NoSuchElementException (java.util.NoSuchElementException)2 Callback (com.stumbleupon.async.Callback)1 Deferred (com.stumbleupon.async.Deferred)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Aggregator (net.opentsdb.core.Aggregator)1 Query (net.opentsdb.core.Query)1 TSDB (net.opentsdb.core.TSDB)1 TSQuery (net.opentsdb.core.TSQuery)1 TSSubQuery (net.opentsdb.core.TSSubQuery)1 TopNSortingEntry (net.opentsdb.query.expression.HighestMax.TopNSortingEntry)1