Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
223328b2
提交
223328b2
authored
7月 15, 2013
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Slightly improve code coverage
上级
91bf5c5f
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
55 行增加
和
41 行删除
+55
-41
PgServerThread.java
h2/src/main/org/h2/server/pg/PgServerThread.java
+18
-22
TestPgServer.java
h2/src/test/org/h2/test/unit/TestPgServer.java
+34
-19
TestTraceSystem.java
h2/src/test/org/h2/test/unit/TestTraceSystem.java
+3
-0
没有找到文件。
h2/src/main/org/h2/server/pg/PgServerThread.java
浏览文件 @
223328b2
...
@@ -115,7 +115,7 @@ public class PgServerThread implements Runnable {
...
@@ -115,7 +115,7 @@ public class PgServerThread implements Runnable {
return
dataIn
.
readInt
();
return
dataIn
.
readInt
();
}
}
private
in
t
readShort
()
throws
IOException
{
private
shor
t
readShort
()
throws
IOException
{
return
dataIn
.
readShort
();
return
dataIn
.
readShort
();
}
}
...
@@ -143,7 +143,7 @@ public class PgServerThread implements Runnable {
...
@@ -143,7 +143,7 @@ public class PgServerThread implements Runnable {
byte
[]
data
=
DataUtils
.
newBytes
(
len
);
byte
[]
data
=
DataUtils
.
newBytes
(
len
);
dataInRaw
.
readFully
(
data
,
0
,
len
);
dataInRaw
.
readFully
(
data
,
0
,
len
);
dataIn
=
new
DataInputStream
(
new
ByteArrayInputStream
(
data
,
0
,
len
));
dataIn
=
new
DataInputStream
(
new
ByteArrayInputStream
(
data
,
0
,
len
));
switch
Block:
switch
(
x
)
{
switch
(
x
)
{
case
0
:
case
0
:
server
.
trace
(
"Init"
);
server
.
trace
(
"Init"
);
int
version
=
readInt
();
int
version
=
readInt
();
...
@@ -269,7 +269,7 @@ public class PgServerThread implements Runnable {
...
@@ -269,7 +269,7 @@ public class PgServerThread implements Runnable {
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
sendErrorResponse
(
e
);
sendErrorResponse
(
e
);
break
switchBlock
;
break
;
}
}
int
resultCodeCount
=
readShort
();
int
resultCodeCount
=
readShort
();
portal
.
resultColumnFormat
=
new
int
[
resultCodeCount
];
portal
.
resultColumnFormat
=
new
int
[
resultCodeCount
];
...
@@ -509,11 +509,11 @@ public class PgServerThread implements Runnable {
...
@@ -509,11 +509,11 @@ public class PgServerThread implements Runnable {
switch
(
pgType
)
{
switch
(
pgType
)
{
case
PgServer
.
PG_TYPE_INT2
:
case
PgServer
.
PG_TYPE_INT2
:
writeInt
(
2
);
writeInt
(
2
);
dataOut
.
writeShort
(
rs
.
getShort
(
column
));
writeShort
(
rs
.
getShort
(
column
));
break
;
break
;
case
PgServer
.
PG_TYPE_INT4
:
case
PgServer
.
PG_TYPE_INT4
:
writeInt
(
4
);
writeInt
(
4
);
dataOut
.
writeInt
(
rs
.
getInt
(
column
));
writeInt
(
rs
.
getInt
(
column
));
break
;
break
;
case
PgServer
.
PG_TYPE_INT8
:
case
PgServer
.
PG_TYPE_INT8
:
writeInt
(
8
);
writeInt
(
8
);
...
@@ -565,33 +565,23 @@ public class PgServerThread implements Runnable {
...
@@ -565,33 +565,23 @@ public class PgServerThread implements Runnable {
// binary
// binary
switch
(
pgType
)
{
switch
(
pgType
)
{
case
PgServer
.
PG_TYPE_INT2
:
case
PgServer
.
PG_TYPE_INT2
:
if
(
paramLen
!=
4
)
{
checkParamLength
(
4
,
paramLen
);
throw
DbException
.
getInvalidValueException
(
"paramLen"
,
paramLen
);
prep
.
setShort
(
col
,
readShort
());
}
prep
.
setShort
(
col
,
dataIn
.
readShort
());
break
;
break
;
case
PgServer
.
PG_TYPE_INT4
:
case
PgServer
.
PG_TYPE_INT4
:
if
(
paramLen
!=
4
)
{
checkParamLength
(
4
,
paramLen
);
throw
DbException
.
getInvalidValueException
(
"paramLen"
,
paramLen
);
prep
.
setInt
(
col
,
readInt
());
}
prep
.
setInt
(
col
,
dataIn
.
readInt
());
break
;
break
;
case
PgServer
.
PG_TYPE_INT8
:
case
PgServer
.
PG_TYPE_INT8
:
if
(
paramLen
!=
8
)
{
checkParamLength
(
8
,
paramLen
);
throw
DbException
.
getInvalidValueException
(
"paramLen"
,
paramLen
);
}
prep
.
setLong
(
col
,
dataIn
.
readLong
());
prep
.
setLong
(
col
,
dataIn
.
readLong
());
break
;
break
;
case
PgServer
.
PG_TYPE_FLOAT4
:
case
PgServer
.
PG_TYPE_FLOAT4
:
if
(
paramLen
!=
4
)
{
checkParamLength
(
4
,
paramLen
);
throw
DbException
.
getInvalidValueException
(
"paramLen"
,
paramLen
);
}
prep
.
setFloat
(
col
,
dataIn
.
readFloat
());
prep
.
setFloat
(
col
,
dataIn
.
readFloat
());
break
;
break
;
case
PgServer
.
PG_TYPE_FLOAT8
:
case
PgServer
.
PG_TYPE_FLOAT8
:
if
(
paramLen
!=
8
)
{
checkParamLength
(
8
,
paramLen
);
throw
DbException
.
getInvalidValueException
(
"paramLen"
,
paramLen
);
}
prep
.
setDouble
(
col
,
dataIn
.
readDouble
());
prep
.
setDouble
(
col
,
dataIn
.
readDouble
());
break
;
break
;
case
PgServer
.
PG_TYPE_BYTEA
:
case
PgServer
.
PG_TYPE_BYTEA
:
...
@@ -608,6 +598,12 @@ public class PgServerThread implements Runnable {
...
@@ -608,6 +598,12 @@ public class PgServerThread implements Runnable {
}
}
}
}
private
static
void
checkParamLength
(
int
expected
,
int
got
)
{
if
(
expected
!=
got
)
{
throw
DbException
.
getInvalidValueException
(
"paramLen"
,
got
);
}
}
private
void
sendErrorResponse
(
Exception
re
)
throws
IOException
{
private
void
sendErrorResponse
(
Exception
re
)
throws
IOException
{
SQLException
e
=
DbException
.
toSQLException
(
re
);
SQLException
e
=
DbException
.
toSQLException
(
re
);
server
.
traceError
(
e
);
server
.
traceError
(
e
);
...
...
h2/src/test/org/h2/test/unit/TestPgServer.java
浏览文件 @
223328b2
...
@@ -41,13 +41,23 @@ public class TestPgServer extends TestBase {
...
@@ -41,13 +41,23 @@ public class TestPgServer extends TestBase {
@Override
@Override
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
testP
G
Adapter
();
testP
g
Adapter
();
testKeyAlias
();
testKeyAlias
();
testCancelQuery
();
testCancelQuery
();
testBinaryTypes
();
testBinaryTypes
();
}
}
private
void
testPGAdapter
()
throws
SQLException
{
private
boolean
getPgJdbcDriver
()
{
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
return
true
;
}
catch
(
ClassNotFoundException
e
)
{
println
(
"PostgreSQL JDBC driver not found - PgServer not tested"
);
return
false
;
}
}
private
void
testPgAdapter
()
throws
SQLException
{
deleteDb
(
"test"
);
deleteDb
(
"test"
);
Server
server
=
Server
.
createPgServer
(
"-baseDir"
,
getBaseDir
(),
"-pgPort"
,
"5535"
,
"-pgDaemon"
);
Server
server
=
Server
.
createPgServer
(
"-baseDir"
,
getBaseDir
(),
"-pgPort"
,
"5535"
,
"-pgDaemon"
);
assertEquals
(
5535
,
server
.
getPort
());
assertEquals
(
5535
,
server
.
getPort
());
...
@@ -55,23 +65,24 @@ public class TestPgServer extends TestBase {
...
@@ -55,23 +65,24 @@ public class TestPgServer extends TestBase {
server
.
start
();
server
.
start
();
assertStartsWith
(
server
.
getStatus
(),
"PG server running at pg://"
);
assertStartsWith
(
server
.
getStatus
(),
"PG server running at pg://"
);
try
{
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
if
(
getPgJdbcDriver
())
{
testPgClient
();
testPgClient
();
}
catch
(
ClassNotFoundException
e
)
{
}
println
(
"PostgreSQL JDBC driver not found - PgServer not tested"
);
}
finally
{
}
finally
{
server
.
stop
();
server
.
stop
();
}
}
}
}
private
void
testCancelQuery
()
throws
Exception
{
private
void
testCancelQuery
()
throws
Exception
{
if
(!
getPgJdbcDriver
())
{
return
;
}
Server
server
=
Server
.
createPgServer
(
"-pgPort"
,
"5535"
,
"-pgDaemon"
,
"-key"
,
"test"
,
"mem:test"
);
Server
server
=
Server
.
createPgServer
(
"-pgPort"
,
"5535"
,
"-pgDaemon"
,
"-key"
,
"test"
,
"mem:test"
);
server
.
start
();
server
.
start
();
ExecutorService
executor
=
Executors
.
newSingleThreadExecutor
();
ExecutorService
executor
=
Executors
.
newSingleThreadExecutor
();
try
{
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost:5535/test"
,
"sa"
,
"sa"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost:5535/test"
,
"sa"
,
"sa"
);
final
Statement
stat
=
conn
.
createStatement
();
final
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create alias sleep for \"java.lang.Thread.sleep\""
);
stat
.
execute
(
"create alias sleep for \"java.lang.Thread.sleep\""
);
...
@@ -101,8 +112,6 @@ public class TestPgServer extends TestBase {
...
@@ -101,8 +112,6 @@ public class TestPgServer extends TestBase {
}
finally
{
}
finally
{
conn
.
close
();
conn
.
close
();
}
}
}
catch
(
ClassNotFoundException
e
)
{
println
(
"PostgreSQL JDBC driver not found - PgServer not tested"
);
}
finally
{
}
finally
{
server
.
stop
();
server
.
stop
();
executor
.
shutdown
();
executor
.
shutdown
();
...
@@ -119,6 +128,7 @@ public class TestPgServer extends TestBase {
...
@@ -119,6 +128,7 @@ public class TestPgServer extends TestBase {
stat
.
execute
(
"create table test(id int primary key, name varchar)"
);
stat
.
execute
(
"create table test(id int primary key, name varchar)"
);
stat
.
execute
(
"create index idx_test_name on test(name, id)"
);
stat
.
execute
(
"create index idx_test_name on test(name, id)"
);
stat
.
execute
(
"grant all on test to test"
);
stat
.
execute
(
"grant all on test to test"
);
stat
.
close
();
conn
.
close
();
conn
.
close
();
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost:5535/test"
,
"test"
,
"test"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost:5535/test"
,
"test"
,
"test"
);
...
@@ -131,7 +141,13 @@ public class TestPgServer extends TestBase {
...
@@ -131,7 +141,13 @@ public class TestPgServer extends TestBase {
assertEquals
(
6
,
rs
.
getInt
(
1
));
assertEquals
(
6
,
rs
.
getInt
(
1
));
stat
.
execute
(
"deallocate test"
);
stat
.
execute
(
"deallocate test"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test values(?, ?)"
);
PreparedStatement
prep
;
prep
=
conn
.
prepareStatement
(
"select * from test where name = ?"
);
prep
.
setNull
(
1
,
Types
.
VARCHAR
);
rs
=
prep
.
executeQuery
();
assertFalse
(
rs
.
next
());
prep
=
conn
.
prepareStatement
(
"insert into test values(?, ?)"
);
ParameterMetaData
meta
=
prep
.
getParameterMetaData
();
ParameterMetaData
meta
=
prep
.
getParameterMetaData
();
assertEquals
(
2
,
meta
.
getParameterCount
());
assertEquals
(
2
,
meta
.
getParameterCount
());
prep
.
setInt
(
1
,
1
);
prep
.
setInt
(
1
,
1
);
...
@@ -272,11 +288,12 @@ public class TestPgServer extends TestBase {
...
@@ -272,11 +288,12 @@ public class TestPgServer extends TestBase {
}
}
private
void
testKeyAlias
()
throws
SQLException
{
private
void
testKeyAlias
()
throws
SQLException
{
if
(!
getPgJdbcDriver
())
{
return
;
}
Server
server
=
Server
.
createPgServer
(
"-pgPort"
,
"5535"
,
"-pgDaemon"
,
"-key"
,
"test"
,
"mem:test"
);
Server
server
=
Server
.
createPgServer
(
"-pgPort"
,
"5535"
,
"-pgDaemon"
,
"-key"
,
"test"
,
"mem:test"
);
server
.
start
();
server
.
start
();
try
{
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost:5535/test"
,
"sa"
,
"sa"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost:5535/test"
,
"sa"
,
"sa"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
...
@@ -288,19 +305,19 @@ public class TestPgServer extends TestBase {
...
@@ -288,19 +305,19 @@ public class TestPgServer extends TestBase {
assertEquals
(
"MEMORY"
,
rs
.
getString
(
1
));
assertEquals
(
"MEMORY"
,
rs
.
getString
(
1
));
conn
.
close
();
conn
.
close
();
}
catch
(
ClassNotFoundException
e
)
{
println
(
"PostgreSQL JDBC driver not found - PgServer not tested"
);
}
finally
{
}
finally
{
server
.
stop
();
server
.
stop
();
}
}
}
}
private
void
testBinaryTypes
()
throws
SQLException
{
private
void
testBinaryTypes
()
throws
SQLException
{
if
(!
getPgJdbcDriver
())
{
return
;
}
Server
server
=
Server
.
createPgServer
(
"-pgPort"
,
"5535"
,
"-pgDaemon"
,
"-key"
,
"test"
,
"mem:test"
);
Server
server
=
Server
.
createPgServer
(
"-pgPort"
,
"5535"
,
"-pgDaemon"
,
"-key"
,
"test"
,
"mem:test"
);
server
.
start
();
server
.
start
();
try
{
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost:5535/test"
,
"sa"
,
"sa"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost:5535/test"
,
"sa"
,
"sa"
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
...
@@ -335,8 +352,6 @@ public class TestPgServer extends TestBase {
...
@@ -335,8 +352,6 @@ public class TestPgServer extends TestBase {
rs
.
getBytes
(
10
));
rs
.
getBytes
(
10
));
conn
.
close
();
conn
.
close
();
}
catch
(
ClassNotFoundException
e
)
{
println
(
"PostgreSQL JDBC driver not found - PgServer not tested"
);
}
finally
{
}
finally
{
server
.
stop
();
server
.
stop
();
}
}
...
...
h2/src/test/org/h2/test/unit/TestTraceSystem.java
浏览文件 @
223328b2
...
@@ -35,8 +35,11 @@ public class TestTraceSystem extends TestBase {
...
@@ -35,8 +35,11 @@ public class TestTraceSystem extends TestBase {
private
static
void
testAdapter
()
{
private
static
void
testAdapter
()
{
TraceSystem
ts
=
new
TraceSystem
(
null
);
TraceSystem
ts
=
new
TraceSystem
(
null
);
ts
.
setName
(
"test"
);
ts
.
setLevelFile
(
TraceSystem
.
ADAPTER
);
ts
.
setLevelFile
(
TraceSystem
.
ADAPTER
);
ts
.
getTrace
(
"test"
).
debug
(
"test"
);
ts
.
getTrace
(
"test"
).
info
(
"test"
);
ts
.
getTrace
(
"test"
).
info
(
"test"
);
ts
.
getTrace
(
"test"
).
error
(
new
Exception
(),
"test"
);
ts
.
close
();
ts
.
close
();
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论