Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
23adb2e7
提交
23adb2e7
authored
13 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
assertThrows
上级
c3e7d739
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
35 行增加
和
32 行删除
+35
-32
TestBase.java
h2/src/test/org/h2/test/TestBase.java
+16
-10
TestCases.java
h2/src/test/org/h2/test/db/TestCases.java
+2
-7
TestCluster.java
h2/src/test/org/h2/test/db/TestCluster.java
+4
-12
ProxyCodeGenerator.java
h2/src/test/org/h2/test/utils/ProxyCodeGenerator.java
+13
-3
没有找到文件。
h2/src/test/org/h2/test/TestBase.java
浏览文件 @
23adb2e7
...
@@ -16,6 +16,7 @@ import java.lang.reflect.Constructor;
...
@@ -16,6 +16,7 @@ import java.lang.reflect.Constructor;
import
java.lang.reflect.InvocationHandler
;
import
java.lang.reflect.InvocationHandler
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Modifier
;
import
java.lang.reflect.Proxy
;
import
java.lang.reflect.Proxy
;
import
java.sql.Connection
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.DriverManager
;
...
@@ -1353,18 +1354,23 @@ public abstract class TestBase {
...
@@ -1353,18 +1354,23 @@ public abstract class TestBase {
}
}
}
}
};
};
if
(
obj
==
this
)
{
Class
<?>[]
interfaces
=
c
.
getInterfaces
();
// class proxies
if
(
Modifier
.
isFinal
(
c
.
getModifiers
()))
{
try
{
// interface class proxies
Class
<?>
pc
=
ProxyCodeGenerator
.
getClassProxy
(
getClass
());
if
(
interfaces
.
length
==
0
)
{
Constructor
cons
=
pc
.
getConstructor
(
new
Class
<?>[]
{
InvocationHandler
.
class
});
throw
new
RuntimeException
(
"Can not create a proxy for the class "
+
return
(
T
)
cons
.
newInstance
(
new
Object
[]
{
ih
});
c
.
getSimpleName
()
+
}
catch
(
Exception
e
)
{
" because it doesn't implement any interfaces and is final"
);
throw
new
RuntimeException
(
e
);
}
}
return
(
T
)
Proxy
.
newProxyInstance
(
c
.
getClassLoader
(),
interfaces
,
ih
);
}
try
{
Class
<?>
pc
=
ProxyCodeGenerator
.
getClassProxy
(
c
);
Constructor
cons
=
pc
.
getConstructor
(
new
Class
<?>[]
{
InvocationHandler
.
class
});
return
(
T
)
cons
.
newInstance
(
new
Object
[]
{
ih
});
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
return
(
T
)
Proxy
.
newProxyInstance
(
c
.
getClassLoader
(),
c
.
getInterfaces
(),
ih
);
}
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestCases.java
浏览文件 @
23adb2e7
...
@@ -505,16 +505,11 @@ public class TestCases extends TestBase {
...
@@ -505,16 +505,11 @@ public class TestCases extends TestBase {
conn
.
close
();
conn
.
close
();
}
}
private
void
testInvalidDatabaseName
()
{
private
void
testInvalidDatabaseName
()
throws
SQLException
{
if
(
config
.
memory
)
{
if
(
config
.
memory
)
{
return
;
return
;
}
}
try
{
assertThrows
(
ErrorCode
.
INVALID_DATABASE_NAME_1
,
this
).
getConnection
(
"cases/"
);
getConnection
(
"cases/"
);
fail
();
}
catch
(
SQLException
e
)
{
assertEquals
(
ErrorCode
.
INVALID_DATABASE_NAME_1
,
e
.
getErrorCode
());
}
}
}
private
void
testReuseSpace
()
throws
SQLException
{
private
void
testReuseSpace
()
throws
SQLException
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestCluster.java
浏览文件 @
23adb2e7
...
@@ -322,18 +322,10 @@ public class TestCluster extends TestBase {
...
@@ -322,18 +322,10 @@ public class TestCluster extends TestBase {
// try to connect in standalone mode - should fail
// try to connect in standalone mode - should fail
// should not be able to connect in standalone mode
// should not be able to connect in standalone mode
try
{
assertThrows
(
ErrorCode
.
CLUSTER_ERROR_DATABASE_RUNS_CLUSTERED_1
,
this
).
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test"
,
user
,
password
);
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test"
,
user
,
password
);
fail
();
assertThrows
(
ErrorCode
.
CLUSTER_ERROR_DATABASE_RUNS_CLUSTERED_1
,
this
).
}
catch
(
SQLException
e
)
{
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port2
+
"/test"
,
user
,
password
);
assertKnownException
(
e
);
}
try
{
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port2
+
"/test"
,
user
,
password
);
fail
();
}
catch
(
SQLException
e
)
{
assertKnownException
(
e
);
}
// test a cluster connection
// test a cluster connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
user
,
password
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
user
,
password
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/utils/ProxyCodeGenerator.java
浏览文件 @
23adb2e7
...
@@ -159,11 +159,21 @@ public class ProxyCodeGenerator {
...
@@ -159,11 +159,21 @@ public class ProxyCodeGenerator {
writer
.
println
(
" }"
);
writer
.
println
(
" }"
);
writer
.
println
(
" @SuppressWarnings(\"unchecked\")"
);
writer
.
println
(
" @SuppressWarnings(\"unchecked\")"
);
writer
.
println
(
" private static <T extends RuntimeException> T convertException(Throwable e) {"
);
writer
.
println
(
" private static <T extends RuntimeException> T convertException(Throwable e) {"
);
writer
.
println
(
" if (e instanceof Error) {"
);
writer
.
println
(
" throw (Error) e;"
);
writer
.
println
(
" }"
);
writer
.
println
(
" return (T) e;"
);
writer
.
println
(
" return (T) e;"
);
writer
.
println
(
" }"
);
writer
.
println
(
" }"
);
for
(
Method
m
:
methods
.
values
())
{
for
(
Method
m
:
methods
.
values
())
{
Class
<?>
retClass
=
m
.
getReturnType
();
Class
<?>
retClass
=
m
.
getReturnType
();
writer
.
print
(
" public "
+
getClassName
(
retClass
)
+
writer
.
print
(
" "
);
if
(
Modifier
.
isProtected
(
m
.
getModifiers
()))
{
// 'public' would also work
writer
.
print
(
"protected "
);
}
else
{
writer
.
print
(
"public "
);
}
writer
.
print
(
getClassName
(
retClass
)
+
" "
+
m
.
getName
()
+
"("
);
" "
+
m
.
getName
()
+
"("
);
int
i
=
0
;
int
i
=
0
;
for
(
Class
<?>
p
:
m
.
getParameterTypes
())
{
for
(
Class
<?>
p
:
m
.
getParameterTypes
())
{
...
@@ -192,7 +202,7 @@ public class ProxyCodeGenerator {
...
@@ -192,7 +202,7 @@ public class ProxyCodeGenerator {
}
else
if
(
retClass
==
byte
.
class
)
{
}
else
if
(
retClass
==
byte
.
class
)
{
writer
.
print
(
"Byte"
);
writer
.
print
(
"Byte"
);
}
else
if
(
retClass
==
char
.
class
)
{
}
else
if
(
retClass
==
char
.
class
)
{
writer
.
print
(
"Char"
);
writer
.
print
(
"Char
acter
"
);
}
else
if
(
retClass
==
short
.
class
)
{
}
else
if
(
retClass
==
short
.
class
)
{
writer
.
print
(
"Short"
);
writer
.
print
(
"Short"
);
}
else
if
(
retClass
==
int
.
class
)
{
}
else
if
(
retClass
==
int
.
class
)
{
...
@@ -210,7 +220,7 @@ public class ProxyCodeGenerator {
...
@@ -210,7 +220,7 @@ public class ProxyCodeGenerator {
}
}
writer
.
print
(
"ih.invoke(this, "
);
writer
.
print
(
"ih.invoke(this, "
);
writer
.
println
(
getClassName
(
m
.
getDeclaringClass
())
+
writer
.
println
(
getClassName
(
m
.
getDeclaringClass
())
+
".class.getMethod(\""
+
m
.
getName
()
+
".class.get
Declared
Method(\""
+
m
.
getName
()
+
"\","
);
"\","
);
writer
.
print
(
" new Class[] {"
);
writer
.
print
(
" new Class[] {"
);
i
=
0
;
i
=
0
;
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论