提交 7263a660 authored 作者: Thomas Mueller's avatar Thomas Mueller

Multi-version concurrency: SELECT ... FOR UPDATE threw a "concurrent update"…

Multi-version concurrency: SELECT ... FOR UPDATE threw a "concurrent update" exception immediately instead of a "lock timeout" exception after the set lock timeout if the row was already locked by another connection.
上级 061f55d2
......@@ -15,6 +15,7 @@ import java.sql.Savepoint;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Random;
import org.h2.constant.ErrorCode;
import org.h2.engine.Constants;
import org.h2.test.TestBase;
import org.h2.util.New;
......@@ -35,6 +36,7 @@ public class TestTransaction extends TestBase {
}
public void test() throws SQLException {
testConcurrentSelectForUpdate();
testLogMode();
testRollback();
testRollback2();
......@@ -87,6 +89,28 @@ public class TestTransaction extends TestBase {
conn.close();
}
private void testConcurrentSelectForUpdate() throws SQLException {
deleteDb("transaction");
Connection conn = getConnection("transaction");
conn.setAutoCommit(false);
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar)");
stat.execute("insert into test values(1, 'Hello'), (2, 'World')");
conn.commit();
PreparedStatement prep = conn.prepareStatement("select * from test for update");
prep.execute();
Connection conn2 = getConnection("transaction");
conn2.setAutoCommit(false);
try {
conn2.createStatement().execute("select * from test for update");
fail();
} catch (SQLException e) {
assertEquals(ErrorCode.LOCK_TIMEOUT_1, e.getErrorCode());
}
conn2.close();
conn.close();
}
private void testForUpdate() throws SQLException {
deleteDb("transaction");
Connection conn = getConnection("transaction");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论