提交 00eff4a4 authored 作者: andrei's avatar andrei

little cleanup in TestMvcc2

上级 270907f7
...@@ -9,7 +9,6 @@ import java.sql.Connection; ...@@ -9,7 +9,6 @@ import java.sql.Connection;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.concurrent.atomic.AtomicBoolean;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.util.Task; import org.h2.util.Task;
...@@ -65,33 +64,26 @@ public class TestMvcc2 extends TestBase { ...@@ -65,33 +64,26 @@ public class TestMvcc2 extends TestBase {
stat2.execute("set lock_timeout 1000"); stat2.execute("set lock_timeout 1000");
stat.execute("create table test(id int primary key, name varchar)"); stat.execute("create table test(id int primary key, name varchar)");
conn.setAutoCommit(false); conn.setAutoCommit(false);
final AtomicBoolean committed = new AtomicBoolean(false);
Task t = new Task() { Task t = new Task() {
@Override @Override
public void call() throws SQLException { public void call() {
try { try {
//System.out.println("insert2 hallo");
stat2.execute("insert into test values(0, 'Hallo')"); stat2.execute("insert into test values(0, 'Hallo')");
//System.out.println("insert2 hallo done"); fail();
} catch (SQLException e) { } catch (SQLException e) {
//System.out.println("insert2 hallo e " + e); assertTrue(e.toString(),
if (!committed.get()) { e.getErrorCode() == ErrorCode.DUPLICATE_KEY_1 ||
throw e; e.getErrorCode() == ErrorCode.CONCURRENT_UPDATE_1);
}
} }
} }
}; };
//System.out.println("insert hello");
stat.execute("insert into test values(0, 'Hello')"); stat.execute("insert into test values(0, 'Hello')");
t.execute(); t.execute();
Thread.sleep(500);
//System.out.println("insert hello commit");
committed.set(true);
conn.commit(); conn.commit();
t.get(); t.get();
ResultSet rs; ResultSet rs;
rs = stat.executeQuery("select name from test"); rs = stat.executeQuery("select name from test");
rs.next(); assertTrue(rs.next());
assertEquals("Hello", rs.getString(1)); assertEquals("Hello", rs.getString(1));
stat.execute("drop table test"); stat.execute("drop table test");
conn2.close(); conn2.close();
...@@ -111,16 +103,17 @@ public class TestMvcc2 extends TestBase { ...@@ -111,16 +103,17 @@ public class TestMvcc2 extends TestBase {
@Override @Override
public void call() throws SQLException { public void call() throws SQLException {
stat2.execute("update test set name = 'Hallo'"); stat2.execute("update test set name = 'Hallo'");
assertEquals(1, stat2.getUpdateCount());
} }
}; };
stat.execute("update test set name = 'Hi'"); stat.execute("update test set name = 'Hi'");
assertEquals(1, stat.getUpdateCount());
t.execute(); t.execute();
Thread.sleep(500);
conn.commit(); conn.commit();
t.get(); t.get();
ResultSet rs; ResultSet rs;
rs = stat.executeQuery("select name from test"); rs = stat.executeQuery("select name from test");
rs.next(); assertTrue(rs.next());
assertEquals("Hallo", rs.getString(1)); assertEquals("Hallo", rs.getString(1));
stat.execute("drop table test"); stat.execute("drop table test");
conn2.close(); conn2.close();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论