From 4ef430d1e19bbe37a1b57e820f1878eb9c0f3517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Fri, 20 Feb 2015 20:26:59 +0100 Subject: [PATCH] [Test] Add `date_histogram` test for time zone corner case Add test case for time zone issue reported in #8209, already fixed on master by previous changes in TimeZoneRounding classes. --- .../bucket/DateHistogramTests.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramTests.java b/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramTests.java index 9cf446d4c53..cabb878dc73 100644 --- a/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramTests.java +++ b/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramTests.java @@ -35,7 +35,6 @@ import org.hamcrest.Matchers; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.format.DateTimeFormat; -import org.joda.time.tz.DateTimeZoneBuilder; import org.junit.After; import org.junit.Test; @@ -1283,6 +1282,30 @@ public class DateHistogramTests extends ElasticsearchIntegrationTest { assertThat(histo.getBuckets().get(0).getKeyAsString(), equalTo("2014-01-01T00:00:00.000+02:00")); } + public void testIssue8209() throws InterruptedException, ExecutionException { + assertAcked(client().admin().indices().prepareCreate("test8209").addMapping("type", "d", "type=date").get()); + indexRandom(true, + client().prepareIndex("test8209", "type").setSource("d", "2014-01-01T0:00:00Z"), + client().prepareIndex("test8209", "type").setSource("d", "2014-04-01T0:00:00Z"), + client().prepareIndex("test8209", "type").setSource("d", "2014-04-30T0:00:00Z")); + ensureSearchable("test8209"); + SearchResponse response = client().prepareSearch("test8209") + .addAggregation(dateHistogram("histo").field("d").interval(DateHistogramInterval.MONTH).timeZone("CET") + .minDocCount(0)) + .execute().actionGet(); + assertSearchResponse(response); + Histogram histo = response.getAggregations().get("histo"); + assertThat(histo.getBuckets().size(), equalTo(4)); + assertThat(histo.getBuckets().get(0).getKeyAsString(), equalTo("2014-01-01T00:00:00.000+01:00")); + assertThat(histo.getBuckets().get(0).getDocCount(), equalTo(1L)); + assertThat(histo.getBuckets().get(1).getKeyAsString(), equalTo("2014-02-01T00:00:00.000+01:00")); + assertThat(histo.getBuckets().get(1).getDocCount(), equalTo(0L)); + assertThat(histo.getBuckets().get(2).getKeyAsString(), equalTo("2014-03-01T00:00:00.000+01:00")); + assertThat(histo.getBuckets().get(2).getDocCount(), equalTo(0L)); + assertThat(histo.getBuckets().get(3).getKeyAsString(), equalTo("2014-04-01T00:00:00.000+02:00")); + assertThat(histo.getBuckets().get(3).getDocCount(), equalTo(2L)); + } + /** * see issue #9634, negative interval in date_histogram should raise exception */