|
6 | 6 |
|
7 | 7 | package org.elasticsearch.xpack.dataframe.integration; |
8 | 8 |
|
| 9 | +import org.apache.http.entity.ContentType; |
| 10 | +import org.apache.http.entity.StringEntity; |
9 | 11 | import org.elasticsearch.client.Request; |
| 12 | +import org.elasticsearch.client.dataframe.transforms.DataFrameTransformTaskState; |
| 13 | +import org.elasticsearch.common.Strings; |
| 14 | +import org.elasticsearch.common.xcontent.XContentBuilder; |
10 | 15 | import org.elasticsearch.common.xcontent.support.XContentMapValues; |
11 | 16 | import org.junit.Before; |
12 | 17 |
|
|
17 | 22 | import java.util.List; |
18 | 23 | import java.util.Map; |
19 | 24 | import java.util.Set; |
| 25 | +import java.util.concurrent.TimeUnit; |
20 | 26 |
|
| 27 | +import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; |
21 | 28 | import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue; |
22 | 29 | import static org.hamcrest.Matchers.containsString; |
23 | 30 | import static org.hamcrest.Matchers.equalTo; |
@@ -723,6 +730,44 @@ public void testPivotWithWeightedAvgAgg() throws Exception { |
723 | 730 | assertEquals(4.47169811, actual.doubleValue(), 0.000001); |
724 | 731 | } |
725 | 732 |
|
| 733 | + public void testBulkIndexFailuresCauseTaskToFail() throws Exception { |
| 734 | + String transformId = "bulk-failure-pivot"; |
| 735 | + String dataFrameIndex = "pivot-failure-index"; |
| 736 | + createPivotReviewsTransform(transformId, dataFrameIndex, null, null, null); |
| 737 | + |
| 738 | + try (XContentBuilder builder = jsonBuilder()) { |
| 739 | + builder.startObject(); |
| 740 | + { |
| 741 | + builder.startObject("mappings") |
| 742 | + .startObject("properties") |
| 743 | + .startObject("reviewer") |
| 744 | + // This type should cause mapping coercion type conflict on bulk index |
| 745 | + .field("type", "long") |
| 746 | + .endObject() |
| 747 | + .endObject() |
| 748 | + .endObject(); |
| 749 | + } |
| 750 | + builder.endObject(); |
| 751 | + final StringEntity entity = new StringEntity(Strings.toString(builder), ContentType.APPLICATION_JSON); |
| 752 | + Request req = new Request("PUT", dataFrameIndex); |
| 753 | + req.setEntity(entity); |
| 754 | + client().performRequest(req); |
| 755 | + } |
| 756 | + startDataframeTransform(transformId, false, null); |
| 757 | + |
| 758 | + assertBusy(() -> assertEquals(DataFrameTransformTaskState.FAILED.value(), getDataFrameTaskState(transformId)), |
| 759 | + 120, |
| 760 | + TimeUnit.SECONDS); |
| 761 | + |
| 762 | + Map<?, ?> state = getDataFrameState(transformId); |
| 763 | + assertThat((String) XContentMapValues.extractValue("state.reason", state), |
| 764 | + containsString("task encountered more than 10 failures; latest failure: Bulk index experienced failures.")); |
| 765 | + |
| 766 | + // Force stop the transform as bulk indexing caused it to go into a failed state |
| 767 | + stopDataFrameTransform(transformId, true); |
| 768 | + deleteIndex(dataFrameIndex); |
| 769 | + } |
| 770 | + |
726 | 771 | private void assertOnePivotValue(String query, double expected) throws IOException { |
727 | 772 | Map<String, Object> searchResult = getAsMap(query); |
728 | 773 |
|
|
0 commit comments