Skip to content

Commit 72e830c

Browse files
committed
Allow testing of dynamically loaded CSVLexers
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1303878 13f79535-47bb-0310-9956-ffa450edef68
1 parent 5111efd commit 72e830c

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

src/test/java/org/apache/commons/csv/PerformanceTest.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.io.BufferedReader;
2121
import java.io.FileReader;
2222
import java.io.IOException;
23+
import java.lang.reflect.Constructor;
24+
import java.lang.reflect.InvocationTargetException;
2325

2426
/**
2527
* Basic test harness.
@@ -86,10 +88,14 @@ public static void main(String [] args) throws Exception {
8688
testCSVLexer(false, test);
8789
} else if ("lexnew".equals(test)) {
8890
testCSVLexer(true, test);
91+
} else if (test.startsWith("CSVLexer")) {
92+
testCSVLexer(false, test);
8993
} else if ("extb".equals(test)) {
9094
testExtendedBuffer(false);
9195
} else if ("exts".equals(test)) {
9296
testExtendedBuffer(true);
97+
} else {
98+
System.out.println("Invalid test name: "+test);
9399
}
94100
}
95101
}
@@ -198,11 +204,26 @@ private static void testParseCommonsCSV() throws Exception {
198204
show();
199205
}
200206

207+
208+
private static Constructor<Lexer> getLexerCtor(String clazz) throws Exception {
209+
@SuppressWarnings("unchecked")
210+
Class<Lexer> lexer = (Class<Lexer>) Class.forName("org.apache.commons.csv."+clazz);
211+
Constructor<Lexer> ctor = lexer.getConstructor(new Class<?>[]{CSVFormat.class, ExtendedBufferedReader.class});
212+
return ctor;
213+
}
214+
201215
private static void testCSVLexer(final boolean newToken, String test) throws Exception {
202216
Token token = new Token();
217+
String dynamic = "";
203218
for (int i = 0; i < max; i++) {
204-
final BufferedReader reader = getReader();
205-
Lexer lexer = new CSVLexer(format, new ExtendedBufferedReader(reader));
219+
final ExtendedBufferedReader input = new ExtendedBufferedReader(getReader());
220+
Lexer lexer = null;
221+
if (test.startsWith("CSVLexer")) {
222+
dynamic="!";
223+
lexer = getLexerCtor(test).newInstance(new Object[]{format, input});
224+
} else {
225+
lexer = new CSVLexer(format, input);
226+
}
206227
int count = 0;
207228
int fields = 0;
208229
long t0 = System.currentTimeMillis();
@@ -229,8 +250,8 @@ private static void testCSVLexer(final boolean newToken, String test) throws Exc
229250

230251
} while (!token.type.equals(Token.Type.EOF));
231252
Stats s = new Stats(count, fields);
232-
reader.close();
233-
show(test, s, t0);
253+
input.close();
254+
show(lexer.getClass().getSimpleName()+dynamic+" "+(newToken ? "new" : "reset"), s, t0);
234255
}
235256
show();
236257
}

0 commit comments

Comments
 (0)