提交 c32db7f4 authored 作者: thomasmueller's avatar thomasmueller

Add concurrent test case

上级 d18d1e10
...@@ -7,7 +7,9 @@ package org.h2.test.mvcc; ...@@ -7,7 +7,9 @@ package org.h2.test.mvcc;
import java.sql.Connection; import java.sql.Connection;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.ArrayList;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
...@@ -30,6 +32,7 @@ public class TestMvccMultiThreaded extends TestBase { ...@@ -30,6 +32,7 @@ public class TestMvccMultiThreaded extends TestBase {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
testConcurrentSelectForUpdate();
testMergeWithUniqueKeyViolation(); testMergeWithUniqueKeyViolation();
// not supported currently // not supported currently
if (!config.multiThreaded) { if (!config.multiThreaded) {
...@@ -38,6 +41,44 @@ public class TestMvccMultiThreaded extends TestBase { ...@@ -38,6 +41,44 @@ public class TestMvccMultiThreaded extends TestBase {
} }
} }
private void testConcurrentSelectForUpdate() throws Exception {
deleteDb(getTestName());
Connection conn = getConnection(getTestName() + ";MULTI_THREADED=TRUE");
Statement stat = conn.createStatement();
stat.execute("create table test(id int not null primary key, updated int not null)");
stat.execute("insert into test(id, updated) values(1, 100)");
ArrayList<Task> tasks = new ArrayList<>();
int count = 3;
for(int i=0; i<count; i++) {
Task task = new Task() {
@Override
public void call() throws Exception {
Connection conn = getConnection(getTestName());
Statement stat = conn.createStatement();
while(!stop) {
try {
stat.execute("select * from test where id=1 for update");
} catch (SQLException e) {
assertEquals(ErrorCode.DEADLOCK_1, e.getErrorCode());
}
}
conn.close();
}
}.execute();
tasks.add(task);
}
for (int i = 0; i < 10; i++) {
Thread.sleep(100);
ResultSet rs = stat.executeQuery("select * from test");
assertTrue(rs.next());
}
for(Task t : tasks) {
t.get();
}
conn.close();
deleteDb(getTestName());
}
private void testMergeWithUniqueKeyViolation() throws Exception { private void testMergeWithUniqueKeyViolation() throws Exception {
deleteDb(getTestName()); deleteDb(getTestName());
Connection conn = getConnection(getTestName()); Connection conn = getConnection(getTestName());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论