|
40 | 40 | import java.util.function.Consumer;
|
41 | 41 | import java.util.function.Function;
|
42 | 42 |
|
| 43 | +import static org.elasticsearch.xpack.ccr.action.AutoFollowCoordinator.AutoFollower.recordLeaderIndexAsFollowFunction; |
43 | 44 | import static org.hamcrest.Matchers.equalTo;
|
44 | 45 | import static org.hamcrest.Matchers.is;
|
| 46 | +import static org.hamcrest.Matchers.notNullValue; |
45 | 47 | import static org.hamcrest.Matchers.nullValue;
|
46 | 48 | import static org.hamcrest.Matchers.sameInstance;
|
47 | 49 | import static org.mockito.Matchers.anyString;
|
@@ -384,6 +386,33 @@ public void testGetLeaderIndicesToFollow_shardsNotStarted() {
|
384 | 386 | assertThat(result.get(1).getName(), equalTo("index2"));
|
385 | 387 | }
|
386 | 388 |
|
| 389 | + public void testRecordLeaderIndexAsFollowFunction() { |
| 390 | + AutoFollowMetadata autoFollowMetadata = new AutoFollowMetadata(Collections.emptyMap(), |
| 391 | + Collections.singletonMap("pattern1", Collections.emptyList()), Collections.emptyMap()); |
| 392 | + ClusterState clusterState = new ClusterState.Builder(new ClusterName("name")) |
| 393 | + .metaData(new MetaData.Builder().putCustom(AutoFollowMetadata.TYPE, autoFollowMetadata)) |
| 394 | + .build(); |
| 395 | + Function<ClusterState, ClusterState> function = recordLeaderIndexAsFollowFunction("pattern1", new Index("index1", "index1")); |
| 396 | + |
| 397 | + ClusterState result = function.apply(clusterState); |
| 398 | + AutoFollowMetadata autoFollowMetadataResult = result.metaData().custom(AutoFollowMetadata.TYPE); |
| 399 | + assertThat(autoFollowMetadataResult.getFollowedLeaderIndexUUIDs().get("pattern1"), notNullValue()); |
| 400 | + assertThat(autoFollowMetadataResult.getFollowedLeaderIndexUUIDs().get("pattern1").size(), equalTo(1)); |
| 401 | + assertThat(autoFollowMetadataResult.getFollowedLeaderIndexUUIDs().get("pattern1").get(0), equalTo("index1")); |
| 402 | + } |
| 403 | + |
| 404 | + public void testRecordLeaderIndexAsFollowFunctionNoEntry() { |
| 405 | + AutoFollowMetadata autoFollowMetadata = new AutoFollowMetadata(Collections.emptyMap(), Collections.emptyMap(), |
| 406 | + Collections.emptyMap()); |
| 407 | + ClusterState clusterState = new ClusterState.Builder(new ClusterName("name")) |
| 408 | + .metaData(new MetaData.Builder().putCustom(AutoFollowMetadata.TYPE, autoFollowMetadata)) |
| 409 | + .build(); |
| 410 | + Function<ClusterState, ClusterState> function = recordLeaderIndexAsFollowFunction("pattern1", new Index("index1", "index1")); |
| 411 | + |
| 412 | + ClusterState result = function.apply(clusterState); |
| 413 | + assertThat(result, sameInstance(clusterState)); |
| 414 | + } |
| 415 | + |
387 | 416 | public void testGetFollowerIndexName() {
|
388 | 417 | AutoFollowPattern autoFollowPattern = new AutoFollowPattern("remote", Collections.singletonList("metrics-*"), null, null,
|
389 | 418 | null, null, null, null, null, null, null, null, null);
|
|
0 commit comments