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();
}
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);
}
});
}
Aggregations