3636import static org .junit .jupiter .api .Assertions .assertThrows ;
3737import static org .junit .jupiter .api .Assertions .assertTrue ;
3838
39+ import net .sf .jsqlparser .statement .UnsupportedStatement ;
40+ import net .sf .jsqlparser .statement .select .PlainSelect ;
3941import net .sf .jsqlparser .test .MemoryLeakVerifier ;
40- import org .junit .jupiter .api .Disabled ;
4142import org .junit .jupiter .api .Test ;
4243import org .junit .jupiter .api .function .Executable ;
4344
@@ -217,12 +218,19 @@ public void accept(Statement statement) {
217218 }
218219
219220 @ Test
220- @ Disabled
221221 public void testParseStatementsFail () throws Exception {
222- // This will not fail, but always return the Unsupported Statements
223- // Since we can't LOOKAHEAD in the Statements() production
224- assertThrows (JSQLParserException .class ,
225- () -> CCJSqlParserUtil .parseStatements ("select * from dual;WHATEVER!!" ));
222+ String sqlStr = "select * from dual;WHATEVER!!" ;
223+
224+ // Won't fail but return Unsupported Statement instead
225+ assertDoesNotThrow (new Executable () {
226+ @ Override
227+ public void execute () throws Throwable {
228+ final Statements statements = CCJSqlParserUtil .parseStatements (sqlStr );
229+ assertEquals (2 , statements .size ());
230+ assertTrue (statements .get (0 ) instanceof PlainSelect );
231+ assertTrue (statements .get (1 ) instanceof UnsupportedStatement );
232+ }
233+ });
226234 }
227235
228236 @ Test
@@ -335,20 +343,16 @@ public void testCondExpressionIssue1482_2() throws JSQLParserException {
335343 assertEquals ("test_table_enum.f1_enum IN ('TEST2'::test.\" test_enum\" )" , expr .toString ());
336344 }
337345
338-
339-
340346 /**
341347 * The purpose of the test is to run into a timeout and to stop the parser when this happens. We
342348 * provide an INVALID statement for this purpose, which will fail the SIMPLE parse and then hang
343349 * with COMPLEX parsing until the timeout occurs.
344350 * <p>
345351 * We repeat that test multiple times and want to see no stale references to the Parser after
346352 * timeout.
347- *
348- * @throws JSQLParserException
349353 */
350354 @ Test
351- public void testParserInterruptedByTimeout () throws InterruptedException {
355+ public void testParserInterruptedByTimeout () {
352356 MemoryLeakVerifier verifier = new MemoryLeakVerifier ();
353357
354358 int parallelThreads = Runtime .getRuntime ().availableProcessors () + 1 ;
@@ -371,17 +375,15 @@ public void run() {
371375 }
372376 });
373377 }
374-
378+ timeOutService . shutdownNow ();
375379 executorService .shutdown ();
376- timeOutService .shutdown ();
377380
378381 // we should not run in any timeout here (because we expect that the Parser has timed out by
379382 // itself)
380383 assertDoesNotThrow (new Executable () {
381384 @ Override
382385 public void execute () throws Throwable {
383386 executorService .awaitTermination (10 , TimeUnit .SECONDS );
384- timeOutService .awaitTermination (10 , TimeUnit .SECONDS );
385387 }
386388 });
387389
@@ -390,7 +392,7 @@ public void execute() throws Throwable {
390392 }
391393
392394 @ Test
393- public void testTimeOutIssue1582 () throws InterruptedException {
395+ public void testTimeOutIssue1582 () {
394396 // This statement is INVALID on purpose
395397 // There are crafted INTO keywords in order to make it fail but only after a long time (40
396398 // seconds plus)
@@ -443,7 +445,7 @@ public void execute() throws Throwable {
443445
444446 // Supposed to time out
445447 @ Test
446- void testComplexIssue1792 () throws JSQLParserException , InterruptedException {
448+ void testComplexIssue1792 () throws JSQLParserException {
447449 ExecutorService executorService = Executors .newCachedThreadPool ();
448450 CCJSqlParserUtil .LOGGER .setLevel (Level .ALL );
449451
@@ -457,7 +459,7 @@ void testComplexIssue1792() throws JSQLParserException, InterruptedException {
457459 public void execute () throws Throwable {
458460 try {
459461 CCJSqlParserUtil .parse (INVALID_SQL , executorService , parser -> {
460- parser .withTimeOut (6000 );
462+ parser .withTimeOut (10000 );
461463 parser .withAllowComplexParsing (false );
462464 });
463465 } catch (JSQLParserException ex ) {
@@ -467,7 +469,6 @@ public void execute() throws Throwable {
467469 }
468470 });
469471
470-
471472 // Expect to time-out with COMPLEX Parsing allowed
472473 // CCJSqlParserUtil.LOGGER will report:
473474 // 1) Allowed Complex Parsing: true
@@ -478,7 +479,7 @@ public void execute() throws Throwable {
478479 public void execute () throws Throwable {
479480 try {
480481 CCJSqlParserUtil .parse (INVALID_SQL , executorService , parser -> {
481- parser .withTimeOut (6000 );
482+ parser .withTimeOut (1000 );
482483 parser .withAllowComplexParsing (true );
483484 });
484485 } catch (JSQLParserException ex ) {
@@ -487,9 +488,7 @@ public void execute() throws Throwable {
487488 }
488489 }
489490 });
490-
491- executorService .shutdown ();
492- executorService .awaitTermination (1 , TimeUnit .MINUTES );
491+ executorService .shutdownNow ();
493492 CCJSqlParserUtil .LOGGER .setLevel (Level .OFF );
494493 }
495494}
0 commit comments