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`
...
@@ -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
* old database files in the test directory and trace files. It also starts
* a TCP server if the test uses remote connections.
* a TCP server if the test uses remote connections.
*/
*/
void
beforeTest
()
throws
SQLException
{
public
void
beforeTest
()
throws
SQLException
{
Driver
.
load
();
Driver
.
load
();
FileUtils
.
deleteRecursive
(
TestBase
.
BASE_TEST_DIR
,
true
);
FileUtils
.
deleteRecursive
(
TestBase
.
BASE_TEST_DIR
,
true
);
DeleteDbFiles
.
execute
(
TestBase
.
BASE_TEST_DIR
,
null
,
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`
...
@@ -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
);
FileUtils
.
deleteRecursive
(
"trace.db"
,
true
);
if
(
networked
&&
server
!=
null
)
{
if
(
networked
&&
server
!=
null
)
{
server
.
stop
();
server
.
stop
();
...
...
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
69097413
...
@@ -1421,7 +1421,7 @@ public abstract class TestBase {
...
@@ -1421,7 +1421,7 @@ public abstract class TestBase {
}
}
try
{
try
{
Class
<?>
pc
=
ProxyCodeGenerator
.
getClassProxy
(
c
);
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
});
return
(
T
)
cons
.
newInstance
(
new
Object
[]
{
ih
});
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
...
...
h2/src/test/org/h2/test/jdbc/TestJavaObject.java
浏览文件 @
69097413
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
*/
*/
package
org
.
h2
.
test
.
jdbc
;
package
org
.
h2
.
test
.
jdbc
;
import
java.io.Serializable
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.Date
;
import
java.sql.Date
;
import
java.sql.PreparedStatement
;
import
java.sql.PreparedStatement
;
...
@@ -18,7 +19,6 @@ import java.sql.Types;
...
@@ -18,7 +19,6 @@ import java.sql.Types;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.UUID
;
import
java.util.UUID
;
import
org.h2.constant.SysProperties
;
import
org.h2.constant.SysProperties
;
import
org.h2.test.TestAll
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
/**
/**
...
@@ -35,13 +35,13 @@ public class TestJavaObject extends TestBase {
...
@@ -35,13 +35,13 @@ public class TestJavaObject extends TestBase {
* @param a ignored
* @param a ignored
*/
*/
public
static
void
main
(
String
...
a
)
throws
Exception
{
public
static
void
main
(
String
...
a
)
throws
Exception
{
// System.setProperty("h2.serializeJavaObject", "false"
);
TestBase
test
=
createCaller
().
init
(
);
test
.
config
.
traceTest
=
true
;
TestAll
conf
=
new
TestAll
()
;
test
.
config
.
memory
=
true
;
conf
.
traceTest
=
true
;
test
.
config
.
networked
=
true
;
conf
.
memory
=
true
;
test
.
config
.
beforeTest
()
;
// conf.networked = true
;
test
.
test
()
;
TestBase
.
createCaller
().
init
(
conf
).
t
est
();
test
.
config
.
afterT
est
();
}
}
@Override
@Override
...
@@ -49,7 +49,7 @@ public class TestJavaObject extends TestBase {
...
@@ -49,7 +49,7 @@ public class TestJavaObject extends TestBase {
SysProperties
.
SERIALIZE_JAVA_OBJECT
=
false
;
SysProperties
.
SERIALIZE_JAVA_OBJECT
=
false
;
try
{
try
{
trace
(
"Test Java Object"
);
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
(
Arrays
.
asList
(
UUID
.
randomUUID
(),
null
),
Arrays
.
asList
(
UUID
.
randomUUID
(),
UUID
.
randomUUID
()),
true
);
doTest
(
new
Timestamp
(
System
.
currentTimeMillis
()),
new
Timestamp
(
System
.
currentTimeMillis
()
+
10000
),
false
);
doTest
(
new
Timestamp
(
System
.
currentTimeMillis
()),
new
Timestamp
(
System
.
currentTimeMillis
()
+
10000
),
false
);
doTest
(
200
,
100
,
false
);
doTest
(
200
,
100
,
false
);
...
@@ -66,8 +66,8 @@ public class TestJavaObject extends TestBase {
...
@@ -66,8 +66,8 @@ public class TestJavaObject extends TestBase {
private
void
doTest
(
Object
o1
,
Object
o2
,
boolean
hash
)
throws
SQLException
{
private
void
doTest
(
Object
o1
,
Object
o2
,
boolean
hash
)
throws
SQLException
{
deleteDb
(
"javaObject"
);
deleteDb
(
"javaObject"
);
Connection
conn
=
getConnection
(
"javaObject"
);
Connection
conn
=
getConnection
(
"javaObject"
);
Statement
st
m
t
=
conn
.
createStatement
();
Statement
st
a
t
=
conn
.
createStatement
();
st
m
t
.
execute
(
"create table t(id identity, val other)"
);
st
a
t
.
execute
(
"create table t(id identity, val other)"
);
PreparedStatement
ins
=
conn
.
prepareStatement
(
"insert into t(val) values(?)"
);
PreparedStatement
ins
=
conn
.
prepareStatement
(
"insert into t(val) values(?)"
);
...
@@ -77,30 +77,30 @@ public class TestJavaObject extends TestBase {
...
@@ -77,30 +77,30 @@ public class TestJavaObject extends TestBase {
ins
.
setObject
(
1
,
o2
,
Types
.
JAVA_OBJECT
);
ins
.
setObject
(
1
,
o2
,
Types
.
JAVA_OBJECT
);
assertEquals
(
1
,
ins
.
executeUpdate
());
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
());
assertTrue
(
rs
.
next
());
Object
x
;
Object
smallest
;
if
(
hash
)
{
if
(
hash
)
{
if
(
o1
.
getClass
()
!=
o2
.
getClass
())
{
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
{
}
else
{
assertFalse
(
o1
.
hashCode
()
==
o2
.
hashCode
());
assertFalse
(
o1
.
hashCode
()
==
o2
.
hashCode
());
x
=
o1
.
hashCode
()
<
o2
.
hashCode
()
?
o1
:
o2
;
smallest
=
o1
.
hashCode
()
<
o2
.
hashCode
()
?
o1
:
o2
;
}
}
}
else
{
}
else
{
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
int
compare
=
((
Comparable
<
Object
>)
o1
).
compareTo
(
o2
);
int
compare
=
((
Comparable
<
Object
>)
o1
).
compareTo
(
o2
);
assertFalse
(
compare
==
0
);
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
);
Object
y
=
rs
.
getObject
(
1
);
assertTrue
(
x
.
equals
(
y
));
assertTrue
(
smallest
.
equals
(
y
));
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
rs
.
close
();
rs
.
close
();
...
@@ -120,11 +120,41 @@ public class TestJavaObject extends TestBase {
...
@@ -120,11 +120,41 @@ public class TestJavaObject extends TestBase {
assertFalse
(
rs
.
next
());
assertFalse
(
rs
.
next
());
rs
.
close
();
rs
.
close
();
st
m
t
.
close
();
st
a
t
.
close
();
prep
.
close
();
prep
.
close
();
conn
.
close
();
conn
.
close
();
deleteDb
(
"javaObject"
);
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论