Fix some inconsistencies in the types deprecation code. (#36517)
* Make sure to test conversion for both typed and typeless HLRC requests. * Update a few more statements to deprecatedAndMaybeLog. * Make sure Rest*SearchTemplateActionTests extend RestActionTestCase.
This commit is contained in:
parent
7f612d5dd8
commit
33152f648f
|
@ -152,6 +152,10 @@ public class RequestConvertersTests extends ESTestCase {
|
|||
getAndExistsTest(RequestConverters::get, HttpGet.METHOD_NAME);
|
||||
}
|
||||
|
||||
public void testGetWithType() {
|
||||
getAndExistsWithTypeTest(RequestConverters::get, HttpGet.METHOD_NAME);
|
||||
}
|
||||
|
||||
public void testMultiGet() throws IOException {
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
MultiGetRequest multiGetRequest = new MultiGetRequest();
|
||||
|
@ -175,7 +179,7 @@ public class RequestConvertersTests extends ESTestCase {
|
|||
|
||||
int numberOfRequests = randomIntBetween(0, 32);
|
||||
for (int i = 0; i < numberOfRequests; i++) {
|
||||
MultiGetRequest.Item item = new MultiGetRequest.Item(randomAlphaOfLength(4), randomAlphaOfLength(4), randomAlphaOfLength(4));
|
||||
MultiGetRequest.Item item = new MultiGetRequest.Item(randomAlphaOfLength(4), randomAlphaOfLength(4));
|
||||
if (randomBoolean()) {
|
||||
item.routing(randomAlphaOfLength(4));
|
||||
}
|
||||
|
@ -201,11 +205,23 @@ public class RequestConvertersTests extends ESTestCase {
|
|||
assertToXContentBody(multiGetRequest, request.getEntity());
|
||||
}
|
||||
|
||||
public void testMultiGetWithType() throws IOException {
|
||||
MultiGetRequest multiGetRequest = new MultiGetRequest();
|
||||
MultiGetRequest.Item item = new MultiGetRequest.Item(randomAlphaOfLength(4),
|
||||
randomAlphaOfLength(4),
|
||||
randomAlphaOfLength(4));
|
||||
multiGetRequest.add(item);
|
||||
|
||||
Request request = RequestConverters.multiGet(multiGetRequest);
|
||||
assertEquals(HttpPost.METHOD_NAME, request.getMethod());
|
||||
assertEquals("/_mget", request.getEndpoint());
|
||||
assertToXContentBody(multiGetRequest, request.getEntity());
|
||||
}
|
||||
|
||||
public void testDelete() {
|
||||
String index = randomAlphaOfLengthBetween(3, 10);
|
||||
String type = randomAlphaOfLengthBetween(3, 10);
|
||||
String id = randomAlphaOfLengthBetween(3, 10);
|
||||
DeleteRequest deleteRequest = new DeleteRequest(index, type, id);
|
||||
DeleteRequest deleteRequest = new DeleteRequest(index, id);
|
||||
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
|
||||
|
@ -223,9 +239,21 @@ public class RequestConvertersTests extends ESTestCase {
|
|||
}
|
||||
|
||||
Request request = RequestConverters.delete(deleteRequest);
|
||||
assertEquals("/" + index + "/" + type + "/" + id, request.getEndpoint());
|
||||
assertEquals(expectedParams, request.getParameters());
|
||||
assertEquals(HttpDelete.METHOD_NAME, request.getMethod());
|
||||
assertEquals("/" + index + "/_doc/" + id, request.getEndpoint());
|
||||
assertEquals(expectedParams, request.getParameters());
|
||||
assertNull(request.getEntity());
|
||||
}
|
||||
|
||||
public void testDeleteWithType() {
|
||||
String index = randomAlphaOfLengthBetween(3, 10);
|
||||
String type = randomAlphaOfLengthBetween(3, 10);
|
||||
String id = randomAlphaOfLengthBetween(3, 10);
|
||||
DeleteRequest deleteRequest = new DeleteRequest(index, type, id);
|
||||
|
||||
Request request = RequestConverters.delete(deleteRequest);
|
||||
assertEquals(HttpDelete.METHOD_NAME, request.getMethod());
|
||||
assertEquals("/" + index + "/" + type + "/" + id, request.getEndpoint());
|
||||
assertNull(request.getEntity());
|
||||
}
|
||||
|
||||
|
@ -233,11 +261,14 @@ public class RequestConvertersTests extends ESTestCase {
|
|||
getAndExistsTest(RequestConverters::exists, HttpHead.METHOD_NAME);
|
||||
}
|
||||
|
||||
public void testExistsWithType() {
|
||||
getAndExistsWithTypeTest(RequestConverters::exists, HttpHead.METHOD_NAME);
|
||||
}
|
||||
|
||||
private static void getAndExistsTest(Function<GetRequest, Request> requestConverter, String method) {
|
||||
String index = randomAlphaOfLengthBetween(3, 10);
|
||||
String type = randomAlphaOfLengthBetween(3, 10);
|
||||
String id = randomAlphaOfLengthBetween(3, 10);
|
||||
GetRequest getRequest = new GetRequest(index, type, id);
|
||||
GetRequest getRequest = new GetRequest(index, id);
|
||||
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
if (randomBoolean()) {
|
||||
|
@ -285,12 +316,24 @@ public class RequestConvertersTests extends ESTestCase {
|
|||
}
|
||||
}
|
||||
Request request = requestConverter.apply(getRequest);
|
||||
assertEquals("/" + index + "/" + type + "/" + id, request.getEndpoint());
|
||||
assertEquals("/" + index + "/_doc/" + id, request.getEndpoint());
|
||||
assertEquals(expectedParams, request.getParameters());
|
||||
assertNull(request.getEntity());
|
||||
assertEquals(method, request.getMethod());
|
||||
}
|
||||
|
||||
private static void getAndExistsWithTypeTest(Function<GetRequest, Request> requestConverter, String method) {
|
||||
String index = randomAlphaOfLengthBetween(3, 10);
|
||||
String type = randomAlphaOfLengthBetween(3, 10);
|
||||
String id = randomAlphaOfLengthBetween(3, 10);
|
||||
GetRequest getRequest = new GetRequest(index, type, id);
|
||||
|
||||
Request request = requestConverter.apply(getRequest);
|
||||
assertEquals("/" + index + "/" + type + "/" + id, request.getEndpoint());
|
||||
assertNull(request.getEntity());
|
||||
assertEquals(method, request.getMethod());
|
||||
}
|
||||
|
||||
public void testReindex() throws IOException {
|
||||
ReindexRequest reindexRequest = new ReindexRequest();
|
||||
reindexRequest.setSourceIndices("source_idx");
|
||||
|
@ -1335,7 +1378,26 @@ public class RequestConvertersTests extends ESTestCase {
|
|||
int numberOfRequests = randomIntBetween(0, 5);
|
||||
for (int i = 0; i < numberOfRequests; i++) {
|
||||
String index = randomAlphaOfLengthBetween(3, 10);
|
||||
String type = randomBoolean() ? null : randomAlphaOfLengthBetween(3, 10);
|
||||
String id = randomAlphaOfLengthBetween(3, 10);
|
||||
TermVectorsRequest tvRequest = new TermVectorsRequest(index, id);
|
||||
String[] fields = generateRandomStringArray(10, 5, false, false);
|
||||
tvRequest.setFields(fields);
|
||||
mtvRequest.add(tvRequest);
|
||||
}
|
||||
|
||||
Request request = RequestConverters.mtermVectors(mtvRequest);
|
||||
assertEquals(HttpGet.METHOD_NAME, request.getMethod());
|
||||
assertEquals("_mtermvectors", request.getEndpoint());
|
||||
assertToXContentBody(mtvRequest, request.getEntity());
|
||||
}
|
||||
|
||||
public void testMultiTermVectorsWithType() throws IOException {
|
||||
MultiTermVectorsRequest mtvRequest = new MultiTermVectorsRequest();
|
||||
|
||||
int numberOfRequests = randomIntBetween(0, 5);
|
||||
for (int i = 0; i < numberOfRequests; i++) {
|
||||
String index = randomAlphaOfLengthBetween(3, 10);
|
||||
String type = randomAlphaOfLengthBetween(3, 10);
|
||||
String id = randomAlphaOfLengthBetween(3, 10);
|
||||
TermVectorsRequest tvRequest = new TermVectorsRequest(index, type, id);
|
||||
String[] fields = generateRandomStringArray(10, 5, false, false);
|
||||
|
|
|
@ -18,35 +18,21 @@
|
|||
*/
|
||||
package org.elasticsearch.script.mustache;
|
||||
|
||||
import org.elasticsearch.client.node.NodeClient;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.rest.FakeRestChannel;
|
||||
import org.elasticsearch.test.rest.FakeRestRequest;
|
||||
import org.elasticsearch.usage.UsageService;
|
||||
import org.elasticsearch.test.rest.RestActionTestCase;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
public class RestMultiSearchTemplateActionTests extends RestActionTestCase {
|
||||
|
||||
public class RestMultiSearchTemplateActionTests extends ESTestCase {
|
||||
private RestController controller;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
controller = new RestController(Collections.emptySet(), null,
|
||||
mock(NodeClient.class),
|
||||
new NoneCircuitBreakerService(),
|
||||
new UsageService());
|
||||
new RestMultiSearchTemplateAction(Settings.EMPTY, controller);
|
||||
@Before
|
||||
public void setUpAction() {
|
||||
new RestMultiSearchTemplateAction(Settings.EMPTY, controller());
|
||||
}
|
||||
|
||||
public void testTypeInPath() {
|
||||
|
@ -60,7 +46,7 @@ public class RestMultiSearchTemplateActionTests extends ESTestCase {
|
|||
.withContent(bytesContent, XContentType.JSON)
|
||||
.build();
|
||||
|
||||
performRequest(request);
|
||||
dispatchRequest(request);
|
||||
assertWarnings(RestMultiSearchTemplateAction.TYPES_DEPRECATION_MESSAGE);
|
||||
}
|
||||
|
||||
|
@ -74,13 +60,7 @@ public class RestMultiSearchTemplateActionTests extends ESTestCase {
|
|||
.withContent(bytesContent, XContentType.JSON)
|
||||
.build();
|
||||
|
||||
performRequest(request);
|
||||
dispatchRequest(request);
|
||||
assertWarnings(RestMultiSearchTemplateAction.TYPES_DEPRECATION_MESSAGE);
|
||||
}
|
||||
|
||||
private void performRequest(RestRequest request) {
|
||||
RestChannel channel = new FakeRestChannel(request, false, 1);
|
||||
ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
|
||||
controller.dispatchRequest(request, channel, threadContext);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,35 +18,21 @@
|
|||
*/
|
||||
package org.elasticsearch.script.mustache;
|
||||
|
||||
import org.elasticsearch.client.node.NodeClient;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.action.search.RestSearchAction;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.rest.FakeRestChannel;
|
||||
import org.elasticsearch.test.rest.FakeRestRequest;
|
||||
import org.elasticsearch.usage.UsageService;
|
||||
import org.elasticsearch.test.rest.RestActionTestCase;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
public class RestSearchTemplateActionTests extends RestActionTestCase {
|
||||
|
||||
public class RestSearchTemplateActionTests extends ESTestCase {
|
||||
private RestController controller;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
controller = new RestController(Collections.emptySet(), null,
|
||||
mock(NodeClient.class),
|
||||
new NoneCircuitBreakerService(),
|
||||
new UsageService());
|
||||
new RestSearchTemplateAction(Settings.EMPTY, controller);
|
||||
@Before
|
||||
public void setUpAction() {
|
||||
new RestSearchTemplateAction(Settings.EMPTY, controller());
|
||||
}
|
||||
|
||||
public void testTypeInPath() {
|
||||
|
@ -55,7 +41,7 @@ public class RestSearchTemplateActionTests extends ESTestCase {
|
|||
.withPath("/some_index/some_type/_search/template")
|
||||
.build();
|
||||
|
||||
performRequest(request);
|
||||
dispatchRequest(request);
|
||||
assertWarnings(RestSearchAction.TYPES_DEPRECATION_MESSAGE);
|
||||
}
|
||||
|
||||
|
@ -69,13 +55,7 @@ public class RestSearchTemplateActionTests extends ESTestCase {
|
|||
.withParams(params)
|
||||
.build();
|
||||
|
||||
performRequest(request);
|
||||
dispatchRequest(request);
|
||||
assertWarnings(RestSearchAction.TYPES_DEPRECATION_MESSAGE);
|
||||
}
|
||||
|
||||
private void performRequest(RestRequest request) {
|
||||
RestChannel channel = new FakeRestChannel(request, false, 1);
|
||||
ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
|
||||
controller.dispatchRequest(request, channel, threadContext);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class RestGetAction extends BaseRestHandler {
|
|||
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
|
||||
String type = request.param("type");
|
||||
if (!type.equals(MapperService.SINGLE_MAPPING_NAME)) {
|
||||
deprecationLogger.deprecated(TYPES_DEPRECATION_MESSAGE);
|
||||
deprecationLogger.deprecatedAndMaybeLog("get_with_types", TYPES_DEPRECATION_MESSAGE);
|
||||
}
|
||||
|
||||
final GetRequest getRequest = new GetRequest(request.param("index"), type, request.param("id"));
|
||||
|
|
|
@ -65,7 +65,7 @@ public class RestMultiGetAction extends BaseRestHandler {
|
|||
@Override
|
||||
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
|
||||
if (request.param("type") != null) {
|
||||
deprecationLogger.deprecated(TYPES_DEPRECATION_MESSAGE);
|
||||
deprecationLogger.deprecatedAndMaybeLog("mget_with_types", TYPES_DEPRECATION_MESSAGE);
|
||||
}
|
||||
|
||||
MultiGetRequest multiGetRequest = new MultiGetRequest();
|
||||
|
|
|
@ -64,7 +64,7 @@ public class RestExplainAction extends BaseRestHandler {
|
|||
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
|
||||
ExplainRequest explainRequest;
|
||||
if (request.hasParam("type")) {
|
||||
deprecationLogger.deprecated(TYPES_DEPRECATION_MESSAGE);
|
||||
deprecationLogger.deprecatedAndMaybeLog("explain_with_types", TYPES_DEPRECATION_MESSAGE);
|
||||
explainRequest = new ExplainRequest(request.param("index"),
|
||||
request.param("type"),
|
||||
request.param("id"));
|
||||
|
|
Loading…
Reference in New Issue