forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CCR] Added validation checks that were left out of elastic#30120
- Loading branch information
Showing
3 changed files
with
133 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
.../ccr/src/test/java/org/elasticsearch/xpack/ccr/action/FollowExistingIndexActionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.ccr.action; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.IndexSettings; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class FollowExistingIndexActionTests extends ESTestCase { | ||
|
||
public void testValidation() { | ||
FollowExistingIndexAction.Request request = new FollowExistingIndexAction.Request(); | ||
request.setLeaderIndex("index1"); | ||
request.setFollowIndex("index2"); | ||
|
||
{ | ||
Exception e = expectThrows(IllegalArgumentException.class, () -> FollowExistingIndexAction.validate(null, null, request)); | ||
assertThat(e.getMessage(), equalTo("leader index [index1] does not exist")); | ||
} | ||
{ | ||
IndexMetaData leaderIMD = createIMD("index1", 5); | ||
Exception e = expectThrows(IllegalArgumentException.class, () -> FollowExistingIndexAction.validate(leaderIMD, null, request)); | ||
assertThat(e.getMessage(), equalTo("follow index [index2] does not exist")); | ||
} | ||
{ | ||
IndexMetaData leaderIMD = createIMD("index1", 5); | ||
IndexMetaData followIMD = createIMD("index2", 5); | ||
Exception e = expectThrows(IllegalArgumentException.class, | ||
() -> FollowExistingIndexAction.validate(leaderIMD, followIMD, request)); | ||
assertThat(e.getMessage(), equalTo("leader index [index1] does not have soft deletes enabled")); | ||
} | ||
{ | ||
IndexMetaData leaderIMD = createIMD("index1", 5, IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true"); | ||
IndexMetaData followIMD = createIMD("index2", 4); | ||
Exception e = expectThrows(IllegalArgumentException.class, | ||
() -> FollowExistingIndexAction.validate(leaderIMD, followIMD, request)); | ||
assertThat(e.getMessage(), | ||
equalTo("leader index primary shards [5] does not match with the number of shards of the follow index [4]")); | ||
} | ||
{ | ||
IndexMetaData leaderIMD = createIMD("index1", 5, IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true"); | ||
IndexMetaData followIMD = createIMD("index2", 5); | ||
FollowExistingIndexAction.validate(leaderIMD, followIMD, request); | ||
} | ||
} | ||
|
||
private static IndexMetaData createIMD(String index, int numShards, String... settings) { | ||
assert settings.length % 2 == 0; | ||
Settings.Builder settingsBuilder = settings(Version.CURRENT); | ||
for (int i = 0; i < settings.length; i += 2) { | ||
settingsBuilder.put(settings[i], settings[i + 1]); | ||
} | ||
return IndexMetaData.builder(index).settings(settingsBuilder) | ||
.numberOfShards(numShards) | ||
.numberOfReplicas(0) | ||
.setRoutingNumShards(numShards).build(); | ||
} | ||
|
||
} |