Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
loser646
TDengine
提交
62b857e4
T
TDengine
项目概览
loser646
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
62b857e4
编写于
11月 05, 2020
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
dd2732ea
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
67 addition
and
88 deletion
+67
-88
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java
.../jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java
+67
-88
未找到文件。
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java
浏览文件 @
62b857e4
...
...
@@ -13,7 +13,7 @@ import static org.junit.Assert.*;
public
class
TSDBDriverTest
{
private
static
String
[]
validURLs
=
{
private
static
final
String
[]
validURLs
=
{
"jdbc:TAOS://localhost:0"
,
"jdbc:TAOS://localhost"
,
"jdbc:TAOS://localhost:6030/test"
,
...
...
@@ -27,99 +27,50 @@ public class TSDBDriverTest {
"jdbc:TAOS://:/test"
,
"jdbc:TAOS://localhost:0/?user=root&password=taosdata"
};
private
static
boolean
islibLoaded
;
private
static
boolean
islibLoaded
=
false
;
private
static
boolean
isTaosdActived
;
@BeforeClass
public
static
void
before
()
{
String
osName
=
System
.
getProperty
(
"os.name"
).
toLowerCase
();
if
(!
osName
.
equals
(
"linux"
)
&&
!
osName
.
equals
(
"windows"
))
{
islibLoaded
=
false
;
if
(!
osName
.
equals
(
"linux"
))
return
;
}
// try to load taos lib
try
{
System
.
loadLibrary
(
"taos"
);
islibLoaded
=
true
;
}
catch
(
UnsatisfiedLinkError
error
)
{
System
.
out
.
println
(
"load tdengine lib failed."
);
islibLoaded
=
false
;
error
.
printStackTrace
()
;
}
// check taosd is activated
try
{
if
(
osName
.
equals
(
"linux"
))
{
String
[]
cmd
=
{
"/bin/bash"
,
"-c"
,
"ps -ef | grep taosd | grep -v \"grep\""
};
Process
exec
=
Runtime
.
getRuntime
().
exec
(
cmd
);
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
exec
.
getInputStream
()));
int
lineCnt
=
0
;
while
(
reader
.
readLine
()
!=
null
)
{
lineCnt
++;
}
if
(
lineCnt
>
0
)
isTaosdActived
=
true
;
else
isTaosdActived
=
false
;
}
else
{
isTaosdActived
=
false
;
String
[]
cmd
=
{
"/bin/bash"
,
"-c"
,
"ps -ef | grep taosd | grep -v \"grep\""
};
Process
exec
=
Runtime
.
getRuntime
().
exec
(
cmd
);
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
exec
.
getInputStream
()));
int
lineCnt
=
0
;
while
(
reader
.
readLine
()
!=
null
)
{
lineCnt
++;
}
if
(
lineCnt
>
0
)
isTaosdActived
=
true
;
}
catch
(
IOException
e
)
{
isTaosdActived
=
false
;
e
.
printStackTrace
()
;
}
}
@Test
public
void
testParseURL
()
{
TSDBDriver
driver
=
new
TSDBDriver
();
String
url
=
"jdbc:TAOS://127.0.0.1:0/db?user=root&password=taosdata&charset=UTF-8"
;
Properties
config
=
new
Properties
();
Properties
actual
=
driver
.
parseURL
(
url
,
config
);
assertEquals
(
"failure - host should be 127.0.0.1"
,
"127.0.0.1"
,
actual
.
get
(
"host"
));
assertEquals
(
"failure - port should be 0"
,
"0"
,
actual
.
get
(
"port"
));
assertEquals
(
"failure - dbname should be db"
,
"db"
,
actual
.
get
(
"dbname"
));
assertEquals
(
"failure - user should be root"
,
"root"
,
actual
.
get
(
"user"
));
assertEquals
(
"failure - password should be taosdata"
,
"taosdata"
,
actual
.
get
(
"password"
));
assertEquals
(
"failure - charset should be UTF-8"
,
"UTF-8"
,
actual
.
get
(
"charset"
));
url
=
"jdbc:TAOS://127.0.0.1:0"
;
config
=
new
Properties
();
actual
=
driver
.
parseURL
(
url
,
config
);
assertEquals
(
"failure - host should be 127.0.0.1"
,
"127.0.0.1"
,
actual
.
getProperty
(
"host"
));
assertEquals
(
"failure - port should be 0"
,
"0"
,
actual
.
get
(
"port"
));
assertEquals
(
"failure - dbname should be null"
,
null
,
actual
.
get
(
"dbname"
));
url
=
"jdbc:TAOS://127.0.0.1:0/db"
;
config
=
new
Properties
();
actual
=
driver
.
parseURL
(
url
,
config
);
assertEquals
(
"failure - host should be 127.0.0.1"
,
"127.0.0.1"
,
actual
.
getProperty
(
"host"
));
assertEquals
(
"failure - port should be 0"
,
"0"
,
actual
.
get
(
"port"
));
assertEquals
(
"failure - dbname should be db"
,
"db"
,
actual
.
get
(
"dbname"
));
url
=
"jdbc:TAOS://:/?"
;
config
=
new
Properties
();
config
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_USER
,
"root"
);
config
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_PASSWORD
,
"taosdata"
);
actual
=
driver
.
parseURL
(
url
,
config
);
assertEquals
(
"failure - user should be root"
,
"root"
,
actual
.
getProperty
(
"user"
));
assertEquals
(
"failure - password should be taosdata"
,
"taosdata"
,
actual
.
getProperty
(
"password"
));
assertEquals
(
"failure - host should be null"
,
null
,
actual
.
getProperty
(
"host"
));
assertEquals
(
"failure - port should be null"
,
null
,
actual
.
getProperty
(
"port"
));
assertEquals
(
"failure - dbname should be null"
,
null
,
actual
.
getProperty
(
"dbname"
));
}
@Test
public
void
testConnectWithJdbcURL
()
{
final
String
url
=
"jdbc:TAOS://localhost:6030/log?user=root&password=taosdata"
;
try
{
if
(
islibLoaded
)
{
if
(
islibLoaded
&&
isTaosdActived
)
{
Connection
conn
=
DriverManager
.
getConnection
(
url
);
assertNotNull
(
"failure - connection should not be null"
,
conn
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
if
(!
isTaosdActived
)
assertEquals
(
"failure - should throw SQLException"
,
"TDengine Error: Unable to establish connection"
,
e
.
getMessage
());
else
fail
(
"failure - should not throw Exception"
);
fail
(
"failure - should not throw Exception"
);
}
}
...
...
@@ -131,16 +82,13 @@ public class TSDBDriverTest {
connProps
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
,
"en_US.UTF-8"
);
connProps
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
try
{
if
(
islibLoaded
)
{
if
(
islibLoaded
&&
isTaosdActived
)
{
Connection
conn
=
DriverManager
.
getConnection
(
jdbcUrl
,
connProps
);
assertNotNull
(
"failure - connection should not be null"
,
conn
);
}
}
catch
(
SQLException
e
)
{
if
(!
isTaosdActived
)
{
assertEquals
(
"failure - should throw SQLException"
,
SQLException
.
class
,
e
.
getClass
());
}
else
{
fail
(
"failure - should not throw Exception"
);
}
e
.
printStackTrace
();
fail
(
"failure - should not throw Exception"
);
}
}
...
...
@@ -152,17 +100,13 @@ public class TSDBDriverTest {
connProps
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
,
"en_US.UTF-8"
);
connProps
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
try
{
if
(
islibLoaded
)
{
if
(
islibLoaded
&&
isTaosdActived
)
{
Connection
conn
=
DriverManager
.
getConnection
(
jdbcUrl
,
connProps
);
System
.
out
.
println
(
conn
);
assertNotNull
(
"failure - connection should not be null"
,
conn
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
if
(!
isTaosdActived
)
assertEquals
(
"failure - should throw SQLException"
,
"TDengine Error: Unable to establish connection"
,
e
.
getMessage
());
else
fail
(
"failure - should not throw Exception"
);
fail
(
"failure - should not throw Exception"
);
}
}
...
...
@@ -172,18 +116,55 @@ public class TSDBDriverTest {
for
(
String
url
:
validURLs
)
{
assertTrue
(
"failure - acceptsURL(\" "
+
url
+
" \") should be true"
,
driver
.
acceptsURL
(
url
));
}
new
TSDBDriver
()
.
acceptsURL
(
null
);
driver
.
acceptsURL
(
null
);
fail
(
"acceptsURL throws exception when parameter is null"
);
}
@Test
public
void
testParseURL
()
{
TSDBDriver
driver
=
new
TSDBDriver
();
String
url
=
"jdbc:TAOS://127.0.0.1:0/db?user=root&password=taosdata&charset=UTF-8"
;
Properties
config
=
new
Properties
();
Properties
actual
=
driver
.
parseURL
(
url
,
config
);
assertEquals
(
"failure - host should be 127.0.0.1"
,
"127.0.0.1"
,
actual
.
get
(
"host"
));
assertEquals
(
"failure - port should be 0"
,
"0"
,
actual
.
get
(
"port"
));
assertEquals
(
"failure - dbname should be db"
,
"db"
,
actual
.
get
(
"dbname"
));
assertEquals
(
"failure - user should be root"
,
"root"
,
actual
.
get
(
"user"
));
assertEquals
(
"failure - password should be taosdata"
,
"taosdata"
,
actual
.
get
(
"password"
));
assertEquals
(
"failure - charset should be UTF-8"
,
"UTF-8"
,
actual
.
get
(
"charset"
));
url
=
"jdbc:TAOS://127.0.0.1:0"
;
config
=
new
Properties
();
actual
=
driver
.
parseURL
(
url
,
config
);
assertEquals
(
"failure - host should be 127.0.0.1"
,
"127.0.0.1"
,
actual
.
getProperty
(
"host"
));
assertEquals
(
"failure - port should be 0"
,
"0"
,
actual
.
get
(
"port"
));
assertNull
(
"failure - dbname should be null"
,
actual
.
get
(
"dbname"
));
url
=
"jdbc:TAOS://127.0.0.1:0/db"
;
config
=
new
Properties
();
actual
=
driver
.
parseURL
(
url
,
config
);
assertEquals
(
"failure - host should be 127.0.0.1"
,
"127.0.0.1"
,
actual
.
getProperty
(
"host"
));
assertEquals
(
"failure - port should be 0"
,
"0"
,
actual
.
get
(
"port"
));
assertEquals
(
"failure - dbname should be db"
,
"db"
,
actual
.
get
(
"dbname"
));
url
=
"jdbc:TAOS://:/?"
;
config
=
new
Properties
();
config
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_USER
,
"root"
);
config
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_PASSWORD
,
"taosdata"
);
actual
=
driver
.
parseURL
(
url
,
config
);
assertEquals
(
"failure - user should be root"
,
"root"
,
actual
.
getProperty
(
"user"
));
assertEquals
(
"failure - password should be taosdata"
,
"taosdata"
,
actual
.
getProperty
(
"password"
));
assertNull
(
"failure - host should be null"
,
actual
.
getProperty
(
"host"
));
assertNull
(
"failure - port should be null"
,
actual
.
getProperty
(
"port"
));
assertNull
(
"failure - dbname should be null"
,
actual
.
getProperty
(
"dbname"
));
}
@Test
public
void
testGetPropertyInfo
()
throws
SQLException
{
Driver
driver
=
new
TSDBDriver
();
final
String
url
=
"jdbc:TAOS://localhost:6030/log?user=root&password=taosdata"
;
Properties
connProps
=
new
Properties
();
connProps
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
connProps
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_LOCALE
,
"en_US.UTF-8"
);
connProps
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
DriverPropertyInfo
[]
propertyInfo
=
driver
.
getPropertyInfo
(
url
,
connProps
);
for
(
DriverPropertyInfo
info
:
propertyInfo
)
{
if
(
info
.
name
.
equals
(
TSDBDriver
.
PROPERTY_KEY_HOST
))
...
...
@@ -200,20 +181,18 @@ public class TSDBDriverTest {
}
@Test
public
void
testGetMajorVersion
()
throws
SQLException
{
Driver
driver
=
new
TSDBDriver
();
assertEquals
(
"failure - getMajorVersion should be 2"
,
2
,
driver
.
getMajorVersion
());
public
void
testGetMajorVersion
()
{
assertEquals
(
"failure - getMajorVersion should be 2"
,
2
,
new
TSDBDriver
().
getMajorVersion
());
}
@Test
public
void
testGetMinorVersion
()
{
Driver
driver
=
new
TSDBDriver
();
assertEquals
(
"failure - getMinorVersion should be 0"
,
0
,
driver
.
getMinorVersion
());
assertEquals
(
"failure - getMinorVersion should be 0"
,
0
,
new
TSDBDriver
().
getMinorVersion
());
}
@Test
public
void
testJdbcCompliant
()
{
//
assertFalse("failure - jdbcCompliant should be false", new TSDBDriver().jdbcCompliant());
assertFalse
(
"failure - jdbcCompliant should be false"
,
new
TSDBDriver
().
jdbcCompliant
());
}
@Test
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录