Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
69097413
提交
69097413
authored
7月 13, 2012
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improved test case.
上级
67b3f30f
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
56 行增加
和
23 行删除
+56
-23
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+5
-2
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+1
-1
TestJavaObject.java
h2/src/test/org/h2/test/jdbc/TestJavaObject.java
+50
-20
没有找到文件。
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
69097413
...
...
@@ -731,7 +731,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
* old database files in the test directory and trace files. It also starts
* a TCP server if the test uses remote connections.
*/
void
beforeTest
()
throws
SQLException
{
public
void
beforeTest
()
throws
SQLException
{
Driver
.
load
();
FileUtils
.
deleteRecursive
(
TestBase
.
BASE_TEST_DIR
,
true
);
DeleteDbFiles
.
execute
(
TestBase
.
BASE_TEST_DIR
,
null
,
true
);
...
...
@@ -749,7 +749,10 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
}
}
private
void
afterTest
()
{
/**
* Stop the server if it was started.
*/
public
void
afterTest
()
{
FileUtils
.
deleteRecursive
(
"trace.db"
,
true
);
if
(
networked
&&
server
!=
null
)
{
server
.
stop
();
...
...
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
69097413
...
...
@@ -1421,7 +1421,7 @@ public abstract class TestBase {
}
try
{
Class
<?>
pc
=
ProxyCodeGenerator
.
getClassProxy
(
c
);
Constructor
cons
=
pc
.
getConstructor
(
new
Class
<?>[]
{
InvocationHandler
.
class
});
Constructor
<?>
cons
=
pc
.
getConstructor
(
new
Class
<?>[]
{
InvocationHandler
.
class
});
return
(
T
)
cons
.
newInstance
(
new
Object
[]
{
ih
});
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
...
...
h2/src/test/org/h2/test/jdbc/TestJavaObject.java
浏览文件 @
69097413
...
...
@@ -6,6 +6,7 @@
*/
package
org
.
h2
.
test
.
jdbc
;
import
java.io.Serializable
;
import
java.sql.Connection
;
import
java.sql.Date
;
import
java.sql.PreparedStatement
;
...
...
@@ -18,7 +19,6 @@ import java.sql.Types;
import
java.util.Arrays
;
import
java.util.UUID
;
import
org.h2.constant.SysProperties
;
import
org.h2.test.TestAll
;
import
org.h2.test.TestBase
;
/**
...
...
@@ -35,13 +35,13 @@ public class TestJavaObject extends TestBase {
* @param a ignored
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
// System.setProperty("h2.serializeJavaObject", "false"
);
TestAll
conf
=
new
TestAll
()
;
conf
.
traceTest
=
true
;
conf
.
memory
=
true
;
// conf.networked = true
;
TestBase
.
createCaller
().
init
(
conf
).
t
est
();
TestBase
test
=
createCaller
().
init
(
);
test
.
config
.
traceTest
=
true
;
test
.
config
.
memory
=
true
;
test
.
config
.
networked
=
true
;
test
.
config
.
beforeTest
()
;
test
.
test
()
;
test
.
config
.
afterT
est
();
}
@Override
...
...
@@ -49,7 +49,7 @@ public class TestJavaObject extends TestBase {
SysProperties
.
SERIALIZE_JAVA_OBJECT
=
false
;
try
{
trace
(
"Test Java Object"
);
startServerIfRequired
(
);
doTest
(
new
MyObj
(
1
),
new
MyObj
(
2
),
false
);
doTest
(
Arrays
.
asList
(
UUID
.
randomUUID
(),
null
),
Arrays
.
asList
(
UUID
.
randomUUID
(),
UUID
.
randomUUID
()),
true
);
doTest
(
new
Timestamp
(
System
.
currentTimeMillis
()),
new
Timestamp
(
System
.
currentTimeMillis
()
+
10000
),
false
);
doTest
(
200
,
100
,
false
);
...
...
@@ -66,8 +66,8 @@ public class TestJavaObject extends TestBase {
private
void
doTest
(
Object
o1
,
Object
o2
,
boolean
hash
)
throws
SQLException
{
deleteDb
(
"javaObject"
);
Connection
conn
=
getConnection
(
"javaObject"
);
Statement
st
m
t
=
conn
.
createStatement
();
st
m
t
.
execute
(
"create table t(id identity, val other)"
);
Statement
st
a
t
=
conn
.
createStatement
();
st
a
t
.
execute
(
"create table t(id identity, val other)"
);
PreparedStatement
ins
=
conn
.
prepareStatement
(
"insert into t(val) values(?)"
);
...
...
@@ -77,30 +77,30 @@ public class TestJavaObject extends TestBase {
ins
.
setObject
(
1
,
o2
,
Types
.
JAVA_OBJECT
);
assertEquals
(
1
,
ins
.
executeUpdate
());
ResultSet
rs
=
st
m
t
.
executeQuery
(
"select val from t order by val limit 1"
);
ResultSet
rs
=
st
a
t
.
executeQuery
(
"select val from t order by val limit 1"
);
assertTrue
(
rs
.
next
());
Object
x
;
Object
smallest
;
if
(
hash
)
{
if
(
o1
.
getClass
()
!=
o2
.
getClass
())
{
x
=
o1
.
getClass
().
getName
().
compareTo
(
o2
.
getClass
().
getName
())
<
0
?
o1
:
o2
;
smallest
=
o1
.
getClass
().
getName
().
compareTo
(
o2
.
getClass
().
getName
())
<
0
?
o1
:
o2
;
}
else
{
assertFalse
(
o1
.
hashCode
()
==
o2
.
hashCode
());
x
=
o1
.
hashCode
()
<
o2
.
hashCode
()
?
o1
:
o2
;
smallest
=
o1
.
hashCode
()
<
o2
.
hashCode
()
?
o1
:
o2
;
}
}
else
{
@SuppressWarnings
(
"unchecked"
)
int
compare
=
((
Comparable
<
Object
>)
o1
).
compareTo
(
o2
);
assertFalse
(
compare
==
0
);
x
=
compare
<
0
?
o1
:
o2
;
smallest
=
compare
<
0
?
o1
:
o2
;
}
assertEquals
(
x
.
toString
(),
rs
.
getString
(
1
));
assertEquals
(
smallest
.
toString
(),
rs
.
getString
(
1
));
Object
y
=
rs
.
getObject
(
1
);
assertTrue
(
x
.
equals
(
y
));
assertTrue
(
smallest
.
equals
(
y
));
assertFalse
(
rs
.
next
());
rs
.
close
();
...
...
@@ -120,11 +120,41 @@ public class TestJavaObject extends TestBase {
assertFalse
(
rs
.
next
());
rs
.
close
();
st
m
t
.
close
();
st
a
t
.
close
();
prep
.
close
();
conn
.
close
();
deleteDb
(
"javaObject"
);
trace
(
"ok: "
+
o1
.
getClass
().
getName
()
+
" vs "
+
o2
.
getClass
().
getName
());
// trace("ok: " + o1.getClass().getName() + " vs " + o2.getClass().getName());
}
/**
* A test class.
*/
public
static
class
MyObj
implements
Comparable
<
MyObj
>,
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
final
int
value
;
MyObj
(
int
value
)
{
this
.
value
=
value
;
}
public
String
toString
()
{
return
""
+
value
;
}
public
int
compareTo
(
MyObj
o
)
{
return
value
-
o
.
value
;
}
public
boolean
equals
(
Object
o
)
{
return
value
==
((
MyObj
)
o
).
value
;
}
public
int
hashCode
()
{
return
-
value
;
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论