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.
()
| 360 | * responses for parsing tests. |
| 361 | */ |
| 362 | private void setupAnswerSearchQuery() { |
| 363 | mock_plugin = mock(SearchPlugin.class); |
| 364 | Whitebox.setInternalState(tsdb, "search", mock_plugin); |
| 365 | |
| 366 | when(mock_plugin.executeQuery((SearchQuery)any())).thenAnswer( |
| 367 | new Answer<Deferred<SearchQuery>>() { |
| 368 | |
| 369 | @Override |
| 370 | public Deferred<SearchQuery> answer(InvocationOnMock invocation) |
| 371 | throws Throwable { |
| 372 | final Object[] args = invocation.getArguments(); |
| 373 | search_query = (SearchQuery)args[0]; |
| 374 | |
| 375 | List<Object> results = new ArrayList<Object>(1); |
| 376 | |
| 377 | // if we want an empty response, return an empty response |
| 378 | if (search_query.getQuery().toUpperCase().equals("EMTPY")) { |
| 379 | search_query.setResults(results); |
| 380 | search_query.setTotalResults(0); |
| 381 | |
| 382 | return Deferred.fromResult(search_query); |
| 383 | } |
| 384 | |
| 385 | switch(search_query.getType()) { |
| 386 | case TSMETA: |
| 387 | final TSMeta meta = new TSMeta("000001000001000001"); |
| 388 | meta.setCreated(1356998400); |
| 389 | meta.setDescription("System CPU metric"); |
| 390 | |
| 391 | UIDMeta uid = new UIDMeta(UniqueIdType.METRIC, "000001"); |
| 392 | final Field uid_name = UIDMeta.class.getDeclaredField("name"); |
| 393 | uid_name.setAccessible(true); |
| 394 | uid_name.set(uid, "sys.cpu.0"); |
| 395 | |
| 396 | final Field metric = TSMeta.class.getDeclaredField("metric"); |
| 397 | metric.setAccessible(true); |
| 398 | metric.set(meta, uid); |
| 399 | |
| 400 | final ArrayList<UIDMeta> tags = new ArrayList<UIDMeta>(2); |
| 401 | uid = new UIDMeta(UniqueIdType.TAGK, "000001"); |
| 402 | uid_name.set(uid, "host"); |
| 403 | tags.add(uid); |
| 404 | uid = new UIDMeta(UniqueIdType.TAGV, "000001"); |
| 405 | uid_name.set(uid, "web01"); |
| 406 | tags.add(uid); |
| 407 | |
| 408 | final Field tags_field = TSMeta.class.getDeclaredField("tags"); |
| 409 | tags_field.setAccessible(true); |
| 410 | tags_field.set(meta, tags); |
| 411 | results.add(meta); |
| 412 | break; |
| 413 | |
| 414 | case LOOKUP: |
| 415 | case TSMETA_SUMMARY: |
| 416 | final HashMap<String, Object> ts = new HashMap<String, Object>(1); |
| 417 | ts.put("metric", "sys.cpu.0"); |
| 418 | final HashMap<String, String> tag_map = |
| 419 | new HashMap<String, String>(2); |
no test coverage detected