Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小楼昨夜-听风雨
TDengine
提交
df853a96
T
TDengine
项目概览
小楼昨夜-听风雨
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
df853a96
编写于
2月 04, 2021
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
8b6b8192
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
158 addition
and
0 deletion
+158
-0
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InvalidResultSetPointerTest.java
.../com/taosdata/jdbc/cases/InvalidResultSetPointerTest.java
+158
-0
未找到文件。
src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InvalidResultSetPointerTest.java
0 → 100644
浏览文件 @
df853a96
package
com.taosdata.jdbc.cases
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.sql.*
;
import
java.util.Properties
;
public
class
InvalidResultSetPointerTest
{
private
static
String
host
=
"127.0.0.1"
;
private
static
String
driverType
=
"jni"
;
private
static
final
String
dbName
=
"test"
;
private
static
final
String
stbName
=
"weather"
;
private
static
final
String
tbName
=
"subweather"
;
private
static
Connection
connection
;
private
static
int
numOfSTb
=
300000
;
private
static
int
numOfTb
=
3
;
private
static
int
numOfThreads
=
1
;
@Test
public
void
test
()
throws
SQLException
{
execute
(
"use "
+
dbName
);
int
a
=
numOfSTb
/
numOfThreads
;
if
(
a
<
1
)
{
numOfThreads
=
numOfSTb
;
a
=
1
;
}
int
b
=
0
;
if
(
numOfThreads
!=
0
)
{
b
=
numOfSTb
%
numOfThreads
;
}
multiThreadingClass
instance
[]
=
new
multiThreadingClass
[
numOfThreads
];
int
last
=
0
;
for
(
int
i
=
0
;
i
<
numOfThreads
;
i
++)
{
instance
[
i
]
=
new
multiThreadingClass
();
instance
[
i
].
id
=
i
;
instance
[
i
].
from
=
last
;
if
(
i
<
b
)
{
instance
[
i
].
to
=
last
+
a
;
}
else
{
instance
[
i
].
to
=
last
+
a
-
1
;
}
last
=
instance
[
i
].
to
+
1
;
instance
[
i
].
numOfTb
=
numOfTb
;
instance
[
i
].
connection
=
connection
;
instance
[
i
].
dbName
=
dbName
;
instance
[
i
].
tbName
=
tbName
;
instance
[
i
].
start
();
}
for
(
int
i
=
0
;
i
<
numOfThreads
;
i
++)
{
try
{
instance
[
i
].
join
();
}
catch
(
InterruptedException
ie
)
{
ie
.
printStackTrace
();
}
}
if
(
connection
!=
null
)
{
this
.
connection
.
close
();
System
.
out
.
println
(
"connection closed."
);
}
}
@BeforeClass
public
static
void
beforeClass
()
{
try
{
String
url
=
"jdbc:TAOS://"
+
host
+
":6030/?user=root&password=taosdata"
;
if
(
driverType
.
equals
(
"restful"
))
{
Class
.
forName
(
"com.taosdata.jdbc.rs.RestfulDriver"
);
url
=
"jdbc:TAOS-RS://"
+
host
+
":6041/?user=root&password=taosdata"
;
}
else
{
Class
.
forName
(
"com.taosdata.jdbc.TSDBDriver"
);
}
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
"charset"
,
"UTF-8"
);
properties
.
setProperty
(
"locale"
,
"en_US.UTF-8"
);
properties
.
setProperty
(
"timezone"
,
"UTC-8"
);
System
.
out
.
println
(
"get connection starting..."
);
connection
=
DriverManager
.
getConnection
(
url
,
properties
);
if
(
connection
!=
null
)
System
.
out
.
println
(
"[ OK ] Connection established."
);
}
catch
(
ClassNotFoundException
|
SQLException
e
)
{
e
.
printStackTrace
();
}
}
private
void
execute
(
String
sql
)
{
try
(
Statement
statement
=
connection
.
createStatement
())
{
long
start
=
System
.
currentTimeMillis
();
boolean
execute
=
statement
.
execute
(
sql
);
long
end
=
System
.
currentTimeMillis
();
printSql
(
sql
,
execute
,
(
end
-
start
));
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
private
void
printSql
(
String
sql
,
boolean
succeed
,
long
cost
)
{
System
.
out
.
println
(
"[ "
+
(
succeed
?
"OK"
:
"ERROR!"
)
+
" ] time cost: "
+
cost
+
" ms, execute statement ====> "
+
sql
);
}
private
void
executeQuery
(
String
sql
)
{
try
(
Statement
statement
=
connection
.
createStatement
())
{
long
start
=
System
.
currentTimeMillis
();
ResultSet
resultSet
=
statement
.
executeQuery
(
sql
);
long
end
=
System
.
currentTimeMillis
();
printSql
(
sql
,
true
,
(
end
-
start
));
// printResult(resultSet);
resultSet
.
close
();
statement
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
class
multiThreadingClass
extends
Thread
{
public
int
id
;
public
int
from
,
to
;
public
int
numOfTb
;
public
Connection
connection
;
public
String
dbName
,
stbName
,
tbName
;
public
void
run
()
{
System
.
out
.
println
(
"ID: "
+
id
+
" from: "
+
from
+
" to: "
+
to
);
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
System
.
out
.
println
(
"Thread "
+
id
+
" interrupted."
);
}
for
(
int
i
=
from
;
i
<
to
;
i
++)
{
for
(
int
j
=
0
;
j
<
numOfTb
;
j
++)
{
if
(
j
%
1000
==
0
)
{
try
{
System
.
out
.
print
(
id
+
"s."
);
Thread
.
sleep
(
1
);
}
catch
(
InterruptedException
e
)
{
System
.
out
.
println
(
"Thread "
+
id
+
" interrupted."
);
}
}
final
String
sql
=
"select last_row(humidity) from "
+
dbName
+
"."
+
tbName
+
i
+
"_"
+
j
;
// System.out.println(sql);
executeQuery
(
sql
);
}
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录