Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import static org.elasticsearch.cluster.routing.UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING;
import static org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
Expand Down Expand Up @@ -214,7 +213,7 @@ public void testNewReplicasWork() throws Exception {
logger.debug("--> creating [{}] replicas for index [{}]", numReplicas, index);
Request setNumberOfReplicas = new Request("PUT", "/" + index + "/_settings");
setNumberOfReplicas.setJsonEntity("{ \"index\": { \"number_of_replicas\" : " + numReplicas + " }}");
Response response = client().performRequest(setNumberOfReplicas);
client().performRequest(setNumberOfReplicas);

ensureGreenLongWait(index);

Expand Down Expand Up @@ -836,10 +835,10 @@ public void testRecovery() throws Exception {
* old and new versions. All of the snapshots include an index, a template,
* and some routing configuration.
*/
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/38603")
public void testSnapshotRestore() throws IOException {
int count;
if (isRunningAgainstOldCluster() && getOldClusterVersion().major < 8) {
Version oldClusterVersion = getOldClusterVersion();
if (isRunningAgainstOldCluster() && oldClusterVersion.major < 8) {
// Create the index
count = between(200, 300);
indexRandomDocuments(count, true, true, i -> jsonBuilder().startObject().field("field", "value").endObject());
Expand All @@ -859,7 +858,7 @@ public void testSnapshotRestore() throws IOException {
// Stick a routing attribute into to cluster settings so we can see it after the restore
Request addRoutingSettings = new Request("PUT", "/_cluster/settings");
addRoutingSettings.setJsonEntity(
"{\"persistent\": {\"cluster.routing.allocation.exclude.test_attr\": \"" + getOldClusterVersion() + "\"}}");
"{\"persistent\": {\"cluster.routing.allocation.exclude.test_attr\": \"" + oldClusterVersion + "\"}}");
client().performRequest(addRoutingSettings);

// Stick a template into the cluster so we can see it after the restore
Expand Down Expand Up @@ -890,7 +889,7 @@ public void testSnapshotRestore() throws IOException {
templateBuilder.startObject("alias2"); {
templateBuilder.startObject("filter"); {
templateBuilder.startObject("term"); {
templateBuilder.field("version", isRunningAgainstOldCluster() ? getOldClusterVersion() : Version.CURRENT);
templateBuilder.field("version", isRunningAgainstOldCluster() ? oldClusterVersion : Version.CURRENT);
}
templateBuilder.endObject();
}
Expand All @@ -901,12 +900,6 @@ public void testSnapshotRestore() throws IOException {
templateBuilder.endObject().endObject();
Request createTemplateRequest = new Request("PUT", "/_template/test_template");
createTemplateRequest.setJsonEntity(Strings.toString(templateBuilder));

// In 7.0, type names are no longer expected by default in put index template requests.
// We therefore use the deprecated typed APIs when running against the current version, but testing with a pre-7 version
if (isRunningAgainstOldCluster() == false && getOldClusterVersion().major < 7) {
createTemplateRequest.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "true");
}
createTemplateRequest.setOptions(allowTypesRemovalWarnings());

client().performRequest(createTemplateRequest);
Expand All @@ -932,7 +925,7 @@ public void testSnapshotRestore() throws IOException {
createSnapshot.setJsonEntity("{\"indices\": \"" + index + "\"}");
client().performRequest(createSnapshot);

checkSnapshot("old_snap", count, getOldClusterVersion());
checkSnapshot("old_snap", count, oldClusterVersion);
if (false == isRunningAgainstOldCluster()) {
checkSnapshot("new_snap", count, Version.CURRENT);
}
Expand Down Expand Up @@ -1029,7 +1022,8 @@ public void testSoftDeletes() throws Exception {
}
}

private void checkSnapshot(final String snapshotName, final int count, final Version tookOnVersion) throws IOException {
private void checkSnapshot(final String snapshotName, final int count, final Version tookOnVersion)
throws IOException {
// Check the snapshot metadata, especially the version
Request listSnapshotRequest = new Request("GET", "/_snapshot/repo/" + snapshotName);
Map<String, Object> listSnapshotResponse = entityAsMap(client().performRequest(listSnapshotRequest));
Expand Down Expand Up @@ -1112,12 +1106,6 @@ && getOldClusterVersion().onOrAfter(Version.V_6_1_0) && getOldClusterVersion().b

// Check that the template was restored successfully
Request getTemplateRequest = new Request("GET", "/_template/test_template");

// In 7.0, type names are no longer returned by default in get index template requests.
// We therefore use the deprecated typed APIs when running against the current version.
if (isRunningAgainstAncientCluster() == false) {
getTemplateRequest.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "true");
}
getTemplateRequest.setOptions(allowTypesRemovalWarnings());

Map<String, Object> getTemplateResponse = entityAsMap(client().performRequest(getTemplateRequest));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ public final boolean isRunningAgainstOldCluster() {

private final Version oldClusterVersion = Version.fromString(System.getProperty("tests.old_cluster_version"));

public final boolean isRunningAgainstAncientCluster() {
/**
* @return true if test is running against an old cluster before that last major, in this case
* when System.getProperty("tests.is_old_cluster" == true) and oldClusterVersion is before {@link Version#V_7_0_0}
*/
protected final boolean isRunningAgainstAncientCluster() {
return isRunningAgainstOldCluster() && oldClusterVersion.before(Version.V_7_0_0);
}

Expand Down