Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
99de15f1
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
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看板
未验证
提交
99de15f1
编写于
6月 09, 2021
作者:
S
Shengliang Guan
提交者:
GitHub
6月 09, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6421 from taosdata/xiaoping/add_test_case
Add jdbc test case back
上级
8b6d4cd8
a76457b4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
292 addition
and
0 deletion
+292
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
...est/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
+292
-0
未找到文件。
src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java
浏览文件 @
99de15f1
...
...
@@ -6,6 +6,8 @@ import java.io.IOException;
import
java.math.BigDecimal
;
import
java.sql.*
;
import
java.time.LocalTime
;
import
java.util.ArrayList
;
import
java.util.Random
;
public
class
TSDBPreparedStatementTest
{
...
...
@@ -295,6 +297,296 @@ public class TSDBPreparedStatementTest {
assertAllNullExceptTimestamp
(
rs
,
ts
);
}
}
@Test
public
void
executeTest
()
throws
SQLException
{
Statement
stmt
=
conn
.
createStatement
();
int
numOfRows
=
1000
;
for
(
int
loop
=
0
;
loop
<
10
;
loop
++){
stmt
.
execute
(
"drop table if exists weather_test"
);
stmt
.
execute
(
"create table weather_test(ts timestamp, f1 nchar(4), f2 float, f3 double, f4 timestamp, f5 int, f6 bool, f7 binary(10))"
);
TSDBPreparedStatement
s
=
(
TSDBPreparedStatement
)
conn
.
prepareStatement
(
"insert into ? values(?, ?, ?, ?, ?, ?, ?, ?)"
);
Random
r
=
new
Random
();
s
.
setTableName
(
"weather_test"
);
ArrayList
<
Long
>
ts
=
new
ArrayList
<
Long
>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
ts
.
add
(
System
.
currentTimeMillis
()
+
i
);
}
s
.
setTimestamp
(
0
,
ts
);
int
random
=
10
+
r
.
nextInt
(
5
);
ArrayList
<
String
>
s2
=
new
ArrayList
<
String
>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
if
(
i
%
random
==
0
)
{
s2
.
add
(
null
);
}
else
{
s2
.
add
(
"分支"
+
i
%
4
);
}
}
s
.
setNString
(
1
,
s2
,
4
);
random
=
10
+
r
.
nextInt
(
5
);
ArrayList
<
Float
>
s3
=
new
ArrayList
<
Float
>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
if
(
i
%
random
==
0
)
{
s3
.
add
(
null
);
}
else
{
s3
.
add
(
r
.
nextFloat
());
}
}
s
.
setFloat
(
2
,
s3
);
random
=
10
+
r
.
nextInt
(
5
);
ArrayList
<
Double
>
s4
=
new
ArrayList
<
Double
>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
if
(
i
%
random
==
0
)
{
s4
.
add
(
null
);
}
else
{
s4
.
add
(
r
.
nextDouble
());
}
}
s
.
setDouble
(
3
,
s4
);
random
=
10
+
r
.
nextInt
(
5
);
ArrayList
<
Long
>
ts2
=
new
ArrayList
<
Long
>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
if
(
i
%
random
==
0
)
{
ts2
.
add
(
null
);
}
else
{
ts2
.
add
(
System
.
currentTimeMillis
()
+
i
);
}
}
s
.
setTimestamp
(
4
,
ts2
);
random
=
10
+
r
.
nextInt
(
5
);
ArrayList
<
Integer
>
vals
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
if
(
i
%
random
==
0
)
{
vals
.
add
(
null
);
}
else
{
vals
.
add
(
r
.
nextInt
());
}
}
s
.
setInt
(
5
,
vals
);
random
=
10
+
r
.
nextInt
(
5
);
ArrayList
<
Boolean
>
sb
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
if
(
i
%
random
==
0
)
{
sb
.
add
(
null
);
}
else
{
sb
.
add
(
i
%
2
==
0
?
true
:
false
);
}
}
s
.
setBoolean
(
6
,
sb
);
random
=
10
+
r
.
nextInt
(
5
);
ArrayList
<
String
>
s5
=
new
ArrayList
<
String
>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
if
(
i
%
random
==
0
)
{
s5
.
add
(
null
);
}
else
{
s5
.
add
(
"test"
+
i
%
10
);
}
}
s
.
setString
(
7
,
s5
,
10
);
s
.
columnDataAddBatch
();
s
.
columnDataExecuteBatch
();
s
.
columnDataCloseBatch
();
String
sql
=
"select * from weather_test"
;
PreparedStatement
statement
=
conn
.
prepareStatement
(
sql
);
ResultSet
rs
=
statement
.
executeQuery
();
int
rows
=
0
;
while
(
rs
.
next
())
{
rows
++;
}
Assert
.
assertEquals
(
numOfRows
,
rows
);
}
}
@Test
public
void
bindDataSelectColumnTest
()
throws
SQLException
{
Statement
stmt
=
conn
.
createStatement
();
int
numOfRows
=
1000
;
for
(
int
loop
=
0
;
loop
<
10
;
loop
++){
stmt
.
execute
(
"drop table if exists weather_test"
);
stmt
.
execute
(
"create table weather_test(ts timestamp, f1 nchar(4), f2 float, f3 double, f4 timestamp, f5 int, f6 bool, f7 binary(10))"
);
TSDBPreparedStatement
s
=
(
TSDBPreparedStatement
)
conn
.
prepareStatement
(
"insert into ? (ts, f1, f7) values(?, ?, ?)"
);
Random
r
=
new
Random
();
s
.
setTableName
(
"weather_test"
);
ArrayList
<
Long
>
ts
=
new
ArrayList
<
Long
>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
ts
.
add
(
System
.
currentTimeMillis
()
+
i
);
}
s
.
setTimestamp
(
0
,
ts
);
int
random
=
10
+
r
.
nextInt
(
5
);
ArrayList
<
String
>
s2
=
new
ArrayList
<
String
>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
if
(
i
%
random
==
0
)
{
s2
.
add
(
null
);
}
else
{
s2
.
add
(
"分支"
+
i
%
4
);
}
}
s
.
setNString
(
1
,
s2
,
4
);
random
=
10
+
r
.
nextInt
(
5
);
ArrayList
<
String
>
s3
=
new
ArrayList
<
String
>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
if
(
i
%
random
==
0
)
{
s3
.
add
(
null
);
}
else
{
s3
.
add
(
"test"
+
i
%
10
);
}
}
s
.
setString
(
2
,
s3
,
10
);
s
.
columnDataAddBatch
();
s
.
columnDataExecuteBatch
();
s
.
columnDataCloseBatch
();
String
sql
=
"select * from weather_test"
;
PreparedStatement
statement
=
conn
.
prepareStatement
(
sql
);
ResultSet
rs
=
statement
.
executeQuery
();
int
rows
=
0
;
while
(
rs
.
next
())
{
rows
++;
}
Assert
.
assertEquals
(
numOfRows
,
rows
);
}
}
@Test
public
void
bindDataWithSingleTagTest
()
throws
SQLException
{
Statement
stmt
=
conn
.
createStatement
();
String
types
[]
=
new
String
[]
{
"tinyint"
,
"smallint"
,
"int"
,
"bigint"
,
"bool"
,
"float"
,
"double"
,
"binary(10)"
,
"nchar(10)"
};
for
(
String
type
:
types
)
{
stmt
.
execute
(
"drop table if exists weather_test"
);
stmt
.
execute
(
"create table weather_test(ts timestamp, f1 nchar(10), f2 binary(10)) tags (t "
+
type
+
")"
);
int
numOfRows
=
1
;
TSDBPreparedStatement
s
=
(
TSDBPreparedStatement
)
conn
.
prepareStatement
(
"insert into ? using weather_test tags(?) values(?, ?, ?)"
);
Random
r
=
new
Random
();
s
.
setTableName
(
"w1"
);
switch
(
type
)
{
case
"tinyint"
:
case
"smallint"
:
case
"int"
:
case
"bigint"
:
s
.
setTagInt
(
0
,
1
);
break
;
case
"float"
:
s
.
setTagFloat
(
0
,
1.23f
);
break
;
case
"double"
:
s
.
setTagDouble
(
0
,
3.14159265
);
break
;
case
"bool"
:
s
.
setTagBoolean
(
0
,
true
);
break
;
case
"binary(10)"
:
s
.
setTagString
(
0
,
"test"
);
break
;
case
"nchar(10)"
:
s
.
setTagNString
(
0
,
"test"
);
break
;
default
:
break
;
}
ArrayList
<
Long
>
ts
=
new
ArrayList
<
Long
>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
ts
.
add
(
System
.
currentTimeMillis
()
+
i
);
}
s
.
setTimestamp
(
0
,
ts
);
int
random
=
10
+
r
.
nextInt
(
5
);
ArrayList
<
String
>
s2
=
new
ArrayList
<
String
>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
s2
.
add
(
"分支"
+
i
%
4
);
}
s
.
setNString
(
1
,
s2
,
10
);
random
=
10
+
r
.
nextInt
(
5
);
ArrayList
<
String
>
s3
=
new
ArrayList
<
String
>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
s3
.
add
(
"test"
+
i
%
4
);
}
s
.
setString
(
2
,
s3
,
10
);
s
.
columnDataAddBatch
();
s
.
columnDataExecuteBatch
();
s
.
columnDataCloseBatch
();
String
sql
=
"select * from weather_test"
;
PreparedStatement
statement
=
conn
.
prepareStatement
(
sql
);
ResultSet
rs
=
statement
.
executeQuery
();
int
rows
=
0
;
while
(
rs
.
next
())
{
rows
++;
}
Assert
.
assertEquals
(
numOfRows
,
rows
);
}
}
@Test
public
void
bindDataWithMultipleTagsTest
()
throws
SQLException
{
Statement
stmt
=
conn
.
createStatement
();
stmt
.
execute
(
"drop table if exists weather_test"
);
stmt
.
execute
(
"create table weather_test(ts timestamp, f1 nchar(10), f2 binary(10)) tags (t1 int, t2 binary(10))"
);
int
numOfRows
=
1
;
TSDBPreparedStatement
s
=
(
TSDBPreparedStatement
)
conn
.
prepareStatement
(
"insert into ? using weather_test tags(?,?) (ts, f2) values(?, ?)"
);
s
.
setTableName
(
"w2"
);
s
.
setTagInt
(
0
,
1
);
s
.
setTagString
(
1
,
"test"
);
ArrayList
<
Long
>
ts
=
new
ArrayList
<
Long
>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
ts
.
add
(
System
.
currentTimeMillis
()
+
i
);
}
s
.
setTimestamp
(
0
,
ts
);
ArrayList
<
String
>
s2
=
new
ArrayList
<
String
>();
for
(
int
i
=
0
;
i
<
numOfRows
;
i
++)
{
s2
.
add
(
"test"
+
i
%
4
);
}
s
.
setString
(
1
,
s2
,
10
);
s
.
columnDataAddBatch
();
s
.
columnDataExecuteBatch
();
s
.
columnDataCloseBatch
();
String
sql
=
"select * from weather_test"
;
PreparedStatement
statement
=
conn
.
prepareStatement
(
sql
);
ResultSet
rs
=
statement
.
executeQuery
();
int
rows
=
0
;
while
(
rs
.
next
())
{
rows
++;
}
Assert
.
assertEquals
(
numOfRows
,
rows
);
}
@Test
public
void
createTwoSameDbTest
()
throws
SQLException
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录