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

Fix test case

上级 1af72d41
...@@ -49,20 +49,26 @@ public class TestMvccMultiThreaded extends TestBase { ...@@ -49,20 +49,26 @@ public class TestMvccMultiThreaded extends TestBase {
stat.execute("insert into test(id, updated) values(1, 100)"); stat.execute("insert into test(id, updated) values(1, 100)");
ArrayList<Task> tasks = new ArrayList<>(); ArrayList<Task> tasks = new ArrayList<>();
int count = 3; int count = 3;
for(int i=0; i<count; i++) { for (int i = 0; i < count; i++) {
Task task = new Task() { Task task = new Task() {
@Override @Override
public void call() throws Exception { public void call() throws Exception {
Connection conn = getConnection(getTestName()); Connection conn = getConnection(getTestName());
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
while(!stop) { try {
try { while (!stop) {
stat.execute("select * from test where id=1 for update"); try {
} catch (SQLException e) { stat.execute("select * from test where id=1 for update");
assertEquals(ErrorCode.DEADLOCK_1, e.getErrorCode()); } catch (SQLException e) {
int errorCode = e.getErrorCode();
assertEquals(e.getMessage(),
errorCode == ErrorCode.DEADLOCK_1 ||
errorCode == ErrorCode.LOCK_TIMEOUT_1);
}
} }
} finally {
conn.close();
} }
conn.close();
} }
}.execute(); }.execute();
tasks.add(task); tasks.add(task);
...@@ -72,7 +78,7 @@ public class TestMvccMultiThreaded extends TestBase { ...@@ -72,7 +78,7 @@ public class TestMvccMultiThreaded extends TestBase {
ResultSet rs = stat.executeQuery("select * from test"); ResultSet rs = stat.executeQuery("select * from test");
assertTrue(rs.next()); assertTrue(rs.next());
} }
for(Task t : tasks) { for (Task t : tasks) {
t.get(); t.get();
} }
conn.close(); conn.close();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论