Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
458dd3d8
提交
458dd3d8
authored
5月 03, 2017
作者:
Noel Grandin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cleanup new testcase
上级
ddf7b783
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
52 行增加
和
70 行删除
+52
-70
TestMvccMultiThreaded2.java
h2/src/test/org/h2/test/mvcc/TestMvccMultiThreaded2.java
+52
-70
没有找到文件。
h2/src/test/org/h2/test/mvcc/TestMvccMultiThreaded2.java
浏览文件 @
458dd3d8
...
@@ -10,19 +10,18 @@ import java.sql.PreparedStatement;
...
@@ -10,19 +10,18 @@ import java.sql.PreparedStatement;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.sql.Statement
;
import
java.util.Map
;
import
java.util.ArrayList
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
org.h2.test.TestBase
;
import
org.h2.jdbc.JdbcSQLException
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.ErrorCode
;
import
org.h2.jdbc.JdbcSQLException
;
import
org.h2.test.TestBase
;
import
org.h2.util.IOUtils
;
/**
/**
* Additional MVCC (multi version concurrency) test cases.
* Additional MVCC (multi version concurrency) test cases.
*/
*/
public
class
TestMvccMultiThreaded2
extends
TestBase
{
public
class
TestMvccMultiThreaded2
extends
TestBase
{
private
static
final
AtomicBoolean
running
=
new
AtomicBoolean
(
true
);
private
static
final
String
URL
=
";MVCC=TRUE;LOCK_TIMEOUT=120000;MULTI_THREADED=TRUE"
;
private
static
final
String
url
=
";MVCC=TRUE;LOCK_TIMEOUT=120000;MULTI_THREADED=TRUE"
;
/**
/**
* Run just this test.
* Run just this test.
...
@@ -39,19 +38,17 @@ public class TestMvccMultiThreaded2 extends TestBase {
...
@@ -39,19 +38,17 @@ public class TestMvccMultiThreaded2 extends TestBase {
}
}
@Override
@Override
public
void
test
()
throws
SQLException
{
public
void
test
()
throws
SQLException
,
InterruptedException
{
if
(
config
.
cipher
!=
null
||
!
config
.
lazy
)
{
return
;
}
testSelectForUpdateConcurrency
();
testSelectForUpdateConcurrency
();
}
}
private
void
testSelectForUpdateConcurrency
()
throws
SQLException
{
private
void
testSelectForUpdateConcurrency
()
throws
SQLException
,
InterruptedException
{
deleteDb
(
getTestName
());
deleteDb
(
getTestName
());
Connection
conn
=
getConnection
(
getTestName
()
+
url
);
Connection
conn
=
getConnection
(
getTestName
()
+
URL
);
conn
.
setAutoCommit
(
false
);
conn
.
setAutoCommit
(
false
);
String
sql
=
"CREATE TABLE test
mvccmultithreaded2
("
String
sql
=
"CREATE TABLE test ("
+
"entity_id INTEGER NOT NULL PRIMARY KEY, "
+
"entity_id INTEGER NOT NULL PRIMARY KEY, "
+
"lastUpdated INTEGER NOT NULL)"
;
+
"lastUpdated INTEGER NOT NULL)"
;
...
@@ -59,52 +56,41 @@ public class TestMvccMultiThreaded2 extends TestBase {
...
@@ -59,52 +56,41 @@ public class TestMvccMultiThreaded2 extends TestBase {
smtm
.
executeUpdate
(
sql
);
smtm
.
executeUpdate
(
sql
);
PreparedStatement
ps
=
conn
.
prepareStatement
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"INSERT INTO test
mvccmultithreaded2
(entity_id, lastUpdated) VALUES (?, ?)"
);
"INSERT INTO test (entity_id, lastUpdated) VALUES (?, ?)"
);
ps
.
setInt
(
1
,
1
);
ps
.
setInt
(
1
,
1
);
ps
.
setInt
(
2
,
100
);
ps
.
setInt
(
2
,
100
);
ps
.
executeUpdate
();
ps
.
executeUpdate
();
conn
.
commit
();
conn
.
commit
();
int
howManyThreads
=
100
;
ArrayList
<
SelectForUpdate
>
threads
=
new
ArrayList
<
SelectForUpdate
>()
;
Thread
[]
threads
=
new
SelectForUpdate
[
howManyThreads
];
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
for
(
int
i
=
0
;
i
<
howManyThreads
;
i
++)
{
SelectForUpdate
sfu
=
new
SelectForUpdate
();
threads
[
i
]
=
new
SelectForUpdate
(
);
threads
.
add
(
sfu
);
threads
[
i
]
.
start
();
sfu
.
start
();
}
}
try
{
for
(
SelectForUpdate
sfu
:
threads
)
{
for
(
int
i
=
0
;
i
<
howManyThreads
;
i
++)
{
sfu
.
join
();
threads
[
i
].
join
();
}
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
smtm
=
conn
.
createStatement
();
IOUtils
.
closeSilently
(
conn
);
smtm
.
execute
(
"DROP TABLE testmvccmultithreaded2"
);
deleteDb
(
getTestName
());
if
(
conn
!=
null
)
{
try
{
conn
.
close
();
}
catch
(
SQLException
e1
)
{
e1
.
printStackTrace
();
}
}
}
}
private
class
SelectForUpdate
extends
Thread
{
private
class
SelectForUpdate
extends
Thread
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
long
start
=
System
.
currentTimeMillis
();
final
long
start
=
System
.
currentTimeMillis
();
boolean
done
=
false
;
boolean
done
=
false
;
Connection
conn
=
null
;
Connection
conn
=
null
;
while
(
running
.
get
()
&&
!
done
)
{
try
{
try
{
conn
=
getConnection
(
getTestName
()
+
url
);
conn
=
getConnection
(
getTestName
()
+
URL
);
conn
.
setAutoCommit
(
false
);
conn
.
setAutoCommit
(
false
);
while
(!
done
)
{
try
{
PreparedStatement
ps
=
conn
.
prepareStatement
(
PreparedStatement
ps
=
conn
.
prepareStatement
(
"SELECT * FROM testmvccmultithreaded2
WHERE entity_id = ? FOR UPDATE"
);
"SELECT * FROM test
WHERE entity_id = ? FOR UPDATE"
);
ps
.
setString
(
1
,
"1"
);
ps
.
setString
(
1
,
"1"
);
ResultSet
rs
=
ps
.
executeQuery
();
ResultSet
rs
=
ps
.
executeQuery
();
...
@@ -114,23 +100,19 @@ public class TestMvccMultiThreaded2 extends TestBase {
...
@@ -114,23 +100,19 @@ public class TestMvccMultiThreaded2 extends TestBase {
conn
.
commit
();
conn
.
commit
();
long
now
=
System
.
currentTimeMillis
();
long
now
=
System
.
currentTimeMillis
();
if
(
now
-
start
>
1000
*
60
)
done
=
true
;
if
(
now
-
start
>
1000
*
60
)
done
=
true
;
}
catch
(
JdbcSQLException
e1
)
{
}
catch
(
JdbcSQLException
e1
)
{
// skip DUPLICATE_KEY_1 to just focus on
// skip DUPLICATE_KEY_1 to just focus on this bug.
// this bug.
if
(
e1
.
getErrorCode
()
!=
ErrorCode
.
DUPLICATE_KEY_1
)
{
if
(
e1
.
getErrorCode
()
!=
ErrorCode
.
DUPLICATE_KEY_1
)
throw
e1
;
e1
.
printStackTrace
();
}
catch
(
SQLException
e2
)
{
e2
.
printStackTrace
();
}
}
}
}
if
(
conn
!=
null
)
{
try
{
conn
.
close
();
}
catch
(
SQLException
e1
)
{
e1
.
printStackTrace
();
}
}
}
catch
(
SQLException
e
)
{
TestBase
.
logError
(
"error"
,
e
);
}
}
IOUtils
.
closeSilently
(
conn
);
}
}
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论