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