Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f447a3e4
提交
f447a3e4
authored
9月 01, 2007
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code style
上级
aed847e4
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
41 个修改的文件
包含
1135 行增加
和
1149 行删除
+1135
-1149
ant-build.properties
h2/ant-build.properties
+2
-2
FileFunctions.java
h2/src/test/org/h2/samples/FileFunctions.java
+1
-1
Function.java
h2/src/test/org/h2/samples/Function.java
+5
-5
FunctionMultiReturn.java
h2/src/test/org/h2/samples/FunctionMultiReturn.java
+10
-10
InitDatabaseFromJar.java
h2/src/test/org/h2/samples/InitDatabaseFromJar.java
+11
-5
MixedMode.java
h2/src/test/org/h2/samples/MixedMode.java
+8
-8
Newsfeed.java
h2/src/test/org/h2/samples/Newsfeed.java
+3
-3
SQLInjection.java
h2/src/test/org/h2/samples/SQLInjection.java
+18
-12
SecurePassword.java
h2/src/test/org/h2/samples/SecurePassword.java
+1
-1
ShowProgress.java
h2/src/test/org/h2/samples/ShowProgress.java
+10
-9
TriggerSample.java
h2/src/test/org/h2/samples/TriggerSample.java
+4
-4
BenchC.java
h2/src/test/org/h2/test/bench/BenchC.java
+67
-73
BenchCThread.java
h2/src/test/org/h2/test/bench/BenchCThread.java
+186
-186
TestAutoRecompile.java
h2/src/test/org/h2/test/db/TestAutoRecompile.java
+4
-4
TestCompatibility.java
h2/src/test/org/h2/test/db/TestCompatibility.java
+6
-9
TestLobObject.java
h2/src/test/org/h2/test/db/TestLobObject.java
+1
-0
TestSQLInjection.java
h2/src/test/org/h2/test/db/TestSQLInjection.java
+18
-18
TestSpaceReuse.java
h2/src/test/org/h2/test/db/TestSpaceReuse.java
+3
-3
TestSpeed.java
h2/src/test/org/h2/test/db/TestSpeed.java
+334
-334
TestTempTables.java
h2/src/test/org/h2/test/db/TestTempTables.java
+6
-5
TestTransaction.java
h2/src/test/org/h2/test/db/TestTransaction.java
+65
-61
TestTwoPhaseCommit.java
h2/src/test/org/h2/test/db/TestTwoPhaseCommit.java
+11
-11
TestView.java
h2/src/test/org/h2/test/db/TestView.java
+4
-4
TestBitField.java
h2/src/test/org/h2/test/unit/TestBitField.java
+16
-16
TestCache.java
h2/src/test/org/h2/test/unit/TestCache.java
+5
-5
TestCompress.java
h2/src/test/org/h2/test/unit/TestCompress.java
+12
-14
TestDataPage.java
h2/src/test/org/h2/test/unit/TestDataPage.java
+10
-10
TestExit.java
h2/src/test/org/h2/test/unit/TestExit.java
+21
-27
TestFileLock.java
h2/src/test/org/h2/test/unit/TestFileLock.java
+3
-2
TestIntArray.java
h2/src/test/org/h2/test/unit/TestIntArray.java
+33
-33
TestIntIntHashMap.java
h2/src/test/org/h2/test/unit/TestIntIntHashMap.java
+3
-3
TestOverflow.java
h2/src/test/org/h2/test/unit/TestOverflow.java
+22
-22
TestPattern.java
h2/src/test/org/h2/test/unit/TestPattern.java
+18
-18
TestSampleApps.java
h2/src/test/org/h2/test/unit/TestSampleApps.java
+16
-17
TestScriptReader.java
h2/src/test/org/h2/test/unit/TestScriptReader.java
+39
-40
TestSecurity.java
h2/src/test/org/h2/test/unit/TestSecurity.java
+17
-22
TestStreams.java
h2/src/test/org/h2/test/unit/TestStreams.java
+21
-21
TestStringCache.java
h2/src/test/org/h2/test/unit/TestStringCache.java
+22
-22
TestStringUtils.java
h2/src/test/org/h2/test/unit/TestStringUtils.java
+43
-61
TestTools.java
h2/src/test/org/h2/test/unit/TestTools.java
+44
-36
TestValueHashMap.java
h2/src/test/org/h2/test/unit/TestValueHashMap.java
+12
-12
没有找到文件。
h2/ant-build.properties
浏览文件 @
f447a3e4
#Fri Aug 24 22:06:59 CEST 2007
javac
=
javac
#Sat Sep 01 17:01:19 CEST 2007
benchmark.drivers.dir
=
C
\:
/data/java
javac
=
javac
path.servlet.jar
=
C
\:
/data/classpath/servlet-api.jar
version.name.maven
=
1.0.57
jdk
=
1.4
h2/src/test/org/h2/samples/FileFunctions.java
浏览文件 @
f447a3e4
...
...
@@ -46,7 +46,7 @@ public class FileFunctions {
public
static
byte
[]
readFile
(
String
fileName
)
throws
IOException
{
RandomAccessFile
file
=
new
RandomAccessFile
(
fileName
,
"r"
);
try
{
byte
[]
buff
=
new
byte
[(
int
)
file
.
length
()];
byte
[]
buff
=
new
byte
[(
int
)
file
.
length
()];
file
.
readFully
(
buff
);
return
buff
;
}
finally
{
...
...
h2/src/test/org/h2/samples/Function.java
浏览文件 @
f447a3e4
...
...
@@ -23,9 +23,9 @@ public class Function {
stat
.
execute
(
"CREATE ALIAS IS_PRIME FOR \"org.h2.samples.Function.isPrime\" "
);
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"SELECT IS_PRIME(X), X FROM SYSTEM_RANGE(1, 20) ORDER BY X"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
boolean
isPrime
=
rs
.
getBoolean
(
1
);
if
(
isPrime
)
{
if
(
isPrime
)
{
int
x
=
rs
.
getInt
(
2
);
System
.
out
.
println
(
x
+
" is prime"
);
}
...
...
@@ -53,11 +53,11 @@ public class Function {
SimpleResultSet
rs
=
new
SimpleResultSet
();
rs
.
addColumn
(
"X"
,
Types
.
INTEGER
,
10
,
0
);
rs
.
addColumn
(
"Y"
,
Types
.
INTEGER
,
10
,
0
);
if
(
id
==
null
)
{
if
(
id
==
null
)
{
return
rs
;
}
for
(
int
x
=
0
;
x
<
id
.
intValue
();
x
++)
{
for
(
int
y
=
0
;
y
<
id
.
intValue
();
y
++)
{
for
(
int
x
=
0
;
x
<
id
.
intValue
();
x
++)
{
for
(
int
y
=
0
;
y
<
id
.
intValue
();
y
++)
{
rs
.
addRow
(
new
Object
[]
{
new
Integer
(
x
),
new
Integer
(
y
)
});
}
}
...
...
h2/src/test/org/h2/samples/FunctionMultiReturn.java
浏览文件 @
f447a3e4
...
...
@@ -25,7 +25,7 @@ public class FunctionMultiReturn {
prep
.
setDouble
(
1
,
5.0
);
prep
.
setDouble
(
2
,
0.5
);
ResultSet
rs
=
prep
.
executeQuery
();
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
double
x
=
rs
.
getDouble
(
1
);
double
y
=
rs
.
getDouble
(
2
);
System
.
out
.
println
(
"result: (x="
+
x
+
", y="
+
y
+
")"
);
...
...
@@ -35,7 +35,7 @@ public class FunctionMultiReturn {
stat
.
execute
(
"INSERT INTO TEST(R, A) VALUES(5.0, 0.5), (10.0, 0.6)"
);
stat
.
execute
(
"CREATE ALIAS P2C_SET FOR \"org.h2.samples.FunctionMultiReturn.polar2CartesianSet\" "
);
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM P2C_SET('SELECT * FROM TEST')"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
double
r
=
rs
.
getDouble
(
"R"
);
double
a
=
rs
.
getDouble
(
"A"
);
double
x
=
rs
.
getDouble
(
"X"
);
...
...
@@ -45,18 +45,18 @@ public class FunctionMultiReturn {
stat
.
execute
(
"CREATE ALIAS P2C_A FOR \"org.h2.samples.FunctionMultiReturn.polar2CartesianArray\" "
);
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT R, A, P2C_A(R, A) FROM TEST"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
double
r
=
rs
.
getDouble
(
1
);
double
a
=
rs
.
getDouble
(
2
);
Object
o
=
rs
.
getObject
(
3
);
Object
[]
xy
=
(
Object
[])
o
;
double
x
=
((
Double
)
xy
[
0
]).
doubleValue
();
double
y
=
((
Double
)
xy
[
1
]).
doubleValue
();
System
.
out
.
println
(
"(r="
+
r
+
" a="
+
a
+
") : (x="
+
x
+
", y="
+
y
+
")"
);
double
x
=
((
Double
)
xy
[
0
]).
doubleValue
();
double
y
=
((
Double
)
xy
[
1
]).
doubleValue
();
System
.
out
.
println
(
"(r="
+
r
+
" a="
+
a
+
") : (x="
+
x
+
", y="
+
y
+
")"
);
}
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT R, A, ARRAY_GET(E, 1), ARRAY_GET(E, 2) FROM (SELECT R, A, P2C_A(R, A) E FROM TEST)"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
double
r
=
rs
.
getDouble
(
1
);
double
a
=
rs
.
getDouble
(
2
);
double
x
=
rs
.
getDouble
(
3
);
...
...
@@ -75,7 +75,7 @@ public class FunctionMultiReturn {
SimpleResultSet
rs
=
new
SimpleResultSet
();
rs
.
addColumn
(
"X"
,
Types
.
DOUBLE
,
0
,
0
);
rs
.
addColumn
(
"Y"
,
Types
.
DOUBLE
,
0
,
0
);
if
(
r
!=
null
&&
alpha
!=
null
)
{
if
(
r
!=
null
&&
alpha
!=
null
)
{
double
x
=
r
.
doubleValue
()
*
Math
.
cos
(
alpha
.
doubleValue
());
double
y
=
r
.
doubleValue
()
*
Math
.
sin
(
alpha
.
doubleValue
());
rs
.
addRow
(
new
Object
[]
{
new
Double
(
x
),
new
Double
(
y
)
});
...
...
@@ -99,9 +99,9 @@ public class FunctionMultiReturn {
result
.
addColumn
(
"A"
,
Types
.
DOUBLE
,
0
,
0
);
result
.
addColumn
(
"X"
,
Types
.
DOUBLE
,
0
,
0
);
result
.
addColumn
(
"Y"
,
Types
.
DOUBLE
,
0
,
0
);
if
(
query
!=
null
)
{
if
(
query
!=
null
)
{
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
query
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
double
r
=
rs
.
getDouble
(
"R"
);
double
alpha
=
rs
.
getDouble
(
"A"
);
double
x
=
r
*
Math
.
cos
(
alpha
);
...
...
h2/src/test/org/h2/samples/InitDatabaseFromJar.java
浏览文件 @
f447a3e4
...
...
@@ -4,8 +4,13 @@
*/
package
org
.
h2
.
samples
;
import
java.io.*
;
import
java.sql.*
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
import
java.sql.Statement
;
import
org.h2.tools.RunScript
;
public
class
InitDatabaseFromJar
{
...
...
@@ -29,12 +34,13 @@ public class InitDatabaseFromJar {
Class
.
forName
(
"org.h2.Driver"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:test"
);
InputStream
in
=
getClass
().
getResourceAsStream
(
"script.sql"
);
if
(
in
==
null
)
{
System
.
out
.
println
(
"Please add the file script.sql to the classpath, package "
+
getClass
().
getPackage
().
getName
());
if
(
in
==
null
)
{
System
.
out
.
println
(
"Please add the file script.sql to the classpath, package "
+
getClass
().
getPackage
().
getName
());
}
else
{
RunScript
.
execute
(
conn
,
new
InputStreamReader
(
in
));
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
System
.
out
.
println
(
rs
.
getString
(
1
));
}
conn
.
close
();
...
...
h2/src/test/org/h2/samples/MixedMode.java
浏览文件 @
f447a3e4
...
...
@@ -30,14 +30,14 @@ public class MixedMode {
System
.
out
.
println
(
"Execute this a few times: SELECT TIME FROM TIMER"
);
System
.
out
.
println
(
"To stop this application (and the server), run: DROP TABLE TIMER"
);
try
{
while
(
true
)
{
// runs forever, except if you drop the table remotely
stat
.
execute
(
"MERGE INTO TIMER VALUES(1, NOW())"
);
Thread
.
sleep
(
1000
);
}
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
"Error: "
+
e
.
toString
());
}
while
(
true
)
{
// runs forever, except if you drop the table remotely
stat
.
execute
(
"MERGE INTO TIMER VALUES(1, NOW())"
);
Thread
.
sleep
(
1000
);
}
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
"Error: "
+
e
.
toString
());
}
conn
.
close
();
// stop the server
...
...
h2/src/test/org/h2/samples/Newsfeed.java
浏览文件 @
f447a3e4
...
...
@@ -22,10 +22,10 @@ public class Newsfeed {
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:"
,
"sa"
,
""
);
InputStream
in
=
Newsfeed
.
class
.
getResourceAsStream
(
"newsfeed.sql"
);
ResultSet
rs
=
RunScript
.
execute
(
conn
,
new
InputStreamReader
(
in
,
"ISO-8859-1"
));
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
String
file
=
rs
.
getString
(
"FILE"
);
String
content
=
rs
.
getString
(
"CONTENT"
);
if
(
file
.
equals
(
"-newsletter-"
))
{
if
(
file
.
equals
(
"-newsletter-"
))
{
System
.
out
.
println
(
convertHtml2Text
(
content
));
}
else
{
FileOutputStream
out
=
new
FileOutputStream
(
file
);
...
...
@@ -52,7 +52,7 @@ public class Newsfeed {
s
=
StringUtils
.
replaceAll
(
s
,
"<br />"
,
""
);
s
=
StringUtils
.
replaceAll
(
s
,
"<br/>"
,
""
);
s
=
StringUtils
.
replaceAll
(
s
,
"<br>"
,
""
);
if
(
s
.
indexOf
(
'<'
)
>=
0
||
s
.
indexOf
(
'>'
)
>=
0
)
{
if
(
s
.
indexOf
(
'<'
)
>=
0
||
s
.
indexOf
(
'>'
)
>=
0
)
{
throw
new
Error
(
"Unsupported HTML Tag: < or > in "
+
s
);
}
return
s
;
...
...
h2/src/test/org/h2/samples/SQLInjection.java
浏览文件 @
f447a3e4
...
...
@@ -4,8 +4,14 @@
*/
package
org
.
h2
.
samples
;
import
java.io.*
;
import
java.sql.*
;
import
java.io.BufferedReader
;
import
java.io.InputStreamReader
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
public
class
SQLInjection
{
...
...
@@ -43,14 +49,14 @@ public class SQLInjection {
// loginByNameInsecure();
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
//
loginStoredProcedureInsecure();
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
// loginStoredProcedureInsecure();
limitRowAccess
();
}
// loginByNameSecure();
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
stat
.
execute
(
"SET ALLOW_LITERALS NONE"
);
stat
.
execute
(
"SET ALLOW_LITERALS NUMBERS"
);
stat
.
execute
(
"SET ALLOW_LITERALS ALL"
);
...
...
@@ -75,7 +81,7 @@ public class SQLInjection {
listActiveItems
();
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
stat
.
execute
(
"DROP CONSTANT IF EXISTS TYPE_INACTIVE"
);
stat
.
execute
(
"DROP CONSTANT IF EXISTS TYPE_ACTIVE"
);
stat
.
execute
(
"CREATE CONSTANT TYPE_INACTIVE VALUE 0"
);
...
...
@@ -86,7 +92,7 @@ public class SQLInjection {
// listItemsSortedInsecure();
// listItemsSortedSecure();
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
if
(
url
.
startsWith
(
"jdbc:h2:"
))
{
listItemsSortedSecureParam
();
// storePasswordHashWithSalt();
}
...
...
@@ -188,7 +194,7 @@ public class SQLInjection {
}
else
{
System
.
out
.
println
(
"Access denied!"
);
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
e
);
}
}
...
...
@@ -209,7 +215,7 @@ public class SQLInjection {
}
else
{
System
.
out
.
println
(
"Access denied!"
);
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
}
}
...
...
@@ -241,7 +247,7 @@ public class SQLInjection {
while
(
rs
.
next
())
{
System
.
out
.
println
(
rs
.
getString
(
1
)
+
": "
+
rs
.
getString
(
2
));
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
e
);
}
}
...
...
@@ -258,7 +264,7 @@ public class SQLInjection {
while
(
rs
.
next
())
{
System
.
out
.
println
(
rs
.
getString
(
1
)
+
": "
+
rs
.
getString
(
2
));
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
e
);
}
}
...
...
@@ -274,7 +280,7 @@ public class SQLInjection {
while
(
rs
.
next
())
{
System
.
out
.
println
(
rs
.
getString
(
1
)
+
": "
+
rs
.
getString
(
2
));
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
}
}
...
...
h2/src/test/org/h2/samples/SecurePassword.java
浏览文件 @
f447a3e4
...
...
@@ -39,7 +39,7 @@ public class SecurePassword {
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
stat
.
executeUpdate
(
"INSERT INTO TEST VALUES(1, 'Hello')"
);
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM TEST"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
System
.
out
.
println
(
rs
.
getString
(
"NAME"
));
}
conn
.
close
();
...
...
h2/src/test/org/h2/samples/ShowProgress.java
浏览文件 @
f447a3e4
...
...
@@ -35,21 +35,21 @@ public class ShowProgress implements DatabaseEventListener {
long
time
;
time
=
System
.
currentTimeMillis
();
int
len
=
1000
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
long
last
=
System
.
currentTimeMillis
();
if
(
last
>
time
+
1000
)
{
if
(
last
>
time
+
1000
)
{
time
=
last
;
System
.
out
.
println
(
"Inserting "
+
(
100L
*
i
/
len
)
+
"%"
);
System
.
out
.
println
(
"Inserting "
+
(
100L
*
i
/
len
)
+
"%"
);
}
prep
.
setInt
(
1
,
i
);
prep
.
execute
();
}
boolean
abnormalTermination
=
true
;
if
(
abnormalTermination
)
{
((
JdbcConnection
)
conn
).
setPowerOffCount
(
1
);
if
(
abnormalTermination
)
{
((
JdbcConnection
)
conn
).
setPowerOffCount
(
1
);
try
{
stat
.
execute
(
"INSERT INTO TEST VALUES(-1, 'Test' || SPACE(100))"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
}
}
else
{
conn
.
close
();
...
...
@@ -75,12 +75,12 @@ public class ShowProgress implements DatabaseEventListener {
public
void
setProgress
(
int
state
,
String
name
,
int
current
,
int
max
)
{
long
time
=
System
.
currentTimeMillis
();
if
(
time
<
last
+
5000
)
{
if
(
time
<
last
+
5000
)
{
return
;
}
last
=
time
;
String
stateName
=
"?"
;
switch
(
state
)
{
switch
(
state
)
{
case
STATE_SCAN_FILE:
stateName
=
"Scan "
+
name
;
break
;
...
...
@@ -95,7 +95,8 @@ public class ShowProgress implements DatabaseEventListener {
Thread
.
sleep
(
1
);
}
catch
(
InterruptedException
e
)
{
}
System
.
out
.
println
(
"State: "
+
stateName
+
" "
+
(
100
*
current
/
max
)
+
"% ("
+
current
+
" of "
+
max
+
") "
+
(
time
-
start
)+
" ms"
);
System
.
out
.
println
(
"State: "
+
stateName
+
" "
+
(
100
*
current
/
max
)
+
"% ("
+
current
+
" of "
+
max
+
") "
+
(
time
-
start
)
+
" ms"
);
}
public
void
closingDatabase
()
{
...
...
h2/src/test/org/h2/samples/TriggerSample.java
浏览文件 @
f447a3e4
...
...
@@ -49,11 +49,11 @@ public class TriggerSample {
Object
[]
oldRow
,
Object
[]
newRow
)
throws
SQLException
{
BigDecimal
diff
=
null
;
if
(
newRow
!=
null
)
{
diff
=
(
BigDecimal
)
newRow
[
1
];
if
(
newRow
!=
null
)
{
diff
=
(
BigDecimal
)
newRow
[
1
];
}
if
(
oldRow
!=
null
)
{
BigDecimal
m
=
(
BigDecimal
)
oldRow
[
1
];
if
(
oldRow
!=
null
)
{
BigDecimal
m
=
(
BigDecimal
)
oldRow
[
1
];
diff
=
diff
==
null
?
m
.
negate
()
:
diff
.
subtract
(
m
);
}
PreparedStatement
prep
=
conn
.
prepareStatement
(
...
...
h2/src/test/org/h2/test/bench/BenchC.java
浏览文件 @
f447a3e4
差异被折叠。
点击展开。
h2/src/test/org/h2/test/bench/BenchCThread.java
浏览文件 @
f447a3e4
差异被折叠。
点击展开。
h2/src/test/org/h2/test/db/TestAutoRecompile.java
浏览文件 @
f447a3e4
...
...
@@ -15,7 +15,7 @@ public class TestAutoRecompile extends TestBase {
public
void
test
()
throws
Exception
{
deleteDb
(
"autoRecompile"
);
Connection
conn
=
getConnection
(
"autoRecompile"
);
Connection
conn
=
getConnection
(
"autoRecompile"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT * FROM TEST"
);
...
...
@@ -26,19 +26,19 @@ public class TestAutoRecompile extends TestBase {
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, X INT, Y INT)"
);
check
(
prep
.
executeQuery
().
getMetaData
().
getColumnCount
(),
3
);
// TODO test auto-recompile with insert..select, views and so on
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(1, 2, 3)"
);
stat
.
execute
(
"ALTER TABLE TEST ADD COLUMN Z INT"
);
try
{
prep
.
execute
();
error
(
"must fail"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
}
try
{
prep
.
execute
();
error
(
"must fail"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
}
conn
.
close
();
...
...
h2/src/test/org/h2/test/db/TestCompatibility.java
浏览文件 @
f447a3e4
...
...
@@ -13,18 +13,18 @@ import org.h2.test.TestBase;
public
class
TestCompatibility
extends
TestBase
{
private
Connection
conn
;
public
void
test
()
throws
Exception
{
deleteDb
(
"compatibility"
);
conn
=
getConnection
(
"compatibility"
);
testHsqlDb
();
testMySQL
();
conn
.
close
();
}
private
void
testHsqlDb
()
throws
Exception
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"DROP TABLE TEST IF EXISTS; CREATE TABLE TEST(ID INT PRIMARY KEY); "
);
...
...
@@ -37,15 +37,13 @@ public class TestCompatibility extends TestBase {
stat
.
execute
(
"DROP TABLE TEST IF EXISTS"
);
stat
.
execute
(
"CREATE TABLE TEST(ID INT)"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1)"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT LIMIT ? 1 ID FROM TEST"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"SELECT LIMIT ? 1 ID FROM TEST"
);
prep
.
setInt
(
1
,
2
);
prep
.
executeQuery
();
stat
.
execute
(
"DROP TABLE TEST IF EXISTS"
);
}
private
void
testMySQL
()
throws
Exception
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SELECT 1"
);
...
...
@@ -53,6 +51,5 @@ public class TestCompatibility extends TestBase {
stat
.
execute
(
"CREATE TABLE TEST(ID INT, NAME VARCHAR)"
);
stat
.
execute
(
"INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World')"
);
}
}
h2/src/test/org/h2/test/db/TestLobObject.java
浏览文件 @
f447a3e4
...
...
@@ -9,6 +9,7 @@ import java.io.Serializable;
class
TestLobObject
implements
Serializable
{
private
static
final
long
serialVersionUID
=
904356179316518715L
;
String
data
;
TestLobObject
(
String
data
)
{
this
.
data
=
data
;
}
...
...
h2/src/test/org/h2/test/db/TestSQLInjection.java
浏览文件 @
f447a3e4
...
...
@@ -13,13 +13,13 @@ import java.sql.Statement;
import
org.h2.test.TestBase
;
public
class
TestSQLInjection
extends
TestBase
{
Connection
conn
;
Statement
stat
;
public
void
test
()
throws
Exception
{
deleteDb
(
"sqlInjection"
);
reconnect
(
"sqlInjection"
);
reconnect
(
"sqlInjection"
);
stat
.
execute
(
"DROP TABLE IF EXISTS USERS"
);
stat
.
execute
(
"CREATE TABLE USERS(NAME VARCHAR PRIMARY KEY, PASSWORD VARCHAR, TYPE VARCHAR)"
);
stat
.
execute
(
"CREATE SCHEMA CONST"
);
...
...
@@ -32,56 +32,56 @@ public class TestSQLInjection extends TestBase {
checkFalse
(
checkPasswordSecure
(
"abcdef"
));
checkFalse
(
checkPasswordSecure
(
"' OR ''='"
));
stat
.
execute
(
"SET ALLOW_LITERALS NONE"
);
try
{
check
(
checkPasswordInsecure
(
"123456"
));
error
(
"Should fail now"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
}
check
(
checkPasswordSecure
(
"123456"
));
checkFalse
(
checkPasswordSecure
(
"' OR ''='"
));
conn
.
close
();
if
(
config
.
memory
)
{
if
(
config
.
memory
)
{
return
;
}
reconnect
(
"sqlInjection"
);
reconnect
(
"sqlInjection"
);
try
{
check
(
checkPasswordInsecure
(
"123456"
));
error
(
"Should fail now"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
}
check
(
checkPasswordSecure
(
"123456"
));
checkFalse
(
checkPasswordSecure
(
"' OR ''='"
));
conn
.
close
();
}
boolean
checkPasswordInsecure
(
String
pwd
)
throws
SQLException
{
String
sql
=
"SELECT * FROM USERS WHERE PASSWORD='"
+
pwd
+
"'"
;
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
sql
);
return
(
rs
.
next
());
String
sql
=
"SELECT * FROM USERS WHERE PASSWORD='"
+
pwd
+
"'"
;
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
sql
);
return
(
rs
.
next
());
}
boolean
checkPasswordSecure
(
String
pwd
)
throws
Exception
{
String
sql
=
"SELECT * FROM USERS WHERE PASSWORD=?"
;
PreparedStatement
prep
=
conn
.
prepareStatement
(
sql
);
prep
.
setString
(
1
,
pwd
);
ResultSet
rs
=
prep
.
executeQuery
();
return
(
rs
.
next
());
ResultSet
rs
=
prep
.
executeQuery
();
return
(
rs
.
next
());
}
private
void
reconnect
(
String
name
)
throws
Exception
{
if
(!
config
.
memory
)
{
if
(
conn
!=
null
)
{
if
(!
config
.
memory
)
{
if
(
conn
!=
null
)
{
conn
.
close
();
conn
=
null
;
}
}
if
(
conn
==
null
)
{
if
(
conn
==
null
)
{
conn
=
getConnection
(
name
);
stat
=
conn
.
createStatement
();
}
...
...
h2/src/test/org/h2/test/db/TestSpaceReuse.java
浏览文件 @
f447a3e4
...
...
@@ -12,7 +12,7 @@ import org.h2.test.TestBase;
public
class
TestSpaceReuse
extends
TestBase
{
public
void
test
()
throws
Exception
{
if
(
config
.
memory
)
{
if
(
config
.
memory
)
{
return
;
}
deleteDb
(
"spaceReuse"
);
...
...
@@ -27,11 +27,11 @@ public class TestSpaceReuse extends TestBase {
conn
.
createStatement
().
execute
(
"delete from t"
);
conn
.
close
();
now
=
new
File
(
baseDir
+
"/spaceReuse.data.db"
).
length
();
if
(
first
==
0
)
{
if
(
first
==
0
)
{
first
=
now
;
}
}
if
(
now
>
first
)
{
if
(
now
>
first
)
{
this
.
error
(
"first: "
+
first
+
" now: "
+
now
);
}
}
...
...
h2/src/test/org/h2/test/db/TestSpeed.java
浏览文件 @
f447a3e4
差异被折叠。
点击展开。
h2/src/test/org/h2/test/db/TestTempTables.java
浏览文件 @
f447a3e4
...
...
@@ -34,8 +34,9 @@ public class TestTempTables extends TestBase {
s2
.
execute
(
"DROP TABLE LT"
);
s1
.
execute
(
"DROP TABLE LT"
);
// temp tables: 'on commit' syntax is currently not documented, because not tested well
// and hopefully nobody is using it, as it looks like functional sugar
// temp tables: 'on commit' syntax is currently not documented, because
// not tested well
// and hopefully nobody is using it, as it looks like functional sugar
// (this features are here for compatibility only)
ResultSet
rs
;
c1
.
setAutoCommit
(
false
);
...
...
@@ -47,7 +48,7 @@ public class TestTempTables extends TestBase {
rs
=
s1
.
executeQuery
(
"select * from test_temp"
);
checkResultRowCount
(
rs
,
0
);
s1
.
execute
(
"drop table test_temp"
);
s1
.
execute
(
"create local temporary table test_temp(id int) on commit drop"
);
s1
.
execute
(
"insert into test_temp values(1)"
);
rs
=
s1
.
executeQuery
(
"select * from test_temp"
);
...
...
@@ -56,10 +57,10 @@ public class TestTempTables extends TestBase {
try
{
rs
=
s1
.
executeQuery
(
"select * from test_temp"
);
error
(
"test_temp should have been dropped automatically"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
}
c1
.
close
();
c2
.
close
();
}
...
...
h2/src/test/org/h2/test/db/TestTransaction.java
浏览文件 @
f447a3e4
...
...
@@ -16,12 +16,12 @@ import java.util.Vector;
import
org.h2.test.TestBase
;
public
class
TestTransaction
extends
TestBase
{
public
void
test
()
throws
Exception
{
testSavepoint
();
testIsolation
();
}
public
void
testSavepoint
()
throws
Exception
{
deleteDb
(
"transaction"
);
Connection
conn
=
getConnection
(
"transaction"
);
...
...
@@ -35,40 +35,44 @@ public class TestTransaction extends TestBase {
int
len
=
getSize
(
2000
,
10000
);
Random
random
=
new
Random
(
10
);
Savepoint
sp
=
null
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
int
tableId
=
random
.
nextInt
(
2
);
String
table
=
"TEST"
+
tableId
;
String
table
=
"TEST"
+
tableId
;
int
op
=
random
.
nextInt
(
6
);
switch
(
op
)
{
switch
(
op
)
{
case
0
:
stat
.
execute
(
"INSERT INTO "
+
table
+
"(NAME) VALUES('op"
+
i
+
"')"
);
stat
.
execute
(
"INSERT INTO "
+
table
+
"(NAME) VALUES('op"
+
i
+
"')"
);
count
[
tableId
]++;
break
;
case
1
:
if
(
count
[
tableId
]
>
0
)
{
stat
.
execute
(
"DELETE FROM "
+
table
+
" WHERE ID=SELECT MIN(ID) FROM "
+
table
);
if
(
count
[
tableId
]
>
0
)
{
stat
.
execute
(
"DELETE FROM "
+
table
+
" WHERE ID=SELECT MIN(ID) FROM "
+
table
);
count
[
tableId
]--;
}
break
;
case
2
:
sp
=
conn
.
setSavepoint
();
countSave
[
0
]
=
count
[
0
];
countSave
[
1
]
=
count
[
1
];
countSave
[
0
]
=
count
[
0
];
countSave
[
1
]
=
count
[
1
];
break
;
case
3
:
if
(
sp
!=
null
)
{
if
(
sp
!=
null
)
{
conn
.
rollback
(
sp
);
count
[
0
]
=
countSave
[
0
];
count
[
1
]
=
countSave
[
1
];
count
[
0
]
=
countSave
[
0
];
count
[
1
]
=
countSave
[
1
];
}
break
;
case
4
:
conn
.
commit
();
sp
=
null
;
countCommitted
[
0
]
=
count
[
0
];
countCommitted
[
1
]
=
count
[
1
];
countCommitted
[
0
]
=
count
[
0
];
countCommitted
[
1
]
=
count
[
1
];
break
;
case
5
:
conn
.
rollback
();
sp
=
null
;
count
[
0
]
=
countCommitted
[
0
];
count
[
1
]
=
countCommitted
[
1
];
count
[
0
]
=
countCommitted
[
0
];
count
[
1
]
=
countCommitted
[
1
];
break
;
}
checkTableCount
(
stat
,
"TEST0"
,
count
[
0
]);
...
...
@@ -76,22 +80,22 @@ public class TestTransaction extends TestBase {
}
conn
.
close
();
}
private
void
checkTableCount
(
Statement
stat
,
String
tableName
,
int
count
)
throws
Exception
{
ResultSet
rs
;
rs
=
stat
.
executeQuery
(
"SELECT COUNT(*) FROM "
+
tableName
);
rs
.
next
();
check
(
count
,
rs
.
getInt
(
1
));
}
public
void
testIsolation
()
throws
Exception
{
Connection
conn
=
getConnection
(
"transaction"
);
trace
(
"default TransactionIsolation="
+
conn
.
getTransactionIsolation
());
trace
(
"default TransactionIsolation="
+
conn
.
getTransactionIsolation
());
conn
.
setTransactionIsolation
(
Connection
.
TRANSACTION_READ_COMMITTED
);
check
(
conn
.
getTransactionIsolation
()
==
Connection
.
TRANSACTION_READ_COMMITTED
);
check
(
conn
.
getTransactionIsolation
()
==
Connection
.
TRANSACTION_READ_COMMITTED
);
conn
.
setTransactionIsolation
(
Connection
.
TRANSACTION_SERIALIZABLE
);
check
(
conn
.
getTransactionIsolation
()
==
Connection
.
TRANSACTION_SERIALIZABLE
);
Statement
stat
=
conn
.
createStatement
();
check
(
conn
.
getTransactionIsolation
()
==
Connection
.
TRANSACTION_SERIALIZABLE
);
Statement
stat
=
conn
.
createStatement
();
check
(
conn
.
getAutoCommit
());
conn
.
setAutoCommit
(
false
);
checkFalse
(
conn
.
getAutoCommit
());
...
...
@@ -101,10 +105,10 @@ public class TestTransaction extends TestBase {
conn
.
commit
();
test
(
stat
,
"INSERT INTO TEST VALUES(0)"
);
conn
.
rollback
();
testValue
(
stat
,
"SELECT COUNT(*) FROM TEST"
,
"1"
);
testValue
(
stat
,
"SELECT COUNT(*) FROM TEST"
,
"1"
);
conn
.
setAutoCommit
(
false
);
test
(
stat
,
"DELETE FROM TEST"
);
//testValue("SELECT COUNT(*) FROM TEST", "0");
//
testValue("SELECT COUNT(*) FROM TEST", "0");
conn
.
rollback
();
testValue
(
stat
,
"SELECT COUNT(*) FROM TEST"
,
"1"
);
conn
.
commit
();
...
...
@@ -114,78 +118,78 @@ public class TestTransaction extends TestBase {
testNestedResultSets
(
conn
);
conn
.
close
();
}
void
testNestedResultSets
(
Connection
conn
)
throws
Exception
{
Statement
stat
=
conn
.
createStatement
();
test
(
stat
,
"CREATE TABLE NEST1(ID INT PRIMARY KEY,VALUE VARCHAR(255))"
);
test
(
stat
,
"CREATE TABLE NEST2(ID INT PRIMARY KEY,VALUE VARCHAR(255))"
);
DatabaseMetaData
meta
=
conn
.
getMetaData
();
DatabaseMetaData
meta
=
conn
.
getMetaData
();
Vector
result
;
ResultSet
rs1
,
rs2
;
result
=
new
Vector
();
rs1
=
meta
.
getTables
(
null
,
null
,
"NEST%"
,
null
);
while
(
rs1
.
next
())
{
String
table
=
rs1
.
getString
(
"TABLE_NAME"
);
rs2
=
meta
.
getColumns
(
null
,
null
,
table
,
null
);
while
(
rs2
.
next
())
{
String
column
=
rs2
.
getString
(
"COLUMN_NAME"
);
trace
(
"Table: "
+
table
+
" Column: "
+
column
);
result
.
add
(
table
+
"."
+
column
);
ResultSet
rs1
,
rs2
;
result
=
new
Vector
();
rs1
=
meta
.
getTables
(
null
,
null
,
"NEST%"
,
null
);
while
(
rs1
.
next
())
{
String
table
=
rs1
.
getString
(
"TABLE_NAME"
);
rs2
=
meta
.
getColumns
(
null
,
null
,
table
,
null
);
while
(
rs2
.
next
())
{
String
column
=
rs2
.
getString
(
"COLUMN_NAME"
);
trace
(
"Table: "
+
table
+
" Column: "
+
column
);
result
.
add
(
table
+
"."
+
column
);
}
}
if
(
result
.
size
()!=
4
)
{
error
(
"Wrong result, should be NEST1.ID, NEST1.NAME, NEST2.ID, NEST2.NAME but is "
+
result
);
if
(
result
.
size
()
!=
4
)
{
error
(
"Wrong result, should be NEST1.ID, NEST1.NAME, NEST2.ID, NEST2.NAME but is "
+
result
);
}
result
=
new
Vector
();
result
=
new
Vector
();
test
(
stat
,
"INSERT INTO NEST1 VALUES(1,'A')"
);
test
(
stat
,
"INSERT INTO NEST1 VALUES(2,'B')"
);
test
(
stat
,
"INSERT INTO NEST2 VALUES(1,'1')"
);
test
(
stat
,
"INSERT INTO NEST2 VALUES(2,'2')"
);
Statement
s1
=
conn
.
createStatement
();
Statement
s2
=
conn
.
createStatement
();
rs1
=
s1
.
executeQuery
(
"SELECT * FROM NEST1 ORDER BY ID"
);
while
(
rs1
.
next
())
{
rs2
=
s2
.
executeQuery
(
"SELECT * FROM NEST2 ORDER BY ID"
);
while
(
rs2
.
next
())
{
String
v1
=
rs1
.
getString
(
"VALUE"
);
String
v2
=
rs2
.
getString
(
"VALUE"
);
result
.
add
(
v1
+
"/"
+
v2
);
Statement
s1
=
conn
.
createStatement
();
Statement
s2
=
conn
.
createStatement
();
rs1
=
s1
.
executeQuery
(
"SELECT * FROM NEST1 ORDER BY ID"
);
while
(
rs1
.
next
())
{
rs2
=
s2
.
executeQuery
(
"SELECT * FROM NEST2 ORDER BY ID"
);
while
(
rs2
.
next
())
{
String
v1
=
rs1
.
getString
(
"VALUE"
);
String
v2
=
rs2
.
getString
(
"VALUE"
);
result
.
add
(
v1
+
"/"
+
v2
);
}
}
if
(
result
.
size
()!=
4
)
{
error
(
"Wrong result, should be A/1, A/2, B/1, B/2 but is "
+
result
);
if
(
result
.
size
()
!=
4
)
{
error
(
"Wrong result, should be A/1, A/2, B/1, B/2 but is "
+
result
);
}
result
=
new
Vector
();
rs1
=
s1
.
executeQuery
(
"SELECT * FROM NEST1 ORDER BY ID"
);
rs2
=
s1
.
executeQuery
(
"SELECT * FROM NEST2 ORDER BY ID"
);
result
=
new
Vector
();
rs1
=
s1
.
executeQuery
(
"SELECT * FROM NEST1 ORDER BY ID"
);
rs2
=
s1
.
executeQuery
(
"SELECT * FROM NEST2 ORDER BY ID"
);
try
{
rs1
.
next
();
error
(
"next worked on a closed result set"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
}
// this is already closed, so but closing again should no do any harm
rs1
.
close
();
while
(
rs2
.
next
())
{
String
v1
=
rs2
.
getString
(
"VALUE"
);
while
(
rs2
.
next
())
{
String
v1
=
rs2
.
getString
(
"VALUE"
);
result
.
add
(
v1
);
}
if
(
result
.
size
()!=
2
)
{
error
(
"Wrong result, should be A, B but is "
+
result
);
if
(
result
.
size
()
!=
2
)
{
error
(
"Wrong result, should be A, B but is "
+
result
);
}
test
(
stat
,
"DROP TABLE NEST1"
);
test
(
stat
,
"DROP TABLE NEST2"
);
}
void
testValue
(
Statement
stat
,
String
sql
,
String
data
)
throws
Exception
{
ResultSet
rs
=
stat
.
executeQuery
(
sql
);
ResultSet
rs
=
stat
.
executeQuery
(
sql
);
rs
.
next
();
String
s
=
rs
.
getString
(
1
);
if
(
s
==
null
?
(
data
!=
null
)
:
(!
s
.
equals
(
data
)))
{
error
(
"s= "
+
s
+
" should be: "
+
data
);
String
s
=
rs
.
getString
(
1
);
if
(
s
==
null
?
(
data
!=
null
)
:
(!
s
.
equals
(
data
)))
{
error
(
"s= "
+
s
+
" should be: "
+
data
);
}
}
void
test
(
Statement
stat
,
String
sql
)
throws
Exception
{
trace
(
sql
);
stat
.
execute
(
sql
);
...
...
h2/src/test/org/h2/test/db/TestTwoPhaseCommit.java
浏览文件 @
f447a3e4
...
...
@@ -13,21 +13,21 @@ import org.h2.test.TestBase;
public
class
TestTwoPhaseCommit
extends
TestBase
{
public
void
test
()
throws
Exception
{
if
(
config
.
memory
||
config
.
networked
||
config
.
logMode
==
0
)
{
if
(
config
.
memory
||
config
.
networked
||
config
.
logMode
==
0
)
{
return
;
}
deleteDb
(
"twoPhaseCommit"
);
prepare
();
openWith
(
true
);
test
(
true
);
prepare
();
openWith
(
false
);
test
(
false
);
}
void
test
(
boolean
rolledBack
)
throws
Exception
{
Connection
conn
=
getConnection
(
"twoPhaseCommit"
);
Statement
stat
=
conn
.
createStatement
();
...
...
@@ -36,7 +36,7 @@ public class TestTwoPhaseCommit extends TestBase {
rs
.
next
();
check
(
rs
.
getInt
(
1
),
1
);
check
(
rs
.
getString
(
2
),
"Hello"
);
if
(
rolledBack
)
{
if
(
rolledBack
)
{
}
else
{
rs
.
next
();
check
(
rs
.
getInt
(
1
),
2
);
...
...
@@ -45,18 +45,18 @@ public class TestTwoPhaseCommit extends TestBase {
checkFalse
(
rs
.
next
());
conn
.
close
();
}
void
openWith
(
boolean
rollback
)
throws
Exception
{
Connection
conn
=
getConnection
(
"twoPhaseCommit"
);
Statement
stat
=
conn
.
createStatement
();
ArrayList
list
=
new
ArrayList
();
ResultSet
rs
=
stat
.
executeQuery
(
"SELECT * FROM INFORMATION_SCHEMA.IN_DOUBT"
);
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
list
.
add
(
rs
.
getString
(
"TRANSACTION"
));
}
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
String
s
=
(
String
)
list
.
get
(
i
);
if
(
rollback
)
{
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
String
s
=
(
String
)
list
.
get
(
i
);
if
(
rollback
)
{
stat
.
execute
(
"ROLLBACK TRANSACTION "
+
s
);
}
else
{
stat
.
execute
(
"COMMIT TRANSACTION "
+
s
);
...
...
@@ -64,7 +64,7 @@ public class TestTwoPhaseCommit extends TestBase {
}
conn
.
close
();
}
void
prepare
()
throws
Exception
{
deleteDb
(
"twoPhaseCommit"
);
Connection
conn
=
getConnection
(
"twoPhaseCommit"
);
...
...
h2/src/test/org/h2/test/db/TestView.java
浏览文件 @
f447a3e4
...
...
@@ -17,10 +17,10 @@ public class TestView extends TestBase {
Statement
s
=
conn
.
createStatement
();
s
.
execute
(
"create table t0(id int primary key)"
);
s
.
execute
(
"insert into t0 values(1), (2), (3)"
);
for
(
int
i
=
0
;
i
<
30
;
i
++)
{
s
.
execute
(
"create view t"
+
(
i
+
1
)
+
" as select * from t"
+
i
);
s
.
execute
(
"select * from t"
+
(
i
+
1
));
ResultSet
rs
=
s
.
executeQuery
(
"select count(*) from t"
+
(
i
+
1
)
+
" where id=2"
);
for
(
int
i
=
0
;
i
<
30
;
i
++)
{
s
.
execute
(
"create view t"
+
(
i
+
1
)
+
" as select * from t"
+
i
);
s
.
execute
(
"select * from t"
+
(
i
+
1
));
ResultSet
rs
=
s
.
executeQuery
(
"select count(*) from t"
+
(
i
+
1
)
+
" where id=2"
);
check
(
rs
.
next
());
check
(
rs
.
getInt
(
1
),
1
);
}
...
...
h2/src/test/org/h2/test/unit/TestBitField.java
浏览文件 @
f447a3e4
...
...
@@ -15,22 +15,22 @@ import org.h2.util.BitField;
*/
public
class
TestBitField
extends
TestBase
{
public
void
test
()
throws
Exception
{
testRandom
();
testGetSet
();
}
void
testRandom
()
throws
Exception
{
BitField
bits
=
new
BitField
();
BitSet
set
=
new
BitSet
();
int
max
=
300
;
int
count
=
100000
;
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
int
idx
=
random
.
nextInt
(
max
);
if
(
random
.
nextBoolean
())
{
if
(
random
.
nextBoolean
())
{
if
(
random
.
nextBoolean
())
{
if
(
random
.
nextBoolean
())
{
bits
.
set
(
idx
);
set
.
set
(
idx
);
}
else
{
...
...
@@ -44,26 +44,26 @@ public class TestBitField extends TestBase {
}
}
}
void
testGetSet
()
throws
Exception
{
BitField
bits
=
new
BitField
();
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
bits
.
set
(
i
);
if
(!
bits
.
get
(
i
))
{
throw
new
Exception
(
"not set: "
+
i
);
if
(!
bits
.
get
(
i
))
{
throw
new
Exception
(
"not set: "
+
i
);
}
if
(
bits
.
get
(
i
+
1
))
{
throw
new
Exception
(
"set: "
+
i
);
if
(
bits
.
get
(
i
+
1
))
{
throw
new
Exception
(
"set: "
+
i
);
}
}
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
if
(!
bits
.
get
(
i
))
{
throw
new
Exception
(
"not set: "
+
i
);
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
if
(!
bits
.
get
(
i
))
{
throw
new
Exception
(
"not set: "
+
i
);
}
}
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
int
k
=
bits
.
nextClearBit
(
0
);
if
(
k
!=
10000
)
{
if
(
k
!=
10000
)
{
throw
new
Exception
(
""
+
k
);
}
}
...
...
h2/src/test/org/h2/test/unit/TestCache.java
浏览文件 @
f447a3e4
...
...
@@ -12,9 +12,9 @@ import java.util.Random;
import
org.h2.test.TestBase
;
public
class
TestCache
extends
TestBase
{
public
void
test
()
throws
Exception
{
if
(
config
.
memory
)
{
if
(
config
.
memory
)
{
return
;
}
deleteDb
(
"cache"
);
...
...
@@ -26,7 +26,7 @@ public class TestCache extends TestBase {
PreparedStatement
prep
=
conn
.
prepareStatement
(
"INSERT INTO TEST VALUES(?, ?)"
);
PreparedStatement
prep2
=
conn
.
prepareStatement
(
"INSERT INTO MAIN VALUES(?, ?)"
);
int
max
=
10000
;
for
(
int
i
=
0
;
i
<
max
;
i
++)
{
for
(
int
i
=
0
;
i
<
max
;
i
++)
{
prep
.
setInt
(
1
,
i
);
prep
.
setString
(
2
,
"Hello "
+
i
);
prep
.
execute
();
...
...
@@ -39,10 +39,10 @@ public class TestCache extends TestBase {
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SET CACHE_SIZE 1024"
);
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
stat
.
executeQuery
(
"SELECT * FROM MAIN WHERE ID BETWEEN 40 AND 50"
);
stat
.
executeQuery
(
"SELECT * FROM MAIN WHERE ID = "
+
random
.
nextInt
(
max
));
if
((
i
%
10
)
==
0
)
{
if
((
i
%
10
)
==
0
)
{
stat
.
executeQuery
(
"SELECT * FROM TEST"
);
}
}
...
...
h2/src/test/org/h2/test/unit/TestCompress.java
浏览文件 @
f447a3e4
...
...
@@ -10,15 +10,15 @@ import org.h2.test.TestBase;
import
org.h2.tools.CompressTool
;
public
class
TestCompress
extends
TestBase
{
public
void
test
()
throws
Exception
{
if
(
config
.
big
)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
if
(
config
.
big
)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
test
(
i
);
}
for
(
int
i
=
100
;
i
<
10000
;
i
+=
(
i
+
i
+
1
))
{
for
(
int
i
=
100
;
i
<
10000
;
i
+=
(
i
+
i
+
1
))
{
test
(
i
);
}
}
}
else
{
test
(
0
);
test
(
1
);
...
...
@@ -27,17 +27,17 @@ public class TestCompress extends TestBase {
test
(
200
);
}
}
void
test
(
int
len
)
throws
Exception
{
for
(
int
pattern
=
0
;
pattern
<
3
;
pattern
++)
{
for
(
int
pattern
=
0
;
pattern
<
3
;
pattern
++)
{
byte
[]
buff
=
new
byte
[
len
];
switch
(
pattern
)
{
switch
(
pattern
)
{
case
0
:
// leave empty
break
;
case
1
:
{
for
(
int
x
=
0
;
x
<
len
;
x
++)
{
buff
[
x
]
=
(
byte
)(
x
&
10
);
for
(
int
x
=
0
;
x
<
len
;
x
++)
{
buff
[
x
]
=
(
byte
)
(
x
&
10
);
}
break
;
}
...
...
@@ -47,11 +47,9 @@ public class TestCompress extends TestBase {
break
;
}
}
String
[]
algorithm
=
new
String
[]{
"LZF"
,
"Deflate"
,
"No"
};
String
[]
algorithm
=
new
String
[]
{
"LZF"
,
"Deflate"
,
"No"
};
CompressTool
utils
=
CompressTool
.
getInstance
();
for
(
int
i
=
0
;
i
<
algorithm
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
algorithm
.
length
;
i
++)
{
byte
[]
out
=
utils
.
compress
(
buff
,
algorithm
[
i
]);
byte
[]
test
=
utils
.
expand
(
out
);
check
(
test
.
length
,
buff
.
length
);
...
...
h2/src/test/org/h2/test/unit/TestDataPage.java
浏览文件 @
f447a3e4
...
...
@@ -22,21 +22,21 @@ import org.h2.value.ValueString;
*/
public
class
TestDataPage
extends
TestBase
implements
DataHandler
{
boolean
text
;
public
void
test
()
throws
Exception
{
testAll
();
text
=
true
;
testAll
();
}
private
void
testAll
()
throws
Exception
{
DataPage
page
=
DataPage
.
create
(
this
,
128
);
char
[]
data
=
new
char
[
0x10000
];
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
data
[
i
]
=
(
char
)
i
;
for
(
int
i
=
0
;
i
<
data
.
length
;
i
++)
{
data
[
i
]
=
(
char
)
i
;
}
String
s
=
new
String
(
data
);
page
.
writeString
(
s
);
...
...
@@ -45,7 +45,7 @@ public class TestDataPage extends TestBase implements DataHandler {
page
.
reset
();
check
(
s
,
page
.
readString
());
page
.
reset
();
page
.
writeString
(
"H\u1111!"
);
page
.
writeString
(
"John\tBrack's \"how are you\" M\u1111ller"
);
page
.
writeValue
(
ValueInt
.
get
(
10
));
...
...
@@ -60,8 +60,8 @@ public class TestDataPage extends TestBase implements DataHandler {
trace
(
page
.
readString
());
trace
(
page
.
readValue
().
getInt
());
trace
(
page
.
readValue
().
getString
());
trace
(
""
+
page
.
readValue
().
getFloat
());
trace
(
""
+
page
.
readValue
().
getDouble
());
trace
(
""
+
page
.
readValue
().
getFloat
());
trace
(
""
+
page
.
readValue
().
getDouble
());
trace
(
page
.
readValue
().
toString
());
page
.
reset
();
...
...
@@ -98,7 +98,7 @@ public class TestDataPage extends TestBase implements DataHandler {
}
public
int
getChecksum
(
byte
[]
data
,
int
start
,
int
end
)
{
return
end
-
start
;
return
end
-
start
;
}
public
void
checkPowerOff
()
throws
SQLException
{
...
...
h2/src/test/org/h2/test/unit/TestExit.java
浏览文件 @
f447a3e4
...
...
@@ -16,18 +16,14 @@ import org.h2.test.TestBase;
public
class
TestExit
extends
TestBase
implements
DatabaseEventListener
{
public
void
test
()
throws
Exception
{
if
(
config
.
codeCoverage
)
{
if
(
config
.
codeCoverage
)
{
return
;
}
String
classPath
=
"bin"
+
File
.
pathSeparator
+
"."
;
String
classPath
=
"bin"
+
File
.
pathSeparator
+
"."
;
deleteDb
(
"exit"
);
String
[]
procDef
;
procDef
=
new
String
[]{
"java"
,
"-cp"
,
classPath
,
getClass
().
getName
(),
""
+
OPEN_WITH_CLOSE_ON_EXIT
};
procDef
=
new
String
[]
{
"java"
,
"-cp"
,
classPath
,
getClass
().
getName
(),
""
+
OPEN_WITH_CLOSE_ON_EXIT
};
Process
proc
=
Runtime
.
getRuntime
().
exec
(
procDef
);
while
(
true
)
{
int
ch
=
proc
.
getErrorStream
().
read
();
...
...
@@ -44,50 +40,48 @@ public class TestExit extends TestBase implements DatabaseEventListener {
System
.
out
.
print
((
char
)
ch
);
}
proc
.
waitFor
();
if
(!
getClosedFile
().
exists
())
{
if
(!
getClosedFile
().
exists
())
{
error
(
"did not close database"
);
}
procDef
=
new
String
[]{
"java"
,
"-cp"
,
classPath
,
getClass
().
getName
(),
""
+
OPEN_WITHOUT_CLOSE_ON_EXIT
};
procDef
=
new
String
[]
{
"java"
,
"-cp"
,
classPath
,
getClass
().
getName
(),
""
+
OPEN_WITHOUT_CLOSE_ON_EXIT
};
proc
=
Runtime
.
getRuntime
().
exec
(
procDef
);
proc
.
waitFor
();
if
(
getClosedFile
().
exists
())
{
if
(
getClosedFile
().
exists
())
{
error
(
"closed database"
);
}
}
static
final
int
OPEN_WITH_CLOSE_ON_EXIT
=
1
,
OPEN_WITHOUT_CLOSE_ON_EXIT
=
2
;
public
static
Connection
conn
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
if
(
args
.
length
==
0
)
{
if
(
args
.
length
==
0
)
{
System
.
exit
(
1
);
}
int
action
=
Integer
.
parseInt
(
args
[
0
]);
TestExit
app
=
new
TestExit
();
app
.
execute
(
action
);
}
void
execute
(
int
action
)
throws
Exception
{
Class
.
forName
(
"org.h2.Driver"
);
String
url
=
""
;
switch
(
action
)
{
switch
(
action
)
{
case
OPEN_WITH_CLOSE_ON_EXIT:
url
=
"jdbc:h2:"
+
baseDir
+
"/exit;database_event_listener='"
+
getClass
().
getName
()
+
"';db_close_on_exit=true"
;
url
=
"jdbc:h2:"
+
baseDir
+
"/exit;database_event_listener='"
+
getClass
().
getName
()
+
"';db_close_on_exit=true"
;
break
;
case
OPEN_WITHOUT_CLOSE_ON_EXIT:
url
=
"jdbc:h2:"
+
baseDir
+
"/exit;database_event_listener='"
+
getClass
().
getName
()
+
"';db_close_on_exit=false"
;
url
=
"jdbc:h2:"
+
baseDir
+
"/exit;database_event_listener='"
+
getClass
().
getName
()
+
"';db_close_on_exit=false"
;
break
;
}
conn
=
open
(
url
);
Connection
conn2
=
open
(
url
);
conn2
.
close
();
}
private
static
Connection
open
(
String
url
)
throws
Exception
{
getClosedFile
().
delete
();
return
DriverManager
.
getConnection
(
url
,
"sa"
,
""
);
...
...
@@ -102,16 +96,16 @@ public class TestExit extends TestBase implements DatabaseEventListener {
public
void
closingDatabase
()
{
try
{
getClosedFile
().
createNewFile
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
TestBase
.
logError
(
"error"
,
e
);
}
}
private
static
File
getClosedFile
()
{
return
new
File
(
baseDir
+
"/closed.txt"
);
}
public
void
setProgress
(
int
state
,
String
name
,
int
x
,
int
max
)
{
public
void
setProgress
(
int
state
,
String
name
,
int
x
,
int
max
)
{
}
public
void
init
(
String
url
)
{
...
...
h2/src/test/org/h2/test/unit/TestFileLock.java
浏览文件 @
f447a3e4
...
...
@@ -23,13 +23,14 @@ public class TestFileLock extends TestBase implements Runnable {
private
static
volatile
int
locks
;
private
static
volatile
boolean
stop
;
public
TestFileLock
()
{}
public
TestFileLock
()
{
}
public
void
test
()
throws
Exception
{
test
(
false
);
test
(
true
);
}
void
test
(
boolean
allowSockets
)
throws
Exception
{
int
threadCount
=
getSize
(
3
,
5
);
wait
=
getSize
(
20
,
200
);
...
...
h2/src/test/org/h2/test/unit/TestIntArray.java
浏览文件 @
f447a3e4
...
...
@@ -10,7 +10,7 @@ import org.h2.test.TestBase;
import
org.h2.util.IntArray
;
public
class
TestIntArray
extends
TestBase
{
public
void
test
()
throws
Exception
{
testRandom
();
}
...
...
@@ -19,11 +19,11 @@ public class TestIntArray extends TestBase {
IntArray
array
=
new
IntArray
();
int
[]
test
=
new
int
[
0
];
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
int
idx
=
test
.
length
==
0
?
0
:
random
.
nextInt
(
test
.
length
);
int
v
=
random
.
nextInt
(
100
);
int
op
=
random
.
nextInt
(
9
);
switch
(
op
)
{
int
v
=
random
.
nextInt
(
100
);
int
op
=
random
.
nextInt
(
9
);
switch
(
op
)
{
case
0
:
array
.
add
(
idx
,
v
);
test
=
add
(
test
,
idx
,
v
);
...
...
@@ -46,7 +46,7 @@ public class TestIntArray extends TestBase {
check
(
a
,
b
);
break
;
case
4
:
if
(
test
.
length
>
idx
)
{
if
(
test
.
length
>
idx
)
{
check
(
array
.
get
(
idx
),
get
(
test
,
idx
));
}
break
;
...
...
@@ -55,7 +55,7 @@ public class TestIntArray extends TestBase {
test
=
remove
(
test
,
idx
);
break
;
case
6
:
if
(
test
.
length
>
idx
)
{
if
(
test
.
length
>
idx
)
{
v
=
test
[
idx
];
array
.
removeValue
(
v
);
test
=
removeValue
(
test
,
v
);
...
...
@@ -70,34 +70,34 @@ public class TestIntArray extends TestBase {
break
;
}
check
(
array
.
size
(),
test
.
length
);
for
(
int
j
=
0
;
j
<
test
.
length
;
j
++)
{
for
(
int
j
=
0
;
j
<
test
.
length
;
j
++)
{
check
(
test
[
j
],
array
.
get
(
j
));
}
}
}
int
[]
add
(
int
[]
array
,
int
i
,
int
value
)
{
int
[]
a2
=
new
int
[
array
.
length
+
1
];
int
[]
a2
=
new
int
[
array
.
length
+
1
];
System
.
arraycopy
(
array
,
0
,
a2
,
0
,
array
.
length
);
if
(
i
<
array
.
length
)
{
System
.
arraycopy
(
a2
,
i
,
a2
,
i
+
1
,
a2
.
length
-
i
-
1
);
if
(
i
<
array
.
length
)
{
System
.
arraycopy
(
a2
,
i
,
a2
,
i
+
1
,
a2
.
length
-
i
-
1
);
}
array
=
a2
;
array
[
i
]
=
value
;
return
array
;
}
int
[]
add
(
int
[]
array
,
int
value
)
{
return
add
(
array
,
array
.
length
,
value
);
return
add
(
array
,
array
.
length
,
value
);
}
int
[]
addValueSorted
(
int
[]
array
,
int
value
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
array
[
i
]
<
value
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
array
[
i
]
<
value
)
{
continue
;
}
if
(
array
[
i
]
==
value
)
{
if
(
array
[
i
]
==
value
)
{
return
array
;
}
else
{
return
add
(
array
,
i
,
value
);
...
...
@@ -105,32 +105,32 @@ public class TestIntArray extends TestBase {
}
return
add
(
array
,
value
);
}
int
findNextValueIndex
(
int
[]
array
,
int
value
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
array
[
i
]
>=
value
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
array
[
i
]
>=
value
)
{
return
i
;
}
}
return
array
.
length
;
}
int
get
(
int
[]
array
,
int
i
)
{
return
array
[
i
];
}
int
[]
remove
(
int
[]
array
,
int
i
)
{
int
[]
a2
=
new
int
[
array
.
length
-
1
];
int
[]
a2
=
new
int
[
array
.
length
-
1
];
System
.
arraycopy
(
array
,
0
,
a2
,
0
,
i
);
if
(
i
<
a2
.
length
)
{
System
.
arraycopy
(
array
,
i
+
1
,
a2
,
i
,
array
.
length
-
i
-
1
);
if
(
i
<
a2
.
length
)
{
System
.
arraycopy
(
array
,
i
+
1
,
a2
,
i
,
array
.
length
-
i
-
1
);
}
return
a2
;
}
int
[]
removeValue
(
int
[]
array
,
int
value
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
array
[
i
]
==
value
)
{
for
(
int
i
=
0
;
i
<
array
.
length
;
i
++)
{
if
(
array
[
i
]
==
value
)
{
return
remove
(
array
,
i
);
}
}
...
...
@@ -141,14 +141,14 @@ public class TestIntArray extends TestBase {
array
[
i
]
=
value
;
return
array
;
}
int
size
(
int
[]
array
)
{
return
array
.
length
;
}
int
[]
sort
(
int
[]
array
)
{
Arrays
.
sort
(
array
);
return
array
;
}
}
h2/src/test/org/h2/test/unit/TestIntIntHashMap.java
浏览文件 @
f447a3e4
...
...
@@ -30,11 +30,11 @@ public class TestIntIntHashMap extends TestBase {
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
map
.
put
(
x
[
i
],
i
);
}
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
if
(
map
.
get
(
x
[
i
])
!=
i
)
{
throw
new
Error
(
"get "
+
x
[
i
]
+
" = "
+
map
.
get
(
i
)
+
" should be "
+
i
);
}
}
}
for
(
int
i
=
1
;
i
<
len
;
i
+=
2
)
{
map
.
remove
(
x
[
i
]);
}
...
...
@@ -46,7 +46,7 @@ public class TestIntIntHashMap extends TestBase {
for
(
int
i
=
1
;
i
<
len
;
i
+=
2
)
{
map
.
put
(
x
[
i
],
i
);
}
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
if
(
map
.
get
(
x
[
i
])
!=
i
)
{
throw
new
Error
(
"get "
+
x
[
i
]
+
" = "
+
map
.
get
(
i
)
+
" should be "
+
i
);
}
...
...
h2/src/test/org/h2/test/unit/TestOverflow.java
浏览文件 @
f447a3e4
...
...
@@ -31,50 +31,50 @@ public class TestOverflow extends TestBase {
private
void
test
(
int
type
,
long
min
,
long
max
)
throws
Exception
{
values
=
new
ArrayList
();
this
.
type
=
type
;
this
.
min
=
new
BigInteger
(
""
+
min
);
this
.
max
=
new
BigInteger
(
""
+
max
);
this
.
min
=
new
BigInteger
(
""
+
min
);
this
.
max
=
new
BigInteger
(
""
+
max
);
add
(
0
);
add
(
min
);
add
(
max
);
add
(
max
-
1
);
add
(
min
+
1
);
add
(
max
-
1
);
add
(
min
+
1
);
add
(
1
);
add
(-
1
);
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
40
;
i
++)
{
if
(
max
>
Integer
.
MAX_VALUE
)
{
for
(
int
i
=
0
;
i
<
40
;
i
++)
{
if
(
max
>
Integer
.
MAX_VALUE
)
{
add
(
random
.
nextLong
());
}
else
{
add
((
random
.
nextBoolean
()
?
1
:
-
1
)
*
random
.
nextInt
((
int
)
max
));
add
((
random
.
nextBoolean
()
?
1
:
-
1
)
*
random
.
nextInt
((
int
)
max
));
}
}
for
(
int
a
=
0
;
a
<
values
.
size
();
a
++)
{
for
(
int
b
=
0
;
b
<
values
.
size
();
b
++)
{
for
(
int
a
=
0
;
a
<
values
.
size
();
a
++)
{
for
(
int
b
=
0
;
b
<
values
.
size
();
b
++)
{
Value
va
=
(
Value
)
values
.
get
(
a
);
Value
vb
=
(
Value
)
values
.
get
(
b
);
testValues
(
va
,
vb
);
}
}
}
void
checkIfExpected
(
String
a
,
String
b
)
throws
Exception
{
if
(
successExpected
)
{
if
(
successExpected
)
{
check
(
a
,
b
);
}
}
void
onSuccess
()
throws
Exception
{
if
(!
successExpected
&&
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
if
(!
successExpected
&&
SysProperties
.
OVERFLOW_EXCEPTIONS
)
{
error
(
"unexpected success"
);
}
}
void
onError
()
throws
Exception
{
if
(
successExpected
)
{
if
(
successExpected
)
{
error
(
"unexpected error"
);
}
}
private
void
testValues
(
Value
va
,
Value
vb
)
throws
Exception
{
BigInteger
a
=
new
BigInteger
(
va
.
getString
());
BigInteger
b
=
new
BigInteger
(
vb
.
getString
());
...
...
@@ -82,32 +82,32 @@ public class TestOverflow extends TestBase {
try
{
checkIfExpected
(
va
.
negate
().
getString
(),
a
.
negate
().
toString
());
onSuccess
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
onError
();
}
successExpected
=
inRange
(
a
.
add
(
b
));
try
{
checkIfExpected
(
va
.
add
(
vb
).
getString
(),
a
.
add
(
b
).
toString
());
onSuccess
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
onError
();
}
successExpected
=
inRange
(
a
.
subtract
(
b
));
try
{
checkIfExpected
(
va
.
subtract
(
vb
).
getString
(),
a
.
subtract
(
b
).
toString
());
onSuccess
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
onError
();
}
successExpected
=
inRange
(
a
.
multiply
(
b
));
try
{
checkIfExpected
(
va
.
multiply
(
vb
).
getString
(),
a
.
multiply
(
b
).
toString
());
onSuccess
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
onError
();
}
}
private
boolean
inRange
(
BigInteger
v
)
{
return
v
.
compareTo
(
min
)
>=
0
&&
v
.
compareTo
(
max
)
<=
0
;
}
...
...
@@ -115,5 +115,5 @@ public class TestOverflow extends TestBase {
private
void
add
(
long
l
)
throws
SQLException
{
values
.
add
(
ValueString
.
get
(
""
+
l
).
convertTo
(
type
));
}
}
h2/src/test/org/h2/test/unit/TestPattern.java
浏览文件 @
f447a3e4
...
...
@@ -12,7 +12,7 @@ import org.h2.value.CompareMode;
* @author Thomas
*/
public
class
TestPattern
extends
TestBase
{
public
void
test
()
throws
Exception
{
CompareMode
mode
=
new
CompareMode
(
null
,
null
);
CompareLike
comp
=
new
CompareLike
(
mode
,
null
,
null
,
null
,
false
);
...
...
@@ -21,41 +21,41 @@ public class TestPattern extends TestBase {
test
(
comp
,
"A"
,
"A%%"
);
test
(
comp
,
"A_A"
,
"%\\_%"
);
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
String
pattern
=
getRandomPattern
();
String
value
=
getRandomValue
();
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
String
pattern
=
getRandomPattern
();
String
value
=
getRandomValue
();
test
(
comp
,
value
,
pattern
);
}
}
void
test
(
CompareLike
comp
,
String
value
,
String
pattern
)
throws
Exception
{
String
regexp
=
initPatternRegexp
(
pattern
,
'\\'
);
boolean
resultRegexp
=
value
.
matches
(
regexp
);
boolean
result
=
comp
.
test
(
pattern
,
value
,
'\\'
);
if
(
result
!=
resultRegexp
)
{
error
(
"Error: >"
+
value
+
"< LIKE >"
+
pattern
+
"< result="
+
result
+
" resultReg="
+
resultRegexp
);
if
(
result
!=
resultRegexp
)
{
error
(
"Error: >"
+
value
+
"< LIKE >"
+
pattern
+
"< result="
+
result
+
" resultReg="
+
resultRegexp
);
}
}
static
String
getRandomValue
()
{
StringBuffer
buff
=
new
StringBuffer
();
int
len
=
(
int
)(
Math
.
random
()
*
10
);
int
len
=
(
int
)
(
Math
.
random
()
*
10
);
String
s
=
"AB_%\\"
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
buff
.
append
(
s
.
charAt
((
int
)
(
Math
.
random
()*
s
.
length
())));
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
buff
.
append
(
s
.
charAt
((
int
)
(
Math
.
random
()
*
s
.
length
())));
}
return
buff
.
toString
();
}
static
String
getRandomPattern
()
{
StringBuffer
buff
=
new
StringBuffer
();
int
len
=
(
int
)(
Math
.
random
()
*
4
);
int
len
=
(
int
)
(
Math
.
random
()
*
4
);
String
s
=
"A%_\\"
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
char
c
=
s
.
charAt
((
int
)
(
Math
.
random
()*
s
.
length
()));
if
((
c
==
'_'
||
c
==
'%'
)
&&
Math
.
random
()
>
0.5
)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
char
c
=
s
.
charAt
((
int
)
(
Math
.
random
()
*
s
.
length
()));
if
((
c
==
'_'
||
c
==
'%'
)
&&
Math
.
random
()
>
0.5
)
{
buff
.
append
(
'\\'
);
}
else
if
(
c
==
'\\'
)
{
}
else
if
(
c
==
'\\'
)
{
buff
.
append
(
c
);
}
buff
.
append
(
c
);
...
...
@@ -79,7 +79,7 @@ public class TestPattern extends TestBase {
buff
.
append
(
".*"
);
}
else
if
(
c
==
'_'
)
{
buff
.
append
(
'.'
);
}
else
if
(
c
==
'\\'
)
{
}
else
if
(
c
==
'\\'
)
{
buff
.
append
(
"\\\\"
);
}
else
{
buff
.
append
(
c
);
...
...
@@ -87,8 +87,8 @@ public class TestPattern extends TestBase {
// TODO regexp: there are other chars that need escaping
}
String
regexp
=
buff
.
toString
();
//
System.out.println("regexp = " + regexp);
//
System.out.println("regexp = " + regexp);
return
regexp
;
}
}
h2/src/test/org/h2/test/unit/TestSampleApps.java
浏览文件 @
f447a3e4
...
...
@@ -16,39 +16,38 @@ public class TestSampleApps extends TestBase {
public
void
test
()
throws
Exception
{
testApp
(
org
.
h2
.
samples
.
Compact
.
class
,
null
,
"Compacting...\nDone."
);
testApp
(
org
.
h2
.
samples
.
CsvSample
.
class
,
null
,
"NAME: Bob Meier\n"
+
"EMAIL: bob.meier@abcde.abc\n"
+
"PHONE: +41123456789\n\n"
+
"NAME: John Jones\n"
+
"EMAIL: john.jones@abcde.abc\n"
+
"PHONE: +41976543210\n"
);
testApp
(
org
.
h2
.
samples
.
Function
.
class
,
null
,
testApp
(
org
.
h2
.
samples
.
CsvSample
.
class
,
null
,
"NAME: Bob Meier\n"
+
"EMAIL: bob.meier@abcde.abc\n"
+
"PHONE: +41123456789\n\n"
+
"NAME: John Jones\n"
+
"EMAIL: john.jones@abcde.abc\n"
+
"PHONE: +41976543210\n"
);
testApp
(
org
.
h2
.
samples
.
Function
.
class
,
null
,
"2 is prime\n3 is prime\n5 is prime\n7 is prime\n11 is prime\n13 is prime\n17 is prime\n19 is prime"
);
testApp
(
org
.
h2
.
samples
.
SecurePassword
.
class
,
null
,
"Hello"
);
testApp
(
org
.
h2
.
samples
.
SecurePassword
.
class
,
null
,
"Hello"
);
// TODO test ShowProgress (percent numbers are hardware specific)
// TODO test ShutdownServer (server needs to be started in a separate process)
// TODO test ShutdownServer (server needs to be started in a separate
// process)
testApp
(
org
.
h2
.
samples
.
TriggerSample
.
class
,
null
,
"The sum is 20.00"
);
// tools
testApp
(
org
.
h2
.
tools
.
ChangePassword
.
class
,
new
String
[]{
"-?"
},
"java org.h2.tools.ChangePassword [-dir <dir>] "
+
"[-db <database>] [-cipher <cipher>] [-decrypt <pwd>] [-encrypt <pwd>] [-quiet]"
);
testApp
(
org
.
h2
.
tools
.
ChangePassword
.
class
,
new
String
[]
{
"-?"
},
"java org.h2.tools.ChangePassword [-dir <dir>] "
+
"[-db <database>] [-cipher <cipher>] [-decrypt <pwd>] [-encrypt <pwd>] [-quiet]"
);
testApp
(
org
.
h2
.
tools
.
ChangePassword
.
class
,
null
,
"java org.h2.tools.ChangePassword [-dir <dir>] "
+
"[-db <database>] [-cipher <cipher>] [-decrypt <pwd>] [-encrypt <pwd>] [-quiet]"
);
testApp
(
org
.
h2
.
tools
.
DeleteDbFiles
.
class
,
new
String
[]{
"-?"
},
"java org.h2.tools.DeleteDbFiles [-dir <dir>] [-db <database>] [-quiet]"
);
testApp
(
org
.
h2
.
tools
.
DeleteDbFiles
.
class
,
new
String
[]
{
"-?"
},
"java org.h2.tools.DeleteDbFiles [-dir <dir>] [-db <database>] [-quiet]"
);
}
private
void
testApp
(
Class
clazz
,
String
[]
args
,
String
expected
)
throws
Exception
{
DeleteDbFiles
.
execute
(
"data"
,
"test"
,
true
);
Method
m
=
clazz
.
getMethod
(
"main"
,
new
Class
[]
{
String
[].
class
});
Method
m
=
clazz
.
getMethod
(
"main"
,
new
Class
[]
{
String
[].
class
});
PrintStream
oldOut
=
System
.
out
,
oldErr
=
System
.
err
;
ByteArrayOutputStream
buff
=
new
ByteArrayOutputStream
();
PrintStream
out
=
new
PrintStream
(
buff
,
false
,
"UTF-8"
);
System
.
setOut
(
out
);
System
.
setErr
(
out
);
try
{
m
.
invoke
(
null
,
new
Object
[]
{
args
});
}
catch
(
Throwable
e
)
{
m
.
invoke
(
null
,
new
Object
[]
{
args
});
}
catch
(
Throwable
e
)
{
TestBase
.
logError
(
"error"
,
e
);
}
out
.
flush
();
...
...
h2/src/test/org/h2/test/unit/TestScriptReader.java
浏览文件 @
f447a3e4
...
...
@@ -20,24 +20,24 @@ public class TestScriptReader extends TestBase {
private
void
testRandom
()
throws
Exception
{
int
len
=
getSize
(
1000
,
10000
);
Random
random
=
new
Random
(
10
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
int
l
=
random
.
nextInt
(
10
);
String
[]
sql
=
new
String
[
l
];
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
sql
[
j
]
=
randomStatement
(
random
);
buff
.
append
(
sql
[
j
]);
if
(
j
<
l
-
1
)
{
if
(
j
<
l
-
1
)
{
buff
.
append
(
";"
);
}
}
String
s
=
buff
.
toString
();
StringReader
reader
=
new
StringReader
(
s
);
ScriptReader
source
=
new
ScriptReader
(
reader
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
String
e
=
source
.
readStatement
();
String
c
=
sql
[
j
];
if
(
c
.
length
()
==
0
&&
j
==
l
-
1
)
{
if
(
c
.
length
()
==
0
&&
j
==
l
-
1
)
{
c
=
null
;
}
check
(
e
,
c
);
...
...
@@ -45,25 +45,25 @@ public class TestScriptReader extends TestBase {
check
(
source
.
readStatement
(),
null
);
}
}
private
String
randomStatement
(
Random
random
)
{
StringBuffer
buff
=
new
StringBuffer
();
int
len
=
random
.
nextInt
(
5
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
switch
(
random
.
nextInt
(
10
))
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
switch
(
random
.
nextInt
(
10
))
{
case
0
:
{
int
l
=
random
.
nextInt
(
4
);
String
[]
ch
=
new
String
[]{
"\n"
,
"\r"
,
" "
,
"*"
,
"a"
,
"0"
};
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
int
l
=
random
.
nextInt
(
4
);
String
[]
ch
=
new
String
[]
{
"\n"
,
"\r"
,
" "
,
"*"
,
"a"
,
"0"
};
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
break
;
}
case
1
:
{
buff
.
append
(
'\''
);
int
l
=
random
.
nextInt
(
4
);
String
[]
ch
=
new
String
[]{
";"
,
"\n"
,
"\r"
,
"--"
,
"//"
,
"/"
,
"-"
,
"*"
,
"/*"
,
"*/"
,
"\""
};
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
int
l
=
random
.
nextInt
(
4
);
String
[]
ch
=
new
String
[]
{
";"
,
"\n"
,
"\r"
,
"--"
,
"//"
,
"/"
,
"-"
,
"*"
,
"/*"
,
"*/"
,
"\""
};
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
buff
.
append
(
'\''
);
...
...
@@ -71,9 +71,9 @@ public class TestScriptReader extends TestBase {
}
case
2
:
{
buff
.
append
(
'"'
);
int
l
=
random
.
nextInt
(
4
);
String
[]
ch
=
new
String
[]{
";"
,
"\n"
,
"\r"
,
"--"
,
"//"
,
"/"
,
"-"
,
"*"
,
"/*"
,
"*/"
,
"\'"
};
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
int
l
=
random
.
nextInt
(
4
);
String
[]
ch
=
new
String
[]
{
";"
,
"\n"
,
"\r"
,
"--"
,
"//"
,
"/"
,
"-"
,
"*"
,
"/*"
,
"*/"
,
"\'"
};
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
buff
.
append
(
'"'
);
...
...
@@ -81,17 +81,17 @@ public class TestScriptReader extends TestBase {
}
case
3
:
{
buff
.
append
(
'-'
);
if
(
random
.
nextBoolean
())
{
String
[]
ch
=
new
String
[]{
"\n"
,
"\r"
,
"*"
,
"a"
,
" "
};
int
l
=
1
+
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
if
(
random
.
nextBoolean
())
{
String
[]
ch
=
new
String
[]
{
"\n"
,
"\r"
,
"*"
,
"a"
,
" "
};
int
l
=
1
+
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
}
else
{
buff
.
append
(
'-'
);
String
[]
ch
=
new
String
[]{
";"
,
"-"
,
"//"
,
"/*"
,
"*/"
,
"a"
};
int
l
=
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
String
[]
ch
=
new
String
[]
{
";"
,
"-"
,
"//"
,
"/*"
,
"*/"
,
"a"
};
int
l
=
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
buff
.
append
(
'\n'
);
...
...
@@ -100,17 +100,17 @@ public class TestScriptReader extends TestBase {
}
case
4
:
{
buff
.
append
(
'/'
);
if
(
random
.
nextBoolean
())
{
String
[]
ch
=
new
String
[]{
"\n"
,
"\r"
,
"a"
,
" "
,
"- "
};
int
l
=
1
+
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
if
(
random
.
nextBoolean
())
{
String
[]
ch
=
new
String
[]
{
"\n"
,
"\r"
,
"a"
,
" "
,
"- "
};
int
l
=
1
+
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
}
}
else
{
buff
.
append
(
'*'
);
String
[]
ch
=
new
String
[]{
";"
,
"-"
,
"//"
,
"/* "
,
"--"
,
"\n"
,
"\r"
,
"a"
};
int
l
=
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
String
[]
ch
=
new
String
[]
{
";"
,
"-"
,
"//"
,
"/* "
,
"--"
,
"\n"
,
"\r"
,
"a"
};
int
l
=
random
.
nextInt
(
4
);
for
(
int
j
=
0
;
j
<
l
;
j
++)
{
buff
.
append
(
ch
[
random
.
nextInt
(
ch
.
length
)]);
}
buff
.
append
(
"*/"
);
...
...
@@ -123,16 +123,15 @@ public class TestScriptReader extends TestBase {
}
private
void
testCommon
()
throws
Exception
{
String
s
=
"a;';';\";\";--;\n;/*;\n*/;//;\na;"
;
String
s
=
"a;';';\";\";--;\n;/*;\n*/;//;\na;"
;
StringReader
reader
=
new
StringReader
(
s
);
ScriptReader
source
=
new
ScriptReader
(
reader
);
check
(
source
.
readStatement
(),
"a"
);
check
(
source
.
readStatement
(),
"';'"
);
check
(
source
.
readStatement
(),
"\";\""
);
check
(
source
.
readStatement
(),
"--;\n"
);
check
(
source
.
readStatement
(),
"/*;\n*/"
);
check
(
source
.
readStatement
(),
"//;\na"
);
check
(
source
.
readStatement
(),
"a"
);
check
(
source
.
readStatement
(),
"';'"
);
check
(
source
.
readStatement
(),
"\";\""
);
check
(
source
.
readStatement
(),
"--;\n"
);
check
(
source
.
readStatement
(),
"/*;\n*/"
);
check
(
source
.
readStatement
(),
"//;\na"
);
check
(
source
.
readStatement
(),
null
);
source
.
close
();
}
...
...
h2/src/test/org/h2/test/unit/TestSecurity.java
浏览文件 @
f447a3e4
...
...
@@ -10,19 +10,18 @@ import org.h2.security.XTEA;
import
org.h2.test.TestBase
;
import
org.h2.util.ByteUtils
;
/**
* @author Thomas
*/
public
class
TestSecurity
extends
TestBase
{
public
void
test
()
throws
Exception
{
testSHA
();
testAES
();
testXTEA
();
}
public
void
testSHA
()
throws
Exception
{
SHA256
sha
=
new
SHA256
();
testOneSHA
(
sha
);
...
...
@@ -31,29 +30,26 @@ public class TestSecurity extends TestBase {
private
String
getHashString
(
SHA256
sha
,
byte
[]
data
)
{
byte
[]
result
=
sha
.
getHash
(
data
);
return
ByteUtils
.
convertBytesToString
(
result
);
}
}
private
void
testOneSHA
(
SHA256
sha
)
throws
Exception
{
if
(!
getHashString
(
sha
,
new
byte
[]
{
})
.
equals
(
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
))
{
if
(!
getHashString
(
sha
,
new
byte
[]
{}).
equals
(
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
))
{
throw
new
Exception
(
"x"
);
}
if
(!
getHashString
(
sha
,
new
byte
[]
{
0x19
})
.
equals
(
"68aa2e2ee5dff96e3355e6c7ee373e3d6a4e17f75f9518d843709c0c9bc3e3d4"
))
{
if
(!
getHashString
(
sha
,
new
byte
[]
{
0x19
}).
equals
(
"68aa2e2ee5dff96e3355e6c7ee373e3d6a4e17f75f9518d843709c0c9bc3e3d4"
))
{
throw
new
Exception
(
"x"
);
}
if
(!
getHashString
(
sha
,
new
byte
[]
{
(
byte
)
0xe3
,
(
byte
)
0xd7
,
0x25
,
0x70
,
(
byte
)
0xdc
,
(
byte
)
0xdd
,
0x78
,
0x7c
,
(
byte
)
0xe3
,
(
byte
)
0x88
,
0x7a
,
(
byte
)
0xb2
,
(
byte
)
0xcd
,
0x68
,
0x46
,
0x52
})
.
equals
(
"175ee69b02ba9b58e2b0a5fd13819cea573f3940a94f825128cf4209beabb4e8"
))
{
if
(!
getHashString
(
sha
,
new
byte
[]
{
(
byte
)
0xe3
,
(
byte
)
0xd7
,
0x25
,
0x70
,
(
byte
)
0xdc
,
(
byte
)
0xdd
,
0x78
,
0x7c
,
(
byte
)
0xe3
,
(
byte
)
0x88
,
0x7a
,
(
byte
)
0xb2
,
(
byte
)
0xcd
,
0x68
,
0x46
,
0x52
}).
equals
(
"175ee69b02ba9b58e2b0a5fd13819cea573f3940a94f825128cf4209beabb4e8"
))
{
throw
new
Exception
(
"x"
);
}
}
public
void
testXTEA
()
throws
Exception
{
byte
[]
test
=
new
byte
[
4096
];
XTEA
xtea
=
new
XTEA
();
...
...
@@ -61,25 +57,24 @@ public class TestSecurity extends TestBase {
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
xtea
.
decryptBlock
(
test
,
test
,
0
);
}
}
}
private
void
testAES
()
throws
Exception
{
AES
test
=
new
AES
();
test
.
setKey
(
ByteUtils
.
convertStringToBytes
(
"000102030405060708090A0B0C0D0E0F"
));
byte
[]
in
=
new
byte
[
128
];
byte
[]
enc
=
new
byte
[
128
];
test
.
encrypt
(
enc
,
0
,
128
);
test
.
decrypt
(
enc
,
0
,
128
);
if
(
ByteUtils
.
compareNotNull
(
in
,
enc
)!=
0
)
{
if
(
ByteUtils
.
compareNotNull
(
in
,
enc
)
!=
0
)
{
throw
new
Error
(
"hey!"
);
}
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
test
.
encrypt
(
in
,
0
,
128
);
test
.
decrypt
(
enc
,
0
,
128
);
}
}
}
h2/src/test/org/h2/test/unit/TestStreams.java
浏览文件 @
f447a3e4
...
...
@@ -17,42 +17,42 @@ public class TestStreams extends TestBase {
public
void
test
()
throws
Exception
{
testLZFStreams
();
}
byte
[]
getRandomBytes
(
Random
random
)
{
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
1000
),
random
.
nextInt
(
100000
),
random
.
nextInt
(
1000000
)
};
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
1000
),
random
.
nextInt
(
100000
),
random
.
nextInt
(
1000000
)
};
int
size
=
sizes
[
random
.
nextInt
(
sizes
.
length
)];
byte
[]
buffer
=
new
byte
[
size
];
if
(
random
.
nextInt
(
5
)
==
1
)
{
if
(
random
.
nextInt
(
5
)
==
1
)
{
random
.
nextBytes
(
buffer
);
}
else
if
(
random
.
nextBoolean
())
{
int
patternLen
=
random
.
nextInt
(
100
)
+
1
;
for
(
int
j
=
0
;
j
<
size
;
j
++)
{
buffer
[
j
]
=
(
byte
)(
j
%
patternLen
);
}
else
if
(
random
.
nextBoolean
())
{
int
patternLen
=
random
.
nextInt
(
100
)
+
1
;
for
(
int
j
=
0
;
j
<
size
;
j
++)
{
buffer
[
j
]
=
(
byte
)
(
j
%
patternLen
);
}
}
return
buffer
;
}
private
void
testLZFStreams
()
throws
Exception
{
Random
random
=
new
Random
(
1
);
int
max
=
getSize
(
100
,
1000
);
for
(
int
i
=
0
;
i
<
max
;
i
+=
3
)
{
for
(
int
i
=
0
;
i
<
max
;
i
+=
3
)
{
byte
[]
buffer
=
getRandomBytes
(
random
);
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
LZFOutputStream
comp
=
new
LZFOutputStream
(
out
);
if
(
random
.
nextInt
(
10
)
==
1
)
{
if
(
random
.
nextInt
(
10
)
==
1
)
{
comp
.
write
(
buffer
);
}
else
{
for
(
int
j
=
0
;
j
<
buffer
.
length
;)
{
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
100
),
random
.
nextInt
(
100000
)
};
for
(
int
j
=
0
;
j
<
buffer
.
length
;)
{
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
100
),
random
.
nextInt
(
100000
)
};
int
size
=
sizes
[
random
.
nextInt
(
sizes
.
length
)];
size
=
Math
.
min
(
size
,
buffer
.
length
-
j
);
if
(
size
==
1
)
{
if
(
size
==
1
)
{
comp
.
write
(
buffer
[
j
]);
}
else
{
comp
.
write
(
buffer
,
j
,
size
);
}
j
+=
size
;
j
+=
size
;
}
}
comp
.
close
();
...
...
@@ -60,19 +60,19 @@ public class TestStreams extends TestBase {
ByteArrayInputStream
in
=
new
ByteArrayInputStream
(
compressed
);
LZFInputStream
decompress
=
new
LZFInputStream
(
in
);
byte
[]
test
=
new
byte
[
buffer
.
length
];
for
(
int
j
=
0
;
j
<
buffer
.
length
;)
{
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
100
),
random
.
nextInt
(
100000
)
};
for
(
int
j
=
0
;
j
<
buffer
.
length
;)
{
int
[]
sizes
=
new
int
[]
{
0
,
1
,
random
.
nextInt
(
100
),
random
.
nextInt
(
100000
)
};
int
size
=
sizes
[
random
.
nextInt
(
sizes
.
length
)];
if
(
size
==
1
)
{
if
(
size
==
1
)
{
int
x
=
decompress
.
read
();
if
(
x
<
0
)
{
if
(
x
<
0
)
{
break
;
}
test
[
j
++]
=
(
byte
)
x
;
test
[
j
++]
=
(
byte
)
x
;
}
else
{
size
=
Math
.
min
(
size
,
test
.
length
-
j
);
size
=
Math
.
min
(
size
,
test
.
length
-
j
);
int
l
=
decompress
.
read
(
test
,
j
,
size
);
if
(
l
<
0
)
{
if
(
l
<
0
)
{
break
;
}
else
{
j
+=
l
;
...
...
h2/src/test/org/h2/test/unit/TestStringCache.java
浏览文件 @
f447a3e4
...
...
@@ -10,27 +10,27 @@ import org.h2.test.TestBase;
import
org.h2.util.StringCache
;
public
class
TestStringCache
extends
TestBase
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
TestStringCache
().
runBenchmark
();
}
private
void
runBenchmark
()
throws
Exception
{
returnNew
=
false
;
for
(
int
i
=
0
;
i
<
6
;
i
++)
{
for
(
int
i
=
0
;
i
<
6
;
i
++)
{
useIntern
=
(
i
%
2
)
==
1
;
long
time
=
System
.
currentTimeMillis
();
testSingleThread
(
100000
);
time
=
System
.
currentTimeMillis
()
-
time
;
System
.
out
.
println
(
time
+
" ms (useIntern="
+
useIntern
+
")"
);
time
=
System
.
currentTimeMillis
()
-
time
;
System
.
out
.
println
(
time
+
" ms (useIntern="
+
useIntern
+
")"
);
}
}
private
Random
random
=
new
Random
(
1
);
private
String
[]
some
=
new
String
[]
{
null
,
""
,
"ABC"
,
"this is a medium sized string"
,
"1"
,
"2"
};
private
String
[]
some
=
new
String
[]
{
null
,
""
,
"ABC"
,
"this is a medium sized string"
,
"1"
,
"2"
};
private
volatile
boolean
stop
;
private
boolean
returnNew
;
private
boolean
returnNew
;
private
boolean
useIntern
;
public
void
test
()
throws
Exception
{
...
...
@@ -43,39 +43,39 @@ public class TestStringCache extends TestBase {
testSingleThread
(
getSize
(
5000
,
20000
));
testMultiThreads
();
}
String
randomString
()
{
if
(
random
.
nextBoolean
())
{
if
(
random
.
nextBoolean
())
{
String
s
=
some
[
random
.
nextInt
(
some
.
length
)];
if
(
s
!=
null
&&
random
.
nextBoolean
())
{
if
(
s
!=
null
&&
random
.
nextBoolean
())
{
s
=
new
String
(
s
);
}
return
s
;
}
else
{
int
len
=
random
.
nextBoolean
()
?
random
.
nextInt
(
1000
)
:
random
.
nextInt
(
10
);
StringBuffer
buff
=
new
StringBuffer
(
len
);
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
buff
.
append
(
random
.
nextInt
(
0xfff
));
}
return
buff
.
toString
();
}
}
void
testString
()
{
String
a
=
randomString
();
if
(
returnNew
)
{
if
(
returnNew
)
{
String
b
=
StringCache
.
getNew
(
a
);
try
{
check
(
a
,
b
);
}
catch
(
Exception
e
)
{
TestBase
.
logError
(
"error"
,
e
);
}
if
(
a
!=
null
&&
a
==
b
&&
a
.
length
()>
0
)
{
if
(
a
!=
null
&&
a
==
b
&&
a
.
length
()
>
0
)
{
throw
new
Error
(
"a="
+
System
.
identityHashCode
(
a
)
+
" b="
+
System
.
identityHashCode
(
b
));
}
}
else
{
String
b
;
if
(
useIntern
)
{
if
(
useIntern
)
{
b
=
a
==
null
?
null
:
a
.
intern
();
}
else
{
b
=
StringCache
.
get
(
a
);
...
...
@@ -87,9 +87,9 @@ public class TestStringCache extends TestBase {
}
}
}
private
void
testSingleThread
(
int
len
)
throws
Exception
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
testString
();
}
}
...
...
@@ -97,23 +97,23 @@ public class TestStringCache extends TestBase {
private
void
testMultiThreads
()
throws
Exception
{
int
threadCount
=
getSize
(
3
,
100
);
Thread
[]
threads
=
new
Thread
[
threadCount
];
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
Thread
t
=
new
Thread
(
new
Runnable
()
{
public
void
run
()
{
while
(!
stop
)
{
while
(!
stop
)
{
testString
();
}
}
});
threads
[
i
]
=
t
;
}
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
threads
[
i
].
start
();
}
int
wait
=
getSize
(
200
,
2000
);
Thread
.
sleep
(
wait
);
stop
=
true
;
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
for
(
int
i
=
0
;
i
<
threadCount
;
i
++)
{
threads
[
i
].
join
();
}
}
...
...
h2/src/test/org/h2/test/unit/TestStringUtils.java
浏览文件 @
f447a3e4
...
...
@@ -28,64 +28,46 @@ public class TestStringUtils extends TestBase {
check
(
"Rand&Blue"
,
StringUtils
.
xmlText
(
"Rand&Blue"
));
check
(
"<<[[[]]]>>"
,
StringUtils
.
xmlCData
(
"<<[[[]]]>>"
));
Date
dt
=
StringUtils
.
parseDateTime
(
"2001-02-03 04:05:06 GMT"
,
"yyyy-MM-dd HH:mm:ss z"
,
"en"
,
"GMT"
);
String
s
=
StringUtils
.
xmlStartDoc
()
+
StringUtils
.
xmlComment
(
"Test Comment"
)
+
StringUtils
.
xmlNode
(
"rss"
,
StringUtils
.
xmlAttr
(
"version"
,
"2.0"
),
StringUtils
.
xmlComment
(
"Test Comment\nZeile2"
)
+
StringUtils
.
xmlNode
(
"channel"
,
null
,
StringUtils
.
xmlNode
(
"title"
,
null
,
"H2 Database Engine"
)
+
StringUtils
.
xmlNode
(
"link"
,
null
,
"http://www.h2database.com"
)
+
StringUtils
.
xmlNode
(
"description"
,
null
,
"H2 Database Engine"
)
+
StringUtils
.
xmlNode
(
"language"
,
null
,
"en-us"
)
+
StringUtils
.
xmlNode
(
"pubDate"
,
null
,
StringUtils
.
formatDateTime
(
dt
,
"EEE, d MMM yyyy HH:mm:ss z"
,
"en"
,
"GMT"
))
+
StringUtils
.
xmlNode
(
"lastBuildDate"
,
null
,
StringUtils
.
formatDateTime
(
dt
,
"EEE, d MMM yyyy HH:mm:ss z"
,
"en"
,
"GMT"
))
+
StringUtils
.
xmlNode
(
"item"
,
null
,
StringUtils
.
xmlNode
(
"title"
,
null
,
"New Version 0.9.9.9.9"
)
+
StringUtils
.
xmlNode
(
"link"
,
null
,
"http://www.h2database.com"
)
+
StringUtils
.
xmlNode
(
"description"
,
null
,
StringUtils
.
xmlCData
(
"\nNew Features\nTest\n"
)
)
)
)
);
check
(
s
,
"<?xml version=\"1.0\"?>\n"
+
"<!-- Test Comment -->\n"
+
"<rss version=\"2.0\">\n"
+
" <!--\n"
+
" Test Comment\n"
+
" Zeile2\n"
+
" -->\n"
+
" <channel>\n"
+
" <title>H2 Database Engine</title>\n"
+
" <link>http://www.h2database.com</link>\n"
+
" <description>H2 Database Engine</description>\n"
+
" <language>en-us</language>\n"
+
" <pubDate>Sat, 3 Feb 2001 04:05:06 GMT</pubDate>\n"
+
" <lastBuildDate>Sat, 3 Feb 2001 04:05:06 GMT</lastBuildDate>\n"
+
" <item>\n"
+
" <title>New Version 0.9.9.9.9</title>\n"
+
" <link>http://www.h2database.com</link>\n"
+
" <description>\n"
+
" <![CDATA[\n"
+
" New Features\n"
+
" Test\n"
+
" ]]>\n"
+
" </description>\n"
+
" </item>\n"
+
" </channel>\n"
+
"</rss>\n"
);
String
s
=
StringUtils
.
xmlStartDoc
()
+
StringUtils
.
xmlComment
(
"Test Comment"
)
+
StringUtils
.
xmlNode
(
"rss"
,
StringUtils
.
xmlAttr
(
"version"
,
"2.0"
),
StringUtils
.
xmlComment
(
"Test Comment\nZeile2"
)
+
StringUtils
.
xmlNode
(
"channel"
,
null
,
StringUtils
.
xmlNode
(
"title"
,
null
,
"H2 Database Engine"
)
+
StringUtils
.
xmlNode
(
"link"
,
null
,
"http://www.h2database.com"
)
+
StringUtils
.
xmlNode
(
"description"
,
null
,
"H2 Database Engine"
)
+
StringUtils
.
xmlNode
(
"language"
,
null
,
"en-us"
)
+
StringUtils
.
xmlNode
(
"pubDate"
,
null
,
StringUtils
.
formatDateTime
(
dt
,
"EEE, d MMM yyyy HH:mm:ss z"
,
"en"
,
"GMT"
))
+
StringUtils
.
xmlNode
(
"lastBuildDate"
,
null
,
StringUtils
.
formatDateTime
(
dt
,
"EEE, d MMM yyyy HH:mm:ss z"
,
"en"
,
"GMT"
))
+
StringUtils
.
xmlNode
(
"item"
,
null
,
StringUtils
.
xmlNode
(
"title"
,
null
,
"New Version 0.9.9.9.9"
)
+
StringUtils
.
xmlNode
(
"link"
,
null
,
"http://www.h2database.com"
)
+
StringUtils
.
xmlNode
(
"description"
,
null
,
StringUtils
.
xmlCData
(
"\nNew Features\nTest\n"
)))));
check
(
s
,
"<?xml version=\"1.0\"?>\n"
+
"<!-- Test Comment -->\n"
+
"<rss version=\"2.0\">\n"
+
" <!--\n"
+
" Test Comment\n"
+
" Zeile2\n"
+
" -->\n"
+
" <channel>\n"
+
" <title>H2 Database Engine</title>\n"
+
" <link>http://www.h2database.com</link>\n"
+
" <description>H2 Database Engine</description>\n"
+
" <language>en-us</language>\n"
+
" <pubDate>Sat, 3 Feb 2001 04:05:06 GMT</pubDate>\n"
+
" <lastBuildDate>Sat, 3 Feb 2001 04:05:06 GMT</lastBuildDate>\n"
+
" <item>\n"
+
" <title>New Version 0.9.9.9.9</title>\n"
+
" <link>http://www.h2database.com</link>\n"
+
" <description>\n"
+
" <![CDATA[\n"
+
" New Features\n"
+
" Test\n"
+
" ]]>\n"
+
" </description>\n"
+
" </item>\n"
+
" </channel>\n"
+
"</rss>\n"
);
}
private
void
testURL
()
throws
Exception
{
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
int
len
=
random
.
nextInt
(
10
);
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
if
(
random
.
nextBoolean
())
{
buff
.
append
((
char
)
random
.
nextInt
(
0x3000
));
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
if
(
random
.
nextBoolean
())
{
buff
.
append
((
char
)
random
.
nextInt
(
0x3000
));
}
else
{
buff
.
append
((
char
)
random
.
nextInt
(
255
));
buff
.
append
((
char
)
random
.
nextInt
(
255
));
}
}
String
a
=
buff
.
toString
();
...
...
@@ -99,14 +81,14 @@ public class TestStringUtils extends TestBase {
private
void
testJavaString
()
throws
Exception
{
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
for
(
int
i
=
0
;
i
<
1000
;
i
++)
{
int
len
=
random
.
nextInt
(
10
);
StringBuffer
buff
=
new
StringBuffer
();
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
if
(
random
.
nextBoolean
())
{
buff
.
append
((
char
)
random
.
nextInt
(
0x3000
));
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
if
(
random
.
nextBoolean
())
{
buff
.
append
((
char
)
random
.
nextInt
(
0x3000
));
}
else
{
buff
.
append
((
char
)
random
.
nextInt
(
255
));
buff
.
append
((
char
)
random
.
nextInt
(
255
));
}
}
String
a
=
buff
.
toString
();
...
...
@@ -118,17 +100,17 @@ public class TestStringUtils extends TestBase {
private
void
testSplit
()
throws
Exception
{
check
(
3
,
StringUtils
.
arraySplit
(
"ABC,DEF,G\\,HI"
,
','
,
false
).
length
);
check
(
StringUtils
.
arrayCombine
(
new
String
[]
{
""
,
" "
,
","
},
','
),
", ,\\,"
);
check
(
StringUtils
.
arrayCombine
(
new
String
[]
{
""
,
" "
,
","
},
','
),
", ,\\,"
);
Random
random
=
new
Random
(
1
);
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
int
len
=
random
.
nextInt
(
10
);
StringBuffer
buff
=
new
StringBuffer
();
String
select
=
"abcd,"
;
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
for
(
int
j
=
0
;
j
<
len
;
j
++)
{
char
c
=
select
.
charAt
(
random
.
nextInt
(
select
.
length
()));
if
(
c
==
'a'
)
{
if
(
c
==
'a'
)
{
buff
.
append
(
"\\\\"
);
}
else
if
(
c
==
'b'
)
{
}
else
if
(
c
==
'b'
)
{
buff
.
append
(
"\\,"
);
}
else
{
buff
.
append
(
c
);
...
...
h2/src/test/org/h2/test/unit/TestTools.java
浏览文件 @
f447a3e4
...
...
@@ -4,15 +4,19 @@
*/
package
org
.
h2
.
test
.
unit
;
import
java.sql.*
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.test.TestBase
;
import
org.h2.tools.Backup
;
import
org.h2.tools.Restore
;
import
org.h2.tools.Script
;
import
org.h2.tools.ChangePassword
;
import
org.h2.tools.DeleteDbFiles
;
import
org.h2.tools.Restore
;
import
org.h2.tools.RunScript
;
import
org.h2.tools.Script
;
import
org.h2.tools.Server
;
import
org.h2.util.Resources
;
...
...
@@ -27,90 +31,94 @@ public class TestTools extends TestBase {
testScriptRunscript
();
testBackupRestore
();
}
private
void
testManagementDb
()
throws
Exception
{
int
count
=
getSize
(
2
,
10
);
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
Server
server
=
Server
.
createTcpServer
(
new
String
[]{}).
start
();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
Server
server
=
Server
.
createTcpServer
(
new
String
[]
{}).
start
();
server
.
stop
();
server
=
Server
.
createTcpServer
(
new
String
[]
{
"-tcpPassword"
,
"abc"
}).
start
();
server
=
Server
.
createTcpServer
(
new
String
[]
{
"-tcpPassword"
,
"abc"
}).
start
();
server
.
stop
();
}
}
private
void
testScriptRunscript
()
throws
Exception
{
Class
.
forName
(
"org.h2.Driver"
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/utils"
;
String
url
=
"jdbc:h2:"
+
baseDir
+
"/utils"
;
String
user
=
"sa"
,
password
=
"abc"
;
String
fileName
=
baseDir
+
"/b2.sql"
;
Connection
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
conn
.
createStatement
().
execute
(
"INSERT INTO TEST VALUES(1, 'Hello')"
);
conn
.
close
();
Script
.
main
(
new
String
[]{
"-url"
,
url
,
"-user"
,
user
,
"-password"
,
password
,
"-script"
,
fileName
,
"-options"
,
"nodata"
,
"compression"
,
"lzf"
,
"cipher"
,
"xtea"
,
"password"
,
"'123'"
});
DeleteDbFiles
.
main
(
new
String
[]{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
RunScript
.
main
(
new
String
[]{
"-url"
,
url
,
"-user"
,
user
,
"-password"
,
password
,
"-script"
,
fileName
,
"-options"
,
"compression"
,
"lzf"
,
"cipher"
,
"xtea"
,
"password"
,
"'123'"
});
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils"
,
"sa"
,
"abc"
);
Script
.
main
(
new
String
[]
{
"-url"
,
url
,
"-user"
,
user
,
"-password"
,
password
,
"-script"
,
fileName
,
"-options"
,
"nodata"
,
"compression"
,
"lzf"
,
"cipher"
,
"xtea"
,
"password"
,
"'123'"
});
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
RunScript
.
main
(
new
String
[]
{
"-url"
,
url
,
"-user"
,
user
,
"-password"
,
password
,
"-script"
,
fileName
,
"-options"
,
"compression"
,
"lzf"
,
"cipher"
,
"xtea"
,
"password"
,
"'123'"
});
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils"
,
"sa"
,
"abc"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
checkFalse
(
rs
.
next
());
conn
.
close
();
}
private
void
testBackupRestore
()
throws
Exception
{
Class
.
forName
(
"org.h2.Driver"
);
String
url
=
"jdbc:h2:"
+
baseDir
+
"/utils"
;
String
url
=
"jdbc:h2:"
+
baseDir
+
"/utils"
;
String
user
=
"sa"
,
password
=
"abc"
;
String
fileName
=
baseDir
+
"/b2.zip"
;
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
Connection
conn
=
DriverManager
.
getConnection
(
url
,
user
,
password
);
conn
.
createStatement
().
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)"
);
conn
.
createStatement
().
execute
(
"INSERT INTO TEST VALUES(1, 'Hello')"
);
conn
.
close
();
Backup
.
main
(
new
String
[]
{
"-file"
,
fileName
,
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
Restore
.
main
(
new
String
[]
{
"-file"
,
fileName
,
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils"
,
"sa"
,
"abc"
);
Backup
.
main
(
new
String
[]
{
"-file"
,
fileName
,
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
Restore
.
main
(
new
String
[]
{
"-file"
,
fileName
,
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils"
,
"sa"
,
"abc"
);
ResultSet
rs
=
conn
.
createStatement
().
executeQuery
(
"SELECT * FROM TEST"
);
check
(
rs
.
next
());
checkFalse
(
rs
.
next
());
conn
.
close
();
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
DeleteDbFiles
.
main
(
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
});
}
private
void
testResourceGenerator
()
throws
Exception
{
Resources
.
main
(
new
String
[]
{
"."
});
Resources
.
main
(
new
String
[]
{
"."
});
}
private
void
testChangePassword
()
throws
Exception
{
Class
.
forName
(
"org.h2.Driver"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils;CIPHER=XTEA;STORAGE=TEXT"
,
"sa"
,
"abc 123"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils;CIPHER=XTEA;STORAGE=TEXT"
,
"sa"
,
"abc 123"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"
);
conn
.
close
();
String
[]
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-cipher"
,
"XTEA"
,
"-decrypt"
,
"abc"
,
"-quiet"
};
String
[]
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-cipher"
,
"XTEA"
,
"-decrypt"
,
"abc"
,
"-quiet"
};
ChangePassword
.
main
(
args
);
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-cipher"
,
"AES"
,
"-encrypt"
,
"def"
,
"-quiet"
};
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-cipher"
,
"AES"
,
"-encrypt"
,
"def"
,
"-quiet"
};
ChangePassword
.
main
(
args
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils;CIPHER=AES"
,
"sa"
,
"def 123"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:"
+
baseDir
+
"/utils;CIPHER=AES"
,
"sa"
,
"def 123"
);
stat
=
conn
.
createStatement
();
stat
.
execute
(
"SELECT * FROM TEST"
);
conn
.
close
();
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
};
args
=
new
String
[]
{
"-dir"
,
baseDir
,
"-db"
,
"utils"
,
"-quiet"
};
DeleteDbFiles
.
main
(
args
);
}
private
void
testServer
()
throws
Exception
{
Connection
conn
;
Server
server
=
Server
.
createTcpServer
(
new
String
[]
{
"-ifExists"
,
"false"
,
"-baseDir"
,
baseDir
}).
start
();
Server
server
=
Server
.
createTcpServer
(
new
String
[]
{
"-ifExists"
,
"false"
,
"-baseDir"
,
baseDir
}).
start
();
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
conn
.
close
();
server
.
stop
();
server
=
Server
.
createTcpServer
(
new
String
[]{
"-ifExists"
,
"true"
,
"-tcpPassword"
,
"abc"
,
"-baseDir"
,
baseDir
}).
start
();
server
=
Server
.
createTcpServer
(
new
String
[]
{
"-ifExists"
,
"true"
,
"-tcpPassword"
,
"abc"
,
"-baseDir"
,
baseDir
}).
start
();
try
{
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test2"
,
"sa"
,
""
);
error
(
"should not be able to create new db"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
}
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
...
...
@@ -118,7 +126,7 @@ public class TestTools extends TestBase {
try
{
Server
.
shutdownTcpServer
(
"tcp://localhost"
,
""
,
true
);
error
(
"shouldn't work and should throw an exception"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
// expected
}
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
...
...
@@ -127,7 +135,7 @@ public class TestTools extends TestBase {
try
{
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost/test"
,
"sa"
,
""
);
error
(
"server must have been closed"
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
checkNotGeneralException
(
e
);
}
}
...
...
h2/src/test/org/h2/test/unit/TestValueHashMap.java
浏览文件 @
f447a3e4
...
...
@@ -19,29 +19,29 @@ import org.h2.value.Value;
import
org.h2.value.ValueInt
;
public
class
TestValueHashMap
extends
TestBase
implements
DataHandler
{
CompareMode
compareMode
=
new
CompareMode
(
null
,
null
);
public
void
test
()
throws
Exception
{
ValueHashMap
map
=
new
ValueHashMap
(
this
);
HashMap
hash
=
new
HashMap
();
Random
random
=
new
Random
(
1
);
Random
random
=
new
Random
(
1
);
Comparator
vc
=
new
Comparator
()
{
public
int
compare
(
Object
o1
,
Object
o2
)
{
Value
v1
=
(
Value
)
o1
;
Value
v2
=
(
Value
)
o2
;
Value
v1
=
(
Value
)
o1
;
Value
v2
=
(
Value
)
o2
;
try
{
return
v1
.
compareTo
(
v2
,
compareMode
);
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
throw
new
Error
(
e
);
}
}
};
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
for
(
int
i
=
0
;
i
<
10000
;
i
++)
{
int
op
=
random
.
nextInt
(
10
);
Value
key
=
ValueInt
.
get
(
random
.
nextInt
(
100
));
Value
value
=
ValueInt
.
get
(
random
.
nextInt
(
100
));
switch
(
op
)
{
switch
(
op
)
{
case
0
:
map
.
put
(
key
,
value
);
hash
.
put
(
key
,
value
);
...
...
@@ -53,7 +53,7 @@ public class TestValueHashMap extends TestBase implements DataHandler {
case
2
:
Value
v1
=
(
Value
)
map
.
get
(
key
);
Value
v2
=
(
Value
)
hash
.
get
(
key
);
check
((
v1
==
null
&&
v2
==
null
)
||
v1
.
compareEqual
(
v2
));
check
((
v1
==
null
&&
v2
==
null
)
||
v1
.
compareEqual
(
v2
));
break
;
case
3
:
{
ObjectArray
a1
=
map
.
keys
();
...
...
@@ -61,8 +61,8 @@ public class TestValueHashMap extends TestBase implements DataHandler {
check
(
a1
.
size
(),
a2
.
size
());
a1
.
sort
(
vc
);
a2
.
sort
(
vc
);
for
(
int
j
=
0
;
j
<
a1
.
size
();
j
++)
{
check
(((
Value
)
a1
.
get
(
j
)).
compareEqual
((
Value
)
a2
.
get
(
j
)));
for
(
int
j
=
0
;
j
<
a1
.
size
();
j
++)
{
check
(((
Value
)
a1
.
get
(
j
)).
compareEqual
((
Value
)
a2
.
get
(
j
)));
}
break
;
}
...
...
@@ -72,8 +72,8 @@ public class TestValueHashMap extends TestBase implements DataHandler {
check
(
a1
.
size
(),
a2
.
size
());
a1
.
sort
(
vc
);
a2
.
sort
(
vc
);
for
(
int
j
=
0
;
j
<
a1
.
size
();
j
++)
{
check
(((
Value
)
a1
.
get
(
j
)).
compareEqual
((
Value
)
a2
.
get
(
j
)));
for
(
int
j
=
0
;
j
<
a1
.
size
();
j
++)
{
check
(((
Value
)
a1
.
get
(
j
)).
compareEqual
((
Value
)
a2
.
get
(
j
)));
}
break
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论