Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
029fb026
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1185
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
029fb026
编写于
6月 11, 2020
作者:
S
Shuaiqiang Chang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: add connectiontest
上级
f7322502
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
163 addition
and
0 deletion
+163
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java
.../jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java
+56
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java
...ctor/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java
+107
-0
未找到文件。
src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java
0 → 100644
浏览文件 @
029fb026
package
com.taosdata.jdbc
;
import
org.junit.Test
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.Properties
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
public
class
ConnectionTest
{
static
Connection
connection
=
null
;
static
Statement
statement
=
null
;
static
String
dbName
=
"test"
;
static
String
stbName
=
"st"
;
static
String
host
=
"localhost"
;
@Test
public
static
void
createConnection
()
throws
SQLException
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
}
catch
(
ClassNotFoundException
e
)
{
return
;
}
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
connection
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/"
+
"?user=root&password=taosdata"
,
properties
);
assertTrue
(
null
!=
connection
);
}
@Test
public
void
createDatabase
()
{
try
{
statement
.
executeUpdate
(
"create database if not exists "
+
dbName
);
}
catch
(
SQLException
e
)
{
assert
false
:
"create database error: "
+
e
.
getMessage
();
}
}
@Test
public
void
close
()
{
try
{
if
(!
statement
.
isClosed
())
{
statement
.
executeUpdate
(
"drop database "
+
dbName
);
statement
.
close
();
connection
.
close
();
}
}
catch
(
SQLException
e
)
{
assert
false
:
"close connection error: "
+
e
.
getMessage
();
}
}
}
src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java
浏览文件 @
029fb026
package
com.taosdata.jdbc
;
import
org.junit.AfterClass
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.sql.*
;
import
java.util.Properties
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
public
class
StableTest
{
static
Connection
connection
=
null
;
static
Statement
statement
=
null
;
static
String
dbName
=
"test"
;
static
String
stbName
=
"st"
;
static
String
host
=
"localhost"
;
@BeforeClass
public
static
void
createDatabase
()
throws
SQLException
{
try
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
}
catch
(
ClassNotFoundException
e
)
{
return
;
}
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_HOST
,
host
);
connection
=
DriverManager
.
getConnection
(
"jdbc:TAOS://"
+
host
+
":0/"
+
"?user=root&password=taosdata"
,
properties
);
statement
=
connection
.
createStatement
();
statement
.
executeUpdate
(
"create database if not exists "
+
dbName
);
statement
.
executeQuery
(
"use "
+
dbName
);
}
@Test
public
void
createStable
()
{
String
sql
=
"create table "
+
stbName
+
" (ts timestamp, v1 int, v2 int) tags (tg nchar(20)) "
;
try
{
statement
.
executeUpdate
(
sql
);
}
catch
(
SQLException
e
)
{
assert
false
:
"error create stable"
+
e
.
getMessage
();
}
}
@Test
public
void
createTable
()
{
String
sql
=
"create table t1 using "
+
stbName
+
" tags (\"beijing\")"
;
try
{
statement
.
executeUpdate
(
sql
);
}
catch
(
SQLException
e
)
{
assert
false
:
"error create table"
+
e
.
getMessage
();
}
}
@Test
public
void
describeSTable
()
{
String
sql
=
"describe "
+
stbName
;
int
num
=
0
;
System
.
out
.
println
(
"describe stable"
);
try
{
ResultSet
res
=
statement
.
executeQuery
(
sql
);
while
(
res
.
next
())
{
for
(
int
i
=
1
;
i
<=
res
.
getMetaData
().
getColumnCount
();
i
++)
{
System
.
out
.
printf
(
"%d: %s\n"
,
i
,
res
.
getString
(
i
));
}
num
++;
}
assertEquals
(
4
,
num
);
}
catch
(
SQLException
e
)
{
assert
false
:
"error describe stable"
+
e
.
getMessage
();
}
}
@Test
public
void
describeTable
()
{
String
sql
=
"describe t1"
;
int
num
=
0
;
System
.
out
.
println
(
"describe table"
);
try
{
ResultSet
res
=
statement
.
executeQuery
(
sql
);
while
(
res
.
next
())
{
for
(
int
i
=
1
;
i
<=
res
.
getMetaData
().
getColumnCount
();
i
++)
{
System
.
out
.
printf
(
"%d: %s\n"
,
i
,
res
.
getString
(
i
));
}
num
++;
}
assertEquals
(
4
,
num
);
}
catch
(
SQLException
e
)
{
assert
false
:
"error describe stable"
+
e
.
getMessage
();
}
}
@Test
public
void
validCreateSql
()
{
String
sql
=
"create table t2 using "
+
stbName
+
" tags (\"beijing\")"
;
boolean
valid
=
((
TSDBConnection
)
connection
).
getConnection
().
validateCreateTableSql
(
sql
);
assertEquals
(
true
,
valid
);
}
@AfterClass
public
static
void
close
()
throws
Exception
{
if
(!
statement
.
isClosed
())
{
statement
.
executeUpdate
(
"drop database "
+
dbName
);
statement
.
close
();
connection
.
close
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录