Skip to content

Commit 206abfc

Browse files
Refactor RandomizedRollingUpgradeIT (elastic#139572)
This PR updates the randomized rolling upgrade test to create multiple indices with different mappings before upgrading. In the original implementation, only the first test index was actually being upgraded, since the test would execute sequentially for each index. By the time the test reached the second index, the whole cluster had already been upgraded.
1 parent b55e9e5 commit 206abfc

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

x-pack/plugin/logsdb/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/xpack/logsdb/RandomizedRollingUpgradeIT.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,35 +103,46 @@ protected Object extendedDocValuesParams() {
103103
mappingGenerator = new MappingGenerator(specification);
104104
}
105105

106-
private void testIndexing(String indexName, Settings.Builder settings) throws IOException {
106+
private TestIndexConfig createIndex(String indexName, Settings.Builder settings) throws IOException {
107107
var template = templateGenerator.generate();
108108
TestIndexConfig indexConfig = new TestIndexConfig(indexName, template, settings, mappingGenerator.generate(template));
109109

110110
@SuppressWarnings("unchecked")
111111
Map<String, Object> mappingRaw = (Map<String, Object>) indexConfig.mapping.raw().get("_doc");
112112
String mappingStr = Strings.toString(XContentFactory.jsonBuilder().map(mappingRaw));
113-
logger.info(indexName + " mappings: " + mappingStr);
113+
logger.info(() -> indexName + " mappings: " + mappingStr);
114114
createIndex(indexName, settings.build(), mappingStr);
115115

116+
return indexConfig;
117+
}
118+
119+
private void indexAndQueryDocuments(TestIndexConfig indexConfig) throws IOException {
116120
indexDocuments(indexConfig);
117121
testQueryAll(indexConfig);
118122
testEsqlSource(indexConfig);
123+
}
124+
125+
private void testIndexing(String indexNameBase, Settings.Builder settings) throws IOException {
126+
TestIndexConfig[] indexConfigs = new TestIndexConfig[NUM_INDICES];
127+
128+
for (int i = 0; i < NUM_INDICES; i++) {
129+
indexConfigs[i] = createIndex(indexNameBase + i, settings);
130+
indexAndQueryDocuments(indexConfigs[i]);
131+
}
119132

120133
int numNodes = Integer.parseInt(System.getProperty("tests.num_nodes", "3"));
121134
for (int i = 0; i < numNodes; i++) {
122135
upgradeNode(i);
123-
indexDocuments(indexConfig);
124-
testQueryAll(indexConfig);
125-
testEsqlSource(indexConfig);
136+
for (int j = 0; j < NUM_INDICES; j++) {
137+
indexAndQueryDocuments(indexConfigs[j]);
138+
}
126139
}
127140
}
128141

129142
public void testIndexingStandardSource() throws IOException {
130143
Settings.Builder builder = Settings.builder().put(IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), "stored");
131144
String indexNameBase = "test-index-standard-";
132-
for (int i = 0; i < NUM_INDICES; i++) {
133-
testIndexing(indexNameBase + i, builder);
134-
}
145+
testIndexing(indexNameBase, builder);
135146
}
136147

137148
public void testIndexingSyntheticSource() throws IOException {
@@ -140,9 +151,7 @@ public void testIndexingSyntheticSource() throws IOException {
140151
builder.put(Mapper.SYNTHETIC_SOURCE_KEEP_INDEX_SETTING.getKey(), "arrays");
141152
}
142153
String indexNameBase = "test-index-synthetic-";
143-
for (int i = 0; i < NUM_INDICES; i++) {
144-
testIndexing(indexNameBase + i, builder);
145-
}
154+
testIndexing(indexNameBase, builder);
146155
}
147156

148157
private void indexDocuments(TestIndexConfig indexConfig) throws IOException {

0 commit comments

Comments
 (0)