Search in sources :

Example 71 with DataPoints

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

the class TestDivideSeries method divideOneSeriesEach.

@Test
public void divideOneSeriesEach() 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());
    double[] vals = new double[] { 0.1, 0.181, 0.25, 0.307, 0.357 };
    long ts = START_TIME;
    int i = 0;
    for (final 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 72 with DataPoints

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

the class TestHttpJsonSerializer method formatQueryAsyncV1NoSuchTagId.

@Test(expected = DeferredGroupException.class)
public void formatQueryAsyncV1NoSuchTagId() throws Exception {
    setupFormatQuery();
    HttpQuery query = NettyMocks.getQuery(tsdb, "");
    HttpJsonSerializer serdes = new HttpJsonSerializer(query);
    final TSQuery data_query = getTestQuery(false);
    validateTestQuery(data_query);
    final DataPoints dps = new MockDataPoints().getMock();
    final List<DataPoints[]> results = new ArrayList<DataPoints[]>(1);
    results.add(new DataPoints[] { dps });
    when(dps.getTagsAsync()).thenReturn(Deferred.<Map<String, String>>fromError(new NoSuchUniqueId("No such tagv", new byte[] { 0, 0, 1 })));
    serdes.formatQueryAsyncV1(data_query, results, Collections.<Annotation>emptyList()).joinUninterruptibly();
}
Also used : TSQuery(net.opentsdb.core.TSQuery) MockDataPoints(net.opentsdb.storage.MockDataPoints) NoSuchUniqueId(net.opentsdb.uid.NoSuchUniqueId) ArrayList(java.util.ArrayList) DataPoints(net.opentsdb.core.DataPoints) MockDataPoints(net.opentsdb.storage.MockDataPoints) Matchers.anyString(org.mockito.Matchers.anyString) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 73 with DataPoints

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

the class TestHttpJsonSerializer method formatQueryAsyncV1UnexpectedAggException.

@Test(expected = RuntimeException.class)
public void formatQueryAsyncV1UnexpectedAggException() throws Exception {
    setupFormatQuery();
    HttpQuery query = NettyMocks.getQuery(tsdb, "");
    HttpJsonSerializer serdes = new HttpJsonSerializer(query);
    final TSQuery data_query = getTestQuery(false);
    validateTestQuery(data_query);
    final MockDataPoints mdps = new MockDataPoints();
    final List<DataPoints[]> results = new ArrayList<DataPoints[]>(1);
    results.add(new DataPoints[] { mdps.getMock() });
    when(mdps.getMockDP().timestamp()).thenThrow(new RuntimeException("Unexpected error"));
    serdes.formatQueryAsyncV1(data_query, results, Collections.<Annotation>emptyList()).joinUninterruptibly();
}
Also used : TSQuery(net.opentsdb.core.TSQuery) MockDataPoints(net.opentsdb.storage.MockDataPoints) ArrayList(java.util.ArrayList) DataPoints(net.opentsdb.core.DataPoints) MockDataPoints(net.opentsdb.storage.MockDataPoints) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 74 with DataPoints

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

the class TestHttpJsonSerializer method formatQueryAsyncTimeFilterV1.

@Test
public void formatQueryAsyncTimeFilterV1() throws Exception {
    setupFormatQuery();
    HttpQuery query = NettyMocks.getQuery(tsdb, "");
    HttpJsonSerializer serdes = new HttpJsonSerializer(query);
    final TSQuery data_query = getTestQuery(false, false);
    final List<DataPoints[]> results = new ArrayList<DataPoints[]>(1);
    results.add(new DataPoints[] { new MockDataPoints().getMock() });
    data_query.setEnd("1357000500");
    validateTestQuery(data_query);
    ChannelBuffer cb = serdes.formatQueryAsyncV1(data_query, results, Collections.<Annotation>emptyList()).joinUninterruptibly();
    assertNotNull(cb);
    final String json = cb.toString(Charset.forName("UTF-8"));
    assertTrue(json.contains("\"metric\":\"system.cpu.user\","));
    assertTrue(json.contains("\"1356998700\":1,"));
    assertTrue(json.contains("\"1357000500\":7"));
}
Also used : TSQuery(net.opentsdb.core.TSQuery) MockDataPoints(net.opentsdb.storage.MockDataPoints) ArrayList(java.util.ArrayList) DataPoints(net.opentsdb.core.DataPoints) MockDataPoints(net.opentsdb.storage.MockDataPoints) Matchers.anyString(org.mockito.Matchers.anyString) Annotation(net.opentsdb.meta.Annotation) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 75 with DataPoints

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

the class TestHttpJsonSerializer method formatQueryAsyncV1wStatsSummary.

@Test
public void formatQueryAsyncV1wStatsSummary() throws Exception {
    setupFormatQuery();
    final HttpQuery query = NettyMocks.getQuery(tsdb, "");
    final HttpJsonSerializer serdes = new HttpJsonSerializer(query);
    final TSQuery data_query = getTestQuery(true, true);
    validateTestQuery(data_query);
    final List<DataPoints[]> results = new ArrayList<DataPoints[]>(1);
    results.add(new DataPoints[] { new MockDataPoints().getMock() });
    final ChannelBuffer cb = serdes.formatQueryAsyncV1(data_query, results, Collections.<Annotation>emptyList()).joinUninterruptibly();
    assertNotNull(cb);
    final String json = cb.toString(Charset.forName("UTF-8"));
    assertTrue(json.contains("\"metric\":\"system.cpu.user\","));
    assertTrue(json.contains("\"1356998700\":1,"));
    assertTrue(json.contains("\"1357058700\":201"));
    //assert stats
    assertTrue(json.contains("\"stats\":{"));
    assertTrue(json.contains("\"emittedDPs\":401"));
    System.out.println(json);
    //assert stats summary
    assertTrue(json.contains("{\"statsSummary\":{"));
    assertTrue(json.contains("\"serializationTime\":"));
    assertTrue(json.contains("\"processingPreWriteTime\":"));
    assertTrue(json.contains("\"queryIdx_00\":"));
}
Also used : TSQuery(net.opentsdb.core.TSQuery) MockDataPoints(net.opentsdb.storage.MockDataPoints) ArrayList(java.util.ArrayList) DataPoints(net.opentsdb.core.DataPoints) MockDataPoints(net.opentsdb.storage.MockDataPoints) Matchers.anyString(org.mockito.Matchers.anyString) Annotation(net.opentsdb.meta.Annotation) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

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