Unverified 提交 edcd07a7 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1130 from katzyn/tests

Improve TestScript and TestCrashAPI
......@@ -132,6 +132,8 @@ public class TestTableEngines extends TestBase {
EndlessTableEngine.createTableData.tableEngineParams.get(1));
conn.close();
}
// Prevent memory leak
EndlessTableEngine.createTableData = null;
deleteDb("tableEngine");
}
......@@ -150,6 +152,8 @@ public class TestTableEngines extends TestBase {
assertEquals("param2",
EndlessTableEngine.createTableData.tableEngineParams.get(1));
conn.close();
// Prevent memory leak
EndlessTableEngine.createTableData = null;
deleteDb("tableEngine");
}
......@@ -513,6 +517,8 @@ public class TestTableEngines extends TestBase {
stat.executeUpdate("CREATE TABLE T(ID INT AFFINITY PRIMARY KEY, NAME VARCHAR, AGE INT)" +
" ENGINE \"" + AffinityTableEngine.class.getName() + "\"");
Table tbl = AffinityTableEngine.createdTbl;
// Prevent memory leak
AffinityTableEngine.createdTbl = null;
assertNotNull(tbl);
assertEquals(3, tbl.getIndexes().size());
Index aff = tbl.getIndexes().get(2);
......@@ -552,6 +558,8 @@ public class TestTableEngines extends TestBase {
}
stat.execute("CREATE TABLE u (a int, b int) ENGINE " + engine);
TreeSetTable u = TreeSetIndexTableEngine.created;
// Prevent memory leak
TreeSetIndexTableEngine.created = null;
stat.execute("CREATE INDEX U_IDX_A ON u(a)");
stat.execute("CREATE INDEX U_IDX_B ON u(b)");
setBatchSize(u, 0);
......@@ -704,6 +712,8 @@ public class TestTableEngines extends TestBase {
assertEquals(10, table.getRowCount(null));
}
}
// Prevent memory leak
TreeSetIndexTableEngine.created = null;
int[] zeroBatchSizes = new int[batchSizes.length];
int tests = 1 << (batchSizes.length * 4);
......
......@@ -40,7 +40,8 @@ public class TestScript extends TestBase {
/** If set to true, the test will exit at the first failure. */
private boolean failFast;
private final ArrayList<String> statements = new ArrayList<>();
/** If set to a value the test will add all executed statements to this list */
private ArrayList<String> statements;
private boolean reconnectOften;
private Connection conn;
......@@ -71,10 +72,14 @@ public class TestScript extends TestBase {
*/
public ArrayList<String> getAllStatements(TestAll conf) throws Exception {
config = conf;
if (statements.isEmpty()) {
ArrayList<String> result = new ArrayList<>(4000);
try {
statements = result;
test();
} finally {
this.statements = null;
}
return statements;
return result;
}
@Override
......@@ -181,7 +186,9 @@ public class TestScript extends TestBase {
putBack = null;
errors = null;
println("Running commands in " + scriptFileName);
if (statements == null) {
println("Running commands in " + scriptFileName);
}
final String outFile = "test.out.txt";
conn = getConnection("script");
stat = conn.createStatement();
......@@ -260,7 +267,7 @@ public class TestScript extends TestBase {
if (sql.startsWith("--")) {
write(sql);
} else if (sql.startsWith(">")) {
// do nothing
addWriteResultError("<command>", sql);
} else if (sql.endsWith(";")) {
write(sql);
buff.append(sql, 0, sql.length() - 1);
......@@ -302,7 +309,9 @@ public class TestScript extends TestBase {
}
}
}
statements.add(sql);
if (statements != null) {
statements.add(sql);
}
if (sql.indexOf('?') == -1) {
processStatement(sql);
} else {
......@@ -526,7 +535,6 @@ public class TestScript extends TestBase {
if (ex != null) {
TestBase.logError("script", ex);
}
TestBase.logErrorMessage(errors.toString());
if (failFast) {
conn.close();
System.exit(1);
......@@ -534,17 +542,18 @@ public class TestScript extends TestBase {
}
} else {
addWriteResultError("<nothing>", s);
TestBase.logErrorMessage(errors.toString());
putBack = compare;
}
write(s);
}
private void addWriteResultError(String expected, String got) {
int idx = errors.length();
errors.append(fileName).append('\n');
errors.append("line: ").append(in.getLineNumber()).append('\n');
errors.append("exp: ").append(expected).append('\n');
errors.append("got: ").append(got).append('\n');
TestBase.logErrorMessage(errors.substring(idx));
}
private void write(String s) {
......
......@@ -107,4 +107,3 @@ SELECT TIMESTAMPADD('TIMEZONE_MINUTE', -45, TIMESTAMP WITH TIME ZONE '2010-01-01
SELECT DATEADD(HOUR, 1, TIME '23:00:00');
>> 00:00:00
> rows: 1
......@@ -11,6 +11,7 @@ import java.io.StringWriter;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.sql.BatchUpdateException;
import java.sql.Blob;
import java.sql.CallableStatement;
......@@ -65,7 +66,7 @@ public class TestCrashAPI extends TestBase implements Runnable {
private final HashMap<Class <?>, ArrayList<Method>> classMethods =
new HashMap<>();
private RandomGen random = new RandomGen();
private final ArrayList<String> statements = new ArrayList<>();
private ArrayList<String> statements;
private int openCount;
private long callCount;
private volatile long maxWait = 60;
......@@ -370,6 +371,10 @@ public class TestCrashAPI extends TestBase implements Runnable {
}
private Object callRandom(int seed, int id, int objectId, Object o, Method m) {
// TODO m.isDefault() can be used on Java 8
boolean isDefault =
(m.getModifiers() & (Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC)) == Modifier.PUBLIC
&& m.getDeclaringClass().isInterface();
Class<?>[] paramClasses = m.getParameterTypes();
Object[] params = new Object[paramClasses.length];
for (int i = 0; i < params.length; i++) {
......@@ -385,7 +390,7 @@ public class TestCrashAPI extends TestBase implements Runnable {
TestBase.logError("error", e);
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
printIfBad(seed, id, objectId, t);
printIfBad(seed, id, objectId, t, isDefault);
}
if (result == null) {
return null;
......@@ -398,6 +403,10 @@ public class TestCrashAPI extends TestBase implements Runnable {
}
private void printIfBad(int seed, int id, int objectId, Throwable t) {
printIfBad(seed, id, objectId, t, false);
}
private void printIfBad(int seed, int id, int objectId, Throwable t, boolean isDefault) {
if (t instanceof BatchUpdateException) {
// do nothing
} else if (t.getClass().getName().contains("SQLClientInfoException")) {
......@@ -421,6 +430,8 @@ public class TestCrashAPI extends TestBase implements Runnable {
// General error [HY000]
printError(seed, id, s);
}
} else if (isDefault && t instanceof NullPointerException) {
// do nothing, default methods may throw this exception
} else {
printError(seed, id, t);
}
......@@ -525,10 +536,9 @@ public class TestCrashAPI extends TestBase implements Runnable {
}
startServerIfRequired();
TestScript script = new TestScript();
ArrayList<String> add = script.getAllStatements(config);
statements = script.getAllStatements(config);
initMethods();
org.h2.Driver.load();
statements.addAll(add);
return this;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论