|
@@ -26,19 +26,28 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.common.xcontent.XContentParser;
|
|
|
import org.elasticsearch.common.xcontent.XContentType;
|
|
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
|
|
-import org.elasticsearch.rest.RestController;
|
|
|
-import org.elasticsearch.test.ESTestCase;
|
|
|
+import org.elasticsearch.rest.RestRequest.Method;
|
|
|
import org.elasticsearch.test.rest.FakeRestRequest;
|
|
|
+import org.elasticsearch.test.rest.RestActionTestCase;
|
|
|
+import org.junit.Before;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import static java.util.Collections.singletonMap;
|
|
|
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
|
|
|
-import static org.mockito.Mockito.mock;
|
|
|
|
|
|
-public class RestReindexActionTests extends ESTestCase {
|
|
|
+public class RestReindexActionTests extends RestActionTestCase {
|
|
|
+
|
|
|
+ private RestReindexAction action;
|
|
|
+
|
|
|
+ @Before
|
|
|
+ public void setUpAction() {
|
|
|
+ action = new RestReindexAction(Settings.EMPTY, controller());
|
|
|
+ }
|
|
|
+
|
|
|
public void testBuildRemoteInfoNoRemote() throws IOException {
|
|
|
assertNull(RestReindexAction.buildRemoteInfo(new HashMap<>()));
|
|
|
}
|
|
@@ -160,8 +169,6 @@ public class RestReindexActionTests extends ESTestCase {
|
|
|
}
|
|
|
|
|
|
public void testPipelineQueryParameterIsError() throws IOException {
|
|
|
- RestReindexAction action = new RestReindexAction(Settings.EMPTY, mock(RestController.class));
|
|
|
-
|
|
|
FakeRestRequest.Builder request = new FakeRestRequest.Builder(xContentRegistry());
|
|
|
try (XContentBuilder body = JsonXContent.contentBuilder().prettyPrint()) {
|
|
|
body.startObject(); {
|
|
@@ -185,14 +192,12 @@ public class RestReindexActionTests extends ESTestCase {
|
|
|
|
|
|
public void testSetScrollTimeout() throws IOException {
|
|
|
{
|
|
|
- RestReindexAction action = new RestReindexAction(Settings.EMPTY, mock(RestController.class));
|
|
|
FakeRestRequest.Builder requestBuilder = new FakeRestRequest.Builder(xContentRegistry());
|
|
|
requestBuilder.withContent(new BytesArray("{}"), XContentType.JSON);
|
|
|
ReindexRequest request = action.buildRequest(requestBuilder.build());
|
|
|
assertEquals(AbstractBulkByScrollRequest.DEFAULT_SCROLL_TIMEOUT, request.getScrollTime());
|
|
|
}
|
|
|
{
|
|
|
- RestReindexAction action = new RestReindexAction(Settings.EMPTY, mock(RestController.class));
|
|
|
FakeRestRequest.Builder requestBuilder = new FakeRestRequest.Builder(xContentRegistry());
|
|
|
requestBuilder.withParams(singletonMap("scroll", "10m"));
|
|
|
requestBuilder.withContent(new BytesArray("{}"), XContentType.JSON);
|
|
@@ -210,4 +215,46 @@ public class RestReindexActionTests extends ESTestCase {
|
|
|
|
|
|
return RestReindexAction.buildRemoteInfo(source);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * test deprecation is logged if one or more types are used in source search request inside reindex
|
|
|
+ */
|
|
|
+ public void testTypeInSource() throws IOException {
|
|
|
+ FakeRestRequest.Builder requestBuilder = new FakeRestRequest.Builder(xContentRegistry())
|
|
|
+ .withMethod(Method.POST)
|
|
|
+ .withPath("/_reindex");
|
|
|
+ XContentBuilder b = JsonXContent.contentBuilder().startObject();
|
|
|
+ {
|
|
|
+ b.startObject("source");
|
|
|
+ {
|
|
|
+ b.field("type", randomFrom(Arrays.asList("\"t1\"", "[\"t1\", \"t2\"]", "\"_doc\"")));
|
|
|
+ }
|
|
|
+ b.endObject();
|
|
|
+ }
|
|
|
+ b.endObject();
|
|
|
+ requestBuilder.withContent(new BytesArray(BytesReference.bytes(b).toBytesRef()), XContentType.JSON);
|
|
|
+ dispatchRequest(requestBuilder.build());
|
|
|
+ assertWarnings(RestReindexAction.TYPES_DEPRECATION_MESSAGE);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * test deprecation is logged if a type is used in the destination index request inside reindex
|
|
|
+ */
|
|
|
+ public void testTypeInDestination() throws IOException {
|
|
|
+ FakeRestRequest.Builder requestBuilder = new FakeRestRequest.Builder(xContentRegistry())
|
|
|
+ .withMethod(Method.POST)
|
|
|
+ .withPath("/_reindex");
|
|
|
+ XContentBuilder b = JsonXContent.contentBuilder().startObject();
|
|
|
+ {
|
|
|
+ b.startObject("dest");
|
|
|
+ {
|
|
|
+ b.field("type", (randomBoolean() ? "_doc" : randomAlphaOfLength(4)));
|
|
|
+ }
|
|
|
+ b.endObject();
|
|
|
+ }
|
|
|
+ b.endObject();
|
|
|
+ requestBuilder.withContent(new BytesArray(BytesReference.bytes(b).toBytesRef()), XContentType.JSON);
|
|
|
+ dispatchRequest(requestBuilder.build());
|
|
|
+ assertWarnings(RestReindexAction.TYPES_DEPRECATION_MESSAGE);
|
|
|
+ }
|
|
|
}
|