|
@@ -19,18 +19,31 @@
|
|
|
|
|
|
package org.elasticsearch.rest.action.document;
|
|
|
|
|
|
+import org.elasticsearch.action.ActionRequestValidationException;
|
|
|
+import org.elasticsearch.client.node.NodeClient;
|
|
|
+import org.elasticsearch.common.bytes.BytesArray;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
+import org.elasticsearch.common.xcontent.XContentType;
|
|
|
+import org.elasticsearch.index.VersionType;
|
|
|
import org.elasticsearch.rest.RestRequest;
|
|
|
import org.elasticsearch.rest.RestRequest.Method;
|
|
|
import org.elasticsearch.test.rest.FakeRestRequest;
|
|
|
import org.elasticsearch.test.rest.RestActionTestCase;
|
|
|
import org.junit.Before;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static org.hamcrest.CoreMatchers.containsString;
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
+
|
|
|
public class RestUpdateActionTests extends RestActionTestCase {
|
|
|
|
|
|
+ private RestUpdateAction action;
|
|
|
+
|
|
|
@Before
|
|
|
public void setUpAction() {
|
|
|
- new RestUpdateAction(Settings.EMPTY, controller());
|
|
|
+ action = new RestUpdateAction(Settings.EMPTY, controller());
|
|
|
}
|
|
|
|
|
|
public void testTypeInPath() {
|
|
@@ -47,4 +60,32 @@ public class RestUpdateActionTests extends RestActionTestCase {
|
|
|
.build();
|
|
|
dispatchRequest(validRequest);
|
|
|
}
|
|
|
+
|
|
|
+ public void testUpdateDocVersion() {
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
+ if (randomBoolean()) {
|
|
|
+ params.put("version", Long.toString(randomNonNegativeLong()));
|
|
|
+ params.put("version_type", randomFrom(VersionType.values()).name());
|
|
|
+ } else if (randomBoolean()) {
|
|
|
+ params.put("version", Long.toString(randomNonNegativeLong()));
|
|
|
+ } else {
|
|
|
+ params.put("version_type", randomFrom(VersionType.values()).name());
|
|
|
+ }
|
|
|
+ String content =
|
|
|
+ "{\n" +
|
|
|
+ " \"doc\" : {\n" +
|
|
|
+ " \"name\" : \"new_name\"\n" +
|
|
|
+ " }\n" +
|
|
|
+ "}";
|
|
|
+ FakeRestRequest updateRequest = new FakeRestRequest.Builder(xContentRegistry())
|
|
|
+ .withMethod(RestRequest.Method.POST)
|
|
|
+ .withPath("test/_update/1")
|
|
|
+ .withParams(params)
|
|
|
+ .withContent(new BytesArray(content), XContentType.JSON)
|
|
|
+ .build();
|
|
|
+ ActionRequestValidationException e = expectThrows(ActionRequestValidationException.class,
|
|
|
+ () -> action.prepareRequest(updateRequest, mock(NodeClient.class)));
|
|
|
+ assertThat(e.getMessage(), containsString("internal versioning can not be used for optimistic concurrency control. " +
|
|
|
+ "Please use `if_seq_no` and `if_primary_term` instead"));
|
|
|
+ }
|
|
|
}
|