Mercurial > hg > monetdb-java
comparison tests/OnClientTester.java @ 601:2b5516ed0d92
Allow to select specific OnClient tests from command line
author | Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com> |
---|---|
date | Thu, 09 Dec 2021 15:40:40 +0100 (2021-12-09) |
parents | c2581dbd1dbf |
children | 662e8de9b002 |
comparison
equal
deleted
inserted
replaced
600:c2581dbd1dbf | 601:2b5516ed0d92 |
---|---|
24 import java.sql.DriverManager; | 24 import java.sql.DriverManager; |
25 import java.sql.ResultSet; | 25 import java.sql.ResultSet; |
26 import java.sql.ResultSetMetaData; | 26 import java.sql.ResultSetMetaData; |
27 import java.sql.Statement; | 27 import java.sql.Statement; |
28 import java.sql.SQLException; | 28 import java.sql.SQLException; |
29 import java.util.ArrayList; | |
29 import java.util.List; | 30 import java.util.List; |
30 | 31 |
31 import static java.nio.file.StandardOpenOption.CREATE_NEW; | 32 import static java.nio.file.StandardOpenOption.CREATE_NEW; |
32 | 33 |
33 | 34 |
54 public static final int VERBOSITY_ON = 1; | 55 public static final int VERBOSITY_ON = 1; |
55 public static final int VERBOSITY_SHOW_ALL = 2; | 56 public static final int VERBOSITY_SHOW_ALL = 2; |
56 | 57 |
57 private final String jdbcUrl; | 58 private final String jdbcUrl; |
58 private final int verbosity; | 59 private final int verbosity; |
60 private final ArrayList<String> selectedTests; | |
59 private String currentTestName; | 61 private String currentTestName; |
60 private long startTime; | 62 private long startTime; |
61 private MonetConnection conn; | 63 private MonetConnection conn; |
62 private Statement stmt; | 64 private Statement stmt; |
63 private StringBuilder outBuffer; | 65 private StringBuilder outBuffer; |
64 private Path tmpDir; | 66 private Path tmpDir; |
65 | 67 |
66 public OnClientTester(String jdbcUrl, int verbosity) { | 68 public OnClientTester(String jdbcUrl, int verbosity) { |
67 this.jdbcUrl = jdbcUrl; | 69 this.jdbcUrl = jdbcUrl; |
68 this.verbosity = verbosity; | 70 this.verbosity = verbosity; |
71 this.selectedTests = null; | |
72 } | |
73 | |
74 public OnClientTester(String jdbcUrl, int verbosity, ArrayList<String> selectedTests) { | |
75 this.jdbcUrl = jdbcUrl; | |
76 this.verbosity = verbosity; | |
77 this.selectedTests = selectedTests; | |
69 } | 78 } |
70 | 79 |
71 public static void main(String[] args) { | 80 public static void main(String[] args) { |
72 String jdbcUrl = null; | 81 String jdbcUrl = null; |
73 int verbosity = 0; | 82 int verbosity = 0; |
83 ArrayList<String> selectedTests = new ArrayList<>(); | |
74 | 84 |
75 for (String arg : args) { | 85 for (String arg : args) { |
76 if (arg.equals("-v")) | 86 if (arg.equals("-v")) |
77 verbosity++; | 87 verbosity++; |
78 else if (arg.equals("-vv")) | 88 else if (arg.equals("-vv")) |
79 verbosity += 2; | 89 verbosity += 2; |
80 else if (jdbcUrl == null) | 90 else if (jdbcUrl == null) |
81 jdbcUrl = arg; | 91 jdbcUrl = arg; |
82 else { | 92 else if (arg.startsWith("-")){ |
83 System.err.println("Unexpected argument " + arg); | 93 System.err.println("Unexpected argument " + arg); |
84 System.exit(2); | 94 System.exit(2); |
95 } else { | |
96 selectedTests.add(arg); | |
85 } | 97 } |
86 } | 98 } |
87 if (jdbcUrl == null || jdbcUrl.isEmpty()) { | 99 if (jdbcUrl == null || jdbcUrl.isEmpty()) { |
88 System.err.println("Missing required startup argument: JDBC_connection_URL"); | 100 System.err.println("Missing required startup argument: JDBC_connection_URL"); |
89 System.exit(1); | 101 System.exit(1); |
90 } | 102 } |
91 | 103 |
92 OnClientTester tester = new OnClientTester(jdbcUrl, verbosity); | 104 OnClientTester tester = new OnClientTester(jdbcUrl, verbosity, selectedTests); |
93 int failures = tester.runTests(); | 105 int failures = tester.runTests(); |
94 if (failures > 0) | 106 if (failures > 0) |
95 System.exit(-1); | 107 System.exit(-1); |
96 } | 108 } |
97 | 109 |
110 boolean isSelected(String name) { | |
111 if (selectedTests == null) { | |
112 return true; | |
113 } else { | |
114 return selectedTests.contains(name); | |
115 } | |
116 } | |
117 | |
98 public int runTests() { | 118 public int runTests() { |
99 if (! openConnection()) | 119 if (! openConnection()) |
100 return 1; // failed to open JDBC connection to MonetDB | 120 return 1; // failed to open JDBC connection to MonetDB |
101 | 121 |
102 outBuffer = new StringBuilder(1024); | 122 outBuffer = new StringBuilder(1024); |
103 | 123 |
104 int failures = 0; | 124 int failures = 0; |
105 try { | 125 try { |
106 // all test methods start with test_ and have no arguments | 126 // all test methods start with test_ and have no arguments |
107 test_BugFixLevel(); | 127 if (isSelected("BugFixLevel")) |
108 test_Upload(); | 128 test_BugFixLevel(); |
109 test_ClientRefusesUpload(); | 129 if (isSelected("Upload")) |
110 test_Offset0(); | 130 test_Upload(); |
111 test_Offset1(); | 131 if (isSelected("ClientRefusesUpload")) |
112 test_Offset5(); | 132 test_ClientRefusesUpload(); |
113 test_ServerStopsReading(); | 133 if (isSelected("Offset0")) |
114 test_Download(); | 134 test_Offset0(); |
115 test_ClientRefusesDownload(); | 135 if (isSelected("Offset1")) |
116 test_LargeUpload(); | 136 test_Offset1(); |
117 test_LargeDownload(); | 137 if (isSelected("Offset5")) |
118 test_UploadFromStream(); | 138 test_Offset5(); |
119 test_UploadFromReader(); | 139 if (isSelected("ServerStopsReading")) |
120 test_UploadFromReaderOffset(); | 140 test_ServerStopsReading(); |
121 test_FailUploadLate(); | 141 if (isSelected("Download")) |
122 test_FailUploadLate2(); | 142 test_Download(); |
123 test_FailDownloadLate(); | 143 if (isSelected("ClientRefusesDownload")) |
124 test_FileTransferHandlerUploadUtf8(); | 144 test_ClientRefusesDownload(); |
125 test_FileTransferHandlerUploadLatin1(); | 145 if (isSelected("LargeUpload")) |
126 test_FileTransferHandlerUploadNull(); | 146 test_LargeUpload(); |
127 test_FileTransferHandlerUploadRefused(); | 147 if (isSelected("LargeDownload")) |
128 test_FileTransferHandlerDownloadUtf8(); | 148 test_LargeDownload(); |
129 test_FileTransferHandlerDownloadLatin1(); | 149 if (isSelected("UploadFromStream")) |
130 test_FileTransferHandlerDownloadNull(); | 150 test_UploadFromStream(); |
131 test_FileTransferHandlerDownloadRefused(); | 151 if (isSelected("UploadFromReader")) |
152 test_UploadFromReader(); | |
153 if (isSelected("UploadFromReaderOffset")) | |
154 test_UploadFromReaderOffset(); | |
155 if (isSelected("FailUploadLate")) | |
156 test_FailUploadLate(); | |
157 if (isSelected("FailUploadLate2")) | |
158 test_FailUploadLate2(); | |
159 if (isSelected("FailDownloadLate")) | |
160 test_FailDownloadLate(); | |
161 if (isSelected("FileTransferHandlerUploadUtf8")) | |
162 test_FileTransferHandlerUploadUtf8(); | |
163 if (isSelected("FileTransferHandlerUploadLatin1")) | |
164 test_FileTransferHandlerUploadLatin1(); | |
165 if (isSelected("FileTransferHandlerUploadNull")) | |
166 test_FileTransferHandlerUploadNull(); | |
167 if (isSelected("FileTransferHandlerUploadRefused")) | |
168 test_FileTransferHandlerUploadRefused(); | |
169 if (isSelected("FileTransferHandlerDownloadUtf8")) | |
170 test_FileTransferHandlerDownloadUtf8(); | |
171 if (isSelected("FileTransferHandlerDownloadLatin1")) | |
172 test_FileTransferHandlerDownloadLatin1(); | |
173 if (isSelected("FileTransferHandlerDownloadNull")) | |
174 test_FileTransferHandlerDownloadNull(); | |
175 if (isSelected("FileTransferHandlerDownloadRefused")) | |
176 test_FileTransferHandlerDownloadRefused(); | |
132 } catch (Failure e) { | 177 } catch (Failure e) { |
133 failures++; | 178 failures++; |
134 System.err.println(); | 179 System.err.println(); |
135 System.err.println("Test " + currentTestName + " failed"); | 180 System.err.println("Test " + currentTestName + " failed"); |
136 dumpOutput(); | 181 dumpOutput(); |