3737import java .util .Arrays ;
3838import java .util .EnumSet ;
3939import java .util .HashMap ;
40- import java .util .HashSet ;
4140import java .util .List ;
4241import java .util .Locale ;
4342import java .util .Map ;
4948import static org .elasticsearch .xpack .esql .session .EsqlCCSUtils .initCrossClusterState ;
5049import static org .hamcrest .Matchers .containsInAnyOrder ;
5150import static org .hamcrest .Matchers .containsString ;
51+ import static org .hamcrest .Matchers .empty ;
5252import static org .hamcrest .Matchers .equalTo ;
5353import static org .hamcrest .Matchers .greaterThanOrEqualTo ;
5454import static org .hamcrest .Matchers .hasSize ;
@@ -59,87 +59,76 @@ public class EsqlCCSUtilsTests extends ESTestCase {
5959 private final String REMOTE1_ALIAS = "remote1" ;
6060 private final String REMOTE2_ALIAS = "remote2" ;
6161
62- public void testCreateIndexExpressionFromAvailableClusters () {
62+ public void testQualifyWithRunningRemotes () {
6363
6464 // no clusters marked as skipped
6565 {
6666 EsqlExecutionInfo executionInfo = new EsqlExecutionInfo (true );
67- executionInfo .swapCluster (LOCAL_CLUSTER_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (LOCAL_CLUSTER_ALIAS , "logs* " , false ));
68- executionInfo .swapCluster (REMOTE1_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "* " , true ));
69- executionInfo .swapCluster (REMOTE2_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE2_ALIAS , "mylogs1,mylogs2,logs* " , true ));
67+ executionInfo .swapCluster (LOCAL_CLUSTER_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (LOCAL_CLUSTER_ALIAS , "" , false ));
68+ executionInfo .swapCluster (REMOTE1_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "" , true ));
69+ executionInfo .swapCluster (REMOTE2_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE2_ALIAS , "" , true ));
7070
71- String indexExpr = EsqlCCSUtils .createIndexExpressionFromAvailableClusters (executionInfo );
72- List <String > list = Arrays .stream (Strings .splitStringByCommaToArray (indexExpr )).toList ();
73- assertThat (list .size (), equalTo (5 ));
7471 assertThat (
75- new HashSet <>( list ),
76- equalTo ( Strings . commaDelimitedListToSet ( "logs*, remote1:*, remote2:mylogs1,remote2:mylogs2,remote2:logs*" ) )
72+ asSet ( EsqlCCSUtils . qualifyWithRunningRemotes ( "data" , executionInfo . clusterAliases (), executionInfo ) ),
73+ containsInAnyOrder ( "data" , " remote1:data" , " remote2:data" )
7774 );
7875 }
7976
8077 // one cluster marked as skipped, so not present in revised index expression
8178 {
8279 EsqlExecutionInfo executionInfo = new EsqlExecutionInfo (true );
83- executionInfo .swapCluster (LOCAL_CLUSTER_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (LOCAL_CLUSTER_ALIAS , "logs* " , false ));
84- executionInfo .swapCluster (REMOTE1_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "*,foo " , true ));
80+ executionInfo .swapCluster (LOCAL_CLUSTER_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (LOCAL_CLUSTER_ALIAS , "" , false ));
81+ executionInfo .swapCluster (REMOTE1_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "" , true ));
8582 executionInfo .swapCluster (
8683 REMOTE2_ALIAS ,
87- (k , v ) -> new EsqlExecutionInfo .Cluster (
88- REMOTE2_ALIAS ,
89- "mylogs1,mylogs2,logs*" ,
90- true ,
91- EsqlExecutionInfo .Cluster .Status .SKIPPED
92- )
84+ (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE2_ALIAS , "" , true , EsqlExecutionInfo .Cluster .Status .SKIPPED )
9385 );
9486
95- String indexExpr = EsqlCCSUtils . createIndexExpressionFromAvailableClusters ( executionInfo );
96- List < String > list = Arrays . stream ( Strings . splitStringByCommaToArray ( indexExpr )). toList ();
97- assertThat ( list . size (), equalTo ( 3 ));
98- assertThat ( new HashSet <>( list ), equalTo ( Strings . commaDelimitedListToSet ( "logs*,remote1:*,remote1:foo" )) );
87+ assertThat (
88+ asSet ( EsqlCCSUtils . qualifyWithRunningRemotes ( "data" , executionInfo . clusterAliases (), executionInfo )),
89+ containsInAnyOrder ( "data" , "remote1:data" )
90+ );
9991 }
10092
10193 // two clusters marked as skipped, so only local cluster present in revised index expression
10294 {
10395 EsqlExecutionInfo executionInfo = new EsqlExecutionInfo (true );
104- executionInfo .swapCluster (LOCAL_CLUSTER_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (LOCAL_CLUSTER_ALIAS , "logs* " , false ));
96+ executionInfo .swapCluster (LOCAL_CLUSTER_ALIAS , (k , v ) -> new EsqlExecutionInfo .Cluster (LOCAL_CLUSTER_ALIAS , "" , false ));
10597 executionInfo .swapCluster (
10698 REMOTE1_ALIAS ,
107- (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "*,foo " , true , EsqlExecutionInfo .Cluster .Status .SKIPPED )
99+ (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "" , true , EsqlExecutionInfo .Cluster .Status .SKIPPED )
108100 );
109101 executionInfo .swapCluster (
110102 REMOTE2_ALIAS ,
111- (k , v ) -> new EsqlExecutionInfo .Cluster (
112- REMOTE2_ALIAS ,
113- "mylogs1,mylogs2,logs*" ,
114- true ,
115- EsqlExecutionInfo .Cluster .Status .SKIPPED
116- )
103+ (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE2_ALIAS , "" , true , EsqlExecutionInfo .Cluster .Status .SKIPPED )
117104 );
118105
119- assertThat (EsqlCCSUtils .createIndexExpressionFromAvailableClusters (executionInfo ), equalTo ("logs*" ));
106+ assertThat (
107+ asSet (EsqlCCSUtils .qualifyWithRunningRemotes ("data" , executionInfo .clusterAliases (), executionInfo )),
108+ containsInAnyOrder ("data" )
109+ );
120110 }
121111
122112 // only remotes present and all marked as skipped, so in revised index expression should be empty string
123113 {
124114 EsqlExecutionInfo executionInfo = new EsqlExecutionInfo (true );
125115 executionInfo .swapCluster (
126116 REMOTE1_ALIAS ,
127- (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "*,foo " , true , EsqlExecutionInfo .Cluster .Status .SKIPPED )
117+ (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE1_ALIAS , "" , true , EsqlExecutionInfo .Cluster .Status .SKIPPED )
128118 );
129119 executionInfo .swapCluster (
130120 REMOTE2_ALIAS ,
131- (k , v ) -> new EsqlExecutionInfo .Cluster (
132- REMOTE2_ALIAS ,
133- "mylogs1,mylogs2,logs*" ,
134- true ,
135- EsqlExecutionInfo .Cluster .Status .SKIPPED
136- )
121+ (k , v ) -> new EsqlExecutionInfo .Cluster (REMOTE2_ALIAS , "" , true , EsqlExecutionInfo .Cluster .Status .SKIPPED )
137122 );
138123
139- assertThat (EsqlCCSUtils .createIndexExpressionFromAvailableClusters ( executionInfo ), equalTo ( "" ));
124+ assertThat (asSet ( EsqlCCSUtils .qualifyWithRunningRemotes ( "data" , executionInfo . clusterAliases ( ), executionInfo )), empty ( ));
140125 }
141126 }
142127
128+ private static Set <String > asSet (String expr ) {
129+ return Set .of (Strings .splitStringByCommaToArray (expr ));
130+ }
131+
143132 public void testUpdateExecutionInfoWithUnavailableClusters () {
144133
145134 // skip_unavailable=true clusters are unavailable, both marked as SKIPPED
0 commit comments