Skip to content

Commit 8fb6cbd

Browse files
committed
Strengthen testUpdate in rolling upgrade
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
1 parent e8095fa commit 8fb6cbd

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.elasticsearch.index.IndexSettings;
3535
import org.elasticsearch.index.seqno.RetentionLeaseUtils;
3636
import org.elasticsearch.rest.RestStatus;
37+
import org.elasticsearch.rest.action.document.RestGetAction;
3738
import org.elasticsearch.rest.action.document.RestIndexAction;
3839
import org.elasticsearch.rest.action.document.RestUpdateAction;
3940
import org.elasticsearch.test.rest.yaml.ObjectPath;
@@ -43,6 +44,7 @@
4344
import java.io.IOException;
4445
import java.util.ArrayList;
4546
import java.util.Collection;
47+
import java.util.HashMap;
4648
import java.util.List;
4749
import java.util.Locale;
4850
import java.util.Map;
@@ -694,14 +696,32 @@ public void testUpdateDoc() throws Exception {
694696
.put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1)
695697
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 2);
696698
createIndex(index, settings.build());
699+
indexDocs(index, 0, 100);
697700
}
698-
ensureGreen(index);
699-
indexDocs(index, 0, 10);
700-
for (int i = 0; i < 10; i++) {
701-
Request update = new Request("POST", index + "/test/" + i + "/_update/");
702-
update.setOptions(expectWarnings(RestUpdateAction.TYPES_DEPRECATION_MESSAGE));
703-
update.setJsonEntity("{\"doc\": {\"f\": " + randomNonNegativeLong() + "}}");
704-
client().performRequest(update);
701+
if (randomBoolean()) {
702+
ensureGreen(index);
703+
}
704+
Map<Integer, Long> updates = new HashMap<>();
705+
for (int docId = 0; docId < 100; docId++) {
706+
final int times = randomIntBetween(0, 2);
707+
for (int i = 0; i < times; i++) {
708+
long value = randomNonNegativeLong();
709+
Request update = new Request("POST", index + "/test/" + docId + "/_update");
710+
update.setOptions(expectWarnings(RestUpdateAction.TYPES_DEPRECATION_MESSAGE));
711+
update.setJsonEntity("{\"doc\": {\"updated_field\": " + value + "}}");
712+
client().performRequest(update);
713+
updates.put(docId, value);
714+
}
715+
}
716+
client().performRequest(new Request("POST", index + "/_refresh"));
717+
for (int docId : updates.keySet()) {
718+
Request get = new Request("GET", index + "/test/" + docId);
719+
get.setOptions(expectWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE));
720+
Map<String, Object> doc = entityAsMap(client().performRequest(get));
721+
assertThat(XContentMapValues.extractValue("_source.updated_field", doc), equalTo(updates.get(docId)));
722+
}
723+
if (randomBoolean()) {
724+
syncedFlush(index);
705725
}
706726
}
707727

0 commit comments

Comments
 (0)