Search in sources :

Example 76 with Annotation

use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.

the class TestHttpJsonSerializer method formatQueryAsyncV1NoSuchAggTagId.

@Test(expected = DeferredGroupException.class)
public void formatQueryAsyncV1NoSuchAggTagId() 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.getAggregatedTagsAsync()).thenReturn(Deferred.<List<String>>fromError(new NoSuchUniqueId("No such tagk", 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 77 with Annotation

use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.

the class TestSearchRpc method setupAnswerSearchQuery.

/**
   * Configures an Answer to respond with when the tests call 
   * tsdb.executeSearch(), responding to the type of query requested with valid
   * responses for parsing tests.
   */
private void setupAnswerSearchQuery() {
    mock_plugin = mock(SearchPlugin.class);
    Whitebox.setInternalState(tsdb, "search", mock_plugin);
    when(mock_plugin.executeQuery((SearchQuery) any())).thenAnswer(new Answer<Deferred<SearchQuery>>() {

        @Override
        public Deferred<SearchQuery> answer(InvocationOnMock invocation) throws Throwable {
            final Object[] args = invocation.getArguments();
            search_query = (SearchQuery) args[0];
            List<Object> results = new ArrayList<Object>(1);
            // if we want an empty response, return an empty response
            if (search_query.getQuery().toUpperCase().equals("EMTPY")) {
                search_query.setResults(results);
                search_query.setTotalResults(0);
                return Deferred.fromResult(search_query);
            }
            switch(search_query.getType()) {
                case TSMETA:
                    final TSMeta meta = new TSMeta("000001000001000001");
                    meta.setCreated(1356998400);
                    meta.setDescription("System CPU metric");
                    UIDMeta uid = new UIDMeta(UniqueIdType.METRIC, "000001");
                    final Field uid_name = UIDMeta.class.getDeclaredField("name");
                    uid_name.setAccessible(true);
                    uid_name.set(uid, "sys.cpu.0");
                    final Field metric = TSMeta.class.getDeclaredField("metric");
                    metric.setAccessible(true);
                    metric.set(meta, uid);
                    final ArrayList<UIDMeta> tags = new ArrayList<UIDMeta>(2);
                    uid = new UIDMeta(UniqueIdType.TAGK, "000001");
                    uid_name.set(uid, "host");
                    tags.add(uid);
                    uid = new UIDMeta(UniqueIdType.TAGV, "000001");
                    uid_name.set(uid, "web01");
                    tags.add(uid);
                    final Field tags_field = TSMeta.class.getDeclaredField("tags");
                    tags_field.setAccessible(true);
                    tags_field.set(meta, tags);
                    results.add(meta);
                    break;
                case LOOKUP:
                case TSMETA_SUMMARY:
                    final HashMap<String, Object> ts = new HashMap<String, Object>(1);
                    ts.put("metric", "sys.cpu.0");
                    final HashMap<String, String> tag_map = new HashMap<String, String>(2);
                    tag_map.put("host", "web01");
                    tag_map.put("owner", "ops");
                    ts.put("tags", tag_map);
                    ts.put("tsuid", "000001000001000001");
                    results.add(ts);
                    break;
                case TSUIDS:
                    results.add("000001000001000001");
                    results.add("000002000002000002");
                    break;
                case UIDMETA:
                    UIDMeta uid2 = new UIDMeta(UniqueIdType.METRIC, "000001");
                    final Field name_field = UIDMeta.class.getDeclaredField("name");
                    name_field.setAccessible(true);
                    name_field.set(uid2, "sys.cpu.0");
                    results.add(uid2);
                    uid2 = new UIDMeta(UniqueIdType.TAGK, "000001");
                    name_field.set(uid2, "host");
                    results.add(uid2);
                    break;
                case ANNOTATION:
                    final Annotation note = new Annotation();
                    note.setStartTime(1356998400);
                    note.setEndTime(1356998460);
                    note.setDescription("Something went pear shaped");
                    note.setTSUID("000001000001000001");
                    results.add(note);
                    break;
            }
            search_query.setResults(results);
            search_query.setTotalResults(results.size());
            search_query.setTime(0.42F);
            return Deferred.fromResult(search_query);
        }
    });
}
Also used : SearchQuery(net.opentsdb.search.SearchQuery) HashMap(java.util.HashMap) Deferred(com.stumbleupon.async.Deferred) ArrayList(java.util.ArrayList) TSMeta(net.opentsdb.meta.TSMeta) Annotation(net.opentsdb.meta.Annotation) Field(java.lang.reflect.Field) SearchPlugin(net.opentsdb.search.SearchPlugin) UIDMeta(net.opentsdb.meta.UIDMeta) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Annotation (net.opentsdb.meta.Annotation)77 ArrayList (java.util.ArrayList)68 Test (org.junit.Test)63 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)63 KeyValue (org.hbase.async.KeyValue)50 DataPoints (net.opentsdb.core.DataPoints)18 TSQuery (net.opentsdb.core.TSQuery)15 MockDataPoints (net.opentsdb.storage.MockDataPoints)13 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)10 Matchers.anyString (org.mockito.Matchers.anyString)10 Deferred (com.stumbleupon.async.Deferred)5 IOException (java.io.IOException)5 Callback (com.stumbleupon.async.Callback)4 HashMap (java.util.HashMap)4 List (java.util.List)4 DataPoint (net.opentsdb.core.DataPoint)4 NoSuchUniqueId (net.opentsdb.uid.NoSuchUniqueId)3 Map (java.util.Map)2 IncomingDataPoint (net.opentsdb.core.IncomingDataPoint)2 Query (net.opentsdb.core.Query)2