|
7 | 7 |
|
8 | 8 | import org.elasticsearch.Version;
|
9 | 9 | import org.elasticsearch.cluster.metadata.IndexMetaData;
|
| 10 | +import org.elasticsearch.cluster.metadata.IndexMetaData.State; |
10 | 11 | import org.elasticsearch.common.collect.Tuple;
|
11 | 12 | import org.elasticsearch.common.settings.Settings;
|
12 | 13 | import org.elasticsearch.index.IndexSettings;
|
13 | 14 | import org.elasticsearch.test.ESTestCase;
|
14 | 15 |
|
| 16 | +import java.io.IOException; |
| 17 | + |
15 | 18 | import static org.hamcrest.Matchers.equalTo;
|
16 | 19 |
|
17 | 20 | public class FollowIndexActionTests extends ESTestCase {
|
18 | 21 |
|
19 |
| - public void testValidation() { |
| 22 | + public void testValidation() throws IOException { |
20 | 23 | FollowIndexAction.Request request = new FollowIndexAction.Request();
|
21 | 24 | request.setLeaderIndex("index1");
|
22 | 25 | request.setFollowIndex("index2");
|
@@ -45,22 +48,84 @@ public void testValidation() {
|
45 | 48 | assertThat(e.getMessage(),
|
46 | 49 | equalTo("leader index primary shards [5] does not match with the number of shards of the follow index [4]"));
|
47 | 50 | }
|
| 51 | + { |
| 52 | + IndexMetaData leaderIMD = createIMD("index1", State.CLOSE, "{}", 5, |
| 53 | + new Tuple<>(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true")); |
| 54 | + IndexMetaData followIMD = createIMD("index2", State.OPEN, "{}", 5, |
| 55 | + new Tuple<>(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true")); |
| 56 | + Exception e = expectThrows(IllegalArgumentException.class, |
| 57 | + () -> FollowIndexAction.validate(leaderIMD, followIMD, request)); |
| 58 | + assertThat(e.getMessage(), equalTo("leader and follow index must be open")); |
| 59 | + } |
| 60 | + { |
| 61 | + IndexMetaData leaderIMD = createIMD("index1", State.OPEN, "{\"properties\": {\"field\": {\"type\": \"keyword\"}}}", 5, |
| 62 | + new Tuple<>(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true")); |
| 63 | + IndexMetaData followIMD = createIMD("index2", State.OPEN, "{\"properties\": {\"field\": {\"type\": \"text\"}}}", 5); |
| 64 | + Exception e = expectThrows(IllegalArgumentException.class, |
| 65 | + () -> FollowIndexAction.validate(leaderIMD, followIMD, request)); |
| 66 | + assertThat(e.getMessage(), equalTo("the leader and follower mappings must be identical")); |
| 67 | + } |
| 68 | + { |
| 69 | + String mapping = "{\"properties\": {\"field\": {\"type\": \"text\", \"analyzer\": \"my_analyzer\"}}}"; |
| 70 | + IndexMetaData leaderIMD = createIMD("index1", State.OPEN, mapping, 5, |
| 71 | + new Tuple<>(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true"), |
| 72 | + new Tuple<>("index.analysis.analyzer.my_analyzer.type", "custom"), |
| 73 | + new Tuple<>("index.analysis.analyzer.my_analyzer.tokenizer", "whitespace")); |
| 74 | + IndexMetaData followIMD = createIMD("index2", State.OPEN, mapping, 5, |
| 75 | + new Tuple<>("index.analysis.analyzer.my_analyzer.type", "custom"), |
| 76 | + new Tuple<>("index.analysis.analyzer.my_analyzer.tokenizer", "standard")); |
| 77 | + Exception e = expectThrows(IllegalArgumentException.class, |
| 78 | + () -> FollowIndexAction.validate(leaderIMD, followIMD, request)); |
| 79 | + assertThat(e.getMessage(), equalTo("the leader and follower index analysis settings must be identical")); |
| 80 | + } |
48 | 81 | {
|
49 | 82 | IndexMetaData leaderIMD = createIMD("index1", 5, new Tuple<>(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true"));
|
50 | 83 | IndexMetaData followIMD = createIMD("index2", 5);
|
51 | 84 | FollowIndexAction.validate(leaderIMD, followIMD, request);
|
52 | 85 | }
|
| 86 | + { |
| 87 | + String mapping = "{\"properties\": {\"field\": {\"type\": \"text\", \"analyzer\": \"my_analyzer\"}}}"; |
| 88 | + IndexMetaData leaderIMD = createIMD("index1", State.OPEN, mapping, 5, |
| 89 | + new Tuple<>(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true"), |
| 90 | + new Tuple<>("index.analysis.analyzer.my_analyzer.type", "custom"), |
| 91 | + new Tuple<>("index.analysis.analyzer.my_analyzer.tokenizer", "standard")); |
| 92 | + IndexMetaData followIMD = createIMD("index2", State.OPEN, mapping, 5, |
| 93 | + new Tuple<>("index.analysis.analyzer.my_analyzer.type", "custom"), |
| 94 | + new Tuple<>("index.analysis.analyzer.my_analyzer.tokenizer", "standard")); |
| 95 | + FollowIndexAction.validate(leaderIMD, followIMD, request); |
| 96 | + } |
| 97 | + { |
| 98 | + String mapping = "{\"properties\": {\"field\": {\"type\": \"text\", \"analyzer\": \"my_analyzer\"}}}"; |
| 99 | + IndexMetaData leaderIMD = createIMD("index1", State.OPEN, mapping, 5, |
| 100 | + new Tuple<>(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true"), |
| 101 | + new Tuple<>(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), "1s"), |
| 102 | + new Tuple<>("index.analysis.analyzer.my_analyzer.type", "custom"), |
| 103 | + new Tuple<>("index.analysis.analyzer.my_analyzer.tokenizer", "standard")); |
| 104 | + IndexMetaData followIMD = createIMD("index2", State.OPEN, mapping, 5, |
| 105 | + new Tuple<>(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), "10s"), |
| 106 | + new Tuple<>("index.analysis.analyzer.my_analyzer.type", "custom"), |
| 107 | + new Tuple<>("index.analysis.analyzer.my_analyzer.tokenizer", "standard")); |
| 108 | + FollowIndexAction.validate(leaderIMD, followIMD, request); |
| 109 | + } |
53 | 110 | }
|
54 |
| - |
55 |
| - private static IndexMetaData createIMD(String index, int numShards, Tuple<?, ?>... settings) { |
| 111 | + |
| 112 | + private static IndexMetaData createIMD(String index, int numShards, Tuple<?, ?>... settings) throws IOException { |
| 113 | + return createIMD(index, State.OPEN, "{}", numShards, settings); |
| 114 | + } |
| 115 | + |
| 116 | + private static IndexMetaData createIMD(String index, State state, String mapping, int numShards, |
| 117 | + Tuple<?, ?>... settings) throws IOException { |
56 | 118 | Settings.Builder settingsBuilder = settings(Version.CURRENT);
|
57 | 119 | for (Tuple<?, ?> setting : settings) {
|
58 | 120 | settingsBuilder.put((String) setting.v1(), (String) setting.v2());
|
59 | 121 | }
|
60 | 122 | return IndexMetaData.builder(index).settings(settingsBuilder)
|
61 | 123 | .numberOfShards(numShards)
|
| 124 | + .state(state) |
62 | 125 | .numberOfReplicas(0)
|
63 |
| - .setRoutingNumShards(numShards).build(); |
| 126 | + .setRoutingNumShards(numShards) |
| 127 | + .putMapping("_doc", mapping) |
| 128 | + .build(); |
64 | 129 | }
|
65 | 130 |
|
66 | 131 | }
|
0 commit comments