Skip to content

Commit 50fde6c

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 191f3e1 commit 50fde6c

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.io.IOException;
4242
import java.util.ArrayList;
4343
import java.util.Collection;
44+
import java.util.HashMap;
4445
import java.util.List;
4546
import java.util.Locale;
4647
import java.util.Map;
@@ -653,13 +654,30 @@ public void testUpdateDoc() throws Exception {
653654
.put(IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1)
654655
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 2);
655656
createIndex(index, settings.build());
657+
indexDocs(index, 0, 100);
656658
}
657-
ensureGreen(index);
658-
indexDocs(index, 0, 10);
659-
for (int i = 0; i < 10; i++) {
660-
Request update = new Request("POST", index + "/_update/" + i);
661-
update.setJsonEntity("{\"doc\": {\"f\": " + randomNonNegativeLong() + "}}");
662-
client().performRequest(update);
659+
if (randomBoolean()) {
660+
ensureGreen(index);
661+
}
662+
Map<Integer, Long> updates = new HashMap<>();
663+
for (int docId = 0; docId < 100; docId++) {
664+
final int times = randomIntBetween(0, 2);
665+
for (int i = 0; i < times; i++) {
666+
long value = randomNonNegativeLong();
667+
Request update = new Request("POST", index + "/_update/" + docId);
668+
update.setJsonEntity("{\"doc\": {\"updated_field\": " + value + "}}");
669+
client().performRequest(update);
670+
updates.put(docId, value);
671+
}
672+
}
673+
client().performRequest(new Request("POST", index + "/_refresh"));
674+
for (int docId : updates.keySet()) {
675+
Request get = new Request("GET", index + "/_doc/" + docId);
676+
Map<String, Object> doc = entityAsMap(client().performRequest(get));
677+
assertThat(XContentMapValues.extractValue("_source.updated_field", doc), equalTo(updates.get(docId)));
678+
}
679+
if (randomBoolean()) {
680+
syncedFlush(index);
663681
}
664682
}
665683

0 commit comments

Comments
 (0)