提交 86e619a1 authored 作者: Thomas Mueller's avatar Thomas Mueller

Improve tests (speedup, make more reliable)

上级 8d94ec9e
...@@ -105,14 +105,14 @@ public class TestMemoryUsage extends TestBase { ...@@ -105,14 +105,14 @@ public class TestMemoryUsage extends TestBase {
deleteDb("memoryUsage"); deleteDb("memoryUsage");
conn = getConnection("memoryUsage"); conn = getConnection("memoryUsage");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("SET MAX_LENGTH_INPLACE_LOB 16384"); stat.execute("SET MAX_LENGTH_INPLACE_LOB 8192");
stat.execute("SET CACHE_SIZE 8000"); stat.execute("SET CACHE_SIZE 8000");
stat.execute("CREATE TABLE TEST(ID IDENTITY, DATA CLOB)"); stat.execute("CREATE TABLE TEST(ID IDENTITY, DATA CLOB)");
freeSoftReferences(); freeSoftReferences();
try { try {
int base = Utils.getMemoryUsed(); int base = Utils.getMemoryUsed();
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
stat.execute("INSERT INTO TEST(DATA) SELECT SPACE(16000) FROM SYSTEM_RANGE(1, 400)"); stat.execute("INSERT INTO TEST(DATA) SELECT SPACE(8000) FROM SYSTEM_RANGE(1, 800)");
freeSoftReferences(); freeSoftReferences();
int used = Utils.getMemoryUsed(); int used = Utils.getMemoryUsed();
if ((used - base) > 16000) { if ((used - base) > 16000) {
......
...@@ -19,6 +19,8 @@ import java.sql.ResultSetMetaData; ...@@ -19,6 +19,8 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random;
import org.h2.test.TestAll; import org.h2.test.TestAll;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.New; import org.h2.util.New;
...@@ -34,7 +36,7 @@ public class TestScript extends TestBase { ...@@ -34,7 +36,7 @@ public class TestScript extends TestBase {
private boolean failFast; private boolean failFast;
private boolean alwaysReconnect; private boolean reconnectOften;
private Connection conn; private Connection conn;
private Statement stat; private Statement stat;
private LineNumberReader in; private LineNumberReader in;
...@@ -45,6 +47,8 @@ public class TestScript extends TestBase { ...@@ -45,6 +47,8 @@ public class TestScript extends TestBase {
private StringBuilder errors; private StringBuilder errors;
private ArrayList<String> statements; private ArrayList<String> statements;
private Random random = new Random(1);
/** /**
* Run just this test. * Run just this test.
* *
...@@ -72,10 +76,10 @@ public class TestScript extends TestBase { ...@@ -72,10 +76,10 @@ public class TestScript extends TestBase {
if (config.networked && config.big) { if (config.networked && config.big) {
return; return;
} }
alwaysReconnect = false; reconnectOften = false;
if (!config.memory) { if (!config.memory) {
if (config.big) { if (config.big) {
alwaysReconnect = true; reconnectOften = true;
} }
} }
testScript(); testScript();
...@@ -158,10 +162,11 @@ public class TestScript extends TestBase { ...@@ -158,10 +162,11 @@ public class TestScript extends TestBase {
} }
private void process(String sql) throws Exception { private void process(String sql) throws Exception {
if (alwaysReconnect) { if (reconnectOften) {
if (!containsTempTables()) { if (!containsTempTables()) {
boolean autocommit = conn.getAutoCommit(); boolean autocommit = conn.getAutoCommit();
if (autocommit) { if (autocommit && random.nextInt(10) < 1) {
// reconnect 10% of the time
conn.close(); conn.close();
conn = getConnection("script"); conn = getConnection("script");
conn.setAutoCommit(autocommit); conn.setAutoCommit(autocommit);
...@@ -346,7 +351,7 @@ public class TestScript extends TestBase { ...@@ -346,7 +351,7 @@ public class TestScript extends TestBase {
String compare = readLine(); String compare = readLine();
if (compare != null && compare.startsWith(">")) { if (compare != null && compare.startsWith(">")) {
if (!compare.equals(s)) { if (!compare.equals(s)) {
if (alwaysReconnect && sql.toUpperCase().startsWith("EXPLAIN")) { if (reconnectOften && sql.toUpperCase().startsWith("EXPLAIN")) {
return; return;
} }
errors.append("line: "); errors.append("line: ");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论