@@ -76,6 +76,7 @@ public class MultiClusterSpecIT extends EsqlSpecTestCase {
76
76
77
77
private static TestFeatureService remoteFeaturesService ;
78
78
private static RestClient remoteClusterClient ;
79
+ private static DataLocation dataLocation = null ;
79
80
80
81
@ ParametersFactory (argumentFormatting = "%2$s.%3$s" )
81
82
public static List <Object []> readScriptSpec () throws Exception {
@@ -188,8 +189,9 @@ protected RestClient buildClient(Settings settings, HttpHost[] localHosts) throw
188
189
*/
189
190
static RestClient twoClients (RestClient localClient , RestClient remoteClient ) throws IOException {
190
191
RestClient twoClients = mock (RestClient .class );
192
+ assertNotNull ("data location was set" , dataLocation );
191
193
// write to a single cluster for now due to the precision of some functions such as avg and tests related to updates
192
- final RestClient bulkClient = randomFrom (localClient , remoteClient );
194
+ final RestClient bulkClient = dataLocation == DataLocation . REMOTE_ONLY ? remoteClient : randomFrom (localClient , remoteClient );
193
195
when (twoClients .performRequest (any ())).then (invocation -> {
194
196
Request request = invocation .getArgument (0 );
195
197
String endpoint = request .getEndpoint ();
@@ -214,6 +216,11 @@ static RestClient twoClients(RestClient localClient, RestClient remoteClient) th
214
216
return twoClients ;
215
217
}
216
218
219
+ enum DataLocation {
220
+ REMOTE_ONLY ,
221
+ ANY_CLUSTER
222
+ }
223
+
217
224
static Request [] cloneRequests (Request orig , int numClones ) throws IOException {
218
225
Request [] clones = new Request [numClones ];
219
226
for (int i = 0 ; i < clones .length ; i ++) {
@@ -238,26 +245,33 @@ static Request[] cloneRequests(Request orig, int numClones) throws IOException {
238
245
* Convert FROM employees ... => FROM *:employees,employees
239
246
*/
240
247
static CsvSpecReader .CsvTestCase convertToRemoteIndices (CsvSpecReader .CsvTestCase testCase ) {
248
+ if (dataLocation == null ) {
249
+ dataLocation = randomFrom (DataLocation .values ());
250
+ }
241
251
String query = testCase .query ;
242
252
String [] commands = query .split ("\\ |" );
243
253
String first = commands [0 ].trim ();
244
254
if (commands [0 ].toLowerCase (Locale .ROOT ).startsWith ("from" )) {
245
255
String [] parts = commands [0 ].split ("(?i)metadata" );
246
256
assert parts .length >= 1 : parts ;
247
257
String fromStatement = parts [0 ];
248
-
249
- String [] localIndices = fromStatement .substring ("FROM " .length ()).split ("," );
250
- String remoteIndices = Arrays .stream (localIndices )
251
- .map (index -> "*:" + index .trim () + "," + index .trim ())
252
- .collect (Collectors .joining ("," ));
253
- var newFrom = "FROM " + remoteIndices + " " + commands [0 ].substring (fromStatement .length ());
258
+ String index = fromStatement .substring ("FROM " .length ());
259
+ if (dataLocation == DataLocation .REMOTE_ONLY && randomBoolean ()) {
260
+ index = remoteIndices (index );
261
+ } else {
262
+ index = index + "," + remoteIndices (index );
263
+ }
264
+ var newFrom = "FROM " + index + " " + commands [0 ].substring (fromStatement .length ());
254
265
testCase .query = newFrom + query .substring (first .length ());
255
266
}
256
267
if (commands [0 ].toLowerCase (Locale .ROOT ).startsWith ("ts " )) {
257
268
String [] parts = commands [0 ].split ("\\ s+" );
258
269
assert parts .length >= 2 : commands [0 ];
259
- String [] indices = parts [1 ].split ("," );
260
- parts [1 ] = Arrays .stream (indices ).map (index -> "*:" + index + "," + index ).collect (Collectors .joining ("," ));
270
+ if (dataLocation == DataLocation .REMOTE_ONLY && randomBoolean ()) {
271
+ parts [1 ] = remoteIndices (parts [1 ]);
272
+ } else {
273
+ parts [1 ] = parts [1 ] + "," + remoteIndices (parts [1 ]);
274
+ }
261
275
String newNewMetrics = String .join (" " , parts );
262
276
testCase .query = newNewMetrics + query .substring (first .length ());
263
277
}
@@ -274,6 +288,11 @@ static CsvSpecReader.CsvTestCase convertToRemoteIndices(CsvSpecReader.CsvTestCas
274
288
return testCase ;
275
289
}
276
290
291
+ static String remoteIndices (String localIndices ) {
292
+ String [] parts = localIndices .split ("," );
293
+ return Arrays .stream (parts ).map (index -> "*:" + index .trim ()).collect (Collectors .joining ("," ));
294
+ }
295
+
277
296
static boolean hasIndexMetadata (String query ) {
278
297
String [] commands = query .split ("\\ |" );
279
298
if (commands [0 ].trim ().toLowerCase (Locale .ROOT ).startsWith ("from" )) {
0 commit comments