3131import org .elasticsearch .xcontent .ToXContent ;
3232import org .elasticsearch .xcontent .XContentBuilder ;
3333import org .elasticsearch .xcontent .XContentType ;
34+ import org .elasticsearch .xpack .esql .AssertWarnings ;
3435import org .elasticsearch .xpack .esql .EsqlTestUtils ;
3536import org .elasticsearch .xpack .esql .action .EsqlCapabilities ;
3637import org .junit .After ;
5354import java .util .Map ;
5455import java .util .Set ;
5556import java .util .function .IntFunction ;
56- import java .util .regex .Pattern ;
5757
5858import static java .util .Collections .emptySet ;
5959import static java .util .Map .entry ;
@@ -83,9 +83,6 @@ public abstract class RestEsqlTestCase extends ESRestTestCase {
8383
8484 private static final Logger LOGGER = LogManager .getLogger (RestEsqlTestCase .class );
8585
86- private static final List <String > NO_WARNINGS = List .of ();
87- private static final List <Pattern > NO_WARNINGS_REGEX = List .of ();
88-
8986 private static final String MAPPING_ALL_TYPES ;
9087
9188 static {
@@ -379,7 +376,7 @@ public void testCSVNoHeaderMode() throws IOException {
379376 options .addHeader ("Content-Type" , mediaType );
380377 options .addHeader ("Accept" , "text/csv; header=absent" );
381378 request .setOptions (options );
382- HttpEntity entity = performRequest (request , NO_WARNINGS , NO_WARNINGS_REGEX );
379+ HttpEntity entity = performRequest (request , new AssertWarnings . NoWarnings () );
383380 String actual = Streams .copyToString (new InputStreamReader (entity .getContent (), StandardCharsets .UTF_8 ));
384381 assertEquals ("keyword0,0\r \n " , actual );
385382 }
@@ -430,11 +427,13 @@ public void testOutOfRangeComparisons() throws IOException {
430427 for (String truePredicate : trueForSingleValuesPredicates ) {
431428 String comparison = fieldWithType + truePredicate ;
432429 var query = requestObjectBuilder ().query (format (null , "from {} | where {}" , testIndexName (), comparison ));
433- List <String > expectedWarnings = List .of (
434- "Line 1:29: evaluation of [" + comparison + "] failed, treating result as null. Only first 20 failures recorded." ,
435- "Line 1:29: java.lang.IllegalArgumentException: single-value function encountered multi-value"
430+ AssertWarnings assertWarnings = new AssertWarnings .ExactStrings (
431+ List .of (
432+ "Line 1:29: evaluation of [" + comparison + "] failed, treating result as null. Only first 20 failures recorded." ,
433+ "Line 1:29: java.lang.IllegalArgumentException: single-value function encountered multi-value"
434+ )
436435 );
437- var result = runEsql (query , expectedWarnings , NO_WARNINGS_REGEX , mode );
436+ var result = runEsql (query , assertWarnings , mode );
438437
439438 var values = as (result .get ("values" ), ArrayList .class );
440439 assertThat (
@@ -504,7 +503,7 @@ public void testInternalRange() throws IOException {
504503
505504 for (String p : predicates ) {
506505 var query = requestObjectBuilder ().query (format (null , "from {} | where {}" , testIndexName (), p ));
507- var result = runEsql (query , List . of (), NO_WARNINGS_REGEX , mode );
506+ var result = runEsql (query , new AssertWarnings . NoWarnings () , mode );
508507 var values = as (result .get ("values" ), ArrayList .class );
509508 assertThat (
510509 format (null , "Comparison [{}] should return all rows with single values." , p ),
@@ -996,35 +995,26 @@ private static String expectedTextBody(String format, int count, @Nullable Chara
996995 }
997996
998997 public Map <String , Object > runEsql (RequestObjectBuilder requestObject ) throws IOException {
999- return runEsql (requestObject , NO_WARNINGS , NO_WARNINGS_REGEX , mode );
998+ return runEsql (requestObject , new AssertWarnings . NoWarnings () , mode );
1000999 }
10011000
10021001 public static Map <String , Object > runEsqlSync (RequestObjectBuilder requestObject ) throws IOException {
1003- return runEsqlSync (requestObject , NO_WARNINGS , NO_WARNINGS_REGEX );
1002+ return runEsqlSync (requestObject , new AssertWarnings . NoWarnings () );
10041003 }
10051004
10061005 public static Map <String , Object > runEsqlAsync (RequestObjectBuilder requestObject ) throws IOException {
1007- return runEsqlAsync (requestObject , NO_WARNINGS , NO_WARNINGS_REGEX );
1006+ return runEsqlAsync (requestObject , new AssertWarnings . NoWarnings () );
10081007 }
10091008
1010- static Map <String , Object > runEsql (
1011- RequestObjectBuilder requestObject ,
1012- List <String > expectedWarnings ,
1013- List <Pattern > expectedWarningsRegex ,
1014- Mode mode
1015- ) throws IOException {
1009+ static Map <String , Object > runEsql (RequestObjectBuilder requestObject , AssertWarnings assertWarnings , Mode mode ) throws IOException {
10161010 if (mode == ASYNC ) {
1017- return runEsqlAsync (requestObject , expectedWarnings , expectedWarningsRegex );
1011+ return runEsqlAsync (requestObject , assertWarnings );
10181012 } else {
1019- return runEsqlSync (requestObject , expectedWarnings , expectedWarningsRegex );
1013+ return runEsqlSync (requestObject , assertWarnings );
10201014 }
10211015 }
10221016
1023- public static Map <String , Object > runEsqlSync (
1024- RequestObjectBuilder requestObject ,
1025- List <String > expectedWarnings ,
1026- List <Pattern > expectedWarningsRegex
1027- ) throws IOException {
1017+ public static Map <String , Object > runEsqlSync (RequestObjectBuilder requestObject , AssertWarnings assertWarnings ) throws IOException {
10281018 requestObject .build ();
10291019 Request request = prepareRequest (SYNC );
10301020 String mediaType = attachBody (requestObject , request );
@@ -1040,15 +1030,11 @@ public static Map<String, Object> runEsqlSync(
10401030 }
10411031 request .setOptions (options );
10421032
1043- HttpEntity entity = performRequest (request , expectedWarnings , expectedWarningsRegex );
1033+ HttpEntity entity = performRequest (request , assertWarnings );
10441034 return entityToMap (entity , requestObject .contentType ());
10451035 }
10461036
1047- public static Map <String , Object > runEsqlAsync (
1048- RequestObjectBuilder requestObject ,
1049- List <String > expectedWarnings ,
1050- List <Pattern > expectedWarningsRegex
1051- ) throws IOException {
1037+ public static Map <String , Object > runEsqlAsync (RequestObjectBuilder requestObject , AssertWarnings assertWarnings ) throws IOException {
10521038 addAsyncParameters (requestObject );
10531039 requestObject .build ();
10541040 Request request = prepareRequest (ASYNC );
@@ -1088,7 +1074,7 @@ public static Map<String, Object> runEsqlAsync(
10881074 assertThat (response .getHeader ("X-Elasticsearch-Async-Id" ), nullValue ());
10891075 assertThat (response .getHeader ("X-Elasticsearch-Async-Is-Running" ), is ("?0" ));
10901076 }
1091- assertWarnings (response , expectedWarnings , expectedWarningsRegex );
1077+ assertWarnings (response , assertWarnings );
10921078 json .remove ("is_running" ); // remove this to not mess up later map assertions
10931079 return Collections .unmodifiableMap (json );
10941080 } else {
@@ -1098,7 +1084,7 @@ public static Map<String, Object> runEsqlAsync(
10981084 if (isRunning == false ) {
10991085 // must have completed immediately so keep_on_completion must be true
11001086 assertThat (requestObject .keepOnCompletion (), is (true ));
1101- assertWarnings (response , expectedWarnings , expectedWarningsRegex );
1087+ assertWarnings (response , assertWarnings );
11021088 // we already have the results, but let's remember them so that we can compare to async get
11031089 initialColumns = json .get ("columns" );
11041090 initialValues = json .get ("values" );
@@ -1128,7 +1114,7 @@ public static Map<String, Object> runEsqlAsync(
11281114 assertEquals (initialValues , result .get ("values" ));
11291115 }
11301116
1131- assertWarnings (response , expectedWarnings , expectedWarningsRegex );
1117+ assertWarnings (response , assertWarnings );
11321118 assertDeletable (id );
11331119 return removeAsyncProperties (result );
11341120 }
@@ -1202,7 +1188,7 @@ static String runEsqlAsTextWithFormat(RequestObjectBuilder builder, String forma
12021188 }
12031189 request .setOptions (options );
12041190
1205- HttpEntity entity = performRequest (request , NO_WARNINGS , NO_WARNINGS_REGEX );
1191+ HttpEntity entity = performRequest (request , new AssertWarnings . NoWarnings () );
12061192 return Streams .copyToString (new InputStreamReader (entity .getContent (), StandardCharsets .UTF_8 ));
12071193 }
12081194
@@ -1235,9 +1221,8 @@ private static String attachBody(RequestObjectBuilder requestObject, Request req
12351221 return mediaType ;
12361222 }
12371223
1238- private static HttpEntity performRequest (Request request , List <String > allowedWarnings , List <Pattern > allowedWarningsRegex )
1239- throws IOException {
1240- return assertWarnings (performRequest (request ), allowedWarnings , allowedWarningsRegex );
1224+ private static HttpEntity performRequest (Request request , AssertWarnings assertWarnings ) throws IOException {
1225+ return assertWarnings (performRequest (request ), assertWarnings );
12411226 }
12421227
12431228 private static Response performRequest (Request request ) throws IOException {
@@ -1250,13 +1235,13 @@ private static Response performRequest(Request request) throws IOException {
12501235 return response ;
12511236 }
12521237
1253- private static HttpEntity assertWarnings (Response response , List < String > allowedWarnings , List < Pattern > allowedWarningsRegex ) {
1238+ private static HttpEntity assertWarnings (Response response , AssertWarnings assertWarnings ) {
12541239 List <String > warnings = new ArrayList <>(response .getWarnings ());
12551240 warnings .removeAll (mutedWarnings ());
12561241 if (shouldLog ()) {
12571242 LOGGER .info ("RESPONSE warnings (after muted)={}" , warnings );
12581243 }
1259- EsqlTestUtils .assertWarnings (warnings , allowedWarnings , allowedWarningsRegex );
1244+ assertWarnings .assertWarnings (warnings );
12601245 return response .getEntity ();
12611246 }
12621247
0 commit comments