提交 2bdc3556 authored 作者: Noel Grandin's avatar Noel Grandin

fix some TestRandomSQL bugs

found by running TestRandomSQL for long periods of time
上级 a21876c1
......@@ -922,8 +922,9 @@ public class Select extends Query {
// another order
sortUsingIndex = true;
}
} else if (index.getIndexColumns().length >=
current.getIndexColumns().length) {
} else if (index.getIndexColumns() != null
&& index.getIndexColumns().length >= current
.getIndexColumns().length) {
IndexColumn[] sortColumns = index.getIndexColumns();
IndexColumn[] currentColumns = current.getIndexColumns();
boolean swapIndex = false;
......
......@@ -938,13 +938,12 @@ public class Session extends SessionWithState {
private void cleanTempTables(boolean closeSession) {
if (localTempTables != null && localTempTables.size() > 0) {
synchronized (database) {
Iterator<Table> it = localTempTables.values().iterator();
while (it.hasNext()) {
Table table = it.next();
HashMap<String, Table> tempTables = localTempTables;
localTempTables = null;
for (Table table : tempTables.values()) {
if (closeSession || table.getOnCommitDrop()) {
modificationId++;
table.setModified();
it.remove();
table.removeChildrenAndResources(this);
if (closeSession) {
// need to commit, otherwise recovery might
......
......@@ -8,10 +8,8 @@ package org.h2.test.synth;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.engine.SysProperties;
import org.h2.store.fs.FileUtils;
import org.h2.test.TestAll;
import org.h2.test.TestBase;
import org.h2.util.MathUtils;
......@@ -20,8 +18,6 @@ import org.h2.util.MathUtils;
*/
public class TestRandomSQL extends TestBase {
private int seed;
private boolean exitOnError = true;
private int success, total;
/**
......@@ -33,41 +29,28 @@ public class TestRandomSQL extends TestBase {
TestBase.createCaller().init().test();
}
private void processException(String sql, SQLException e) {
if (e.getSQLState().equals("HY000")) {
TestBase.logError("new TestRandomSQL().init(test).testCase(" + seed + "); " +
"// FAIL: " + e.toString() + " sql: " + sql, e);
if (exitOnError) {
System.exit(0);
}
}
}
protected String getDatabaseName() {
return getTestName() + "/db" + seed;
}
private Connection connect() throws SQLException {
return getConnection(getDatabaseName());
}
private void deleteDb() {
FileUtils.delete(getDatabaseName());
}
@Override
public TestBase init(TestAll conf) throws Exception {
super.init(conf);
return this;
public void test() throws Exception {
if (config.networked) {
return;
}
int len = getSize(2, 6);
for (int a = 0; a < len; a++) {
int s = MathUtils.randomInt(Integer.MAX_VALUE);
testCase(s);
}
}
private void testWithSeed() throws Exception {
private void testWithSeed(int seed) throws Exception {
Connection conn = null;
try {
conn = connect();
conn = getConnection(getDatabaseName(seed));
} catch (SQLException e) {
processException("connect", e);
conn = connect();
if (e.getSQLState().equals("HY000")) {
TestBase.logError("new TestRandomSQL().init(test).testCase(" + seed + "); " +
"// FAIL: " + e.toString() + " sql: " + "connect", e);
}
conn = getConnection(getDatabaseName(seed));
}
Statement stat = conn.createStatement();
......@@ -86,47 +69,47 @@ public class TestRandomSQL extends TestBase {
stat.execute(sql);
success++;
} catch (SQLException e) {
processException(sql, e);
if (e.getSQLState().equals("HY000")) {
TestBase.logError("new TestRandomSQL().init(test).testCase(" + seed + "); " +
"// FAIL: " + e.toString() + " sql: " + sql, e);
}
}
}
}
try {
conn.close();
conn = connect();
conn = getConnection(getDatabaseName(seed));
conn.createStatement().execute("shutdown immediately");
conn.close();
} catch (SQLException e) {
processException("conn.close", e);
if (e.getSQLState().equals("HY000")) {
TestBase.logError("new TestRandomSQL().init(test).testCase(" + seed + "); " +
"// FAIL: " + e.toString() + " sql: " + "conn.close", e);
}
}
}
@Override
public void testCase(int i) throws Exception {
public void testCase(int seed) throws Exception {
String old = SysProperties.getScriptDirectory();
try {
System.setProperty(SysProperties.H2_SCRIPT_DIRECTORY,
getBaseDir() + "/" + getTestName());
seed = i;
printTime("seed: " + seed);
deleteDb();
testWithSeed();
deleteDb(seed);
testWithSeed(seed);
} finally {
System.setProperty(SysProperties.H2_SCRIPT_DIRECTORY, old);
}
deleteDb();
deleteDb(seed);
}
@Override
public void test() throws Exception {
if (config.networked) {
return;
}
int len = getSize(2, 6);
exitOnError = false;
for (int a = 0; a < len; a++) {
int s = MathUtils.randomInt(Integer.MAX_VALUE);
testCase(s);
}
private String getDatabaseName(int seed) {
return getTestName() + "/db" + seed;
}
private void deleteDb(int seed) {
FileUtils.delete(getDatabaseName(seed));
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论