[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.
This commit is contained in:
parent
2753db4685
commit
4ef430d1e1
|
@ -35,7 +35,6 @@ import org.hamcrest.Matchers;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
import org.joda.time.format.DateTimeFormat;
|
import org.joda.time.format.DateTimeFormat;
|
||||||
import org.joda.time.tz.DateTimeZoneBuilder;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Test;
|
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"));
|
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
|
* see issue #9634, negative interval in date_histogram should raise exception
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue