Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
21b02e28
提交
21b02e28
authored
2月 17, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests.
上级
d850a570
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
108 行增加
和
20 行删除
+108
-20
changelog.html
h2/src/docsrc/html/changelog.html
+3
-1
Database.java
h2/src/main/org/h2/engine/Database.java
+1
-1
SessionRemote.java
h2/src/main/org/h2/engine/SessionRemote.java
+0
-4
FileObjectDiskMapped.java
h2/src/main/org/h2/store/fs/FileObjectDiskMapped.java
+3
-3
FileSystem.java
h2/src/main/org/h2/store/fs/FileSystem.java
+2
-1
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+4
-2
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+4
-2
TestPreparedStatement.java
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
+10
-0
TestRecovery.java
h2/src/test/org/h2/test/unit/TestRecovery.java
+35
-6
TestTools.java
h2/src/test/org/h2/test/unit/TestTools.java
+46
-0
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
21b02e28
...
...
@@ -18,7 +18,9 @@ Change Log
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
Hash indexes now are only used for single column indexes.
<ul><li>
CREATE ALIAS: error message when compiling Java code have been improved.
</li><li>
MVCC: creating a table with an incorrect constraint could cause strange errors.
</li><li>
Hash indexes now are only used for single column indexes.
</li><li>
The cache types WEAK_* and TQ are no longer supported.
</li><li>
The file system abstraction no longer throws SQL exceptions.
</li><li>
DatabaseEventListener.diskSpaceIsLow has changed.
...
...
h2/src/main/org/h2/engine/Database.java
浏览文件 @
21b02e28
...
...
@@ -1528,6 +1528,7 @@ public class Database implements DataHandler {
removeDatabaseObject
(
session
,
comment
);
}
obj
.
getSchema
().
remove
(
obj
);
int
id
=
obj
.
getId
();
if
(!
starting
)
{
Table
t
=
getDependentTable
(
obj
,
null
);
if
(
t
!=
null
)
{
...
...
@@ -1536,7 +1537,6 @@ public class Database implements DataHandler {
}
obj
.
removeChildrenAndResources
(
session
);
}
int
id
=
obj
.
getId
();
removeMeta
(
session
,
id
);
}
...
...
h2/src/main/org/h2/engine/SessionRemote.java
浏览文件 @
21b02e28
...
...
@@ -548,10 +548,6 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
// ok
}
public
int
compareTypeSave
(
Value
a
,
Value
b
)
{
throw
DbException
.
throwInternalError
();
}
public
void
freeUpDiskSpace
()
{
// nothing to do
}
...
...
h2/src/main/org/h2/store/fs/FileObjectDiskMapped.java
浏览文件 @
21b02e28
...
...
@@ -38,7 +38,7 @@ public class FileObjectDiskMapped implements FileObject {
reMap
();
}
private
void
unMap
()
{
private
void
unMap
()
throws
IOException
{
if
(
mapped
!=
null
)
{
// first write all data
mapped
.
force
();
...
...
@@ -67,7 +67,7 @@ public class FileObjectDiskMapped implements FileObject {
long
start
=
System
.
currentTimeMillis
();
while
(
bufferWeakRef
.
get
()
!=
null
)
{
if
(
System
.
currentTimeMillis
()
-
start
>
GC_TIMEOUT_MS
)
{
throw
new
Runtime
Exception
(
"Timeout ("
+
GC_TIMEOUT_MS
throw
new
IO
Exception
(
"Timeout ("
+
GC_TIMEOUT_MS
+
" ms) reached while trying to GC mapped buffer"
);
}
System
.
gc
();
...
...
@@ -83,7 +83,7 @@ public class FileObjectDiskMapped implements FileObject {
*/
private
void
reMap
()
throws
IOException
{
if
(
file
.
length
()
>
Integer
.
MAX_VALUE
)
{
throw
new
Runtime
Exception
(
"File over 2GB is not supported yet"
);
throw
new
IO
Exception
(
"File over 2GB is not supported yet"
);
}
int
oldPos
=
0
;
if
(
mapped
!=
null
)
{
...
...
h2/src/main/org/h2/store/fs/FileSystem.java
浏览文件 @
21b02e28
...
...
@@ -10,6 +10,7 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.ArrayList
;
import
org.h2.message.DbException
;
import
org.h2.util.New
;
/**
...
...
@@ -54,7 +55,7 @@ public abstract class FileSystem {
try
{
Class
.
forName
(
c
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
throw
DbException
.
convert
(
e
);
}
}
}
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
21b02e28
...
...
@@ -291,10 +291,13 @@ java org.h2.test.TestAll timer
System
.
setProperty
(
"h2.check2"
,
"true"
);
/*
test recovery of large pages and transaction log
test recovery with 'trace' mode (btree data)
test runscript with setCheckResults, execute, process, setShowResults
rename Page* classes
move classes to the right packages
instead of AVL trees, use general balanced trees
test Row.getMemorySize
remove CipherFactory
document in performance section:
PreparedStatement prep = conn.prepareStatement(
...
...
@@ -511,7 +514,6 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new
TestTempTables
().
runTest
(
this
);
new
TestTransaction
().
runTest
(
this
);
new
TestTriggersConstraints
().
runTest
(
this
);
new
TestTwoPhaseCommit
().
runTest
(
this
);
new
TestView
().
runTest
(
this
);
new
TestViewAlterTable
().
runTest
(
this
);
...
...
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
21b02e28
...
...
@@ -1096,12 +1096,14 @@ public abstract class TestBase {
ArrayList
<
String
>
list2
=
new
ArrayList
<
String
>();
while
(
rs1
.
next
())
{
String
s1
=
rs1
.
getString
(
1
);
list1
.
add
(
s1
);
if
(!
rs2
.
next
())
{
fail
(
"expected: "
+
s1
);
}
String
s2
=
rs2
.
getString
(
1
);
list2
.
add
(
s2
);
if
(!
s1
.
equals
(
s2
))
{
list1
.
add
(
s1
);
list2
.
add
(
s2
);
}
}
for
(
String
s
:
list1
)
{
if
(!
list2
.
remove
(
s
))
{
...
...
h2/src/test/org/h2/test/jdbc/TestPreparedStatement.java
浏览文件 @
21b02e28
...
...
@@ -43,6 +43,7 @@ public class TestPreparedStatement extends TestBase {
deleteDb
(
"preparedStatement"
);
Connection
conn
=
getConnection
(
"preparedStatement"
);
testPrepareExecute
(
conn
);
testUUID
(
conn
);
testScopedGeneratedKey
(
conn
);
testLobTempFiles
(
conn
);
...
...
@@ -75,6 +76,15 @@ public class TestPreparedStatement extends TestBase {
deleteDb
(
"preparedStatement"
);
}
private
void
testPrepareExecute
(
Connection
conn
)
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"prepare test(int, int) as select ?1*?2"
);
ResultSet
rs
=
stat
.
executeQuery
(
"execute test(3, 2)"
);
rs
.
next
();
assertEquals
(
6
,
rs
.
getInt
(
1
));
stat
.
execute
(
"deallocate test"
);
}
private
void
testLobTempFiles
(
Connection
conn
)
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"CREATE TABLE TEST(ID INT PRIMARY KEY, DATA CLOB)"
);
...
...
h2/src/test/org/h2/test/unit/TestRecovery.java
浏览文件 @
21b02e28
...
...
@@ -6,6 +6,8 @@
*/
package
org
.
h2
.
test
.
unit
;
import
java.io.ByteArrayOutputStream
;
import
java.io.PrintStream
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
...
...
@@ -28,26 +30,53 @@ public class TestRecovery extends TestBase {
}
public
void
test
()
throws
SQLException
{
testRunScript
();
}
private
void
testRunScript
()
throws
SQLException
{
DeleteDbFiles
.
execute
(
baseDir
,
"recovery"
,
true
);
DeleteDbFiles
.
execute
(
baseDir
,
"recovery2"
,
true
);
org
.
h2
.
Driver
.
load
();
Connection
conn
=
getConnection
(
"recovery"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test as select * from system_range(1, 100)"
);
stat
.
execute
(
"create table a(id int primary key) as select * from system_range(1, 100)"
);
stat
.
execute
(
"create table b(id int references a(id)) as select * from system_range(1, 100)"
);
stat
.
execute
(
"create table c(d clob) as select space(10000) || 'end'"
);
stat
.
execute
(
"create table d(d varchar) as select space(10000) || 'end'"
);
stat
.
execute
(
"alter table a add foreign key(id) references b(id)"
);
// all rows have the same value - so that SCRIPT can't re-order the rows
stat
.
execute
(
"create table e(id varchar) as select space(10) from system_range(1, 1000)"
);
stat
.
execute
(
"create index idx_e_id on e(id)"
);
conn
.
close
();
Recover
.
execute
(
baseDir
,
"recovery"
);
DeleteDbFiles
.
execute
(
baseDir
,
"recovery"
,
true
);
Recover
rec
=
new
Recover
();
ByteArrayOutputStream
buff
=
new
ByteArrayOutputStream
();
rec
.
setOut
(
new
PrintStream
(
buff
));
rec
.
runTool
(
"-dir"
,
baseDir
,
"-db"
,
"recovery"
,
"-trace"
);
String
out
=
new
String
(
buff
.
toByteArray
());
assertTrue
(
out
.
indexOf
(
"Created file"
)
>=
0
);
conn
=
getConnection
(
"recovery
"
,
"diff"
,
""
);
stat
=
conn
.
createStatement
();
Connection
conn2
=
getConnection
(
"recovery2
"
,
"diff"
,
""
);
Statement
stat2
=
conn2
.
createStatement
();
String
name
=
"recovery.h2.sql"
;
stat
.
execute
(
"runscript from '"
+
baseDir
+
"/"
+
name
+
"'"
);
stat
.
execute
(
"select * from test"
);
stat2
.
execute
(
"runscript from '"
+
baseDir
+
"/"
+
name
+
"'"
);
stat2
.
execute
(
"select * from test"
);
stat2
.
execute
(
"drop user diff"
);
conn2
.
close
();
conn
=
getConnection
(
"recovery"
);
stat
=
conn
.
createStatement
();
conn2
=
getConnection
(
"recovery2"
);
stat2
=
conn2
.
createStatement
();
assertEqualDatabases
(
stat
,
stat2
);
conn
.
close
();
conn2
.
close
();
Recover
.
execute
(
baseDir
,
"recovery"
);
}
}
h2/src/test/org/h2/test/unit/TestTools.java
浏览文件 @
21b02e28
...
...
@@ -13,6 +13,7 @@ import java.math.BigDecimal;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
java.sql.Connection
;
import
java.sql.Date
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
...
...
@@ -34,6 +35,7 @@ import org.h2.tools.Restore;
import
org.h2.tools.RunScript
;
import
org.h2.tools.Script
;
import
org.h2.tools.Server
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.IOUtils
;
import
org.h2.util.JdbcUtils
;
...
...
@@ -57,6 +59,7 @@ public class TestTools extends TestBase {
if
(
config
.
networked
)
{
return
;
}
testSimpleResultSet
();
org
.
h2
.
Driver
.
load
();
testJdbcDriverUtils
();
testWrongServer
();
...
...
@@ -76,6 +79,49 @@ public class TestTools extends TestBase {
deleteDb
(
"utils"
);
}
private
void
testSimpleResultSet
()
throws
SQLException
{
SimpleResultSet
rs
;
rs
=
new
SimpleResultSet
();
rs
.
addColumn
(
"a"
,
Types
.
BIGINT
,
0
,
0
);
rs
.
addColumn
(
"b"
,
Types
.
BINARY
,
0
,
0
);
rs
.
addColumn
(
"c"
,
Types
.
BOOLEAN
,
0
,
0
);
rs
.
addColumn
(
"d"
,
Types
.
DATE
,
0
,
0
);
rs
.
addColumn
(
"e"
,
Types
.
DECIMAL
,
0
,
0
);
rs
.
addColumn
(
"f"
,
Types
.
FLOAT
,
0
,
0
);
rs
.
addColumn
(
"g"
,
Types
.
VARCHAR
,
0
,
0
);
Date
d
=
Date
.
valueOf
(
"2001-02-03"
);
byte
[]
b
=
new
byte
[]{(
byte
)
0xab
};
rs
.
addRow
(
1
,
b
,
true
,
d
,
"10.3"
,
Math
.
PI
,
"-3"
);
rs
.
next
();
assertEquals
(
1
,
rs
.
getLong
(
1
));
assertEquals
((
byte
)
1
,
rs
.
getByte
(
1
));
assertEquals
((
short
)
1
,
rs
.
getShort
(
1
));
assertEquals
(
1
,
rs
.
getLong
(
"a"
));
assertEquals
((
byte
)
1
,
rs
.
getByte
(
"a"
));
assertEquals
((
short
)
1
,
rs
.
getShort
(
"a"
));
assertEquals
(
b
,
rs
.
getBytes
(
2
));
assertEquals
(
b
,
rs
.
getBytes
(
"b"
));
assertTrue
(
rs
.
getBoolean
(
3
));
assertTrue
(
rs
.
getBoolean
(
"c"
));
assertEquals
(
d
.
getTime
(),
rs
.
getDate
(
4
).
getTime
());
assertEquals
(
d
.
getTime
(),
rs
.
getDate
(
"d"
).
getTime
());
assertTrue
(
new
BigDecimal
(
"10.3"
).
equals
(
rs
.
getBigDecimal
(
5
)));
assertTrue
(
new
BigDecimal
(
"10.3"
).
equals
(
rs
.
getBigDecimal
(
"e"
)));
assertEquals
(
10.3
,
rs
.
getDouble
(
5
));
assertEquals
((
float
)
10.3
,
rs
.
getFloat
(
5
));
assertTrue
(
Math
.
PI
==
rs
.
getDouble
(
6
));
assertTrue
(
Math
.
PI
==
rs
.
getDouble
(
"f"
));
assertTrue
((
float
)
Math
.
PI
==
rs
.
getFloat
(
6
));
assertTrue
((
float
)
Math
.
PI
==
rs
.
getFloat
(
"f"
));
assertEquals
(-
3
,
rs
.
getInt
(
7
));
assertEquals
(-
3
,
rs
.
getByte
(
7
));
assertEquals
(-
3
,
rs
.
getShort
(
7
));
assertEquals
(-
3
,
rs
.
getLong
(
7
));
rs
.
beforeFirst
();
assertTrue
(
rs
.
next
());
assertFalse
(
rs
.
next
());
}
private
void
testJdbcDriverUtils
()
{
assertEquals
(
"org.h2.Driver"
,
JdbcUtils
.
getDriver
(
"jdbc:h2:~/test"
));
assertEquals
(
"org.postgresql.Driver"
,
JdbcUtils
.
getDriver
(
"jdbc:postgresql:test"
));
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论