Search in sources :

Example 6 with TSQuery

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

the class TestQueryStats method getStat.

@Test
public void getStat() throws Exception {
    final TSQuery query = new TSQuery();
    query.setStart("1h-ago");
    final QueryStats stats = new QueryStats(remote, query, headers);
    stats.addStat(QueryStat.AGGREGATED_SIZE, 42);
    stats.markSerializationSuccessful();
    assertEquals(42, stats.getStat(QueryStat.AGGREGATED_SIZE));
    assertEquals(-1, stats.getStat(QueryStat.BYTES_FROM_STORAGE));
}
Also used : TSQuery(net.opentsdb.core.TSQuery) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with TSQuery

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

the class TestHttpJsonSerializer method getTestQuery.

/** @return Returns a test TSQuery object to pass on to the serializer */
private TSQuery getTestQuery(final boolean show_stats, final boolean show_summary) {
    final TSQuery data_query = new TSQuery();
    data_query.setStart("1356998400");
    data_query.setEnd("1388534400");
    data_query.setShowStats(show_stats);
    data_query.setShowSummary(show_summary);
    final TSSubQuery sub_query = new TSSubQuery();
    sub_query.setMetric("sys.cpu.user");
    sub_query.setAggregator("sum");
    final ArrayList<TSSubQuery> sub_queries = new ArrayList<TSSubQuery>(1);
    sub_queries.add(sub_query);
    data_query.setQueries(sub_queries);
    return data_query;
}
Also used : TSQuery(net.opentsdb.core.TSQuery) ArrayList(java.util.ArrayList) TSSubQuery(net.opentsdb.core.TSSubQuery)

Example 8 with TSQuery

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

the class TestHttpJsonSerializer method formatQueryAsyncV1NoSuchMetricId.

@Test(expected = DeferredGroupException.class)
public void formatQueryAsyncV1NoSuchMetricId() 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.metricNameAsync()).thenReturn(Deferred.<String>fromError(new NoSuchUniqueId("No such metric", 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) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with TSQuery

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

the class TestHttpJsonSerializer method formatQueryAsyncV1wQuery.

@Test
public void formatQueryAsyncV1wQuery() throws Exception {
    setupFormatQuery();
    HttpQuery query = NettyMocks.getQuery(tsdb, "");
    HttpJsonSerializer serdes = new HttpJsonSerializer(query);
    final TSQuery data_query = getTestQuery(false);
    data_query.setShowQuery(true);
    validateTestQuery(data_query);
    final List<DataPoints[]> results = new ArrayList<DataPoints[]>(1);
    results.add(new DataPoints[] { new MockDataPoints().getMock() });
    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"));
    assertFalse(json.contains("\"timeTotal\""));
    assertTrue(json.contains("\"tsuid\":\"000001000001000001\""));
    assertTrue(json.contains("\"query\":"));
}
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 10 with TSQuery

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

the class TestQueryRpc method parseQueryMTypeWGroupByWildcardExplicit.

@Test
public void parseQueryMTypeWGroupByWildcardExplicit() throws Exception {
    HttpQuery query = NettyMocks.getQuery(tsdb, "/api/query?start=1h-ago&m=sum:sys.cpu.0{host=" + TagVWildcardFilter.FILTER_NAME + "(*quirm)}");
    TSQuery tsq = (TSQuery) parseQuery.invoke(rpc, tsdb, query, expressions);
    TSSubQuery sub = tsq.getQueries().get(0);
    sub.validateAndSetQuery();
    assertEquals(1, sub.getFilters().size());
    assertTrue(sub.getFilters().get(0) instanceof TagVWildcardFilter);
}
Also used : TSQuery(net.opentsdb.core.TSQuery) TagVWildcardFilter(net.opentsdb.query.filter.TagVWildcardFilter) TSSubQuery(net.opentsdb.core.TSSubQuery) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

TSQuery (net.opentsdb.core.TSQuery)63 Test (org.junit.Test)57 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)57 TSSubQuery (net.opentsdb.core.TSSubQuery)30 ArrayList (java.util.ArrayList)18 DataPoints (net.opentsdb.core.DataPoints)17 Annotation (net.opentsdb.meta.Annotation)15 MockDataPoints (net.opentsdb.storage.MockDataPoints)13 Matchers.anyString (org.mockito.Matchers.anyString)10 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)9 TagVWildcardFilter (net.opentsdb.query.filter.TagVWildcardFilter)7 Query (net.opentsdb.core.Query)4 Callback (com.stumbleupon.async.Callback)3 IOException (java.io.IOException)3 NoSuchUniqueId (net.opentsdb.uid.NoSuchUniqueId)3 Deferred (com.stumbleupon.async.Deferred)2 List (java.util.List)2 DataPoint (net.opentsdb.core.DataPoint)2 QueryException (net.opentsdb.core.QueryException)2 TagVLiteralOrFilter (net.opentsdb.query.filter.TagVLiteralOrFilter)2