Skip to content

Commit

Permalink
test: make the performance tests more robust regarding the time-outs
Browse files Browse the repository at this point in the history
  • Loading branch information
manticore-projects committed Jul 24, 2024
1 parent 351a61d commit eb7e1b8
Showing 1 changed file with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import java.util.logging.Logger;

import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.function.Executable;

/**
*
Expand All @@ -35,22 +37,22 @@ public class NestedBracketsPerformanceTest {
public void testIssue766() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(
"SELECT concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat('1','2'),'3'),'4'),'5'),'6'),'7'),'8'),'9'),'10'),'11'),'12'),'13'),'14'),'15'),'16'),'17'),'18'),'19'),'20'),'21'),col1 FROM tbl t1",
true);
true, parser -> parser.withTimeOut(60000));
}

@Test
@Timeout(2000)
public void testIssue766_2() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(
"SELECT concat(concat(concat('1', '2'), '3'), '4'), col1 FROM tbl t1");
"SELECT concat(concat(concat('1', '2'), '3'), '4'), col1 FROM tbl t1", true, parser -> parser.withTimeOut(60000));
}

@Test
@Timeout(2000)
public void testIssue235() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(
"SELECT CASE WHEN ( CASE WHEN ( CASE WHEN ( CASE WHEN ( 1 ) THEN 0 END ) THEN 0 END ) THEN 0 END ) THEN 0 END FROM a",
true);
true, parser -> parser.withTimeOut(60000));
}

@Test
Expand All @@ -71,7 +73,7 @@ public void testNestedCaseWhenWithoutBracketsIssue1162() throws JSQLParserExcept
+ "WHEN WDGFLD.PORTTYPE = 1 THEN 'INPUT PORT'\n" + "ELSE CASE\n"
+ "WHEN WDGFLD.PORTTYPE = 1 THEN 'INPUT PORT'\n"
+ "ELSE CASE WHEN WDGFLD.PORTTYPE = 1 THEN 'INPUT PORT' ELSE '0' END END END END END END END END END END END END END END COLUMNALIAS\n"
+ "FROM TABLE1", true);
+ "FROM TABLE1", true, parser -> parser.withTimeOut(60000));
}

@Test
Expand All @@ -92,26 +94,31 @@ public void testNestedCaseWhenWithBracketsIssue1162() throws JSQLParserException
+ "WHEN WDGFLD.PORTTYPE = 1 THEN 'INPUT PORT'\n" + "ELSE (CASE\n"
+ "WHEN WDGFLD.PORTTYPE = 1 THEN 'INPUT PORT'\n"
+ "ELSE (CASE WHEN WDGFLD.PORTTYPE = 1 THEN 'INPUT PORT' ELSE '0' END) END) END) END) END) END) END) END) END) END) END) END) END) END COLUMNALIAS\n"
+ "FROM TABLE1", true);
+ "FROM TABLE1", true, parser -> parser.withTimeOut(60000));
}

@Test
@Timeout(2000)
@Disabled
@Timeout(10000)
public void testIssue496() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(
Assertions.assertThrowsExactly(JSQLParserException.class,new Executable() {
@Override
public void execute() throws Throwable {
assertSqlCanBeParsedAndDeparsed(
"select isNull(charLen(TEST_ID,0)+ isNull(charLen(TEST_DVC,0)+ isNull(charLen(TEST_NO,0)+ isNull(charLen(ATEST_ID,0)+ isNull(charLen(TESTNO,0)+ isNull(charLen(TEST_CTNT,0)+ isNull(charLen(TEST_MESG_CTNT,0)+ isNull(charLen(TEST_DTM,0)+ isNull(charLen(TEST_DTT,0)+ isNull(charLen(TEST_ADTT,0)+ isNull(charLen(TEST_TCD,0)+ isNull(charLen(TEST_PD,0)+ isNull(charLen(TEST_VAL,0)+ isNull(charLen(TEST_YN,0)+ isNull(charLen(TEST_DTACM,0)+ isNull(charLen(TEST_MST,0) from test_info_m",
true);
true, parser -> parser.withTimeOut(6000));
}
});

}

@Test
// @Todo Investigate performance deterioration since JSQLParser 5.0pre development
@Timeout(2000)
public void testIssue856() throws JSQLParserException {
String sql = "SELECT "
+ buildRecursiveBracketExpression(
"if(month(today()) = 3, sum(\"Table5\".\"Month 002\"), $1)", "0", 3)
+ " FROM mytbl";
assertSqlCanBeParsedAndDeparsed(sql);
assertSqlCanBeParsedAndDeparsed(sql, true, parser -> parser.withTimeOut(60000));
}

@Test
Expand All @@ -127,25 +134,27 @@ public void testRecursiveBracketExpressionIssue1019() {
// maxDepth = 10 collides with the Parser Timeout = 6 seconds
// @todo: implement methods to set the Parser Timeout explicitly and on demand
@Test
@Timeout(10000)
public void testRecursiveBracketExpressionIssue1019_2() throws JSQLParserException {
doIncreaseOfParseTimeTesting("IF(1=1, $1, 2)", "1", 8);
doIncreaseOfParseTimeTesting("IF(1=1, $1, 2)", "1", 10);
}

@Test
@Timeout(2000)
public void testIssue1013() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT ((((((((((((((((tblA)))))))))))))))) FROM mytable");
assertSqlCanBeParsedAndDeparsed("SELECT ((((((((((((((((tblA)))))))))))))))) FROM mytable", true, parser -> parser.withTimeOut(60000));
}

@Test
@Timeout(2000)
public void testIssue1013_2() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT * FROM ((((((((((((((((tblA))))))))))))))))");
assertSqlCanBeParsedAndDeparsed("SELECT * FROM ((((((((((((((((tblA))))))))))))))))", true, parser -> parser.withTimeOut(60000));
}

@Test
@Timeout(2000)
public void testIssue1013_3() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT * FROM (((tblA)))");
assertSqlCanBeParsedAndDeparsed("SELECT * FROM (((tblA)))", true, parser -> parser.withTimeOut(60000));
}

@Test
Expand All @@ -157,15 +166,16 @@ public void testIssue1013_4() throws JSQLParserException {
}
String sql = "SELECT * FROM " + s;
LOG.info("testing " + sql);
assertSqlCanBeParsedAndDeparsed(sql);
assertSqlCanBeParsedAndDeparsed(sql, true, parser -> parser.withTimeOut(60000));
}

/**
* Try to avoid or border huge parsing time increments by adding more bracket constructs.
*
* @throws JSQLParserException
*/
// @Test(timeout = 6000)
@Test
@Timeout(2000)
public void testIncreaseOfParseTime() throws JSQLParserException {
doIncreaseOfParseTimeTesting("concat($1,'B')", "'A'", 50);
}
Expand All @@ -178,7 +188,7 @@ private void doIncreaseOfParseTimeTesting(String template, String finalExpressio
String sql = "SELECT " + buildRecursiveBracketExpression(template, finalExpression, i)
+ " FROM mytbl";
long startTime = System.currentTimeMillis();
assertSqlCanBeParsedAndDeparsed(sql, true);
assertSqlCanBeParsedAndDeparsed(sql, true, parser -> parser.withTimeOut(60000));
long durationTime = System.currentTimeMillis() - startTime;

if (i > 0) {
Expand All @@ -197,6 +207,7 @@ private void doIncreaseOfParseTimeTesting(String template, String finalExpressio
}

@Test
@Timeout(2000)
public void testRecursiveBracketExpression() {
assertEquals("concat('A','B')",
buildRecursiveBracketExpression("concat($1,'B')", "'A'", 0));
Expand Down Expand Up @@ -225,10 +236,11 @@ public void testIssue1103() throws JSQLParserException {
+ "ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(ROUND(0\n"
+ ",0),0),0),0),0),0),0),0)\n" + ",0),0),0),0),0),0),0),0)\n"
+ ",0),0),0),0),0),0),0),0)\n" + ",0),0),0),0),0),0),0),0)",
true);
true, parser -> parser.withTimeOut(60000));
}

@Test
@Timeout(2000)
public void testDeepFunctionParameters() throws JSQLParserException {
String sqlStr = "SELECT a.*\n"
+ " , To_Char( a.eingangsdat, 'MM.YY' ) AS eingmonat\n"
Expand Down Expand Up @@ -352,7 +364,7 @@ public void testDeepFunctionParameters() throws JSQLParserException {
+ " FROM beschfehler\n"
+ " WHERE beschfehler_id = a.beschwkat_id ), 0 ) > 0\n";

assertSqlCanBeParsedAndDeparsed(sqlStr, true);
assertSqlCanBeParsedAndDeparsed(sqlStr, true, parser -> parser.withTimeOut(60000));
}

@Test
Expand Down

0 comments on commit eb7e1b8

Please sign in to comment.