HistogramAction extends Action<HistogramRequest> { @Override public ActionResponse execute(HistogramRequest parameter) { SearchRequestBuilder searchRequestBuilder = getRequestBuilder(parameter); try { SearchResponse response = searchRequestBuilder.execute() .actionGet(getGetQueryTimeout()); return getResponse(response, parameter); } catch (ElasticsearchException e) { throw FoxtrotExceptions.createQueryExecutionException(parameter, e); } } HistogramAction(HistogramRequest parameter, AnalyticsLoader analyticsLoader); @Override String getMetricKey(); @Override void preprocess(); @Override String getRequestCacheKey(); @Override void validateImpl(HistogramRequest parameter); @Override ActionResponse execute(HistogramRequest parameter); @Override SearchRequestBuilder getRequestBuilder(HistogramRequest parameter); @Override ActionResponse getResponse(org.elasticsearch.action.ActionResponse response, HistogramRequest parameter);  }
@Test public void testHistogramActionIntervalMinuteNoFilter() throws FoxtrotException, JsonProcessingException { HistogramRequest histogramRequest = new HistogramRequest(); histogramRequest.setTable(TestUtils.TEST_TABLE_NAME); histogramRequest.setPeriod(Period.minutes); LessThanFilter lessThanFilter = new LessThanFilter(); lessThanFilter.setTemporal(true); lessThanFilter.setField("_timestamp"); lessThanFilter.setValue(System.currentTimeMillis()); histogramRequest.setFilters(Lists.<Filter>newArrayList(lessThanFilter)); HistogramResponse response = HistogramResponse.class.cast(getQueryExecutor().execute(histogramRequest)); filterNonZeroCounts(response); List<HistogramResponse.Count> counts = new ArrayList<HistogramResponse.Count>(); counts.add(new HistogramResponse.Count(1397651100000L, 2)); counts.add(new HistogramResponse.Count(1397658060000L, 3)); counts.add(new HistogramResponse.Count(1397658180000L, 1)); counts.add(new HistogramResponse.Count(1397758200000L, 1)); counts.add(new HistogramResponse.Count(1397958060000L, 1)); counts.add(new HistogramResponse.Count(1398653100000L, 2)); counts.add(new HistogramResponse.Count(1398658200000L, 1)); assertTrue(response.getCounts() .equals(counts)); }
@Test public void testHistogramActionIntervalMinuteWithFilter() throws FoxtrotException, JsonProcessingException { HistogramRequest histogramRequest = new HistogramRequest(); histogramRequest.setTable(TestUtils.TEST_TABLE_NAME); histogramRequest.setPeriod(Period.minutes); GreaterThanFilter greaterThanFilter = new GreaterThanFilter(); greaterThanFilter.setField("battery"); greaterThanFilter.setValue(48); LessThanFilter lessThanFilter = new LessThanFilter(); lessThanFilter.setTemporal(true); lessThanFilter.setField("_timestamp"); lessThanFilter.setValue(System.currentTimeMillis()); histogramRequest.setFilters(Lists.<Filter>newArrayList(greaterThanFilter, lessThanFilter)); HistogramResponse response = HistogramResponse.class.cast(getQueryExecutor().execute(histogramRequest)); filterNonZeroCounts(response); List<HistogramResponse.Count> counts = new ArrayList<HistogramResponse.Count>(); counts.add(new HistogramResponse.Count(1397651100000L, 1)); counts.add(new HistogramResponse.Count(1397658060000L, 2)); counts.add(new HistogramResponse.Count(1397658180000L, 1)); counts.add(new HistogramResponse.Count(1397958060000L, 1)); counts.add(new HistogramResponse.Count(1398658200000L, 1)); assertEquals(response.getCounts(), counts); }
@Test public void testHistogramActionIntervalHourNoFilter() throws FoxtrotException, JsonProcessingException { HistogramRequest histogramRequest = new HistogramRequest(); histogramRequest.setTable(TestUtils.TEST_TABLE_NAME); histogramRequest.setPeriod(Period.hours); LessThanFilter lessThanFilter = new LessThanFilter(); lessThanFilter.setTemporal(true); lessThanFilter.setField("_timestamp"); lessThanFilter.setValue(System.currentTimeMillis()); histogramRequest.setFilters(Lists.<Filter>newArrayList(lessThanFilter)); HistogramResponse response = HistogramResponse.class.cast(getQueryExecutor().execute(histogramRequest)); filterNonZeroCounts(response); List<HistogramResponse.Count> counts = new ArrayList<HistogramResponse.Count>(); counts.add(new HistogramResponse.Count(1397647800000L, 2)); counts.add(new HistogramResponse.Count(1397655000000L, 4)); counts.add(new HistogramResponse.Count(1397755800000L, 1)); counts.add(new HistogramResponse.Count(1397957400000L, 1)); counts.add(new HistogramResponse.Count(1398652200000L, 2)); counts.add(new HistogramResponse.Count(1398655800000L, 1)); assertEquals(response.getCounts(), counts); }
@Test public void testHistogramActionIntervalHourWithFilter() throws FoxtrotException, JsonProcessingException { HistogramRequest histogramRequest = new HistogramRequest(); histogramRequest.setTable(TestUtils.TEST_TABLE_NAME); histogramRequest.setPeriod(Period.hours); GreaterThanFilter greaterThanFilter = new GreaterThanFilter(); greaterThanFilter.setField("battery"); greaterThanFilter.setValue(48); LessThanFilter lessThanFilter = new LessThanFilter(); lessThanFilter.setTemporal(true); lessThanFilter.setField("_timestamp"); lessThanFilter.setValue(System.currentTimeMillis()); histogramRequest.setFilters(Lists.<Filter>newArrayList(greaterThanFilter, lessThanFilter)); HistogramResponse response = HistogramResponse.class.cast(getQueryExecutor().execute(histogramRequest)); filterNonZeroCounts(response); List<HistogramResponse.Count> counts = new ArrayList<HistogramResponse.Count>(); counts.add(new HistogramResponse.Count(1397647800000L, 1)); counts.add(new HistogramResponse.Count(1397655000000L, 3)); counts.add(new HistogramResponse.Count(1397957400000L, 1)); counts.add(new HistogramResponse.Count(1398655800000L, 1)); assertTrue(response.getCounts() .equals(counts)); }
@Test public void testHistogramActionIntervalDayNoFilter() throws FoxtrotException, JsonProcessingException { HistogramRequest histogramRequest = new HistogramRequest(); histogramRequest.setTable(TestUtils.TEST_TABLE_NAME); histogramRequest.setPeriod(Period.days); LessThanFilter lessThanFilter = new LessThanFilter(); lessThanFilter.setTemporal(true); lessThanFilter.setField("_timestamp"); lessThanFilter.setValue(System.currentTimeMillis()); histogramRequest.setFilters(Lists.<Filter>newArrayList(lessThanFilter)); HistogramResponse response = HistogramResponse.class.cast(getQueryExecutor().execute(histogramRequest)); filterNonZeroCounts(response); List<HistogramResponse.Count> counts = new ArrayList<HistogramResponse.Count>(); counts.add(new HistogramResponse.Count(1397586600000L, 6)); counts.add(new HistogramResponse.Count(1397673000000L, 1)); counts.add(new HistogramResponse.Count(1397932200000L, 1)); counts.add(new HistogramResponse.Count(1398623400000L, 3)); assertEquals(response.getCounts(), counts); }
@Test public void testHistogramActionIntervalDayWithFilter() throws FoxtrotException, JsonProcessingException { HistogramRequest histogramRequest = new HistogramRequest(); histogramRequest.setTable(TestUtils.TEST_TABLE_NAME); histogramRequest.setPeriod(Period.days); GreaterThanFilter greaterThanFilter = new GreaterThanFilter(); greaterThanFilter.setField("battery"); greaterThanFilter.setValue(48); LessThanFilter lessThanFilter = new LessThanFilter(); lessThanFilter.setTemporal(true); lessThanFilter.setField("_timestamp"); lessThanFilter.setValue(System.currentTimeMillis()); histogramRequest.setFilters(Lists.<Filter>newArrayList(greaterThanFilter, lessThanFilter)); HistogramResponse response = HistogramResponse.class.cast(getQueryExecutor().execute(histogramRequest)); filterNonZeroCounts(response); List<HistogramResponse.Count> counts = new ArrayList<HistogramResponse.Count>(); counts.add(new HistogramResponse.Count(1397586600000L, 4)); counts.add(new HistogramResponse.Count(1397932200000L, 1)); counts.add(new HistogramResponse.Count(1398623400000L, 1)); assertTrue(response.getCounts() .equals(counts)); }