Skip to content

Commit

Permalink
Strengthen testUpdate in rolling upgrade
Browse files Browse the repository at this point in the history
We hit a bug where we can't partially update documents created in a
mixed cluster between 5.x and 6.x. Although this bug does not affect
7.0 or later, we should have a good test that catches this issue.

Relates #46198
  • Loading branch information
dnhatn committed Sep 7, 2019
1 parent e8095fa commit 8fb6cbd
Showing 1 changed file with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.seqno.RetentionLeaseUtils;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.rest.action.document.RestGetAction;
import org.elasticsearch.rest.action.document.RestIndexAction;
import org.elasticsearch.rest.action.document.RestUpdateAction;
import org.elasticsearch.test.rest.yaml.ObjectPath;
Expand All @@ -43,6 +44,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -694,14 +696,32 @@ public void testUpdateDoc() throws Exception {
.put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1)
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 2);
createIndex(index, settings.build());
indexDocs(index, 0, 100);
}
ensureGreen(index);
indexDocs(index, 0, 10);
for (int i = 0; i < 10; i++) {
Request update = new Request("POST", index + "/test/" + i + "/_update/");
update.setOptions(expectWarnings(RestUpdateAction.TYPES_DEPRECATION_MESSAGE));
update.setJsonEntity("{\"doc\": {\"f\": " + randomNonNegativeLong() + "}}");
client().performRequest(update);
if (randomBoolean()) {
ensureGreen(index);
}
Map<Integer, Long> updates = new HashMap<>();
for (int docId = 0; docId < 100; docId++) {
final int times = randomIntBetween(0, 2);
for (int i = 0; i < times; i++) {
long value = randomNonNegativeLong();
Request update = new Request("POST", index + "/test/" + docId + "/_update");
update.setOptions(expectWarnings(RestUpdateAction.TYPES_DEPRECATION_MESSAGE));
update.setJsonEntity("{\"doc\": {\"updated_field\": " + value + "}}");
client().performRequest(update);
updates.put(docId, value);
}
}
client().performRequest(new Request("POST", index + "/_refresh"));
for (int docId : updates.keySet()) {
Request get = new Request("GET", index + "/test/" + docId);
get.setOptions(expectWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE));
Map<String, Object> doc = entityAsMap(client().performRequest(get));
assertThat(XContentMapValues.extractValue("_source.updated_field", doc), equalTo(updates.get(docId)));
}
if (randomBoolean()) {
syncedFlush(index);
}
}

Expand Down

0 comments on commit 8fb6cbd

Please sign in to comment.