From ab9c7ae677c4fcc4b1bdf21a21ade444bd32749a Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 31 Jan 2019 18:51:57 -0800 Subject: [PATCH] Reverting change to monitoring bulk endpoint code and tests --- .../monitoring/action/MonitoringBulkRequestTests.java | 7 ++++++- .../rest/action/RestMonitoringBulkActionTests.java | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkRequestTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkRequestTests.java index 1bfb72df99fb9..fc3bf633a3964 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkRequestTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/action/MonitoringBulkRequestTests.java @@ -94,6 +94,10 @@ public void testAddRequestContent() throws IOException { if (rarely()) { builder.field("_index", ""); } + if (defaultType == null || randomBoolean()) { + types[i] = randomAlphaOfLength(5); + builder.field("_type", types[i]); + } if (randomBoolean()) { ids[i] = randomAlphaOfLength(10); builder.field("_id", ids[i]); @@ -158,6 +162,7 @@ public void testAddRequestContentWithEmptySource() throws IOException { builder.startObject("index"); { builder.field("_index", ""); + builder.field("_type", "doc"); builder.field("_id", String.valueOf(i)); } builder.endObject(); @@ -203,6 +208,7 @@ public void testAddRequestContentWithUnrecognizedIndexName() throws IOException builder.startObject("index"); { builder.field("_index", indexName); + builder.field("_type", "doc"); } builder.endObject(); } @@ -226,7 +232,6 @@ public void testAddRequestContentWithUnrecognizedIndexName() throws IOException assertThat(e.getMessage(), containsString("unrecognized index name [" + indexName + "]")); //This test's JSON contains outdated references to types assertWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE); - } public void testSerialization() throws IOException { diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java index ff55c6ab90533..10fc10e3f973d 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java @@ -23,6 +23,7 @@ import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestBuilderListener; +import org.elasticsearch.rest.action.document.RestBulkAction; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; import org.elasticsearch.xpack.core.XPackClient; @@ -121,6 +122,8 @@ public void testNoErrors() throws Exception { assertThat(restResponse.status(), is(RestStatus.OK)); assertThat(restResponse.content().utf8ToString(), is("{\"took\":" + response.getTookInMillis() + ",\"ignored\":false,\"errors\":false}")); + //This test's JSON contains outdated references to types + assertWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE); } public void testNoErrorsButIgnored() throws Exception { @@ -131,6 +134,8 @@ public void testNoErrorsButIgnored() throws Exception { assertThat(restResponse.status(), is(RestStatus.OK)); assertThat(restResponse.content().utf8ToString(), is("{\"took\":" + response.getTookInMillis() + ",\"ignored\":true,\"errors\":false}")); + //This test's JSON contains outdated references to types + assertWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE); } public void testWithErrors() throws Exception { @@ -150,6 +155,8 @@ public void testWithErrors() throws Exception { assertThat(restResponse.status(), is(RestStatus.INTERNAL_SERVER_ERROR)); assertThat(restResponse.content().utf8ToString(), is("{\"took\":" + response.getTookInMillis() + ",\"ignored\":false,\"errors\":true,\"error\":" + errorJson + "}")); + //This test's JSON contains outdated references to types + assertWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE); } /** @@ -210,7 +217,7 @@ private static FakeRestRequest createRestRequest(final int nbDocs, if (nbDocs > 0) { final StringBuilder requestBody = new StringBuilder(); for (int n = 0; n < nbDocs; n++) { - requestBody.append("{\"index\":{}}\n"); + requestBody.append("{\"index\":{\"_type\":\"_doc\"}}\n"); requestBody.append("{\"field\":").append(n).append("}\n"); } requestBody.append("\n");