Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e128f2a5
提交
e128f2a5
authored
10月 07, 2015
作者:
Mike Poindexter
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add test for executing UPDATE and SELECT FOR UPDATE simultaneously
This test is for github issue #180
上级
278e6e81
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
148 行增加
和
1 行删除
+148
-1
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+7
-0
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+1
-1
TestMvcc4.java
h2/src/test/org/h2/test/mvcc/TestMvcc4.java
+140
-0
没有找到文件。
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
e128f2a5
...
@@ -107,6 +107,7 @@ import org.h2.test.jdbcx.TestXASimple;
...
@@ -107,6 +107,7 @@ import org.h2.test.jdbcx.TestXASimple;
import
org.h2.test.mvcc.TestMvcc1
;
import
org.h2.test.mvcc.TestMvcc1
;
import
org.h2.test.mvcc.TestMvcc2
;
import
org.h2.test.mvcc.TestMvcc2
;
import
org.h2.test.mvcc.TestMvcc3
;
import
org.h2.test.mvcc.TestMvcc3
;
import
org.h2.test.mvcc.TestMvcc4
;
import
org.h2.test.mvcc.TestMvccMultiThreaded
;
import
org.h2.test.mvcc.TestMvccMultiThreaded
;
import
org.h2.test.poweroff.TestReorderWrites
;
import
org.h2.test.poweroff.TestReorderWrites
;
import
org.h2.test.rowlock.TestRowLocks
;
import
org.h2.test.rowlock.TestRowLocks
;
...
@@ -330,6 +331,11 @@ java org.h2.test.TestAll timer
...
@@ -330,6 +331,11 @@ java org.h2.test.TestAll timer
*/
*/
public
boolean
fast
;
public
boolean
fast
;
/**
* The lock timeout to use
*/
public
int
lockTimeout
=
50
;
/**
/**
* If the transaction log should be kept small (that is, the log should be
* If the transaction log should be kept small (that is, the log should be
* switched early).
* switched early).
...
@@ -739,6 +745,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
...
@@ -739,6 +745,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
addTest
(
new
TestMvcc1
());
addTest
(
new
TestMvcc1
());
addTest
(
new
TestMvcc2
());
addTest
(
new
TestMvcc2
());
addTest
(
new
TestMvcc3
());
addTest
(
new
TestMvcc3
());
addTest
(
new
TestMvcc4
());
addTest
(
new
TestMvccMultiThreaded
());
addTest
(
new
TestMvccMultiThreaded
());
addTest
(
new
TestRowLocks
());
addTest
(
new
TestRowLocks
());
...
...
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
e128f2a5
...
@@ -299,7 +299,7 @@ public abstract class TestBase {
...
@@ -299,7 +299,7 @@ public abstract class TestBase {
}
else
if
(
config
.
throttle
>
0
)
{
}
else
if
(
config
.
throttle
>
0
)
{
url
=
addOption
(
url
,
"THROTTLE"
,
""
+
config
.
throttle
);
url
=
addOption
(
url
,
"THROTTLE"
,
""
+
config
.
throttle
);
}
}
url
=
addOption
(
url
,
"LOCK_TIMEOUT"
,
"
50"
);
url
=
addOption
(
url
,
"LOCK_TIMEOUT"
,
"
"
+
config
.
lockTimeout
);
if
(
config
.
diskUndo
&&
admin
)
{
if
(
config
.
diskUndo
&&
admin
)
{
url
=
addOption
(
url
,
"MAX_MEMORY_UNDO"
,
"3"
);
url
=
addOption
(
url
,
"MAX_MEMORY_UNDO"
,
"3"
);
}
}
...
...
h2/src/test/org/h2/test/mvcc/TestMvcc4.java
0 → 100644
浏览文件 @
e128f2a5
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
mvcc
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.sql.Timestamp
;
import
java.util.Map
;
import
java.util.concurrent.CountDownLatch
;
import
org.h2.test.TestBase
;
/**
* Additional MVCC (multi version concurrency) test cases.
*/
public
class
TestMvcc4
extends
TestBase
{
/**
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
test
=
TestBase
.
createCaller
().
init
();
test
.
config
.
mvcc
=
true
;
test
.
config
.
lockTimeout
=
20000
;
test
.
config
.
memory
=
true
;
test
.
test
();
}
@Override
public
void
test
()
throws
SQLException
{
testSelectForUpdateAndUpdateConcurrency
();
}
private
void
testSelectForUpdateAndUpdateConcurrency
()
throws
SQLException
{
Connection
setup
=
getConnection
(
"mvcc4"
);
setup
.
setAutoCommit
(
false
);
{
Statement
s
=
setup
.
createStatement
();
s
.
executeUpdate
(
"CREATE TABLE test ("
+
"entity_id VARCHAR(100) NOT NULL PRIMARY KEY, "
+
"lastUpdated TIMESTAMP NOT NULL)"
);
PreparedStatement
ps
=
setup
.
prepareStatement
(
"INSERT INTO test (entity_id, lastUpdated) VALUES (?, ?)"
);
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
String
id
=
""
+
i
;
ps
.
setString
(
1
,
id
);
ps
.
setTimestamp
(
2
,
new
Timestamp
(
System
.
currentTimeMillis
()));
ps
.
executeUpdate
();
}
setup
.
commit
();
}
//Create a connection from thread 1
Connection
c1
=
getConnection
(
"mvcc4"
);
c1
.
setAutoCommit
(
false
);
//Fire off a concurrent update.
final
Thread
mainThread
=
Thread
.
currentThread
();
final
CountDownLatch
executedUpdate
=
new
CountDownLatch
(
1
);
new
Thread
()
{
public
void
run
()
{
try
{
Connection
c2
=
getConnection
(
"mvcc4"
);
c2
.
setAutoCommit
(
false
);
PreparedStatement
ps
=
c2
.
prepareStatement
(
"SELECT * FROM test WHERE entity_id = ? FOR UPDATE"
);
ps
.
setString
(
1
,
"1"
);
ps
.
executeQuery
().
next
();
executedUpdate
.
countDown
();
waitForThreadToBlockOnDB
(
mainThread
);
c2
.
commit
();
c2
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
}.
start
();
//Wait until the concurrent update has executed, but not yet committed
try
{
executedUpdate
.
await
();
}
catch
(
InterruptedException
e
)
{
}
{
//Execute an update. This should initially fail, and enter the waiting for lock case.
PreparedStatement
ps
=
c1
.
prepareStatement
(
"UPDATE test SET lastUpdated = ?"
);
ps
.
setTimestamp
(
1
,
new
Timestamp
(
System
.
currentTimeMillis
()));
ps
.
executeUpdate
();
}
c1
.
commit
();
c1
.
close
();
Connection
verify
=
getConnection
(
"mvcc4"
);
{
verify
.
setAutoCommit
(
false
);
PreparedStatement
ps
=
verify
.
prepareStatement
(
"SELECT COUNT(*) FROM test"
);
ResultSet
rs
=
ps
.
executeQuery
();
assertTrue
(
rs
.
next
());
assertTrue
(
rs
.
getInt
(
1
)
==
2
);
verify
.
commit
();
verify
.
close
();
}
setup
.
close
();
}
private
static
void
waitForThreadToBlockOnDB
(
Thread
t
)
{
while
(
true
)
{
Map
<
Thread
,
StackTraceElement
[]>
threadMap
=
Thread
.
getAllStackTraces
();
StackTraceElement
[]
elements
=
threadMap
.
get
(
t
);
if
(
elements
!=
null
&&
elements
.
length
>
1
&&
"wait"
.
equals
(
elements
[
0
].
getMethodName
())
&&
"filterConcurrentUpdate"
.
equals
(
elements
[
1
].
getMethodName
()))
{
return
;
}
try
{
Thread
.
sleep
(
10
);
}
catch
(
InterruptedException
e1
)
{
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论