Skip to content

Commit 191b9fd

Browse files
committed
reduced time to parse exception to minimize impact on building time
1 parent 5ae09ad commit 191b9fd

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/test/java/net/sf/jsqlparser/parser/CCJSqlParserUtilTest.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,13 @@ public void testParseStatementIssue1250() throws Exception {
261261
Statement result = CCJSqlParserUtil.parse("Select test.* from (Select * from sch.PERSON_TABLE // root test\n) as test");
262262
assertEquals("SELECT test.* FROM (SELECT * FROM sch.PERSON_TABLE) AS test", result.toString());
263263
}
264-
264+
265265
@Test
266266
public void testCondExpressionIssue1482() throws JSQLParserException {
267267
Expression expr = CCJSqlParserUtil.parseCondExpression("test_table_enum.f1_enum IN ('TEST2'::test.test_enum)", false);
268268
assertEquals("test_table_enum.f1_enum IN ('TEST2'::test.test_enum)", expr.toString());
269269
}
270-
270+
271271
@Test
272272
public void testCondExpressionIssue1482_2() throws JSQLParserException {
273273
Expression expr = CCJSqlParserUtil.parseCondExpression("test_table_enum.f1_enum IN ('TEST2'::test.\"test_enum\")", false);
@@ -279,29 +279,28 @@ public void testTimeOutIssue1582() throws InterruptedException {
279279
// This statement is INVALID on purpose
280280
// There are crafted INTO keywords in order to make it fail but only after a long time (40 seconds plus)
281281

282-
String sqlStr = "" +
283-
"select\n" +
284-
" t0.operatienr\n" +
285-
" , case\n" +
286-
" when\n" +
287-
" case when (t0.vc_begintijd_operatie is null or lpad((extract('hours' into t0.vc_begintijd_operatie::timestamp))::text,2,'0') ||':'|| lpad(extract('minutes' from t0.vc_begintijd_operatie::timestamp)::text,2,'0') = '00:00') then null\n" +
288-
" else (greatest(((extract('hours' into (t0.vc_eindtijd_operatie::timestamp-t0.vc_begintijd_operatie::timestamp))*60 + extract('minutes' from (t0.vc_eindtijd_operatie::timestamp-t0.vc_begintijd_operatie::timestamp)))/60)::numeric(12,2),0))*60\n" +
289-
" end = 0 then null\n" +
290-
" else '25. Meer dan 4 uur'\n" +
291-
" end \n" +
292-
" as snijtijd_interval";
282+
String sqlStr = ""
283+
+ "select\n"
284+
+ " t0.operatienr\n"
285+
+ " , case\n"
286+
+ " when\n"
287+
+ " case when (t0.vc_begintijd_operatie is null or lpad((extract('hours' into t0.vc_begintijd_operatie::timestamp))::text,2,'0') ||':'|| lpad(extract('minutes' from t0.vc_begintijd_operatie::timestamp)::text,2,'0') = '00:00') then null\n"
288+
+ " else (greatest(((extract('hours' into (t0.vc_eindtijd_operatie::timestamp-t0.vc_begintijd_operatie::timestamp))*60 + extract('minutes' from (t0.vc_eindtijd_operatie::timestamp-t0.vc_begintijd_operatie::timestamp)))/60)::numeric(12,2),0))*60\n"
289+
+ " end = 0 then null\n"
290+
+ " else '25. Meer dan 4 uur'\n"
291+
+ " end \n"
292+
+ " as snijtijd_interval";
293293

294294
// With DEFAULT TIMEOUT 6 Seconds, we expect the statement to timeout normally
295295
// A TimeoutException wrapped into a Parser Exception should be thrown
296-
297296
assertThrows(TimeoutException.class, new Executable() {
298297
@Override
299298
public void execute() throws Throwable {
300299
try {
301300
CCJSqlParserUtil.parse(sqlStr);
302301
} catch (JSQLParserException ex) {
303302
Throwable cause = ((JSQLParserException) ex).getCause();
304-
if (cause!=null) {
303+
if (cause != null) {
305304
throw cause;
306305
} else {
307306
throw ex;
@@ -317,7 +316,10 @@ public void execute() throws Throwable {
317316
@Override
318317
public void execute() throws Throwable {
319318
try {
320-
CCJSqlParserUtil.parse(sqlStr, parser -> parser.withTimeOut(60000));
319+
CCJSqlParserUtil.parse(sqlStr, parser -> {
320+
parser.withTimeOut(10000);
321+
parser.withAllowComplexParsing(false);
322+
});
321323
} catch (JSQLParserException ex) {
322324
Throwable cause = ((JSQLParserException) ex).getCause();
323325
if (cause instanceof TimeoutException) {

0 commit comments

Comments
 (0)