Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
1173ab9b
提交
1173ab9b
authored
10月 10, 2008
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More tests
上级
5b5a787a
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
63 行增加
和
13 行删除
+63
-13
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+2
-0
Db.java
h2/src/test/org/h2/test/db/Db.java
+27
-12
TestFuzzOptimizations.java
h2/src/test/org/h2/test/synth/TestFuzzOptimizations.java
+34
-1
没有找到文件。
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
1173ab9b
...
...
@@ -86,6 +86,7 @@ import org.h2.test.server.TestPgServer;
import
org.h2.test.server.TestWeb
;
import
org.h2.test.synth.TestBtreeIndex
;
import
org.h2.test.synth.TestCrashAPI
;
import
org.h2.test.synth.TestFuzzOptimizations
;
import
org.h2.test.synth.TestHaltApp
;
import
org.h2.test.synth.TestJoin
;
import
org.h2.test.synth.TestKill
;
...
...
@@ -570,6 +571,7 @@ http://www.w3schools.com/sql/
// synth
new
TestCrashAPI
().
runTest
(
this
);
new
TestFuzzOptimizations
().
runTest
(
this
);
new
TestRandomSQL
().
runTest
(
this
);
new
TestKillRestart
().
runTest
(
this
);
new
TestKillRestartMulti
().
runTest
(
this
);
...
...
h2/src/test/org/h2/test/db/Db.java
浏览文件 @
1173ab9b
...
...
@@ -12,6 +12,7 @@ import java.sql.DriverManager;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
...
...
@@ -98,6 +99,20 @@ public class Db {
}
}
static
List
query
(
ResultSet
rs
)
throws
SQLException
{
List
list
=
new
ArrayList
();
ResultSetMetaData
meta
=
rs
.
getMetaData
();
int
columnCount
=
meta
.
getColumnCount
();
while
(
rs
.
next
())
{
HashMap
map
=
new
HashMap
();
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
map
.
put
(
meta
.
getColumnLabel
(
i
+
1
),
rs
.
getObject
(
i
+
1
));
}
list
.
add
(
map
);
}
return
list
;
}
/**
* Execute a SQL statement.
*
...
...
@@ -106,18 +121,7 @@ public class Db {
*/
public
List
query
(
String
sql
)
{
try
{
List
list
=
new
ArrayList
();
ResultSet
rs
=
stat
.
executeQuery
(
sql
);
ResultSetMetaData
meta
=
rs
.
getMetaData
();
int
columnCount
=
meta
.
getColumnCount
();
while
(
rs
.
next
())
{
HashMap
map
=
new
HashMap
();
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
map
.
put
(
meta
.
getColumnLabel
(
i
+
1
),
rs
.
getObject
(
i
+
1
));
}
list
.
add
(
map
);
}
return
list
;
return
query
(
stat
.
executeQuery
(
sql
));
}
catch
(
Exception
e
)
{
throw
convert
(
e
);
}
...
...
@@ -211,6 +215,17 @@ public class Db {
throw
convert
(
e
);
}
}
/**
* Execute the prepared query.
*/
public
List
query
()
{
try
{
return
Db
.
query
(
prep
.
executeQuery
());
}
catch
(
Exception
e
)
{
throw
convert
(
e
);
}
}
}
/**
...
...
h2/src/test/org/h2/test/synth/TestOptimizations.java
→
h2/src/test/org/h2/test/synth/Test
Fuzz
Optimizations.java
浏览文件 @
1173ab9b
...
...
@@ -11,6 +11,7 @@ import java.sql.SQLException;
import
java.util.List
;
import
java.util.Random
;
import
org.h2.constant.SysProperties
;
import
org.h2.test.TestBase
;
import
org.h2.test.db.Db
;
import
org.h2.test.db.Db.Prepared
;
...
...
@@ -19,7 +20,7 @@ import org.h2.test.db.Db.Prepared;
* This test executes random SQL statements to test if optimizations are working
* correctly.
*/
public
class
TestOptimizations
extends
TestBase
{
public
class
Test
Fuzz
Optimizations
extends
TestBase
{
private
Connection
conn
;
...
...
@@ -36,8 +37,39 @@ public class TestOptimizations extends TestBase {
deleteDb
(
"optimizations"
);
conn
=
getConnection
(
"optimizations"
);
testGroupSorted
();
testInSelect
();
conn
.
close
();
}
private
void
testInSelect
()
throws
SQLException
{
boolean
old
=
SysProperties
.
optimizeInJoin
;
Db
db
=
new
Db
(
conn
);
db
.
execute
(
"CREATE TABLE TEST(A INT, B INT)"
);
db
.
execute
(
"CREATE INDEX IDX ON TEST(A)"
);
db
.
execute
(
"INSERT INTO TEST SELECT X/4, MOD(X, 4) FROM SYSTEM_RANGE(1, 16)"
);
db
.
execute
(
"UPDATE TEST SET A = NULL WHERE A = 0"
);
db
.
execute
(
"UPDATE TEST SET B = NULL WHERE B = 0"
);
Random
random
=
new
Random
();
long
seed
=
random
.
nextLong
();
println
(
"seed: "
+
seed
);
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
String
sql
=
"SELECT * FROM TEST T WHERE "
;
sql
+=
random
.
nextBoolean
()
?
"A"
:
"B"
;
sql
+=
" IN(SELECT "
;
sql
+=
new
String
[]
{
"NULL"
,
"0"
,
"A"
,
"B"
}[
random
.
nextInt
(
4
)];
sql
+=
" FROM TEST I WHERE I."
;
sql
+=
random
.
nextBoolean
()
?
"A"
:
"B"
;
sql
+=
"=?) ORDER BY 1, 2"
;
int
v
=
random
.
nextInt
(
3
);
SysProperties
.
optimizeInJoin
=
false
;
List
a
=
db
.
prepare
(
sql
).
set
(
v
).
query
();
SysProperties
.
optimizeInJoin
=
true
;
List
b
=
db
.
prepare
(
sql
).
set
(
v
).
query
();
assertTrue
(
a
.
equals
(
b
));
}
db
.
execute
(
"DROP TABLE TEST"
);
SysProperties
.
optimizeInJoin
=
old
;
}
private
void
testGroupSorted
()
throws
SQLException
{
Db
db
=
new
Db
(
conn
);
...
...
@@ -92,6 +124,7 @@ public class TestOptimizations extends TestBase {
}
db
.
execute
(
"DROP TABLE TEST_INDEXED"
);
}
db
.
execute
(
"DROP TABLE TEST"
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论