Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Tonvia
TDengine
提交
13c8c004
T
TDengine
项目概览
Tonvia
/
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,发现更多精彩内容 >>
提交
13c8c004
编写于
5月 12, 2021
作者:
Z
zyyang-taosdata
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-4144]<fix>: add subscribe test cases
上级
5131e7b1
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
105 addition
and
0 deletion
+105
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TD4144Test.java
...dbc/src/test/java/com/taosdata/jdbc/cases/TD4144Test.java
+105
-0
未找到文件。
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TD4144Test.java
0 → 100644
浏览文件 @
13c8c004
package
com.taosdata.jdbc.cases
;
import
com.taosdata.jdbc.TSDBConnection
;
import
com.taosdata.jdbc.TSDBDriver
;
import
com.taosdata.jdbc.TSDBResultSet
;
import
com.taosdata.jdbc.TSDBSubscribe
;
import
org.junit.AfterClass
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.sql.DriverManager
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.Properties
;
import
java.util.concurrent.TimeUnit
;
public
class
TD4144Test
{
private
static
TSDBConnection
connection
;
private
static
final
String
host
=
"127.0.0.1"
;
private
static
final
String
topic
=
"topic-meter-current-bg-10"
;
private
static
final
String
sql
=
"select * from meters where current > 10"
;
private
static
final
String
sql2
=
"select * from meters where ts >= '2020-08-15 12:20:00.000'"
;
@Test
public
void
test
()
throws
SQLException
{
TSDBSubscribe
subscribe
=
null
;
TSDBResultSet
res
=
null
;
boolean
hasNext
=
false
;
try
{
subscribe
=
connection
.
subscribe
(
topic
,
sql
,
false
);
int
count
=
0
;
while
(
true
)
{
// 等待1秒,避免频繁调用 consume,给服务端造成压力
TimeUnit
.
SECONDS
.
sleep
(
1
);
if
(
res
==
null
)
{
// 消费数据
res
=
subscribe
.
consume
();
hasNext
=
res
.
next
();
}
if
(
res
==
null
)
{
continue
;
}
ResultSetMetaData
metaData
=
res
.
getMetaData
();
int
number
=
0
;
while
(
hasNext
)
{
int
columnCount
=
metaData
.
getColumnCount
();
for
(
int
i
=
1
;
i
<=
columnCount
;
i
++)
{
System
.
out
.
print
(
metaData
.
getColumnLabel
(
i
)
+
": "
+
res
.
getString
(
i
)
+
"\t"
);
}
System
.
out
.
println
();
count
++;
number
++;
hasNext
=
res
.
next
();
if
(!
hasNext
)
{
res
.
close
();
res
=
null
;
System
.
out
.
println
(
"rows: "
+
count
);
}
if
(
hasNext
==
true
&&
number
>=
10
)
{
System
.
out
.
println
(
"batch"
+
number
);
break
;
}
}
}
}
catch
(
SQLException
|
InterruptedException
throwables
)
{
throwables
.
printStackTrace
();
}
finally
{
if
(
subscribe
!=
null
)
subscribe
.
close
(
true
);
}
}
@BeforeClass
public
static
void
beforeClass
()
throws
SQLException
{
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_CHARSET
,
"UTF-8"
);
properties
.
setProperty
(
TSDBDriver
.
PROPERTY_KEY_TIME_ZONE
,
"UTC-8"
);
String
url
=
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
;
connection
=
(
DriverManager
.
getConnection
(
url
,
properties
)).
unwrap
(
TSDBConnection
.
class
);
try
(
Statement
stmt
=
connection
.
createStatement
())
{
stmt
.
execute
(
"drop database if exists power"
);
stmt
.
execute
(
"create database if not exists power"
);
stmt
.
execute
(
"use power"
);
stmt
.
execute
(
"create table meters(ts timestamp, current float, voltage int, phase int) tags(location binary(64), groupId int)"
);
stmt
.
execute
(
"create table d1001 using meters tags(\"Beijing.Chaoyang\", 2)"
);
stmt
.
execute
(
"create table d1002 using meters tags(\"Beijing.Haidian\", 2)"
);
stmt
.
execute
(
"insert into d1001 values(\"2020-08-15 12:00:00.000\", 12, 220, 1),(\"2020-08-15 12:10:00.000\", 12.3, 220, 2),(\"2020-08-15 12:20:00.000\", 12.2, 220, 1)"
);
stmt
.
execute
(
"insert into d1002 values(\"2020-08-15 12:00:00.000\", 9.9, 220, 1),(\"2020-08-15 12:10:00.000\", 10.3, 220, 1),(\"2020-08-15 12:20:00.000\", 11.2, 220, 1)"
);
}
}
@AfterClass
public
static
void
afterClass
()
throws
SQLException
{
if
(
connection
!=
null
)
connection
.
close
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录