1111import org .elasticsearch .common .Strings ;
1212import org .elasticsearch .common .settings .Settings ;
1313
14+ import java .io .IOException ;
1415import java .util .Map ;
16+ import java .util .concurrent .TimeUnit ;
1517
1618import static org .hamcrest .Matchers .equalTo ;
1719
1820public class AutoFollowIT extends ESCCRRestTestCase {
1921
20- public void testAutoFollowPatterns () throws Exception {
22+ public void testMultipleAutoFollowPatternsDifferentClusters () throws Exception {
2123 if ("follow" .equals (targetCluster ) == false ) {
24+ logger .info ("skipping test, waiting for target cluster [follow]" );
2225 return ;
2326 }
27+
28+ int initialNumberOfSuccessfulFollowedIndices = getNumberOfSuccessfulFollowedIndices ();
2429 Request putPatternRequest = new Request ("PUT" , "/_ccr/auto_follow/leader_cluster_pattern" );
2530 putPatternRequest .setJsonEntity ("{\" leader_index_patterns\" : [\" logs-*\" ], \" remote_cluster\" : \" leader_cluster\" }" );
2631 assertOK (client ().performRequest (putPatternRequest ));
@@ -54,10 +59,7 @@ public void testAutoFollowPatterns() throws Exception {
5459 }
5560 }
5661 assertBusy (() -> {
57- Request statsRequest = new Request ("GET" , "/_ccr/stats" );
58- Map <?, ?> response = toMap (client ().performRequest (statsRequest ));
59- Map <?, ?> autoFollowStats = (Map <?, ?>) response .get ("auto_follow_stats" );
60- assertThat (autoFollowStats .get ("number_of_successful_follow_indices" ), equalTo (2 ));
62+ assertThat (getNumberOfSuccessfulFollowedIndices (), equalTo (initialNumberOfSuccessfulFollowedIndices + 2 ));
6163
6264 ensureYellow ("logs-20190101" );
6365 ensureYellow ("logs-20200101" );
@@ -66,4 +68,49 @@ public void testAutoFollowPatterns() throws Exception {
6668 });
6769 }
6870
71+ public void testAutoFollowPatterns () throws Exception {
72+ if ("follow" .equals (targetCluster ) == false ) {
73+ logger .info ("skipping test, waiting for target cluster [follow]" );
74+ return ;
75+ }
76+
77+ int initialNumberOfSuccessfulFollowedIndices = getNumberOfSuccessfulFollowedIndices ();
78+ Request request = new Request ("PUT" , "/_ccr/auto_follow/test_pattern" );
79+ request .setJsonEntity ("{\" leader_index_patterns\" : [\" metrics-*\" ], \" remote_cluster\" : \" leader_cluster\" }" );
80+ assertOK (client ().performRequest (request ));
81+
82+ try (RestClient leaderClient = buildLeaderClient ()) {
83+ Settings settings = Settings .builder ()
84+ .put ("index.soft_deletes.enabled" , true )
85+ .build ();
86+ request = new Request ("PUT" , "/metrics-20210101" );
87+ request .setJsonEntity ("{\" settings\" : " + Strings .toString (settings ) +
88+ ", \" mappings\" : {\" _doc\" : {\" properties\" : {\" field\" : {\" type\" : \" keyword\" }}}} }" );
89+ assertOK (leaderClient .performRequest (request ));
90+
91+ for (int i = 0 ; i < 5 ; i ++) {
92+ String id = Integer .toString (i );
93+ index (leaderClient , "metrics-20210101" , id , "field" , i , "filtered_field" , "true" );
94+ }
95+ }
96+
97+ assertBusy (() -> {
98+ assertThat (getNumberOfSuccessfulFollowedIndices (), equalTo (initialNumberOfSuccessfulFollowedIndices + 1 ));
99+ ensureYellow ("metrics-20210101" );
100+ verifyDocuments ("metrics-20210101" , 5 , "filtered_field:true" );
101+ });
102+ assertBusy (() -> {
103+ verifyCcrMonitoring ("metrics-20210101" , "metrics-20210101" );
104+ verifyAutoFollowMonitoring ();
105+ }, 30 , TimeUnit .SECONDS );
106+ }
107+
108+ private int getNumberOfSuccessfulFollowedIndices () throws IOException {
109+ Request statsRequest = new Request ("GET" , "/_ccr/stats" );
110+ Map <?, ?> response = toMap (client ().performRequest (statsRequest ));
111+ response = (Map <?, ?>) response .get ("auto_follow_stats" );
112+ return (Integer ) response .get ("number_of_successful_follow_indices" );
113+ }
114+
115+
69116}
0 commit comments