Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
15a43d5a
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
15a43d5a
编写于
12月 22, 2021
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-10431 refact dnode test
上级
40122d3c
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
548 addition
and
613 deletion
+548
-613
source/dnode/mgmt/impl/test/CMakeLists.txt
source/dnode/mgmt/impl/test/CMakeLists.txt
+10
-8
source/dnode/mgmt/impl/test/acct/CMakeLists.txt
source/dnode/mgmt/impl/test/acct/CMakeLists.txt
+3
-19
source/dnode/mgmt/impl/test/acct/acct.cpp
source/dnode/mgmt/impl/test/acct/acct.cpp
+22
-68
source/dnode/mgmt/impl/test/cluster/CMakeLists.txt
source/dnode/mgmt/impl/test/cluster/CMakeLists.txt
+3
-19
source/dnode/mgmt/impl/test/cluster/cluster.cpp
source/dnode/mgmt/impl/test/cluster/cluster.cpp
+25
-146
source/dnode/mgmt/impl/test/profile/profile.cpp
source/dnode/mgmt/impl/test/profile/profile.cpp
+1
-1
source/dnode/mgmt/impl/test/show/CMakeLists.txt
source/dnode/mgmt/impl/test/show/CMakeLists.txt
+3
-19
source/dnode/mgmt/impl/test/show/show.cpp
source/dnode/mgmt/impl/test/show/show.cpp
+10
-172
source/dnode/mgmt/impl/test/sut/CMakeLists.txt
source/dnode/mgmt/impl/test/sut/CMakeLists.txt
+14
-0
source/dnode/mgmt/impl/test/sut/deploy.cpp
source/dnode/mgmt/impl/test/sut/deploy.cpp
+0
-161
source/dnode/mgmt/impl/test/sut/inc/base.h
source/dnode/mgmt/impl/test/sut/inc/base.h
+75
-0
source/dnode/mgmt/impl/test/sut/inc/client.h
source/dnode/mgmt/impl/test/sut/inc/client.h
+36
-0
source/dnode/mgmt/impl/test/sut/inc/server.h
source/dnode/mgmt/impl/test/sut/inc/server.h
+32
-0
source/dnode/mgmt/impl/test/sut/src/base.cpp
source/dnode/mgmt/impl/test/sut/src/base.cpp
+169
-0
source/dnode/mgmt/impl/test/sut/src/client.cpp
source/dnode/mgmt/impl/test/sut/src/client.cpp
+73
-0
source/dnode/mgmt/impl/test/sut/src/server.cpp
source/dnode/mgmt/impl/test/sut/src/server.cpp
+72
-0
未找到文件。
source/dnode/mgmt/impl/test/CMakeLists.txt
浏览文件 @
15a43d5a
enable_testing
()
add_subdirectory
(
acct
)
#
add_subdirectory(acct)
# add_subdirectory(auth)
# add_subdirectory(balance)
add_subdirectory
(
cluster
)
add_subdirectory
(
db
)
add_subdirectory
(
dnode
)
#
add_subdirectory(cluster)
#
add_subdirectory(db)
#
add_subdirectory(dnode)
# add_subdirectory(func)
# add_subdirectory(mnode)
add_subdirectory
(
profile
)
#
add_subdirectory(profile)
add_subdirectory
(
show
)
add_subdirectory
(
stb
)
#
add_subdirectory(stb)
# add_subdirectory(sync)
# add_subdirectory(telem)
# add_subdirectory(trans)
add_subdirectory
(
user
)
add_subdirectory
(
vgroup
)
#add_subdirectory(user)
#add_subdirectory(vgroup)
add_subdirectory
(
sut
)
source/dnode/mgmt/impl/test/acct/CMakeLists.txt
浏览文件 @
15a43d5a
add_executable
(
dnode_test_acct
""
)
target_sources
(
dnode_test_acct
PRIVATE
"acct.cpp"
"../sut/deploy.cpp"
)
aux_source_directory
(
. ACCT_SRC
)
add_executable
(
dnode_test_acct
${
ACCT_SRC
}
)
target_link_libraries
(
dnode_test_acct
PUBLIC dnode
PUBLIC util
PUBLIC os
PUBLIC gtest_main
)
target_include_directories
(
dnode_test_acct
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/server/dnode/mgmt"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../inc"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../sut"
PUBLIC sut
)
add_test
(
...
...
source/dnode/mgmt/impl/test/acct/acct.cpp
浏览文件 @
15a43d5a
...
...
@@ -9,103 +9,57 @@
*
*/
#include "
deploy
.h"
#include "
base
.h"
class
DndTestAcct
:
public
::
testing
::
Test
{
protected:
static
SServer
*
CreateServer
(
const
char
*
path
,
const
char
*
fqdn
,
uint16_t
port
,
const
char
*
firstEp
)
{
SServer
*
pServer
=
createServer
(
path
,
fqdn
,
port
,
firstEp
);
ASSERT
(
pServer
);
return
pServer
;
}
static
void
SetUpTestSuite
()
{
initLog
(
"/tmp/tdlog"
);
const
char
*
fqdn
=
"localhost"
;
const
char
*
firstEp
=
"localhost:9012"
;
pServer
=
CreateServer
(
"/tmp/dnode_test_user"
,
fqdn
,
9012
,
firstEp
);
pClient
=
createClient
(
"root"
,
"taosdata"
,
fqdn
,
9012
);
taosMsleep
(
300
);
}
static
void
TearDownTestSuite
()
{
stopServer
(
pServer
);
dropClient
(
pClient
);
pServer
=
NULL
;
pClient
=
NULL
;
}
static
SServer
*
pServer
;
static
SClient
*
pClient
;
static
int32_t
connId
;
};
static
void
SetUpTestSuite
()
{
test
.
Init
(
"/tmp/dnode_test_acct"
,
9012
);
}
static
void
TearDownTestSuite
()
{
test
.
Cleanup
();
}
SServer
*
DndTestAcct
::
pServer
;
SClient
*
DndTestAcct
::
pClient
;
int32_t
DndTestAcct
::
connId
;
static
Testbase
test
;
TEST_F
(
DndTestAcct
,
01
_CreateAcct
)
{
ASSERT_NE
(
pClient
,
nullptr
);
public:
void
SetUp
()
override
{}
void
TearDown
()
override
{}
};
SCreateAcctMsg
*
pReq
=
(
SCreateAcctMsg
*
)
rpcMallocCont
(
sizeof
(
SCreateAcctMsg
));
TEST_F
(
DndTestAcct
,
01
_CreateAcct
)
{
int32_t
contLen
=
sizeof
(
SCreateAcctMsg
);
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
pCont
=
pReq
;
rpcMsg
.
contLen
=
sizeof
(
SCreateAcctMsg
);
rpcMsg
.
msgType
=
TSDB_MSG_TYPE_CREATE_ACCT
;
SCreateAcctMsg
*
pReq
=
(
SCreateAcctMsg
*
)
rpcMallocCont
(
contLen
);
sendMsg
(
pClient
,
&
rpcMsg
);
SRpcMsg
*
pMsg
=
pClient
->
pRsp
;
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TSDB_MSG_TYPE_CREATE_ACCT
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
TSDB_CODE_MND_MSG_NOT_PROCESSED
);
}
TEST_F
(
DndTestAcct
,
02
_AlterAcct
)
{
ASSERT_NE
(
pClient
,
nullptr
);
int32_t
contLen
=
sizeof
(
SCreateAcctMsg
);
SAlterAcctMsg
*
pReq
=
(
SAlterAcctMsg
*
)
rpcMallocCont
(
sizeof
(
SAlterAcctMsg
)
);
SAlterAcctMsg
*
pReq
=
(
SAlterAcctMsg
*
)
rpcMallocCont
(
contLen
);
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
pCont
=
pReq
;
rpcMsg
.
contLen
=
sizeof
(
SAlterAcctMsg
);
rpcMsg
.
msgType
=
TSDB_MSG_TYPE_ALTER_ACCT
;
sendMsg
(
pClient
,
&
rpcMsg
);
SRpcMsg
*
pMsg
=
pClient
->
pRsp
;
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TSDB_MSG_TYPE_ALTER_ACCT
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
TSDB_CODE_MND_MSG_NOT_PROCESSED
);
}
TEST_F
(
DndTestAcct
,
03
_DropAcct
)
{
ASSERT_NE
(
pClient
,
nullptr
);
SDropAcctMsg
*
pReq
=
(
SDropAcctMsg
*
)
rpcMallocCont
(
sizeof
(
SDropAcctMsg
));
int32_t
contLen
=
sizeof
(
SDropAcctMsg
);
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
pCont
=
pReq
;
rpcMsg
.
contLen
=
sizeof
(
SDropAcctMsg
);
rpcMsg
.
msgType
=
TSDB_MSG_TYPE_DROP_ACCT
;
SDropAcctMsg
*
pReq
=
(
SDropAcctMsg
*
)
rpcMallocCont
(
contLen
);
sendMsg
(
pClient
,
&
rpcMsg
);
SRpcMsg
*
pMsg
=
pClient
->
pRsp
;
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TSDB_MSG_TYPE_DROP_ACCT
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
TSDB_CODE_MND_MSG_NOT_PROCESSED
);
}
TEST_F
(
DndTestAcct
,
04
_ShowAcct
)
{
ASSERT_NE
(
pClient
,
nullptr
);
int32_t
contLen
=
sizeof
(
SShowMsg
);
SShowMsg
*
pReq
=
(
SShowMsg
*
)
rpcMallocCont
(
sizeof
(
SShowMsg
)
);
SShowMsg
*
pReq
=
(
SShowMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
type
=
TSDB_MGMT_TABLE_ACCT
;
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
pCont
=
pReq
;
rpcMsg
.
contLen
=
sizeof
(
SShowMsg
);
rpcMsg
.
msgType
=
TSDB_MSG_TYPE_SHOW
;
sendMsg
(
pClient
,
&
rpcMsg
);
SRpcMsg
*
pMsg
=
pClient
->
pRsp
;
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TSDB_MSG_TYPE_SHOW
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
TSDB_CODE_MND_
INVALID_MSG_TYPE
);
ASSERT_EQ
(
pMsg
->
code
,
TSDB_CODE_MND_
MSG_NOT_PROCESSED
);
}
\ No newline at end of file
source/dnode/mgmt/impl/test/cluster/CMakeLists.txt
浏览文件 @
15a43d5a
add_executable
(
dnode_test_cluster
""
)
target_sources
(
dnode_test_cluster
PRIVATE
"cluster.cpp"
"../sut/deploy.cpp"
)
aux_source_directory
(
. CLUSTER_SRC
)
add_executable
(
dnode_test_cluster
${
CLUSTER_SRC
}
)
target_link_libraries
(
dnode_test_cluster
PUBLIC dnode
PUBLIC util
PUBLIC os
PUBLIC gtest_main
)
target_include_directories
(
dnode_test_cluster
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/server/dnode/mgmt"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../inc"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../sut"
PUBLIC sut
)
add_test
(
...
...
source/dnode/mgmt/impl/test/cluster/cluster.cpp
浏览文件 @
15a43d5a
...
...
@@ -9,162 +9,41 @@
*
*/
#include "
deploy
.h"
#include "
base
.h"
class
DndTestCluster
:
public
::
testing
::
Test
{
protected:
static
SServer
*
CreateServer
(
const
char
*
path
,
const
char
*
fqdn
,
uint16_t
port
,
const
char
*
firstEp
)
{
SServer
*
pServer
=
createServer
(
path
,
fqdn
,
port
,
firstEp
);
ASSERT
(
pServer
);
return
pServer
;
}
static
void
SetUpTestSuite
()
{
test
.
Init
(
"/tmp/dnode_test_cluster"
,
9030
);
}
static
void
TearDownTestSuite
()
{
test
.
Cleanup
();
}
static
void
SetUpTestSuite
()
{
initLog
(
"/tmp/tdlog"
);
const
char
*
fqdn
=
"localhost"
;
const
char
*
firstEp
=
"localhost:9030"
;
pServer
=
CreateServer
(
"/tmp/dnode_test_cluster"
,
fqdn
,
9030
,
firstEp
);
pClient
=
createClient
(
"root"
,
"taosdata"
,
fqdn
,
9030
);
taosMsleep
(
1100
);
}
static
void
TearDownTestSuite
()
{
stopServer
(
pServer
);
dropClient
(
pClient
);
pServer
=
NULL
;
pClient
=
NULL
;
}
static
SServer
*
pServer
;
static
SClient
*
pClient
;
static
int32_t
connId
;
static
Testbase
test
;
public:
void
SetUp
()
override
{}
void
TearDown
()
override
{}
void
SendTheCheckShowMetaMsg
(
int8_t
showType
,
const
char
*
showName
,
int32_t
columns
,
const
char
*
db
)
{
SShowMsg
*
pShow
=
(
SShowMsg
*
)
rpcMallocCont
(
sizeof
(
SShowMsg
));
pShow
->
type
=
showType
;
if
(
db
!=
NULL
)
{
strcpy
(
pShow
->
db
,
db
);
}
SRpcMsg
showRpcMsg
=
{
0
};
showRpcMsg
.
pCont
=
pShow
;
showRpcMsg
.
contLen
=
sizeof
(
SShowMsg
);
showRpcMsg
.
msgType
=
TSDB_MSG_TYPE_SHOW
;
sendMsg
(
pClient
,
&
showRpcMsg
);
ASSERT_NE
(
pClient
->
pRsp
,
nullptr
);
ASSERT_EQ
(
pClient
->
pRsp
->
code
,
0
);
ASSERT_NE
(
pClient
->
pRsp
->
pCont
,
nullptr
);
SShowRsp
*
pShowRsp
=
(
SShowRsp
*
)
pClient
->
pRsp
->
pCont
;
ASSERT_NE
(
pShowRsp
,
nullptr
);
pShowRsp
->
showId
=
htonl
(
pShowRsp
->
showId
);
pMeta
=
&
pShowRsp
->
tableMeta
;
pMeta
->
numOfTags
=
htonl
(
pMeta
->
numOfTags
);
pMeta
->
numOfColumns
=
htonl
(
pMeta
->
numOfColumns
);
pMeta
->
sversion
=
htonl
(
pMeta
->
sversion
);
pMeta
->
tversion
=
htonl
(
pMeta
->
tversion
);
pMeta
->
tuid
=
htobe64
(
pMeta
->
tuid
);
pMeta
->
suid
=
htobe64
(
pMeta
->
suid
);
showId
=
pShowRsp
->
showId
;
EXPECT_NE
(
pShowRsp
->
showId
,
0
);
EXPECT_STREQ
(
pMeta
->
tbFname
,
showName
);
EXPECT_EQ
(
pMeta
->
numOfTags
,
0
);
EXPECT_EQ
(
pMeta
->
numOfColumns
,
columns
);
EXPECT_EQ
(
pMeta
->
precision
,
0
);
EXPECT_EQ
(
pMeta
->
tableType
,
0
);
EXPECT_EQ
(
pMeta
->
update
,
0
);
EXPECT_EQ
(
pMeta
->
sversion
,
0
);
EXPECT_EQ
(
pMeta
->
tversion
,
0
);
EXPECT_EQ
(
pMeta
->
tuid
,
0
);
EXPECT_EQ
(
pMeta
->
suid
,
0
);
}
void
CheckSchema
(
int32_t
index
,
int8_t
type
,
int32_t
bytes
,
const
char
*
name
)
{
SSchema
*
pSchema
=
&
pMeta
->
pSchema
[
index
];
pSchema
->
bytes
=
htonl
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
type
);
EXPECT_EQ
(
pSchema
->
bytes
,
bytes
);
EXPECT_STREQ
(
pSchema
->
name
,
name
);
}
void
SendThenCheckShowRetrieveMsg
(
int32_t
rows
)
{
SRetrieveTableMsg
*
pRetrieve
=
(
SRetrieveTableMsg
*
)
rpcMallocCont
(
sizeof
(
SRetrieveTableMsg
));
pRetrieve
->
showId
=
htonl
(
showId
);
pRetrieve
->
free
=
0
;
SRpcMsg
retrieveRpcMsg
=
{
0
};
retrieveRpcMsg
.
pCont
=
pRetrieve
;
retrieveRpcMsg
.
contLen
=
sizeof
(
SRetrieveTableMsg
);
retrieveRpcMsg
.
msgType
=
TSDB_MSG_TYPE_SHOW_RETRIEVE
;
sendMsg
(
pClient
,
&
retrieveRpcMsg
);
ASSERT_NE
(
pClient
->
pRsp
,
nullptr
);
ASSERT_EQ
(
pClient
->
pRsp
->
code
,
0
);
ASSERT_NE
(
pClient
->
pRsp
->
pCont
,
nullptr
);
pRetrieveRsp
=
(
SRetrieveTableRsp
*
)
pClient
->
pRsp
->
pCont
;
ASSERT_NE
(
pRetrieveRsp
,
nullptr
);
pRetrieveRsp
->
numOfRows
=
htonl
(
pRetrieveRsp
->
numOfRows
);
pRetrieveRsp
->
useconds
=
htobe64
(
pRetrieveRsp
->
useconds
);
pRetrieveRsp
->
compLen
=
htonl
(
pRetrieveRsp
->
compLen
);
EXPECT_EQ
(
pRetrieveRsp
->
numOfRows
,
rows
);
EXPECT_EQ
(
pRetrieveRsp
->
useconds
,
0
);
// EXPECT_EQ(pRetrieveRsp->completed, completed);
EXPECT_EQ
(
pRetrieveRsp
->
precision
,
TSDB_TIME_PRECISION_MILLI
);
EXPECT_EQ
(
pRetrieveRsp
->
compressed
,
0
);
EXPECT_EQ
(
pRetrieveRsp
->
compLen
,
0
);
pData
=
pRetrieveRsp
->
data
;
pos
=
0
;
}
void
CheckInt32
()
{
int32_t
data
=
*
((
int32_t
*
)(
pData
+
pos
));
pos
+=
sizeof
(
int32_t
);
EXPECT_GT
(
data
,
0
);
}
void
CheckTimestamp
()
{
int64_t
data
=
*
((
int64_t
*
)(
pData
+
pos
));
pos
+=
sizeof
(
int64_t
);
EXPECT_GT
(
data
,
0
);
}
void
CheckBinary
(
int32_t
len
)
{
pos
+=
sizeof
(
VarDataLenT
);
char
*
data
=
(
char
*
)(
pData
+
pos
);
pos
+=
len
;
}
int32_t
showId
;
STableMetaMsg
*
pMeta
;
SRetrieveTableRsp
*
pRetrieveRsp
;
char
*
pData
;
int32_t
pos
;
};
SServer
*
DndTestCluster
::
pServer
;
SClient
*
DndTestCluster
::
pClient
;
int32_t
DndTestCluster
::
connId
;
Testbase
DndTestCluster
::
test
;
TEST_F
(
DndTestCluster
,
01
_ShowCluster
)
{
SendTheCheckShowMetaMsg
(
TSDB_MGMT_TABLE_CLUSTER
,
"show cluster"
,
3
,
NULL
);
CheckSchema
(
0
,
TSDB_DATA_TYPE_INT
,
4
,
"id"
);
CheckSchema
(
1
,
TSDB_DATA_TYPE_BINARY
,
TSDB_CLUSTER_ID_LEN
+
VARSTR_HEADER_SIZE
,
"name"
);
CheckSchema
(
2
,
TSDB_DATA_TYPE_TIMESTAMP
,
8
,
"create_time"
);
SendThenCheckShowRetrieveMsg
(
1
);
CheckInt32
();
CheckBinary
(
TSDB_CLUSTER_ID_LEN
);
CheckTimestamp
();
test
.
SendShowMetaMsg
(
TSDB_MGMT_TABLE_CLUSTER
);
EXPECT_EQ
(
test
.
GetMetaNum
(),
3
);
EXPECT_STREQ
(
test
.
GetMetaTbName
(),
"show cluster"
);
EXPECT_EQ
(
test
.
GetMetaType
(
0
),
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
test
.
GetMetaBytes
(
0
),
4
);
EXPECT_STREQ
(
test
.
GetMetaName
(
0
),
"id"
);
EXPECT_EQ
(
test
.
GetMetaType
(
0
),
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
test
.
GetMetaBytes
(
0
),
TSDB_CLUSTER_ID_LEN
+
VARSTR_HEADER_SIZE
);
EXPECT_STREQ
(
test
.
GetMetaName
(
0
),
"name"
);
EXPECT_EQ
(
test
.
GetMetaType
(
0
),
TSDB_DATA_TYPE_TIMESTAMP
);
EXPECT_EQ
(
test
.
GetMetaBytes
(
0
),
8
);
EXPECT_STREQ
(
test
.
GetMetaName
(
0
),
"create_time"
);
test
.
SendShowRetrieveMsg
();
test
.
GetShowInt32
();
test
.
GetShowBinary
(
TSDB_CLUSTER_ID_LEN
);
EXPECT_GT
(
test
.
GetShowTimestamp
(),
0
);
}
\ No newline at end of file
source/dnode/mgmt/impl/test/profile/profile.cpp
浏览文件 @
15a43d5a
...
...
@@ -445,7 +445,7 @@ TEST_F(DndTestProfile, 07_KillQueryMsg) {
}
}
TEST_F
(
DndTestProfile
,
08
_KillQueryMsg_InvalidC
O
nn
)
{
TEST_F
(
DndTestProfile
,
08
_KillQueryMsg_InvalidC
o
nn
)
{
ASSERT_NE
(
pClient
,
nullptr
);
SKillQueryMsg
*
pReq
=
(
SKillQueryMsg
*
)
rpcMallocCont
(
sizeof
(
SKillQueryMsg
));
...
...
source/dnode/mgmt/impl/test/show/CMakeLists.txt
浏览文件 @
15a43d5a
add_executable
(
dnode_test_show
""
)
target_sources
(
dnode_test_show
PRIVATE
"show.cpp"
"../sut/deploy.cpp"
)
aux_source_directory
(
. SHOW_SRC
)
add_executable
(
dnode_test_show
${
SHOW_SRC
}
)
target_link_libraries
(
dnode_test_show
PUBLIC dnode
PUBLIC util
PUBLIC os
PUBLIC gtest_main
)
target_include_directories
(
dnode_test_show
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/server/dnode/mgmt"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../inc"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../sut"
PUBLIC sut
)
add_test
(
...
...
source/dnode/mgmt/impl/test/show/show.cpp
浏览文件 @
15a43d5a
...
...
@@ -9,204 +9,42 @@
*
*/
#include "
deploy
.h"
#include "
base
.h"
class
DndTestShow
:
public
::
testing
::
Test
{
protected:
static
SServer
*
CreateServer
(
const
char
*
path
,
const
char
*
fqdn
,
uint16_t
port
,
const
char
*
firstEp
)
{
SServer
*
pServer
=
createServer
(
path
,
fqdn
,
port
,
firstEp
);
ASSERT
(
pServer
);
return
pServer
;
}
static
void
SetUpTestSuite
()
{
test
.
Init
(
"/tmp/dnode_test_show"
,
9091
);
}
static
void
TearDownTestSuite
()
{
test
.
Cleanup
();
}
static
void
SetUpTestSuite
()
{
initLog
(
"/tmp/tdlog"
);
const
char
*
fqdn
=
"localhost"
;
const
char
*
firstEp
=
"localhost:9091"
;
pServer
=
CreateServer
(
"/tmp/dnode_test_show"
,
fqdn
,
9091
,
firstEp
);
pClient
=
createClient
(
"root"
,
"taosdata"
,
fqdn
,
9091
);
taosMsleep
(
300
);
}
static
void
TearDownTestSuite
()
{
stopServer
(
pServer
);
dropClient
(
pClient
);
pServer
=
NULL
;
pClient
=
NULL
;
}
static
SServer
*
pServer
;
static
SClient
*
pClient
;
static
int32_t
connId
;
static
Testbase
test
;
public:
void
SetUp
()
override
{}
void
TearDown
()
override
{}
void
SendTheCheckShowMetaMsg
(
int8_t
showType
,
const
char
*
showName
,
int32_t
columns
)
{
SShowMsg
*
pShow
=
(
SShowMsg
*
)
rpcMallocCont
(
sizeof
(
SShowMsg
));
pShow
->
type
=
showType
;
strcpy
(
pShow
->
db
,
""
);
SRpcMsg
showRpcMsg
=
{
0
};
showRpcMsg
.
pCont
=
pShow
;
showRpcMsg
.
contLen
=
sizeof
(
SShowMsg
);
showRpcMsg
.
msgType
=
TSDB_MSG_TYPE_SHOW
;
sendMsg
(
pClient
,
&
showRpcMsg
);
ASSERT_NE
(
pClient
->
pRsp
,
nullptr
);
ASSERT_EQ
(
pClient
->
pRsp
->
code
,
0
);
ASSERT_NE
(
pClient
->
pRsp
->
pCont
,
nullptr
);
SShowRsp
*
pShowRsp
=
(
SShowRsp
*
)
pClient
->
pRsp
->
pCont
;
ASSERT_NE
(
pShowRsp
,
nullptr
);
pShowRsp
->
showId
=
htonl
(
pShowRsp
->
showId
);
pMeta
=
&
pShowRsp
->
tableMeta
;
pMeta
->
numOfTags
=
htonl
(
pMeta
->
numOfTags
);
pMeta
->
numOfColumns
=
htonl
(
pMeta
->
numOfColumns
);
pMeta
->
sversion
=
htonl
(
pMeta
->
sversion
);
pMeta
->
tversion
=
htonl
(
pMeta
->
tversion
);
pMeta
->
tuid
=
htobe64
(
pMeta
->
tuid
);
pMeta
->
suid
=
htobe64
(
pMeta
->
suid
);
showId
=
pShowRsp
->
showId
;
EXPECT_NE
(
pShowRsp
->
showId
,
0
);
EXPECT_STREQ
(
pMeta
->
tbFname
,
showName
);
EXPECT_EQ
(
pMeta
->
numOfTags
,
0
);
EXPECT_EQ
(
pMeta
->
numOfColumns
,
columns
);
EXPECT_EQ
(
pMeta
->
precision
,
0
);
EXPECT_EQ
(
pMeta
->
tableType
,
0
);
EXPECT_EQ
(
pMeta
->
update
,
0
);
EXPECT_EQ
(
pMeta
->
sversion
,
0
);
EXPECT_EQ
(
pMeta
->
tversion
,
0
);
EXPECT_EQ
(
pMeta
->
tuid
,
0
);
EXPECT_EQ
(
pMeta
->
suid
,
0
);
}
void
CheckSchema
(
int32_t
index
,
int8_t
type
,
int32_t
bytes
,
const
char
*
name
)
{
SSchema
*
pSchema
=
&
pMeta
->
pSchema
[
index
];
pSchema
->
bytes
=
htonl
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
type
);
EXPECT_EQ
(
pSchema
->
bytes
,
bytes
);
EXPECT_STREQ
(
pSchema
->
name
,
name
);
}
void
SendThenCheckShowRetrieveMsg
(
int32_t
rows
)
{
SRetrieveTableMsg
*
pRetrieve
=
(
SRetrieveTableMsg
*
)
rpcMallocCont
(
sizeof
(
SRetrieveTableMsg
));
pRetrieve
->
showId
=
htonl
(
showId
);
pRetrieve
->
free
=
0
;
SRpcMsg
retrieveRpcMsg
=
{
0
};
retrieveRpcMsg
.
pCont
=
pRetrieve
;
retrieveRpcMsg
.
contLen
=
sizeof
(
SRetrieveTableMsg
);
retrieveRpcMsg
.
msgType
=
TSDB_MSG_TYPE_SHOW_RETRIEVE
;
sendMsg
(
pClient
,
&
retrieveRpcMsg
);
ASSERT_NE
(
pClient
->
pRsp
,
nullptr
);
ASSERT_EQ
(
pClient
->
pRsp
->
code
,
0
);
ASSERT_NE
(
pClient
->
pRsp
->
pCont
,
nullptr
);
pRetrieveRsp
=
(
SRetrieveTableRsp
*
)
pClient
->
pRsp
->
pCont
;
ASSERT_NE
(
pRetrieveRsp
,
nullptr
);
pRetrieveRsp
->
numOfRows
=
htonl
(
pRetrieveRsp
->
numOfRows
);
pRetrieveRsp
->
useconds
=
htobe64
(
pRetrieveRsp
->
useconds
);
pRetrieveRsp
->
compLen
=
htonl
(
pRetrieveRsp
->
compLen
);
EXPECT_EQ
(
pRetrieveRsp
->
numOfRows
,
rows
);
EXPECT_EQ
(
pRetrieveRsp
->
useconds
,
0
);
// EXPECT_EQ(pRetrieveRsp->completed, completed);
EXPECT_EQ
(
pRetrieveRsp
->
precision
,
TSDB_TIME_PRECISION_MILLI
);
EXPECT_EQ
(
pRetrieveRsp
->
compressed
,
0
);
EXPECT_EQ
(
pRetrieveRsp
->
compLen
,
0
);
pData
=
pRetrieveRsp
->
data
;
pos
=
0
;
}
void
CheckInt16
(
int16_t
val
)
{
int16_t
data
=
*
((
int16_t
*
)(
pData
+
pos
));
pos
+=
sizeof
(
int16_t
);
EXPECT_EQ
(
data
,
val
);
}
void
CheckInt32
(
int32_t
val
)
{
int32_t
data
=
*
((
int32_t
*
)(
pData
+
pos
));
pos
+=
sizeof
(
int32_t
);
EXPECT_EQ
(
data
,
val
);
}
void
CheckInt64
(
int64_t
val
)
{
int64_t
data
=
*
((
int64_t
*
)(
pData
+
pos
));
pos
+=
sizeof
(
int64_t
);
EXPECT_EQ
(
data
,
val
);
}
void
CheckTimestamp
()
{
int64_t
data
=
*
((
int64_t
*
)(
pData
+
pos
));
pos
+=
sizeof
(
int64_t
);
EXPECT_GT
(
data
,
0
);
}
void
CheckBinary
(
const
char
*
val
,
int32_t
len
)
{
pos
+=
sizeof
(
VarDataLenT
);
char
*
data
=
(
char
*
)(
pData
+
pos
);
pos
+=
len
;
EXPECT_STREQ
(
data
,
val
);
}
void
IgnoreBinary
(
int32_t
len
)
{
pos
+=
sizeof
(
VarDataLenT
);
char
*
data
=
(
char
*
)(
pData
+
pos
);
pos
+=
len
;
}
int32_t
showId
;
STableMetaMsg
*
pMeta
;
SRetrieveTableRsp
*
pRetrieveRsp
;
char
*
pData
;
int32_t
pos
;
};
SServer
*
DndTestShow
::
pServer
;
SClient
*
DndTestShow
::
pClient
;
int32_t
DndTestShow
::
connId
;
Testbase
DndTestShow
::
test
;
TEST_F
(
DndTestShow
,
01
_ShowMsg_InvalidMsgMax
)
{
ASSERT_NE
(
pClient
,
nullptr
);
int32_t
contLen
=
sizeof
(
SShowMsg
);
SShowMsg
*
pReq
=
(
SShowMsg
*
)
rpcMallocCont
(
sizeof
(
SShowMsg
)
);
SShowMsg
*
pReq
=
(
SShowMsg
*
)
rpcMallocCont
(
contLen
);
pReq
->
type
=
TSDB_MGMT_TABLE_MAX
;
strcpy
(
pReq
->
db
,
""
);
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
pCont
=
pReq
;
rpcMsg
.
contLen
=
sizeof
(
SShowMsg
);
rpcMsg
.
msgType
=
TSDB_MSG_TYPE_SHOW
;
sendMsg
(
pClient
,
&
rpcMsg
);
SRpcMsg
*
pMsg
=
pClient
->
pRsp
;
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TSDB_MSG_TYPE_SHOW
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
TSDB_CODE_MND_INVALID_MSG_TYPE
);
}
TEST_F
(
DndTestShow
,
02
_ShowMsg_InvalidMsgStart
)
{
ASSERT_NE
(
pClient
,
nullptr
);
int32_t
contLen
=
sizeof
(
SShowMsg
);
SShowMsg
*
pReq
=
(
SShowMsg
*
)
rpcMallocCont
(
sizeof
(
SShowMsg
));
pReq
->
type
=
TSDB_MGMT_TABLE_START
;
strcpy
(
pReq
->
db
,
""
);
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
pCont
=
pReq
;
rpcMsg
.
contLen
=
sizeof
(
SShowMsg
);
rpcMsg
.
msgType
=
TSDB_MSG_TYPE_SHOW
;
sendMsg
(
pClient
,
&
rpcMsg
);
SRpcMsg
*
pMsg
=
pClient
->
pRsp
;
SRpcMsg
*
pMsg
=
test
.
SendMsg
(
TSDB_MSG_TYPE_SHOW
,
pReq
,
contLen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
TSDB_CODE_MND_INVALID_MSG_TYPE
);
}
source/dnode/mgmt/impl/test/sut/CMakeLists.txt
0 → 100644
浏览文件 @
15a43d5a
aux_source_directory
(
src SUT_SRC
)
add_library
(
sut STATIC
${
SUT_SRC
}
)
target_link_libraries
(
sut
PUBLIC dnode
PUBLIC util
PUBLIC os
PUBLIC gtest_main
)
target_include_directories
(
sut
PUBLIC
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
)
source/dnode/mgmt/impl/test/sut/deploy.cpp
已删除
100644 → 0
浏览文件 @
40122d3c
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "deploy.h"
void
initLog
(
const
char
*
path
)
{
dDebugFlag
=
207
;
vDebugFlag
=
0
;
mDebugFlag
=
207
;
cDebugFlag
=
0
;
jniDebugFlag
=
0
;
tmrDebugFlag
=
0
;
uDebugFlag
=
143
;
rpcDebugFlag
=
0
;
odbcDebugFlag
=
0
;
qDebugFlag
=
0
;
wDebugFlag
=
0
;
sDebugFlag
=
0
;
tsdbDebugFlag
=
0
;
cqDebugFlag
=
0
;
tscEmbeddedInUtil
=
1
;
taosRemoveDir
(
path
);
taosMkDir
(
path
);
char
temp
[
PATH_MAX
];
snprintf
(
temp
,
PATH_MAX
,
"%s/taosdlog"
,
path
);
if
(
taosInitLog
(
temp
,
tsNumOfLogLines
,
1
)
!=
0
)
{
printf
(
"failed to init log file
\n
"
);
}
}
void
*
runServer
(
void
*
param
)
{
SServer
*
pServer
=
(
SServer
*
)
param
;
while
(
1
)
{
taosMsleep
(
100
);
pthread_testcancel
();
}
}
void
initOption
(
SDnodeOpt
*
pOption
,
const
char
*
path
,
const
char
*
fqdn
,
uint16_t
port
,
const
char
*
firstEp
)
{
pOption
->
sver
=
1
;
pOption
->
numOfCores
=
1
;
pOption
->
numOfSupportMnodes
=
1
;
pOption
->
numOfSupportVnodes
=
1
;
pOption
->
numOfSupportQnodes
=
1
;
pOption
->
statusInterval
=
1
;
pOption
->
numOfThreadsPerCore
=
1
;
pOption
->
ratioOfQueryCores
=
1
;
pOption
->
maxShellConns
=
1000
;
pOption
->
shellActivityTimer
=
30
;
pOption
->
serverPort
=
port
;
strcpy
(
pOption
->
dataDir
,
path
);
snprintf
(
pOption
->
localEp
,
TSDB_EP_LEN
,
"%s:%u"
,
fqdn
,
port
);
snprintf
(
pOption
->
localFqdn
,
TSDB_FQDN_LEN
,
"%s"
,
fqdn
);
snprintf
(
pOption
->
firstEp
,
TSDB_EP_LEN
,
"%s"
,
firstEp
);
}
SServer
*
startServer
(
const
char
*
path
,
const
char
*
fqdn
,
uint16_t
port
,
const
char
*
firstEp
)
{
taosMkDir
(
path
);
SDnodeOpt
option
=
{
0
};
initOption
(
&
option
,
path
,
fqdn
,
port
,
firstEp
);
SDnode
*
pDnode
=
dndInit
(
&
option
);
ASSERT
(
pDnode
);
SServer
*
pServer
=
(
SServer
*
)
calloc
(
1
,
sizeof
(
SServer
));
ASSERT
(
pServer
);
pServer
->
pDnode
=
pDnode
;
pServer
->
threadId
=
taosCreateThread
(
runServer
,
pServer
);
ASSERT
(
pServer
->
threadId
);
return
pServer
;
}
SServer
*
createServer
(
const
char
*
path
,
const
char
*
fqdn
,
uint16_t
port
,
const
char
*
firstEp
)
{
taosRemoveDir
(
path
);
return
startServer
(
path
,
fqdn
,
port
,
firstEp
);
}
void
stopServer
(
SServer
*
pServer
)
{
if
(
pServer
==
NULL
)
return
;
if
(
pServer
->
threadId
!=
NULL
)
{
taosDestoryThread
(
pServer
->
threadId
);
}
if
(
pServer
->
pDnode
!=
NULL
)
{
dndCleanup
(
pServer
->
pDnode
);
pServer
->
pDnode
=
NULL
;
}
}
void
processClientRsp
(
void
*
parent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
SClient
*
pClient
=
(
SClient
*
)
parent
;
pClient
->
pRsp
=
pMsg
;
uInfo
(
"response:%s from dnode, pCont:%p contLen:%d code:0x%X"
,
taosMsg
[
pMsg
->
msgType
],
pMsg
->
pCont
,
pMsg
->
contLen
,
pMsg
->
code
);
tsem_post
(
&
pClient
->
sem
);
}
SClient
*
createClient
(
const
char
*
user
,
const
char
*
pass
,
const
char
*
fqdn
,
uint16_t
port
)
{
SClient
*
pClient
=
(
SClient
*
)
calloc
(
1
,
sizeof
(
SClient
));
ASSERT
(
pClient
);
char
secretEncrypt
[
TSDB_PASSWORD_LEN
]
=
{
0
};
taosEncryptPass
((
uint8_t
*
)
pass
,
strlen
(
pass
),
secretEncrypt
);
SRpcInit
rpcInit
;
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
rpcInit
.
label
=
(
char
*
)
"DND-C"
;
rpcInit
.
numOfThreads
=
1
;
rpcInit
.
cfp
=
processClientRsp
;
rpcInit
.
sessions
=
1024
;
rpcInit
.
connType
=
TAOS_CONN_CLIENT
;
rpcInit
.
idleTime
=
30
*
1000
;
rpcInit
.
user
=
(
char
*
)
user
;
rpcInit
.
ckey
=
(
char
*
)
"key"
;
rpcInit
.
parent
=
pClient
;
rpcInit
.
secret
=
(
char
*
)
secretEncrypt
;
rpcInit
.
parent
=
pClient
;
// rpcInit.spi = 1;
pClient
->
clientRpc
=
rpcOpen
(
&
rpcInit
);
ASSERT
(
pClient
->
clientRpc
);
tsem_init
(
&
pClient
->
sem
,
0
,
0
);
strcpy
(
pClient
->
fqdn
,
fqdn
);
pClient
->
port
=
port
;
return
pClient
;
}
void
dropClient
(
SClient
*
pClient
)
{
tsem_destroy
(
&
pClient
->
sem
);
rpcClose
(
pClient
->
clientRpc
);
}
void
sendMsg
(
SClient
*
pClient
,
SRpcMsg
*
pMsg
)
{
SEpSet
epSet
=
{
0
};
epSet
.
inUse
=
0
;
epSet
.
numOfEps
=
1
;
epSet
.
port
[
0
]
=
pClient
->
port
;
memcpy
(
epSet
.
fqdn
[
0
],
pClient
->
fqdn
,
TSDB_FQDN_LEN
);
rpcSendRequest
(
pClient
->
clientRpc
,
&
epSet
,
pMsg
,
NULL
);
tsem_wait
(
&
pClient
->
sem
);
}
source/dnode/mgmt/impl/test/sut/inc/base.h
0 → 100644
浏览文件 @
15a43d5a
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_TEST_BASE_H_
#define _TD_TEST_BASE_H_
#include <gtest/gtest.h>
#include "os.h"
#include "dnode.h"
#include "taosmsg.h"
#include "tconfig.h"
#include "tdataformat.h"
#include "tglobal.h"
#include "tnote.h"
#include "trpc.h"
#include "tthread.h"
#include "ulog.h"
#include "client.h"
#include "server.h"
class
Testbase
{
public:
void
Init
(
const
char
*
path
,
int16_t
port
);
void
Cleanup
();
SRpcMsg
*
SendMsg
(
int8_t
msgType
,
void
*
pCont
,
int32_t
contLen
);
private:
void
InitLog
(
const
char
*
path
);
private:
TestServer
server
;
TestClient
client
;
int32_t
connId
;
public:
void
SendShowMetaMsg
(
int8_t
showType
);
void
SendShowRetrieveMsg
();
const
char
*
GetShowName
();
int8_t
GetShowInt8
();
int16_t
GetShowInt16
();
int32_t
GetShowInt32
();
int64_t
GetShowInt64
();
int64_t
GetShowTimestamp
();
const
char
*
GetShowBinary
(
int32_t
len
);
int32_t
GetMetaColId
(
int32_t
index
);
int8_t
GetMetaType
(
int32_t
index
);
int32_t
GetMetaBytes
(
int32_t
index
);
const
char
*
GetMetaName
(
int32_t
index
);
int32_t
GetMetaNum
();
const
char
*
GetMetaTbName
();
private:
int32_t
showId
;
STableMetaMsg
*
pMeta
;
SRetrieveTableRsp
*
pRetrieveRsp
;
char
*
pData
;
int32_t
pos
;
};
#endif
/* _TD_TEST_BASE_H_ */
\ No newline at end of file
source/dnode/mgmt/impl/test/sut/
deploy
.h
→
source/dnode/mgmt/impl/test/sut/
inc/client
.h
浏览文件 @
15a43d5a
...
...
@@ -13,37 +13,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#i
nclude <gtest/gtest.h>
#
include "os.h"
#i
fndef _TD_TEST_CLIENT_H_
#
define _TD_TEST_CLIENT_H_
#include "dnode.h"
#include "taosmsg.h"
#include "tconfig.h"
#include "tglobal.h"
#include "tnote.h"
#include "trpc.h"
#include "tthread.h"
#include "ulog.h"
#include "tdataformat.h"
class
TestClient
{
public:
bool
Init
(
const
char
*
user
,
const
char
*
pass
,
const
char
*
fqdn
,
uint16_t
port
);
void
Cleanup
();
typedef
struct
{
SDnode
*
pDnode
;
pthread_t
*
threadId
;
}
SServer
;
SRpcMsg
*
SendMsg
(
SRpcMsg
*
pMsg
);
void
SetRpcRsp
(
SRpcMsg
*
pRsp
);
tsem_t
*
GetSem
();
typedef
struct
{
private:
char
fqdn
[
TSDB_FQDN_LEN
];
uint16_t
port
;
void
*
clientRpc
;
SRpcMsg
*
pRsp
;
tsem_t
sem
;
}
SClient
;
void
initLog
(
const
char
*
path
);
SServer
*
createServer
(
const
char
*
path
,
const
char
*
fqdn
,
uint16_t
port
,
const
char
*
firstEp
);
SServer
*
startServer
(
const
char
*
path
,
const
char
*
fqdn
,
uint16_t
port
,
const
char
*
firstEp
);
void
stopServer
(
SServer
*
pServer
);
SClient
*
createClient
(
const
char
*
user
,
const
char
*
pass
,
const
char
*
fqdn
,
uint16_t
port
);
void
dropClient
(
SClient
*
pClient
);
void
sendMsg
(
SClient
*
pClient
,
SRpcMsg
*
pMsg
);
};
#endif
/* _TD_TEST_CLIENT_H_ */
\ No newline at end of file
source/dnode/mgmt/impl/test/sut/inc/server.h
0 → 100644
浏览文件 @
15a43d5a
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_TEST_SERVER_H_
#define _TD_TEST_SERVER_H_
class
TestServer
{
public:
bool
Start
(
const
char
*
path
,
const
char
*
fqdn
,
uint16_t
port
,
const
char
*
firstEp
);
void
Stop
();
private:
SDnodeOpt
BuildOption
(
const
char
*
path
,
const
char
*
fqdn
,
uint16_t
port
,
const
char
*
firstEp
);
private:
SDnode
*
pDnode
;
pthread_t
*
threadId
;
};
#endif
/* _TD_TEST_SERVER_H_ */
\ No newline at end of file
source/dnode/mgmt/impl/test/sut/src/base.cpp
0 → 100644
浏览文件 @
15a43d5a
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base.h"
void
Testbase
::
InitLog
(
const
char
*
path
)
{
dDebugFlag
=
207
;
vDebugFlag
=
0
;
mDebugFlag
=
207
;
cDebugFlag
=
0
;
jniDebugFlag
=
0
;
tmrDebugFlag
=
0
;
uDebugFlag
=
143
;
rpcDebugFlag
=
0
;
odbcDebugFlag
=
0
;
qDebugFlag
=
0
;
wDebugFlag
=
0
;
sDebugFlag
=
0
;
tsdbDebugFlag
=
0
;
cqDebugFlag
=
0
;
tscEmbeddedInUtil
=
1
;
taosRemoveDir
(
path
);
taosMkDir
(
path
);
char
temp
[
PATH_MAX
];
snprintf
(
temp
,
PATH_MAX
,
"%s/taosdlog"
,
path
);
if
(
taosInitLog
(
temp
,
tsNumOfLogLines
,
1
)
!=
0
)
{
printf
(
"failed to init log file
\n
"
);
}
}
void
Testbase
::
Init
(
const
char
*
path
,
int16_t
port
)
{
char
fqdn
[]
=
"localhost"
;
char
firstEp
[
TSDB_EP_LEN
]
=
{
0
};
snprintf
(
firstEp
,
TSDB_EP_LEN
,
"%s:%u"
,
fqdn
,
port
);
InitLog
(
"/tmp/tdlog"
);
server
.
Start
(
path
,
fqdn
,
port
,
firstEp
);
client
.
Init
(
"root"
,
"taosdata"
,
fqdn
,
port
);
taosMsleep
(
1100
);
}
void
Testbase
::
Cleanup
()
{
server
.
Stop
();
client
.
Cleanup
();
}
SRpcMsg
*
Testbase
::
SendMsg
(
int8_t
msgType
,
void
*
pCont
,
int32_t
contLen
)
{
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
pCont
=
pCont
;
rpcMsg
.
contLen
=
sizeof
(
SShowMsg
);
rpcMsg
.
msgType
=
msgType
;
return
client
.
SendMsg
(
&
rpcMsg
);
}
void
Testbase
::
SendShowMetaMsg
(
int8_t
showType
)
{
int32_t
contLen
=
sizeof
(
SShowMsg
);
SShowMsg
*
pShow
=
(
SShowMsg
*
)
rpcMallocCont
(
contLen
);
pShow
->
type
=
showType
;
strcpy
(
pShow
->
db
,
""
);
SRpcMsg
*
pMsg
=
SendMsg
(
TSDB_MSG_TYPE_SHOW
,
pShow
,
contLen
);
SShowRsp
*
pShowRsp
=
(
SShowRsp
*
)
pMsg
->
pCont
;
ASSERT
(
pShowRsp
!=
nullptr
);
pShowRsp
->
showId
=
htonl
(
pShowRsp
->
showId
);
pMeta
=
&
pShowRsp
->
tableMeta
;
pMeta
->
numOfTags
=
htonl
(
pMeta
->
numOfTags
);
pMeta
->
numOfColumns
=
htonl
(
pMeta
->
numOfColumns
);
pMeta
->
sversion
=
htonl
(
pMeta
->
sversion
);
pMeta
->
tversion
=
htonl
(
pMeta
->
tversion
);
pMeta
->
tuid
=
htobe64
(
pMeta
->
tuid
);
pMeta
->
suid
=
htobe64
(
pMeta
->
suid
);
showId
=
pShowRsp
->
showId
;
}
int32_t
Testbase
::
GetMetaColId
(
int32_t
index
)
{
SSchema
*
pSchema
=
&
pMeta
->
pSchema
[
index
];
pSchema
->
colId
=
htonl
(
pSchema
->
colId
);
return
pSchema
->
colId
;
}
int8_t
Testbase
::
GetMetaType
(
int32_t
index
)
{
SSchema
*
pSchema
=
&
pMeta
->
pSchema
[
index
];
return
pSchema
->
type
;
}
int32_t
Testbase
::
GetMetaBytes
(
int32_t
index
)
{
SSchema
*
pSchema
=
&
pMeta
->
pSchema
[
index
];
pSchema
->
bytes
=
htonl
(
pSchema
->
bytes
);
return
pSchema
->
bytes
;
}
const
char
*
Testbase
::
GetMetaName
(
int32_t
index
)
{
SSchema
*
pSchema
=
&
pMeta
->
pSchema
[
index
];
return
pSchema
->
name
;
}
int32_t
Testbase
::
GetMetaNum
()
{
return
pMeta
->
numOfColumns
;
}
const
char
*
Testbase
::
GetMetaTbName
()
{
return
pMeta
->
tbFname
;
}
void
Testbase
::
SendShowRetrieveMsg
()
{
int32_t
contLen
=
sizeof
(
SRetrieveTableMsg
);
SRetrieveTableMsg
*
pRetrieve
=
(
SRetrieveTableMsg
*
)
rpcMallocCont
(
contLen
);
pRetrieve
->
showId
=
htonl
(
showId
);
pRetrieve
->
free
=
0
;
SRpcMsg
*
pMsg
=
SendMsg
(
TSDB_MSG_TYPE_SHOW_RETRIEVE
,
pRetrieve
,
contLen
);
pRetrieveRsp
=
(
SRetrieveTableRsp
*
)
pMsg
->
pCont
;
pData
=
pRetrieveRsp
->
data
;
pos
=
0
;
}
const
char
*
Testbase
::
GetShowName
()
{
return
pMeta
->
tbFname
;
}
int8_t
Testbase
::
GetShowInt8
()
{
int8_t
data
=
*
((
int8_t
*
)(
pData
+
pos
));
pos
+=
sizeof
(
int8_t
);
return
data
;
}
int16_t
Testbase
::
GetShowInt16
()
{
int16_t
data
=
*
((
int16_t
*
)(
pData
+
pos
));
pos
+=
sizeof
(
int16_t
);
return
data
;
}
int32_t
Testbase
::
GetShowInt32
()
{
int32_t
data
=
*
((
int32_t
*
)(
pData
+
pos
));
pos
+=
sizeof
(
int32_t
);
return
data
;
}
int64_t
Testbase
::
GetShowInt64
()
{
int64_t
data
=
*
((
int64_t
*
)(
pData
+
pos
));
pos
+=
sizeof
(
int64_t
);
return
data
;
}
int64_t
Testbase
::
GetShowTimestamp
()
{
int64_t
data
=
*
((
int64_t
*
)(
pData
+
pos
));
pos
+=
sizeof
(
int64_t
);
return
data
;
}
const
char
*
Testbase
::
GetShowBinary
(
int32_t
len
)
{
pos
+=
sizeof
(
VarDataLenT
);
char
*
data
=
(
char
*
)(
pData
+
pos
);
pos
+=
len
;
return
data
;
}
\ No newline at end of file
source/dnode/mgmt/impl/test/sut/src/client.cpp
0 → 100644
浏览文件 @
15a43d5a
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base.h"
static
void
processClientRsp
(
void
*
parent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
TestClient
*
client
=
(
TestClient
*
)
parent
;
client
->
SetRpcRsp
(
pMsg
);
uInfo
(
"response:%s from dnode, code:0x%x"
,
taosMsg
[
pMsg
->
msgType
],
pMsg
->
code
);
tsem_post
(
client
->
GetSem
());
}
void
TestClient
::
SetRpcRsp
(
SRpcMsg
*
pRsp
)
{
this
->
pRsp
=
pRsp
;
};
tsem_t
*
TestClient
::
GetSem
()
{
return
&
sem
;
}
bool
TestClient
::
Init
(
const
char
*
user
,
const
char
*
pass
,
const
char
*
fqdn
,
uint16_t
port
)
{
char
secretEncrypt
[
TSDB_PASSWORD_LEN
]
=
{
0
};
taosEncryptPass
((
uint8_t
*
)
pass
,
strlen
(
pass
),
secretEncrypt
);
SRpcInit
rpcInit
;
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
rpcInit
.
label
=
(
char
*
)
"DND-C"
;
rpcInit
.
numOfThreads
=
1
;
rpcInit
.
cfp
=
processClientRsp
;
rpcInit
.
sessions
=
1024
;
rpcInit
.
connType
=
TAOS_CONN_CLIENT
;
rpcInit
.
idleTime
=
30
*
1000
;
rpcInit
.
user
=
(
char
*
)
user
;
rpcInit
.
ckey
=
(
char
*
)
"key"
;
rpcInit
.
parent
=
this
;
rpcInit
.
secret
=
(
char
*
)
secretEncrypt
;
// rpcInit.spi = 1;
clientRpc
=
rpcOpen
(
&
rpcInit
);
ASSERT
(
clientRpc
);
tsem_init
(
&
sem
,
0
,
0
);
strcpy
(
this
->
fqdn
,
fqdn
);
this
->
port
=
port
;
return
true
;
}
void
TestClient
::
Cleanup
()
{
tsem_destroy
(
&
sem
);
rpcClose
(
clientRpc
);
}
SRpcMsg
*
TestClient
::
SendMsg
(
SRpcMsg
*
pMsg
)
{
SEpSet
epSet
=
{
0
};
epSet
.
inUse
=
0
;
epSet
.
numOfEps
=
1
;
epSet
.
port
[
0
]
=
port
;
memcpy
(
epSet
.
fqdn
[
0
],
fqdn
,
TSDB_FQDN_LEN
);
rpcSendRequest
(
clientRpc
,
&
epSet
,
pMsg
,
NULL
);
tsem_wait
(
&
sem
);
return
pRsp
;
}
source/dnode/mgmt/impl/test/sut/src/server.cpp
0 → 100644
浏览文件 @
15a43d5a
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base.h"
void
*
serverLoop
(
void
*
param
)
{
while
(
1
)
{
taosMsleep
(
100
);
pthread_testcancel
();
}
}
SDnodeOpt
TestServer
::
BuildOption
(
const
char
*
path
,
const
char
*
fqdn
,
uint16_t
port
,
const
char
*
firstEp
)
{
SDnodeOpt
option
=
{
0
};
option
.
sver
=
1
;
option
.
numOfCores
=
1
;
option
.
numOfSupportMnodes
=
1
;
option
.
numOfSupportVnodes
=
1
;
option
.
numOfSupportQnodes
=
1
;
option
.
statusInterval
=
1
;
option
.
numOfThreadsPerCore
=
1
;
option
.
ratioOfQueryCores
=
1
;
option
.
maxShellConns
=
1000
;
option
.
shellActivityTimer
=
30
;
option
.
serverPort
=
port
;
strcpy
(
option
.
dataDir
,
path
);
snprintf
(
option
.
localEp
,
TSDB_EP_LEN
,
"%s:%u"
,
fqdn
,
port
);
snprintf
(
option
.
localFqdn
,
TSDB_FQDN_LEN
,
"%s"
,
fqdn
);
snprintf
(
option
.
firstEp
,
TSDB_EP_LEN
,
"%s"
,
firstEp
);
return
option
;
}
bool
TestServer
::
Start
(
const
char
*
path
,
const
char
*
fqdn
,
uint16_t
port
,
const
char
*
firstEp
)
{
SDnodeOpt
option
=
BuildOption
(
path
,
fqdn
,
port
,
firstEp
);
taosRemoveDir
(
path
);
taosMkDir
(
path
);
pDnode
=
dndInit
(
&
option
);
if
(
pDnode
!=
NULL
)
{
return
false
;
}
threadId
=
taosCreateThread
(
serverLoop
,
NULL
);
if
(
threadId
!=
NULL
)
{
return
false
;
}
return
true
;
}
void
TestServer
::
Stop
()
{
if
(
threadId
!=
NULL
)
{
taosDestoryThread
(
threadId
);
threadId
=
NULL
;
}
if
(
pDnode
!=
NULL
)
{
dndCleanup
(
pDnode
);
pDnode
=
NULL
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录