提交 bf0a4bb5 authored 作者: Thomas Mueller's avatar Thomas Mueller

Server-less multi-connection mode: more bugs are fixed.

上级 b8f74f1b
...@@ -33,13 +33,19 @@ public class TestFileLockSerialized extends TestBase { ...@@ -33,13 +33,19 @@ public class TestFileLockSerialized extends TestBase {
} }
public void test() throws Exception { public void test() throws Exception {
Class.forName("org.h2.Driver"); println("testThreeMostlyReaders true");
testThreeMostlyReaders(true); testThreeMostlyReaders(true);
println("testThreeMostlyReaders false");
testThreeMostlyReaders(false); testThreeMostlyReaders(false);
println("testTwoReaders");
testTwoReaders(); testTwoReaders();
println("testTwoWriters");
testTwoWriters(); testTwoWriters();
println("testPendingWrite");
testPendingWrite(); testPendingWrite();
println("testKillWriter");
testKillWriter(); testKillWriter();
println("testConcurrentReadWrite");
testConcurrentReadWrite(); testConcurrentReadWrite();
} }
...@@ -62,13 +68,13 @@ public class TestFileLockSerialized extends TestBase { ...@@ -62,13 +68,13 @@ public class TestFileLockSerialized extends TestBase {
try { try {
PreparedStatement p = c.prepareStatement("select * from test where id = ?"); PreparedStatement p = c.prepareStatement("select * from test where id = ?");
while (!stop[0]) { while (!stop[0]) {
Thread.sleep(100);
if (write) { if (write) {
if (Math.random() > 0.9) { if (Math.random() > 0.9) {
c.createStatement().execute("update test set id = id"); c.createStatement().execute("update test set id = id");
} }
} }
p.setInt(1, 1); p.setInt(1, 1);
Thread.sleep(10);
p.executeQuery(); p.executeQuery();
p.clearParameters(); p.clearParameters();
} }
...@@ -81,7 +87,7 @@ public class TestFileLockSerialized extends TestBase { ...@@ -81,7 +87,7 @@ public class TestFileLockSerialized extends TestBase {
t.start(); t.start();
threads[i] = t; threads[i] = t;
} }
Thread.sleep(1000); Thread.sleep(400);
stop[0] = true; stop[0] = true;
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
threads[i].join(); threads[i].join();
...@@ -118,17 +124,18 @@ public class TestFileLockSerialized extends TestBase { ...@@ -118,17 +124,18 @@ public class TestFileLockSerialized extends TestBase {
public void run() { public void run() {
while (!stop[0]) { while (!stop[0]) {
try { try {
Thread.sleep(10);
Connection conn = DriverManager.getConnection(writeUrl, "sa", "sa"); Connection conn = DriverManager.getConnection(writeUrl, "sa", "sa");
conn.createStatement().execute("select * from test"); conn.createStatement().execute("select * from test");
conn.close(); conn.close();
} catch (SQLException e) { } catch (Exception e) {
// ignore // ignore
} }
} }
} }
}.start(); }.start();
Thread.sleep(100); Thread.sleep(20);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 2; i++) {
conn = DriverManager.getConnection(writeUrl, "sa", "sa"); conn = DriverManager.getConnection(writeUrl, "sa", "sa");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("drop table test"); stat.execute("drop table test");
...@@ -151,7 +158,7 @@ public class TestFileLockSerialized extends TestBase { ...@@ -151,7 +158,7 @@ public class TestFileLockSerialized extends TestBase {
Connection conn = DriverManager.getConnection(writeUrl, "sa", "sa"); Connection conn = DriverManager.getConnection(writeUrl, "sa", "sa");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key)"); stat.execute("create table test(id int primary key)");
Thread.sleep(500); Thread.sleep(100);
String propFile = baseDir + "/fileLockSerialized.lock.db"; String propFile = baseDir + "/fileLockSerialized.lock.db";
SortedProperties p = SortedProperties.loadProperties(propFile); SortedProperties p = SortedProperties.loadProperties(propFile);
p.setProperty("changePending", "true"); p.setProperty("changePending", "true");
...@@ -162,7 +169,7 @@ public class TestFileLockSerialized extends TestBase { ...@@ -162,7 +169,7 @@ public class TestFileLockSerialized extends TestBase {
} finally { } finally {
out.close(); out.close();
} }
Thread.sleep(500); Thread.sleep(100);
stat.execute("select * from test"); stat.execute("select * from test");
conn.close(); conn.close();
} }
...@@ -199,7 +206,7 @@ public class TestFileLockSerialized extends TestBase { ...@@ -199,7 +206,7 @@ public class TestFileLockSerialized extends TestBase {
// ;TRACE_LEVEL_SYSTEM_OUT=3 // ;TRACE_LEVEL_SYSTEM_OUT=3
// String readUrl = writeUrl + ";ACCESS_MODE_LOG=R;ACCESS_MODE_DATA=R"; // String readUrl = writeUrl + ";ACCESS_MODE_LOG=R;ACCESS_MODE_DATA=R";
trace("create database"); trace(" create database");
Class.forName("org.h2.Driver"); Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection(writeUrl, "sa", "sa"); Connection conn = DriverManager.getConnection(writeUrl, "sa", "sa");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
...@@ -212,12 +219,12 @@ public class TestFileLockSerialized extends TestBase { ...@@ -212,12 +219,12 @@ public class TestFileLockSerialized extends TestBase {
Statement stat2 = conn2.createStatement(); Statement stat2 = conn2.createStatement();
printResult(stat2, "select * from test"); printResult(stat2, "select * from test");
stat2.execute("create local temporary table temp(name varchar)"); stat2.execute("create local temporary table temp(name varchar) not persistent");
printResult(stat2, "select * from temp"); printResult(stat2, "select * from temp");
trace("insert row 1"); trace(" insert row 1");
stat.execute("insert into test values(1)"); stat.execute("insert into test values(1)");
trace("insert row 2"); trace(" insert row 2");
prep3.setInt(1, 2); prep3.setInt(1, 2);
prep3.execute(); prep3.execute();
printResult(stat2, "select * from test"); printResult(stat2, "select * from test");
...@@ -229,13 +236,13 @@ public class TestFileLockSerialized extends TestBase { ...@@ -229,13 +236,13 @@ public class TestFileLockSerialized extends TestBase {
} }
private void printResult(Statement stat, String sql) throws SQLException { private void printResult(Statement stat, String sql) throws SQLException {
trace("query: " + sql); trace(" query: " + sql);
ResultSet rs = stat.executeQuery(sql); ResultSet rs = stat.executeQuery(sql);
int rowCount = 0; int rowCount = 0;
while (rs.next()) { while (rs.next()) {
trace(" " + rs.getString(1)); trace(" " + rs.getString(1));
rowCount++; rowCount++;
} }
trace(" " + rowCount + " row(s)"); trace(" " + rowCount + " row(s)");
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论