|
5 | 5 | */
|
6 | 6 | package org.elasticsearch.xpack.ccr.action;
|
7 | 7 |
|
| 8 | +import org.elasticsearch.Version; |
8 | 9 | import org.elasticsearch.cluster.ClusterName;
|
9 | 10 | import org.elasticsearch.cluster.ClusterState;
|
| 11 | +import org.elasticsearch.cluster.metadata.IndexMetaData; |
10 | 12 | import org.elasticsearch.cluster.metadata.MetaData;
|
| 13 | +import org.elasticsearch.common.settings.Settings; |
11 | 14 | import org.elasticsearch.common.unit.ByteSizeUnit;
|
12 | 15 | import org.elasticsearch.common.unit.ByteSizeValue;
|
13 | 16 | import org.elasticsearch.common.unit.TimeValue;
|
| 17 | +import org.elasticsearch.index.Index; |
14 | 18 | import org.elasticsearch.index.shard.ShardId;
|
15 | 19 | import org.elasticsearch.persistent.PersistentTasksCustomMetaData;
|
16 | 20 | import org.elasticsearch.test.ESTestCase;
|
|
24 | 28 | public class TransportFollowStatsActionTests extends ESTestCase {
|
25 | 29 |
|
26 | 30 | public void testFindFollowerIndicesFromShardFollowTasks() {
|
| 31 | + Settings indexSettings = Settings.builder() |
| 32 | + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) |
| 33 | + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) |
| 34 | + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) |
| 35 | + .build(); |
| 36 | + |
| 37 | + IndexMetaData index1 = IndexMetaData.builder("index1").settings(indexSettings).build(); |
| 38 | + IndexMetaData index2 = IndexMetaData.builder("index2").settings(indexSettings).build(); |
| 39 | + IndexMetaData index3 = IndexMetaData.builder("index3").settings(indexSettings).build(); |
| 40 | + |
27 | 41 | PersistentTasksCustomMetaData.Builder persistentTasks = PersistentTasksCustomMetaData.builder()
|
28 |
| - .addTask("1", ShardFollowTask.NAME, createShardFollowTask("abc"), null) |
29 |
| - .addTask("2", ShardFollowTask.NAME, createShardFollowTask("def"), null); |
| 42 | + .addTask("1", ShardFollowTask.NAME, createShardFollowTask(index1.getIndex()), null) |
| 43 | + .addTask("2", ShardFollowTask.NAME, createShardFollowTask(index2.getIndex()), null) |
| 44 | + .addTask("3", ShardFollowTask.NAME, createShardFollowTask(index3.getIndex()), null); |
30 | 45 |
|
31 | 46 | ClusterState clusterState = ClusterState.builder(new ClusterName("_cluster"))
|
32 |
| - .metaData(MetaData.builder().putCustom(PersistentTasksCustomMetaData.TYPE, persistentTasks.build()).build()) |
| 47 | + .metaData(MetaData.builder() |
| 48 | + .putCustom(PersistentTasksCustomMetaData.TYPE, persistentTasks.build()) |
| 49 | + // only add index1 and index2 |
| 50 | + .put(index1, false) |
| 51 | + .put(index2, false) |
| 52 | + .build()) |
33 | 53 | .build();
|
34 | 54 | Set<String> result = TransportFollowStatsAction.findFollowerIndicesFromShardFollowTasks(clusterState, null);
|
35 | 55 | assertThat(result.size(), equalTo(2));
|
36 |
| - assertThat(result.contains("abc"), is(true)); |
37 |
| - assertThat(result.contains("def"), is(true)); |
| 56 | + assertThat(result.contains(index1.getIndex().getName()), is(true)); |
| 57 | + assertThat(result.contains(index2.getIndex().getName()), is(true)); |
38 | 58 |
|
39 |
| - result = TransportFollowStatsAction.findFollowerIndicesFromShardFollowTasks(clusterState, new String[]{"def"}); |
| 59 | + result = TransportFollowStatsAction.findFollowerIndicesFromShardFollowTasks(clusterState, |
| 60 | + new String[]{index2.getIndex().getName()}); |
40 | 61 | assertThat(result.size(), equalTo(1));
|
41 |
| - assertThat(result.contains("def"), is(true)); |
| 62 | + assertThat(result.contains(index2.getIndex().getName()), is(true)); |
42 | 63 |
|
43 |
| - result = TransportFollowStatsAction.findFollowerIndicesFromShardFollowTasks(clusterState, new String[]{"ghi"}); |
| 64 | + result = TransportFollowStatsAction.findFollowerIndicesFromShardFollowTasks(clusterState, |
| 65 | + new String[]{index3.getIndex().getName()}); |
44 | 66 | assertThat(result.size(), equalTo(0));
|
45 | 67 | }
|
46 | 68 |
|
47 |
| - static ShardFollowTask createShardFollowTask(String followerIndex) { |
| 69 | + static ShardFollowTask createShardFollowTask(Index followerIndex) { |
48 | 70 | return new ShardFollowTask(
|
49 | 71 | null,
|
50 |
| - new ShardId(followerIndex, "", 0), |
| 72 | + new ShardId(followerIndex, 0), |
51 | 73 | new ShardId("leader_index", "", 0),
|
52 | 74 | 1024,
|
53 | 75 | 1024,
|
|
0 commit comments