Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 3f95832

Browse files
add timeout tests
1 parent de482d3 commit 3f95832

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

standalone/src/test/java/com/trivadis/plsql/formatter/standalone/tests/TvdFormatTest.java

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,36 @@ where d.department_name in ('Marketing', 'Operations', 'Public Relations')
2525
order by d.department_name, v.employee_id;
2626
""";
2727

28+
private final String SLOW_PARSING_CODE = """
29+
create or replace package body pkg is
30+
procedure p1 is
31+
l_words text_ct;
32+
begin
33+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
34+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
35+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
36+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
37+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
38+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
39+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
40+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
41+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
42+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
43+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
44+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
45+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
46+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
47+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
48+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
49+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
50+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
51+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
52+
l_words := new text_ct('aahed', 'aalii', 'aapas', 'aargh', 'aarti', 'abaca', 'abaci', 'abacs', 'abaft', 'abaht', 'abaka', 'abamp', 'aband', 'abash', 'abask', 'abaya', 'abbas', 'abbed', 'abbes', 'abcee', 'abeam', 'abear', 'abeat', 'abeer', 'abele', 'abeng', 'abers', 'abets', 'abeys', 'abies', 'abius', 'abjad', 'abjud', 'abler', 'ables', 'ablet', 'ablow', 'abmho', 'abnet', 'abohm');
53+
end p1;
54+
end pkg;
55+
/
56+
""";
57+
2858
@Test
2959
public void jsonArrayDirTest() throws ScriptException, IOException {
3060
var configFileContent = """
@@ -80,4 +110,56 @@ public void jsonObjectFileTest() throws ScriptException, IOException {
80110
Assertions.assertEquals(EXPECTED_QUERY_SQL, actual);
81111
Assertions.assertTrue(getConsoleOutput().contains("1 of 2"));
82112
}
113+
114+
@Test
115+
public void jsonObjectFileWithTimeoutTest() throws ScriptException, IOException {
116+
var inputFile = Paths.get(getTempDir() + "/input.sql");
117+
Files.write(inputFile, SLOW_PARSING_CODE.getBytes());
118+
var configFileContent = """
119+
{
120+
"xml": "#XML#",
121+
"arbori": "#ARBORI#",
122+
"files": [
123+
"#TEMP_DIR#/input.sql"
124+
],
125+
"timeout": 1
126+
}
127+
""".replace("#XML#", getXML())
128+
.replace("#ARBORI#", getArbori())
129+
.replace("#TEMP_DIR#", getTempDir())
130+
.replace("\\", "/");
131+
var configFile = Paths.get(getTempDir() + "/config.json");
132+
Files.write(configFile, configFileContent.getBytes());
133+
var args = new String[]{getTempDir() + "/config.json"};
134+
TvdFormat.main(args);
135+
var actual = getFormattedContent("input.sql").replace("\r", "");
136+
Assertions.assertEquals(SLOW_PARSING_CODE.trim(), actual.trim());
137+
Assertions.assertTrue(getConsoleOutput().contains("timeout..."));
138+
}
139+
140+
@Test
141+
public void jsonObjectFileWithoutTimeoutTest() throws ScriptException, IOException {
142+
var inputFile = Paths.get(getTempDir() + "/input.sql");
143+
Files.write(inputFile, SLOW_PARSING_CODE.getBytes());
144+
var configFileContent = """
145+
{
146+
"xml": "#XML#",
147+
"arbori": "#ARBORI#",
148+
"files": [
149+
"#TEMP_DIR#/input.sql"
150+
],
151+
"timeout": 20
152+
}
153+
""".replace("#XML#", getXML())
154+
.replace("#ARBORI#", getArbori())
155+
.replace("#TEMP_DIR#", getTempDir())
156+
.replace("\\", "/");
157+
var configFile = Paths.get(getTempDir() + "/config.json");
158+
Files.write(configFile, configFileContent.getBytes());
159+
var args = new String[]{getTempDir() + "/config.json"};
160+
TvdFormat.main(args);
161+
var actual = getFormattedContent("input.sql").replace("\r", "");
162+
Assertions.assertNotEquals(SLOW_PARSING_CODE.trim(), actual.trim());
163+
Assertions.assertFalse(getConsoleOutput().contains("timeout..."));
164+
}
83165
}

0 commit comments

Comments
 (0)