Skip to content

Commit ee63638

Browse files
authored
Add random index settings and mappings updates in N-2 BWC tests (#119529)
Relates ES-10434
1 parent 7bee0c1 commit ee63638

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

qa/lucene-index-compatibility/src/javaRestTest/java/org/elasticsearch/lucene/AbstractIndexCompatibilityTestCase.java

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@
99

1010
package org.elasticsearch.lucene;
1111

12+
import org.apache.http.entity.ContentType;
13+
import org.apache.http.entity.InputStreamEntity;
1214
import org.elasticsearch.client.Request;
1315
import org.elasticsearch.common.settings.Settings;
1416
import org.elasticsearch.core.Strings;
17+
import org.elasticsearch.index.IndexSettings;
18+
import org.elasticsearch.index.mapper.MapperService;
19+
import org.elasticsearch.test.XContentTestUtils;
1520
import org.elasticsearch.test.cluster.ElasticsearchCluster;
1621
import org.elasticsearch.test.cluster.local.LocalClusterConfigProvider;
1722
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
1823
import org.elasticsearch.test.cluster.util.Version;
1924
import org.elasticsearch.test.rest.ESRestTestCase;
25+
import org.elasticsearch.xcontent.XContentType;
2026
import org.junit.After;
2127
import org.junit.Before;
2228
import org.junit.ClassRule;
@@ -153,9 +159,9 @@ protected static void indexDocs(String indexName, int numDocs) throws Exception
153159
var request = new Request("POST", "/_bulk");
154160
var docs = new StringBuilder();
155161
IntStream.range(0, numDocs).forEach(n -> docs.append(Strings.format("""
156-
{"index":{"_id":"%s","_index":"%s"}}
157-
{"test":"test"}
158-
""", n, indexName)));
162+
{"index":{"_index":"%s"}}
163+
{"field_0":"%s","field_1":%d,"field_2":"%s"}
164+
""", indexName, Integer.toString(n), n, randomFrom(Locale.getAvailableLocales()).getDisplayName())));
159165
request.setJsonEntity(docs.toString());
160166
var response = assertOK(client().performRequest(request));
161167
assertThat(entityAsMap(response).get("errors"), allOf(notNullValue(), is(false)));
@@ -192,4 +198,38 @@ protected static void restoreIndex(String repository, String snapshot, String in
192198
assertThat(responseBody.evaluate("snapshot.shards.total"), equalTo((int) responseBody.evaluate("snapshot.shards.failed")));
193199
assertThat(responseBody.evaluate("snapshot.shards.successful"), equalTo(0));
194200
}
201+
202+
protected static void updateRandomIndexSettings(String indexName) throws IOException {
203+
final var settings = Settings.builder();
204+
int updates = randomIntBetween(1, 3);
205+
for (int i = 0; i < updates; i++) {
206+
switch (i) {
207+
case 0 -> settings.putList(IndexSettings.DEFAULT_FIELD_SETTING.getKey(), "field_" + randomInt(2));
208+
case 1 -> settings.put(IndexSettings.MAX_INNER_RESULT_WINDOW_SETTING.getKey(), randomIntBetween(1, 100));
209+
case 2 -> settings.put(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey(), randomLongBetween(0L, 1000L));
210+
case 3 -> settings.put(IndexSettings.MAX_SLICES_PER_SCROLL.getKey(), randomIntBetween(1, 1024));
211+
default -> throw new IllegalStateException();
212+
}
213+
}
214+
updateIndexSettings(indexName, settings);
215+
}
216+
217+
protected static void updateRandomMappings(String indexName) throws IOException {
218+
final var runtime = new HashMap<>();
219+
runtime.put("field_" + randomInt(2), Map.of("type", "keyword"));
220+
final var properties = new HashMap<>();
221+
properties.put(randomIdentifier(), Map.of("type", "long"));
222+
var body = XContentTestUtils.convertToXContent(Map.of("runtime", runtime, "properties", properties), XContentType.JSON);
223+
var request = new Request("PUT", indexName + "/_mappings");
224+
request.setEntity(
225+
new InputStreamEntity(
226+
body.streamInput(),
227+
body.length(),
228+
229+
ContentType.create(XContentType.JSON.mediaTypeWithoutParameters())
230+
)
231+
);
232+
assertOK(client().performRequest(request));
233+
}
234+
195235
}

qa/lucene-index-compatibility/src/javaRestTest/java/org/elasticsearch/lucene/FullClusterRestartSearchableSnapshotIndexCompatibilityIT.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public void testSearchableSnapshot() throws Exception {
8282
assertThat(indexVersion(mountedIndex), equalTo(VERSION_MINUS_2));
8383
assertDocCount(client(), mountedIndex, numDocs);
8484

85+
updateRandomIndexSettings(mountedIndex);
86+
updateRandomMappings(mountedIndex);
87+
8588
logger.debug("--> adding replica to test peer-recovery");
8689
updateIndexSettings(mountedIndex, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1));
8790
ensureGreen(mountedIndex);
@@ -130,6 +133,9 @@ public void testSearchableSnapshotUpgrade() throws Exception {
130133

131134
ensureGreen(mountedIndex);
132135

136+
updateRandomIndexSettings(mountedIndex);
137+
updateRandomMappings(mountedIndex);
138+
133139
assertThat(indexVersion(mountedIndex), equalTo(VERSION_MINUS_2));
134140
assertDocCount(client(), mountedIndex, numDocs);
135141
return;
@@ -141,6 +147,9 @@ public void testSearchableSnapshotUpgrade() throws Exception {
141147
assertThat(indexVersion(mountedIndex), equalTo(VERSION_MINUS_2));
142148
assertDocCount(client(), mountedIndex, numDocs);
143149

150+
updateRandomIndexSettings(mountedIndex);
151+
updateRandomMappings(mountedIndex);
152+
144153
logger.debug("--> adding replica to test peer-recovery");
145154
updateIndexSettings(mountedIndex, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1));
146155
ensureGreen(mountedIndex);

qa/lucene-index-compatibility/src/javaRestTest/java/org/elasticsearch/lucene/RollingUpgradeSearchableSnapshotIndexCompatibilityIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public void testMountSearchableSnapshot() throws Exception {
7676

7777
ensureGreen(mountedIndex);
7878

79+
updateRandomIndexSettings(mountedIndex);
80+
updateRandomMappings(mountedIndex);
81+
7982
assertThat(indexVersion(mountedIndex), equalTo(VERSION_MINUS_2));
8083
assertDocCount(client(), mountedIndex, numDocs);
8184

@@ -134,6 +137,9 @@ public void testSearchableSnapshotUpgrade() throws Exception {
134137

135138
ensureGreen(mountedIndex);
136139

140+
updateRandomIndexSettings(mountedIndex);
141+
updateRandomMappings(mountedIndex);
142+
137143
assertThat(indexVersion(mountedIndex), equalTo(VERSION_MINUS_2));
138144
assertDocCount(client(), mountedIndex, numDocs);
139145
}

0 commit comments

Comments
 (0)