36
36
import static org .junit .jupiter .api .Assertions .assertThrows ;
37
37
import static org .junit .jupiter .api .Assertions .assertTrue ;
38
38
39
+ import net .sf .jsqlparser .statement .UnsupportedStatement ;
40
+ import net .sf .jsqlparser .statement .select .PlainSelect ;
39
41
import net .sf .jsqlparser .test .MemoryLeakVerifier ;
40
- import org .junit .jupiter .api .Disabled ;
41
42
import org .junit .jupiter .api .Test ;
42
43
import org .junit .jupiter .api .function .Executable ;
43
44
@@ -217,12 +218,19 @@ public void accept(Statement statement) {
217
218
}
218
219
219
220
@ Test
220
- @ Disabled
221
221
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
+ });
226
234
}
227
235
228
236
@ Test
@@ -335,20 +343,16 @@ public void testCondExpressionIssue1482_2() throws JSQLParserException {
335
343
assertEquals ("test_table_enum.f1_enum IN ('TEST2'::test.\" test_enum\" )" , expr .toString ());
336
344
}
337
345
338
-
339
-
340
346
/**
341
347
* The purpose of the test is to run into a timeout and to stop the parser when this happens. We
342
348
* provide an INVALID statement for this purpose, which will fail the SIMPLE parse and then hang
343
349
* with COMPLEX parsing until the timeout occurs.
344
350
* <p>
345
351
* We repeat that test multiple times and want to see no stale references to the Parser after
346
352
* timeout.
347
- *
348
- * @throws JSQLParserException
349
353
*/
350
354
@ Test
351
- public void testParserInterruptedByTimeout () throws InterruptedException {
355
+ public void testParserInterruptedByTimeout () {
352
356
MemoryLeakVerifier verifier = new MemoryLeakVerifier ();
353
357
354
358
int parallelThreads = Runtime .getRuntime ().availableProcessors () + 1 ;
@@ -371,17 +375,15 @@ public void run() {
371
375
}
372
376
});
373
377
}
374
-
378
+ timeOutService . shutdownNow ();
375
379
executorService .shutdown ();
376
- timeOutService .shutdown ();
377
380
378
381
// we should not run in any timeout here (because we expect that the Parser has timed out by
379
382
// itself)
380
383
assertDoesNotThrow (new Executable () {
381
384
@ Override
382
385
public void execute () throws Throwable {
383
386
executorService .awaitTermination (10 , TimeUnit .SECONDS );
384
- timeOutService .awaitTermination (10 , TimeUnit .SECONDS );
385
387
}
386
388
});
387
389
@@ -390,7 +392,7 @@ public void execute() throws Throwable {
390
392
}
391
393
392
394
@ Test
393
- public void testTimeOutIssue1582 () throws InterruptedException {
395
+ public void testTimeOutIssue1582 () {
394
396
// This statement is INVALID on purpose
395
397
// There are crafted INTO keywords in order to make it fail but only after a long time (40
396
398
// seconds plus)
@@ -443,7 +445,7 @@ public void execute() throws Throwable {
443
445
444
446
// Supposed to time out
445
447
@ Test
446
- void testComplexIssue1792 () throws JSQLParserException , InterruptedException {
448
+ void testComplexIssue1792 () throws JSQLParserException {
447
449
ExecutorService executorService = Executors .newCachedThreadPool ();
448
450
CCJSqlParserUtil .LOGGER .setLevel (Level .ALL );
449
451
@@ -457,7 +459,7 @@ void testComplexIssue1792() throws JSQLParserException, InterruptedException {
457
459
public void execute () throws Throwable {
458
460
try {
459
461
CCJSqlParserUtil .parse (INVALID_SQL , executorService , parser -> {
460
- parser .withTimeOut (6000 );
462
+ parser .withTimeOut (10000 );
461
463
parser .withAllowComplexParsing (false );
462
464
});
463
465
} catch (JSQLParserException ex ) {
@@ -467,7 +469,6 @@ public void execute() throws Throwable {
467
469
}
468
470
});
469
471
470
-
471
472
// Expect to time-out with COMPLEX Parsing allowed
472
473
// CCJSqlParserUtil.LOGGER will report:
473
474
// 1) Allowed Complex Parsing: true
@@ -478,7 +479,7 @@ public void execute() throws Throwable {
478
479
public void execute () throws Throwable {
479
480
try {
480
481
CCJSqlParserUtil .parse (INVALID_SQL , executorService , parser -> {
481
- parser .withTimeOut (6000 );
482
+ parser .withTimeOut (1000 );
482
483
parser .withAllowComplexParsing (true );
483
484
});
484
485
} catch (JSQLParserException ex ) {
@@ -487,9 +488,7 @@ public void execute() throws Throwable {
487
488
}
488
489
}
489
490
});
490
-
491
- executorService .shutdown ();
492
- executorService .awaitTermination (1 , TimeUnit .MINUTES );
491
+ executorService .shutdownNow ();
493
492
CCJSqlParserUtil .LOGGER .setLevel (Level .OFF );
494
493
}
495
494
}
0 commit comments