提交 63f6308a authored 作者: Noel Grandin's avatar Noel Grandin

improve the reliability of TestMvcc4

上级 94f73730
...@@ -11,9 +11,9 @@ import java.sql.ResultSet; ...@@ -11,9 +11,9 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import org.h2.test.TestBase; import org.h2.test.TestBase;
/** /**
...@@ -64,7 +64,7 @@ public class TestMvcc4 extends TestBase { ...@@ -64,7 +64,7 @@ public class TestMvcc4 extends TestBase {
} }
//Create a connection from thread 1 //Create a connection from thread 1
Connection c1 = getConnection("mvcc4"); Connection c1 = getConnection("mvcc4;LOCK_TIMEOUT=10000");
c1.setAutoCommit(false); c1.setAutoCommit(false);
//Fire off a concurrent update. //Fire off a concurrent update.
...@@ -130,21 +130,23 @@ public class TestMvcc4 extends TestBase { ...@@ -130,21 +130,23 @@ public class TestMvcc4 extends TestBase {
*/ */
static void waitForThreadToBlockOnDB(Thread t) { static void waitForThreadToBlockOnDB(Thread t) {
while (true) { while (true) {
// sleep the first time through the loop so we give the main thread a chance
try {
Thread.sleep(20);
} catch (InterruptedException e1) {
// ignore
}
// TODO must not use getAllStackTraces, as the method names are // TODO must not use getAllStackTraces, as the method names are
// implementation details // implementation details
Map<Thread, StackTraceElement[]> threadMap = Thread.getAllStackTraces(); Map<Thread, StackTraceElement[]> threadMap = Thread.getAllStackTraces();
StackTraceElement[] elements = threadMap.get(t); StackTraceElement[] elements = threadMap.get(t);
System.out.println("xxxx" + Arrays.deepToString(elements));
if (elements != null if (elements != null
&& elements.length > 1 && elements.length > 1
&& "wait".equals(elements[0].getMethodName()) && "wait".equals(elements[0].getMethodName())
&& "filterConcurrentUpdate".equals(elements[1].getMethodName())) { && "filterConcurrentUpdate".equals(elements[1].getMethodName())) {
return; return;
} }
try {
Thread.sleep(10);
} catch (InterruptedException e1) {
// ignore
}
} }
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论