Skip to content

Commit 1ef349d

Browse files
committed
Add generic assertion to all aggs.bucket tests to check if all shards were successful
1 parent 36a76cc commit 1ef349d

14 files changed

+340
-167
lines changed

src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramTests.java

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
4141
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
4242
import static org.elasticsearch.search.aggregations.AggregationBuilders.*;
43+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
4344
import static org.hamcrest.Matchers.equalTo;
4445
import static org.hamcrest.Matchers.is;
4546
import static org.hamcrest.core.IsNull.notNullValue;
@@ -90,7 +91,8 @@ public void singleValuedField() throws Exception {
9091
.addAggregation(dateHistogram("histo").field("date").interval(DateHistogram.Interval.MONTH))
9192
.execute().actionGet();
9293

93-
assertThat(response.getFailedShards(), equalTo(0));
94+
assertSearchResponse(response);
95+
9496

9597
DateHistogram histo = response.getAggregations().get("histo");
9698
assertThat(histo, notNullValue());
@@ -125,7 +127,8 @@ public void singleValuedField_OrderedByKeyAsc() throws Exception {
125127
.order(DateHistogram.Order.KEY_ASC))
126128
.execute().actionGet();
127129

128-
assertThat(response.getFailedShards(), equalTo(0));
130+
assertSearchResponse(response);
131+
129132

130133
DateHistogram histo = response.getAggregations().get("histo");
131134
assertThat(histo, notNullValue());
@@ -148,7 +151,8 @@ public void singleValuedField_OrderedByKeyDesc() throws Exception {
148151
.order(DateHistogram.Order.KEY_DESC))
149152
.execute().actionGet();
150153

151-
assertThat(response.getFailedShards(), equalTo(0));
154+
assertSearchResponse(response);
155+
152156

153157
DateHistogram histo = response.getAggregations().get("histo");
154158
assertThat(histo, notNullValue());
@@ -171,7 +175,8 @@ public void singleValuedField_OrderedByCountAsc() throws Exception {
171175
.order(DateHistogram.Order.COUNT_ASC))
172176
.execute().actionGet();
173177

174-
assertThat(response.getFailedShards(), equalTo(0));
178+
assertSearchResponse(response);
179+
175180

176181
DateHistogram histo = response.getAggregations().get("histo");
177182
assertThat(histo, notNullValue());
@@ -194,7 +199,8 @@ public void singleValuedField_OrderedByCountDesc() throws Exception {
194199
.order(DateHistogram.Order.COUNT_DESC))
195200
.execute().actionGet();
196201

197-
assertThat(response.getFailedShards(), equalTo(0));
202+
assertSearchResponse(response);
203+
198204

199205
DateHistogram histo = response.getAggregations().get("histo");
200206
assertThat(histo, notNullValue());
@@ -215,7 +221,8 @@ public void singleValuedField_WithSubAggregation() throws Exception {
215221
.subAggregation(sum("sum").field("value")))
216222
.execute().actionGet();
217223

218-
assertThat(response.getFailedShards(), equalTo(0));
224+
assertSearchResponse(response);
225+
219226

220227
DateHistogram histo = response.getAggregations().get("histo");
221228
assertThat(histo, notNullValue());
@@ -257,7 +264,8 @@ public void singleValuedField_WithSubAggregation_Inherited() throws Exception {
257264
.subAggregation(max("max")))
258265
.execute().actionGet();
259266

260-
assertThat(response.getFailedShards(), equalTo(0));
267+
assertSearchResponse(response);
268+
261269

262270
DateHistogram histo = response.getAggregations().get("histo");
263271
assertThat(histo, notNullValue());
@@ -302,7 +310,8 @@ public void singleValuedField_OrderedBySubAggregationAsc() throws Exception {
302310
.subAggregation(max("sum").field("value")))
303311
.execute().actionGet();
304312

305-
assertThat(response.getFailedShards(), equalTo(0));
313+
assertSearchResponse(response);
314+
306315

307316
DateHistogram histo = response.getAggregations().get("histo");
308317
assertThat(histo, notNullValue());
@@ -326,7 +335,8 @@ public void singleValuedField_OrderedBySubAggregationDesc() throws Exception {
326335
.subAggregation(max("sum").field("value")))
327336
.execute().actionGet();
328337

329-
assertThat(response.getFailedShards(), equalTo(0));
338+
assertSearchResponse(response);
339+
330340

331341
DateHistogram histo = response.getAggregations().get("histo");
332342
assertThat(histo, notNullValue());
@@ -350,7 +360,8 @@ public void singleValuedField_OrderedByMultiValuedSubAggregationAsc_Inherited()
350360
.subAggregation(stats("stats").field("value")))
351361
.execute().actionGet();
352362

353-
assertThat(response.getFailedShards(), equalTo(0));
363+
assertSearchResponse(response);
364+
354365

355366
DateHistogram histo = response.getAggregations().get("histo");
356367
assertThat(histo, notNullValue());
@@ -374,7 +385,8 @@ public void singleValuedField_OrderedByMultiValuedSubAggregationDesc() throws Ex
374385
.subAggregation(stats("stats").field("value")))
375386
.execute().actionGet();
376387

377-
assertThat(response.getFailedShards(), equalTo(0));
388+
assertSearchResponse(response);
389+
378390

379391
DateHistogram histo = response.getAggregations().get("histo");
380392
assertThat(histo, notNullValue());
@@ -397,7 +409,8 @@ public void singleValuedField_WithValueScript() throws Exception {
397409
.interval(DateHistogram.Interval.MONTH))
398410
.execute().actionGet();
399411

400-
assertThat(response.getFailedShards(), equalTo(0));
412+
assertSearchResponse(response);
413+
401414

402415
DateHistogram histo = response.getAggregations().get("histo");
403416
assertThat(histo, notNullValue());
@@ -439,7 +452,8 @@ public void multiValuedField() throws Exception {
439452
.addAggregation(dateHistogram("histo").field("dates").interval(DateHistogram.Interval.MONTH))
440453
.execute().actionGet();
441454

442-
assertThat(response.getFailedShards(), equalTo(0));
455+
assertSearchResponse(response);
456+
443457

444458
DateHistogram histo = response.getAggregations().get("histo");
445459
assertThat(histo, notNullValue());
@@ -480,7 +494,8 @@ public void multiValuedField_OrderedByKeyDesc() throws Exception {
480494
.order(DateHistogram.Order.COUNT_DESC))
481495
.execute().actionGet();
482496

483-
assertThat(response.getFailedShards(), equalTo(0));
497+
assertSearchResponse(response);
498+
484499

485500
DateHistogram histo = response.getAggregations().get("histo");
486501
assertThat(histo, notNullValue());
@@ -524,7 +539,8 @@ public void multiValuedField_WithValueScript() throws Exception {
524539
.interval(DateHistogram.Interval.MONTH))
525540
.execute().actionGet();
526541

527-
assertThat(response.getFailedShards(), equalTo(0));
542+
assertSearchResponse(response);
543+
528544

529545
DateHistogram histo = response.getAggregations().get("histo");
530546
assertThat(histo, notNullValue());
@@ -577,7 +593,8 @@ public void multiValuedField_WithValueScript_WithInheritedSubAggregator() throws
577593
.subAggregation(max("max")))
578594
.execute().actionGet();
579595

580-
assertThat(response.getFailedShards(), equalTo(0));
596+
assertSearchResponse(response);
597+
581598

582599
DateHistogram histo = response.getAggregations().get("histo");
583600
assertThat(histo, notNullValue());
@@ -635,7 +652,8 @@ public void script_SingleValue() throws Exception {
635652
.addAggregation(dateHistogram("histo").script("doc['date'].value").interval(DateHistogram.Interval.MONTH))
636653
.execute().actionGet();
637654

638-
assertThat(response.getFailedShards(), equalTo(0));
655+
assertSearchResponse(response);
656+
639657

640658
DateHistogram histo = response.getAggregations().get("histo");
641659
assertThat(histo, notNullValue());
@@ -670,7 +688,8 @@ public void script_SingleValue_WithSubAggregator_Inherited() throws Exception {
670688
.subAggregation(max("max")))
671689
.execute().actionGet();
672690

673-
assertThat(response.getFailedShards(), equalTo(0));
691+
assertSearchResponse(response);
692+
674693

675694
DateHistogram histo = response.getAggregations().get("histo");
676695
assertThat(histo, notNullValue());
@@ -711,7 +730,8 @@ public void script_MultiValued() throws Exception {
711730
.addAggregation(dateHistogram("histo").script("doc['dates'].values").interval(DateHistogram.Interval.MONTH))
712731
.execute().actionGet();
713732

714-
assertThat(response.getFailedShards(), equalTo(0));
733+
assertSearchResponse(response);
734+
715735

716736
DateHistogram histo = response.getAggregations().get("histo");
717737
assertThat(histo, notNullValue());
@@ -761,7 +781,8 @@ public void script_MultiValued_WithAggregatorInherited() throws Exception {
761781
.subAggregation(max("max")))
762782
.execute().actionGet();
763783

764-
assertThat(response.getFailedShards(), equalTo(0));
784+
assertSearchResponse(response);
785+
765786

766787
DateHistogram histo = response.getAggregations().get("histo");
767788
assertThat(histo, notNullValue());
@@ -813,7 +834,8 @@ public void unmapped() throws Exception {
813834
.addAggregation(dateHistogram("histo").field("date").interval(DateHistogram.Interval.MONTH))
814835
.execute().actionGet();
815836

816-
assertThat(response.getFailedShards(), equalTo(0));
837+
assertSearchResponse(response);
838+
817839

818840
DateHistogram histo = response.getAggregations().get("histo");
819841
assertThat(histo, notNullValue());
@@ -829,7 +851,8 @@ public void partiallyUnmapped() throws Exception {
829851
.addAggregation(dateHistogram("histo").field("date").interval(DateHistogram.Interval.MONTH))
830852
.execute().actionGet();
831853

832-
assertThat(response.getFailedShards(), equalTo(0));
854+
assertSearchResponse(response);
855+
833856

834857
DateHistogram histo = response.getAggregations().get("histo");
835858
assertThat(histo, notNullValue());

0 commit comments

Comments
 (0)