77
88package org .elasticsearch .xpack .esql .action ;
99
10+ import org .apache .logging .log4j .Level ;
11+ import org .apache .logging .log4j .core .LogEvent ;
1012import org .apache .lucene .search .DocIdSetIterator ;
1113import org .elasticsearch .ExceptionsHelper ;
1214import org .elasticsearch .action .ActionFuture ;
1618import org .elasticsearch .client .internal .Client ;
1719import org .elasticsearch .common .Strings ;
1820import org .elasticsearch .common .collect .Iterators ;
21+ import org .elasticsearch .common .logging .Loggers ;
1922import org .elasticsearch .common .settings .Settings ;
2023import org .elasticsearch .common .util .CollectionUtils ;
2124import org .elasticsearch .common .util .concurrent .AbstractRunnable ;
2225import org .elasticsearch .compute .lucene .LuceneSourceOperator ;
2326import org .elasticsearch .compute .lucene .read .ValuesSourceReaderOperatorStatus ;
27+ import org .elasticsearch .compute .operator .Driver ;
2428import org .elasticsearch .compute .operator .DriverStatus ;
2529import org .elasticsearch .compute .operator .DriverTaskRunner ;
2630import org .elasticsearch .compute .operator .OperatorStatus ;
3943import org .elasticsearch .threadpool .ThreadPool ;
4044import org .elasticsearch .transport .TransportService ;
4145import org .elasticsearch .xpack .esql .EsqlTestUtils ;
46+ import org .elasticsearch .xpack .esql .MockAppender ;
4247import org .elasticsearch .xpack .esql .plugin .QueryPragmas ;
4348import org .hamcrest .Matcher ;
49+ import org .junit .AfterClass ;
4450import org .junit .Before ;
51+ import org .junit .BeforeClass ;
4552
4653import java .io .IOException ;
4754import java .util .ArrayList ;
6673import static org .hamcrest .Matchers .in ;
6774import static org .hamcrest .Matchers .lessThanOrEqualTo ;
6875import static org .hamcrest .Matchers .not ;
76+ import static org .hamcrest .Matchers .startsWith ;
6977
7078/**
7179 * Tests that we expose a reasonable task status.
@@ -78,6 +86,25 @@ public class EsqlActionTaskIT extends AbstractPausableIntegTestCase {
7886
7987 private static final Logger LOGGER = LogManager .getLogger (EsqlActionTaskIT .class );
8088
89+ static MockAppender driverMockAppender ;
90+ static org .apache .logging .log4j .Logger driverLog = org .apache .logging .log4j .LogManager .getLogger (Driver .class );
91+ static Level origDriverLogLevel = driverLog .getLevel ();
92+
93+ @ BeforeClass
94+ public static void init () throws IllegalAccessException {
95+ driverMockAppender = new MockAppender ("mock_appender" );
96+ driverMockAppender .start ();
97+ Loggers .addAppender (driverLog , driverMockAppender );
98+ Loggers .setLevel (driverLog , Level .DEBUG );
99+ }
100+
101+ @ AfterClass
102+ public static void cleanup () {
103+ Loggers .removeAppender (driverLog , driverMockAppender );
104+ driverMockAppender .stop ();
105+ Loggers .setLevel (driverLog , origDriverLogLevel );
106+ }
107+
81108 private Boolean nodeLevelReduction ;
82109
83110 /**
@@ -214,6 +241,7 @@ public void testCancelRead() throws Exception {
214241 } finally {
215242 scriptPermits .release (numberOfDocs ());
216243 }
244+ assertCancelledLog ();
217245 }
218246
219247 public void testCancelMerge () throws Exception {
@@ -226,6 +254,7 @@ public void testCancelMerge() throws Exception {
226254 } finally {
227255 scriptPermits .release (numberOfDocs ());
228256 }
257+ assertCancelledLog ();
229258 }
230259
231260 public void testCancelEsqlTask () throws Exception {
@@ -244,6 +273,14 @@ public void testCancelEsqlTask() throws Exception {
244273 } finally {
245274 scriptPermits .release (numberOfDocs ());
246275 }
276+ assertCancelledLog ();
277+ }
278+
279+ private void assertCancelledLog () {
280+ LogEvent event = driverMockAppender .getLastEventAndReset ();
281+ assertThat (event .getLevel (), equalTo (Level .DEBUG ));
282+ assertThat (event .getMessage ().getFormattedMessage (), startsWith ("Cancelling running driver [" ));
283+ assertThat (event .getThrown ().getClass (), equalTo (TaskCancelledException .class ));
247284 }
248285
249286 private ActionFuture <EsqlQueryResponse > startEsql () {
0 commit comments