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 }
@@ -431,11 +428,13 @@ public void testOutOfRangeComparisons() throws IOException {
431428 for (String truePredicate : trueForSingleValuesPredicates ) {
432429 String comparison = fieldWithType + truePredicate ;
433430 var query = requestObjectBuilder ().query (format (null , "from {} | where {}" , testIndexName (), comparison ));
434- List <String > expectedWarnings = List .of (
435- "Line 1:29: evaluation of [" + comparison + "] failed, treating result as null. Only first 20 failures recorded." ,
436- "Line 1:29: java.lang.IllegalArgumentException: single-value function encountered multi-value"
431+ AssertWarnings assertWarnings = new AssertWarnings .ExactStrings (
432+ List .of (
433+ "Line 1:29: evaluation of [" + comparison + "] failed, treating result as null. Only first 20 failures recorded." ,
434+ "Line 1:29: java.lang.IllegalArgumentException: single-value function encountered multi-value"
435+ )
437436 );
438- var result = runEsql (query , expectedWarnings , NO_WARNINGS_REGEX , mode );
437+ var result = runEsql (query , assertWarnings , mode );
439438
440439 var values = as (result .get ("values" ), ArrayList .class );
441440 assertThat (
@@ -505,7 +504,7 @@ public void testInternalRange() throws IOException {
505504
506505 for (String p : predicates ) {
507506 var query = requestObjectBuilder ().query (format (null , "from {} | where {}" , testIndexName (), p ));
508- var result = runEsql (query , List . of (), NO_WARNINGS_REGEX , mode );
507+ var result = runEsql (query , new AssertWarnings . NoWarnings () , mode );
509508 var values = as (result .get ("values" ), ArrayList .class );
510509 assertThat (
511510 format (null , "Comparison [{}] should return all rows with single values." , p ),
@@ -997,35 +996,26 @@ private static String expectedTextBody(String format, int count, @Nullable Chara
997996 }
998997
999998 public Map <String , Object > runEsql (RequestObjectBuilder requestObject ) throws IOException {
1000- return runEsql (requestObject , NO_WARNINGS , NO_WARNINGS_REGEX , mode );
999+ return runEsql (requestObject , new AssertWarnings . NoWarnings () , mode );
10011000 }
10021001
10031002 public static Map <String , Object > runEsqlSync (RequestObjectBuilder requestObject ) throws IOException {
1004- return runEsqlSync (requestObject , NO_WARNINGS , NO_WARNINGS_REGEX );
1003+ return runEsqlSync (requestObject , new AssertWarnings . NoWarnings () );
10051004 }
10061005
10071006 public static Map <String , Object > runEsqlAsync (RequestObjectBuilder requestObject ) throws IOException {
1008- return runEsqlAsync (requestObject , NO_WARNINGS , NO_WARNINGS_REGEX );
1007+ return runEsqlAsync (requestObject , new AssertWarnings . NoWarnings () );
10091008 }
10101009
1011- static Map <String , Object > runEsql (
1012- RequestObjectBuilder requestObject ,
1013- List <String > expectedWarnings ,
1014- List <Pattern > expectedWarningsRegex ,
1015- Mode mode
1016- ) throws IOException {
1010+ static Map <String , Object > runEsql (RequestObjectBuilder requestObject , AssertWarnings assertWarnings , Mode mode ) throws IOException {
10171011 if (mode == ASYNC ) {
1018- return runEsqlAsync (requestObject , expectedWarnings , expectedWarningsRegex );
1012+ return runEsqlAsync (requestObject , assertWarnings );
10191013 } else {
1020- return runEsqlSync (requestObject , expectedWarnings , expectedWarningsRegex );
1014+ return runEsqlSync (requestObject , assertWarnings );
10211015 }
10221016 }
10231017
1024- public static Map <String , Object > runEsqlSync (
1025- RequestObjectBuilder requestObject ,
1026- List <String > expectedWarnings ,
1027- List <Pattern > expectedWarningsRegex
1028- ) throws IOException {
1018+ public static Map <String , Object > runEsqlSync (RequestObjectBuilder requestObject , AssertWarnings assertWarnings ) throws IOException {
10291019 requestObject .build ();
10301020 Request request = prepareRequest (SYNC );
10311021 String mediaType = attachBody (requestObject , request );
@@ -1041,15 +1031,11 @@ public static Map<String, Object> runEsqlSync(
10411031 }
10421032 request .setOptions (options );
10431033
1044- HttpEntity entity = performRequest (request , expectedWarnings , expectedWarningsRegex );
1034+ HttpEntity entity = performRequest (request , assertWarnings );
10451035 return entityToMap (entity , requestObject .contentType ());
10461036 }
10471037
1048- public static Map <String , Object > runEsqlAsync (
1049- RequestObjectBuilder requestObject ,
1050- List <String > expectedWarnings ,
1051- List <Pattern > expectedWarningsRegex
1052- ) throws IOException {
1038+ public static Map <String , Object > runEsqlAsync (RequestObjectBuilder requestObject , AssertWarnings assertWarnings ) throws IOException {
10531039 addAsyncParameters (requestObject );
10541040 requestObject .build ();
10551041 Request request = prepareRequest (ASYNC );
@@ -1089,7 +1075,7 @@ public static Map<String, Object> runEsqlAsync(
10891075 assertThat (response .getHeader ("X-Elasticsearch-Async-Id" ), nullValue ());
10901076 assertThat (response .getHeader ("X-Elasticsearch-Async-Is-Running" ), is ("?0" ));
10911077 }
1092- assertWarnings (response , expectedWarnings , expectedWarningsRegex );
1078+ assertWarnings (response , assertWarnings );
10931079 json .remove ("is_running" ); // remove this to not mess up later map assertions
10941080 return Collections .unmodifiableMap (json );
10951081 } else {
@@ -1099,7 +1085,7 @@ public static Map<String, Object> runEsqlAsync(
10991085 if (isRunning == false ) {
11001086 // must have completed immediately so keep_on_completion must be true
11011087 assertThat (requestObject .keepOnCompletion (), is (true ));
1102- assertWarnings (response , expectedWarnings , expectedWarningsRegex );
1088+ assertWarnings (response , assertWarnings );
11031089 // we already have the results, but let's remember them so that we can compare to async get
11041090 initialColumns = json .get ("columns" );
11051091 initialValues = json .get ("values" );
@@ -1129,7 +1115,7 @@ public static Map<String, Object> runEsqlAsync(
11291115 assertEquals (initialValues , result .get ("values" ));
11301116 }
11311117
1132- assertWarnings (response , expectedWarnings , expectedWarningsRegex );
1118+ assertWarnings (response , assertWarnings );
11331119 assertDeletable (id );
11341120 return removeAsyncProperties (result );
11351121 }
@@ -1203,7 +1189,7 @@ static String runEsqlAsTextWithFormat(RequestObjectBuilder builder, String forma
12031189 }
12041190 request .setOptions (options );
12051191
1206- HttpEntity entity = performRequest (request , NO_WARNINGS , NO_WARNINGS_REGEX );
1192+ HttpEntity entity = performRequest (request , new AssertWarnings . NoWarnings () );
12071193 return Streams .copyToString (new InputStreamReader (entity .getContent (), StandardCharsets .UTF_8 ));
12081194 }
12091195
@@ -1236,9 +1222,8 @@ private static String attachBody(RequestObjectBuilder requestObject, Request req
12361222 return mediaType ;
12371223 }
12381224
1239- private static HttpEntity performRequest (Request request , List <String > allowedWarnings , List <Pattern > allowedWarningsRegex )
1240- throws IOException {
1241- return assertWarnings (performRequest (request ), allowedWarnings , allowedWarningsRegex );
1225+ private static HttpEntity performRequest (Request request , AssertWarnings assertWarnings ) throws IOException {
1226+ return assertWarnings (performRequest (request ), assertWarnings );
12421227 }
12431228
12441229 private static Response performRequest (Request request ) throws IOException {
@@ -1251,13 +1236,13 @@ private static Response performRequest(Request request) throws IOException {
12511236 return response ;
12521237 }
12531238
1254- private static HttpEntity assertWarnings (Response response , List < String > allowedWarnings , List < Pattern > allowedWarningsRegex ) {
1239+ private static HttpEntity assertWarnings (Response response , AssertWarnings assertWarnings ) {
12551240 List <String > warnings = new ArrayList <>(response .getWarnings ());
12561241 warnings .removeAll (mutedWarnings ());
12571242 if (shouldLog ()) {
12581243 LOGGER .info ("RESPONSE warnings (after muted)={}" , warnings );
12591244 }
1260- EsqlTestUtils .assertWarnings (warnings , allowedWarnings , allowedWarningsRegex );
1245+ assertWarnings .assertWarnings (warnings );
12611246 return response .getEntity ();
12621247 }
12631248
0 commit comments