Search in sources :

Example 6 with DataPoints

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

the class BaseTimeSyncedIteratorTest method runQueries.

/**
   * Executes the queries against MockBase through the regular pipeline and stores
   * the results in {@linke #results}
   * @param subs The queries to execute
   */
protected void runQueries(final ArrayList<TSSubQuery> subs) throws Exception {
    query = new TSQuery();
    query.setStart(Long.toString(START_TS));
    query.setQueries(subs);
    query.validateAndSetQuery();
    final Query[] compiled = query.buildQueries(tsdb);
    results = new HashMap<String, Pair<TSSubQuery, DataPoints[]>>(compiled.length);
    iterators = new HashMap<String, ITimeSyncedIterator>(compiled.length);
    int index = 0;
    for (final Query q : compiled) {
        final DataPoints[] dps = q.runAsync().join();
        results.put(Integer.toString(index), new Pair<TSSubQuery, DataPoints[]>(query.getQueries().get(index), dps));
        final ITimeSyncedIterator it = new TimeSyncedIterator(Integer.toString(index), query.getQueries().get(index).getFilterTagKs(), dps);
        it.setFillPolicy(new NumericFillPolicy(FillPolicy.NOT_A_NUMBER));
        iterators.put(Integer.toString(index), it);
        index++;
    }
}
Also used : Query(net.opentsdb.core.Query) TSQuery(net.opentsdb.core.TSQuery) TSSubQuery(net.opentsdb.core.TSSubQuery) DataPoints(net.opentsdb.core.DataPoints) TSSubQuery(net.opentsdb.core.TSSubQuery) TSQuery(net.opentsdb.core.TSQuery) Pair(net.opentsdb.utils.Pair)

Example 7 with DataPoints

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

the class TestAbsolute method evaluateFactorNegativeGroupByLong.

@Test
public void evaluateFactorNegativeGroupByLong() 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.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;
    long v = 1;
    for (DataPoint dp : results[0]) {
        assertEquals(ts, dp.timestamp());
        assertTrue(dp.isInteger());
        assertEquals(v, dp.longValue());
        ts += INTERVAL;
        v += 1;
    }
    ts = START_TIME;
    v = 10;
    for (DataPoint dp : results[1]) {
        assertEquals(ts, dp.timestamp());
        assertTrue(dp.isInteger());
        assertEquals(v, dp.longValue());
        ts += INTERVAL;
        v += 1;
    }
}
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)

Example 8 with DataPoints

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

the class TestAbsolute method evaluateNegativeGroupByDouble.

@Test
public void evaluateNegativeGroupByDouble() throws Exception {
    SeekableView view2 = SeekableViewsForTest.generator(START_TIME, INTERVAL, NUM_POINTS, false, -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;
    for (DataPoint dp : results[0]) {
        assertEquals(ts, dp.timestamp());
        assertTrue(dp.isInteger());
        assertEquals((long) v, dp.longValue());
        ts += INTERVAL;
        v += 1;
    }
    ts = START_TIME;
    v = 10;
    for (DataPoint dp : results[1]) {
        assertEquals(ts, dp.timestamp());
        assertFalse(dp.isInteger());
        assertEquals(v, dp.doubleValue(), 0.001);
        ts += INTERVAL;
        v += 1;
    }
}
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)

Example 9 with DataPoints

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

the class TestAbsolute method evaluatePositiveGroupByLong.

@Test
public void evaluatePositiveGroupByLong() 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.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;
    long v = 1;
    for (DataPoint dp : results[0]) {
        assertEquals(ts, dp.timestamp());
        assertTrue(dp.isInteger());
        assertEquals(v, dp.longValue());
        ts += INTERVAL;
        v += 1;
    }
    ts = START_TIME;
    v = 10;
    for (DataPoint dp : results[1]) {
        assertEquals(ts, dp.timestamp());
        assertTrue(dp.isInteger());
        assertEquals(v, dp.longValue());
        ts += INTERVAL;
        v += 1;
    }
}
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)

Example 10 with DataPoints

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

the class TestAbsolute method evaluateNegativeSubQuerySeries.

@Test
public void evaluateNegativeSubQuerySeries() throws Exception {
    params.add("1");
    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;
    long v = 1;
    for (DataPoint dp : results[0]) {
        assertEquals(ts, dp.timestamp());
        assertTrue(dp.isInteger());
        assertEquals(v, dp.longValue());
        ts += INTERVAL;
        v += 1;
    }
    ts = START_TIME;
    v = 10;
    for (DataPoint dp : results[1]) {
        assertEquals(ts, dp.timestamp());
        assertTrue(dp.isInteger());
        assertEquals(v, dp.longValue());
        ts += INTERVAL;
        v += 1;
    }
}
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

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