Skip to content

Commit 9c511bc

Browse files
committed
test: Replace OldIndexBackwardsCompatibilityIT#testOldClusterStates with a full cluster restart qa test
OldIndexBackwardsCompatibilityIT#testOldClusterStates tested whether global and index metadata could be read from data directory, this can also be tested in full cluster qa test that checks cluster state via api. Relates to #24939
1 parent dc9b674 commit 9c511bc

File tree

4 files changed

+50
-236
lines changed

4 files changed

+50
-236
lines changed

core/src/test/java/org/elasticsearch/VersionTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,4 +352,12 @@ public boolean isCompatible(Version left, Version right) {
352352
return result;
353353
}
354354

355+
// This exists because 5.1.0 was never released due to a mistake in the release process.
356+
// This verifies that we never declare the version as "released" accidentally.
357+
// It would never pass qa tests later on, but those come very far in the build and this is quick to check now.
358+
public void testUnreleasedVersion() {
359+
Version VERSION_5_1_0_UNRELEASED = Version.fromString("5.1.0");
360+
VersionTests.assertUnknownVersion(VERSION_5_1_0_UNRELEASED);
361+
}
362+
355363
}

core/src/test/java/org/elasticsearch/bwcompat/OldIndexBackwardsCompatibilityIT.java

Lines changed: 0 additions & 201 deletions
This file was deleted.

qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,48 @@ public void testAliasWithBadName() throws Exception {
296296
}
297297
}
298298

299+
public void testClusterState() throws Exception {
300+
if (runningAgainstOldCluster) {
301+
XContentBuilder mappingsAndSettings = jsonBuilder();
302+
mappingsAndSettings.startObject();
303+
mappingsAndSettings.field("template", index);
304+
{
305+
mappingsAndSettings.startObject("settings");
306+
mappingsAndSettings.field("number_of_shards", 1);
307+
mappingsAndSettings.field("number_of_replicas", 0);
308+
mappingsAndSettings.endObject();
309+
}
310+
mappingsAndSettings.endObject();
311+
client().performRequest("PUT", "/_template/template_1", Collections.emptyMap(),
312+
new StringEntity(mappingsAndSettings.string(), ContentType.APPLICATION_JSON));
313+
client().performRequest("PUT", "/" + index);
314+
}
315+
316+
// verifying if we can still read some properties from cluster state api:
317+
Map<String, Object> clusterState = toMap(client().performRequest("GET", "/_cluster/state"));
318+
319+
// Check some global properties:
320+
String clusterName = (String) clusterState.get("cluster_name");
321+
assertEquals("full-cluster-restart", clusterName);
322+
String numberOfShards = (String) XContentMapValues.extractValue(
323+
"metadata.templates.template_1.settings.index.number_of_shards", clusterState);
324+
assertEquals("1", numberOfShards);
325+
String numberOfReplicas = (String) XContentMapValues.extractValue(
326+
"metadata.templates.template_1.settings.index.number_of_replicas", clusterState);
327+
assertEquals("0", numberOfReplicas);
328+
329+
// Check some index properties:
330+
numberOfShards = (String) XContentMapValues.extractValue("metadata.indices." + index +
331+
".settings.index.number_of_shards", clusterState);
332+
assertEquals("1", numberOfShards);
333+
numberOfReplicas = (String) XContentMapValues.extractValue("metadata.indices." + index +
334+
".settings.index.number_of_replicas", clusterState);
335+
assertEquals("0", numberOfReplicas);
336+
Version version = Version.fromId(Integer.valueOf((String) XContentMapValues.extractValue("metadata.indices." + index +
337+
".settings.index.version.created", clusterState)));
338+
assertEquals(oldClusterVersion, version);
339+
340+
}
299341

300342
void assertBasicSearchWorks(int count) throws IOException {
301343
logger.info("--> testing basic search");

test/framework/src/main/java/org/elasticsearch/test/OldIndexUtils.java

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,14 @@
2121

2222
import org.apache.logging.log4j.Logger;
2323
import org.apache.lucene.index.IndexWriter;
24-
import org.apache.lucene.util.TestUtil;
2524
import org.elasticsearch.Version;
2625
import org.elasticsearch.cluster.metadata.IndexMetaData;
2726
import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider;
28-
import org.elasticsearch.common.io.FileSystemUtils;
2927
import org.elasticsearch.common.settings.Settings;
30-
import org.elasticsearch.common.util.IndexFolderUpgrader;
3128
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
32-
import org.elasticsearch.env.NodeEnvironment;
3329
import org.elasticsearch.index.MergePolicyConfig;
3430

3531
import java.io.IOException;
36-
import java.io.InputStream;
3732
import java.nio.file.DirectoryStream;
3833
import java.nio.file.FileVisitResult;
3934
import java.nio.file.Files;
@@ -74,32 +69,6 @@ public static Settings getSettings() {
7469
.build();
7570
}
7671

77-
public static void upgradeIndexFolder(InternalTestCluster cluster, String nodeName) throws Exception {
78-
final NodeEnvironment nodeEnvironment = cluster.getInstance(NodeEnvironment.class, nodeName);
79-
IndexFolderUpgrader.upgradeIndicesIfNeeded(Settings.EMPTY, nodeEnvironment);
80-
}
81-
82-
public static void loadIndex(String indexName, String indexFile, Path unzipDir, Path bwcPath, Logger logger, Path... paths) throws
83-
Exception {
84-
Path unzipDataDir = unzipDir.resolve("data");
85-
86-
Path backwardsIndex = bwcPath.resolve(indexFile);
87-
// decompress the index
88-
try (InputStream stream = Files.newInputStream(backwardsIndex)) {
89-
TestUtil.unzip(stream, unzipDir);
90-
}
91-
92-
// check it is unique
93-
assertTrue(Files.exists(unzipDataDir));
94-
Path[] list = FileSystemUtils.files(unzipDataDir);
95-
if (list.length != 1) {
96-
throw new IllegalStateException("Backwards index must contain exactly one cluster");
97-
}
98-
99-
final Path src = getIndexDir(logger, indexName, indexFile, list[0]);
100-
copyIndex(logger, src, src.getFileName().toString(), paths);
101-
}
102-
10372
public static Path getIndexDir(
10473
final Logger logger,
10574
final String indexName,
@@ -166,8 +135,4 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
166135
}
167136
});
168137
}
169-
170-
public static Version extractVersion(String index) {
171-
return Version.fromString(index.substring(index.indexOf('-') + 1, index.lastIndexOf('.')));
172-
}
173138
}

0 commit comments

Comments
 (0)