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

little cleanup in TestMvcc2

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