Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
54dfc8cd
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看板
提交
54dfc8cd
编写于
10月 27, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh(sync): add test
上级
8b5d005d
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
133 addition
and
19 deletion
+133
-19
source/libs/sync/test/CMakeLists.txt
source/libs/sync/test/CMakeLists.txt
+14
-0
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
+1
-1
source/libs/sync/test/syncConfigChangeTest.cpp
source/libs/sync/test/syncConfigChangeTest.cpp
+1
-1
source/libs/sync/test/syncEncodeTest.cpp
source/libs/sync/test/syncEncodeTest.cpp
+1
-1
source/libs/sync/test/syncIndexTest.cpp
source/libs/sync/test/syncIndexTest.cpp
+1
-1
source/libs/sync/test/syncLocalCmdTest.cpp
source/libs/sync/test/syncLocalCmdTest.cpp
+100
-0
source/libs/sync/test/syncRaftIdCheck.cpp
source/libs/sync/test/syncRaftIdCheck.cpp
+1
-1
source/libs/sync/test/syncRaftLogTest3.cpp
source/libs/sync/test/syncRaftLogTest3.cpp
+8
-8
source/libs/sync/test/syncReplicateTest.cpp
source/libs/sync/test/syncReplicateTest.cpp
+1
-1
source/libs/sync/test/syncRespMgrTest.cpp
source/libs/sync/test/syncRespMgrTest.cpp
+3
-3
source/libs/sync/test/syncTestTool.cpp
source/libs/sync/test/syncTestTool.cpp
+2
-2
未找到文件。
source/libs/sync/test/CMakeLists.txt
浏览文件 @
54dfc8cd
...
...
@@ -59,6 +59,7 @@ add_executable(syncRestoreFromSnapshot "")
add_executable
(
syncRaftCfgIndexTest
""
)
add_executable
(
syncHeartbeatTest
""
)
add_executable
(
syncHeartbeatReplyTest
""
)
add_executable
(
syncLocalCmdTest
""
)
target_sources
(
syncTest
...
...
@@ -305,6 +306,10 @@ target_sources(syncHeartbeatReplyTest
PRIVATE
"syncHeartbeatReplyTest.cpp"
)
target_sources
(
syncLocalCmdTest
PRIVATE
"syncLocalCmdTest.cpp"
)
target_include_directories
(
syncTest
...
...
@@ -612,6 +617,11 @@ target_include_directories(syncHeartbeatReplyTest
"
${
TD_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncLocalCmdTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_link_libraries
(
syncTest
...
...
@@ -858,6 +868,10 @@ target_link_libraries(syncHeartbeatReplyTest
sync
gtest_main
)
target_link_libraries
(
syncLocalCmdTest
sync
gtest_main
)
enable_testing
()
...
...
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
浏览文件 @
54dfc8cd
...
...
@@ -270,7 +270,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) {
pMsg
->
msgType
=
9999
;
pMsg
->
contLen
=
256
;
pMsg
->
pCont
=
rpcMallocCont
(
pMsg
->
contLen
);
snprintf
((
char
*
)(
pMsg
->
pCont
),
pMsg
->
contLen
,
"value-myIndex:%u-%d-%d-"
PRId64
,
myIndex
,
i
,
count
,
snprintf
((
char
*
)(
pMsg
->
pCont
),
pMsg
->
contLen
,
"value-myIndex:%u-%d-%d-
%
"
PRId64
,
myIndex
,
i
,
count
,
taosGetTimestampMs
());
return
pMsg
;
}
...
...
source/libs/sync/test/syncConfigChangeTest.cpp
浏览文件 @
54dfc8cd
...
...
@@ -191,7 +191,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) {
pMsg
->
msgType
=
9999
;
pMsg
->
contLen
=
256
;
pMsg
->
pCont
=
rpcMallocCont
(
pMsg
->
contLen
);
snprintf
((
char
*
)(
pMsg
->
pCont
),
pMsg
->
contLen
,
"value-myIndex:%u-%d-%d-"
PRId64
,
myIndex
,
i
,
count
,
snprintf
((
char
*
)(
pMsg
->
pCont
),
pMsg
->
contLen
,
"value-myIndex:%u-%d-%d-
%
"
PRId64
,
myIndex
,
i
,
count
,
taosGetTimestampMs
());
return
pMsg
;
}
...
...
source/libs/sync/test/syncEncodeTest.cpp
浏览文件 @
54dfc8cd
...
...
@@ -186,7 +186,7 @@ int main(int argc, char **argv) {
int32_t
code
=
pSyncNode
->
pLogStore
->
syncLogGetEntry
(
pSyncNode
->
pLogStore
,
pEntry
->
index
,
&
pEntry
);
ASSERT
(
code
==
0
);
syncEntryLog2
((
char
*
)
"==pEntry
2=="
,
pEntry2
);
syncEntryLog2
((
char
*
)
"==pEntry
=="
,
pEntry
);
// step5
uint32_t
len
;
...
...
source/libs/sync/test/syncIndexTest.cpp
浏览文件 @
54dfc8cd
...
...
@@ -13,7 +13,7 @@ void print(SHashObj *pNextIndex) {
SRaftId
*
pRaftId
=
(
SRaftId
*
)
key
;
printf
(
"key:<"
PRIu64
", %d>, value:%"
PRIu64
"
\n
"
,
pRaftId
->
addr
,
pRaftId
->
vgId
,
*
p
);
printf
(
"key:<
%
"
PRIu64
", %d>, value:%"
PRIu64
"
\n
"
,
pRaftId
->
addr
,
pRaftId
->
vgId
,
*
p
);
p
=
(
uint64_t
*
)
taosHashIterate
(
pNextIndex
,
p
);
}
}
...
...
source/libs/sync/test/syncLocalCmdTest.cpp
0 → 100644
浏览文件 @
54dfc8cd
#include <gtest/gtest.h>
#include <stdio.h>
#include "syncIO.h"
#include "syncInt.h"
#include "syncMessage.h"
#include "syncUtil.h"
void
logTest
()
{
sTrace
(
"--- sync log test: trace"
);
sDebug
(
"--- sync log test: debug"
);
sInfo
(
"--- sync log test: info"
);
sWarn
(
"--- sync log test: warn"
);
sError
(
"--- sync log test: error"
);
sFatal
(
"--- sync log test: fatal"
);
}
SyncAppendEntries
*
createMsg
()
{
SyncAppendEntries
*
pMsg
=
syncAppendEntriesBuild
(
20
,
1000
);
pMsg
->
srcId
.
addr
=
syncUtilAddr2U64
(
"127.0.0.1"
,
1234
);
pMsg
->
srcId
.
vgId
=
100
;
pMsg
->
destId
.
addr
=
syncUtilAddr2U64
(
"127.0.0.1"
,
5678
);
pMsg
->
destId
.
vgId
=
100
;
pMsg
->
prevLogIndex
=
11
;
pMsg
->
prevLogTerm
=
22
;
pMsg
->
commitIndex
=
33
;
pMsg
->
privateTerm
=
44
;
strcpy
(
pMsg
->
data
,
"hello world"
);
return
pMsg
;
}
void
test1
()
{
SyncAppendEntries
*
pMsg
=
createMsg
();
syncAppendEntriesLog2
((
char
*
)
"test1:"
,
pMsg
);
syncAppendEntriesDestroy
(
pMsg
);
}
void
test2
()
{
SyncAppendEntries
*
pMsg
=
createMsg
();
uint32_t
len
=
pMsg
->
bytes
;
char
*
serialized
=
(
char
*
)
taosMemoryMalloc
(
len
);
syncAppendEntriesSerialize
(
pMsg
,
serialized
,
len
);
SyncAppendEntries
*
pMsg2
=
syncAppendEntriesBuild
(
pMsg
->
dataLen
,
1000
);
syncAppendEntriesDeserialize
(
serialized
,
len
,
pMsg2
);
syncAppendEntriesLog2
((
char
*
)
"test2: syncAppendEntriesSerialize -> syncAppendEntriesDeserialize "
,
pMsg2
);
taosMemoryFree
(
serialized
);
syncAppendEntriesDestroy
(
pMsg
);
syncAppendEntriesDestroy
(
pMsg2
);
}
void
test3
()
{
SyncAppendEntries
*
pMsg
=
createMsg
();
uint32_t
len
;
char
*
serialized
=
syncAppendEntriesSerialize2
(
pMsg
,
&
len
);
SyncAppendEntries
*
pMsg2
=
syncAppendEntriesDeserialize2
(
serialized
,
len
);
syncAppendEntriesLog2
((
char
*
)
"test3: syncAppendEntriesSerialize3 -> syncAppendEntriesDeserialize2 "
,
pMsg2
);
taosMemoryFree
(
serialized
);
syncAppendEntriesDestroy
(
pMsg
);
syncAppendEntriesDestroy
(
pMsg2
);
}
void
test4
()
{
SyncAppendEntries
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
syncAppendEntries2RpcMsg
(
pMsg
,
&
rpcMsg
);
SyncAppendEntries
*
pMsg2
=
(
SyncAppendEntries
*
)
taosMemoryMalloc
(
rpcMsg
.
contLen
);
syncAppendEntriesFromRpcMsg
(
&
rpcMsg
,
pMsg2
);
syncAppendEntriesLog2
((
char
*
)
"test4: syncAppendEntries2RpcMsg -> syncAppendEntriesFromRpcMsg "
,
pMsg2
);
rpcFreeCont
(
rpcMsg
.
pCont
);
syncAppendEntriesDestroy
(
pMsg
);
syncAppendEntriesDestroy
(
pMsg2
);
}
void
test5
()
{
SyncAppendEntries
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
syncAppendEntries2RpcMsg
(
pMsg
,
&
rpcMsg
);
SyncAppendEntries
*
pMsg2
=
syncAppendEntriesFromRpcMsg2
(
&
rpcMsg
);
syncAppendEntriesLog2
((
char
*
)
"test5: syncAppendEntries2RpcMsg -> syncAppendEntriesFromRpcMsg2 "
,
pMsg2
);
rpcFreeCont
(
rpcMsg
.
pCont
);
syncAppendEntriesDestroy
(
pMsg
);
syncAppendEntriesDestroy
(
pMsg2
);
}
int
main
()
{
tsAsyncLog
=
0
;
sDebugFlag
=
DEBUG_TRACE
+
DEBUG_SCREEN
+
DEBUG_FILE
;
logTest
();
test1
();
test2
();
test3
();
test4
();
test5
();
return
0
;
}
source/libs/sync/test/syncRaftIdCheck.cpp
浏览文件 @
54dfc8cd
...
...
@@ -15,7 +15,7 @@ int main(int argc, char** argv) {
char
host
[
128
];
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
printf
(
""
PRIu64
" -> %s:%d
\n
"
,
u64
,
host
,
port
);
printf
(
"
%
"
PRIu64
" -> %s:%d
\n
"
,
u64
,
host
,
port
);
}
else
if
(
argc
==
3
)
{
uint64_t
u64
;
...
...
source/libs/sync/test/syncRaftLogTest3.cpp
浏览文件 @
54dfc8cd
...
...
@@ -97,8 +97,8 @@ void test1() {
sTrace
(
"lastIndex: %"
PRId64
,
lastIndex
);
sTrace
(
"lastTerm: %"
PRIu64
,
lastTerm
);
sTrace
(
"syncStartIndex: %"
PRId64
,
syncStartIndex
);
sTrace
(
"
"
PRId64
"'s
preIndex: %"
PRId64
,
testIndex
,
preIndex
);
sTrace
(
"
"
PRId64
"'s
preTerm: %"
PRIu64
,
testIndex
,
preTerm
);
sTrace
(
"
testIndex: %"
PRId64
"
preIndex: %"
PRId64
,
testIndex
,
preIndex
);
sTrace
(
"
testIndex: %"
PRId64
"
preTerm: %"
PRIu64
,
testIndex
,
preTerm
);
if
(
gAssert
)
{
assert
(
lastIndex
==
-
1
);
...
...
@@ -170,8 +170,8 @@ void test2() {
SyncIndex
preIndex
=
syncNodeGetPreIndex
(
pSyncNode
,
i
);
SyncTerm
preTerm
=
syncNodeGetPreTerm
(
pSyncNode
,
i
);
sTrace
(
"
"
PRId64
"'s
preIndex: %"
PRId64
,
i
,
preIndex
);
sTrace
(
"
"
PRId64
"'s
preTerm: %"
PRIu64
,
i
,
preTerm
);
sTrace
(
"
i: %"
PRId64
"
preIndex: %"
PRId64
,
i
,
preIndex
);
sTrace
(
"
i: %"
PRId64
"
preTerm: %"
PRIu64
,
i
,
preTerm
);
if
(
gAssert
)
{
SyncIndex
preIndexArr
[
12
]
=
{
-
1
,
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
};
...
...
@@ -292,8 +292,8 @@ void test4() {
SyncIndex
preIndex
=
syncNodeGetPreIndex
(
pSyncNode
,
i
);
SyncTerm
preTerm
=
syncNodeGetPreTerm
(
pSyncNode
,
i
);
sTrace
(
"
"
PRId64
"'s
preIndex: %"
PRId64
,
i
,
preIndex
);
sTrace
(
"
"
PRId64
"'s
preTerm: %"
PRIu64
,
i
,
preTerm
);
sTrace
(
"
i: %"
PRId64
"
preIndex: %"
PRId64
,
i
,
preIndex
);
sTrace
(
"
i: %"
PRId64
"
preTerm: %"
PRIu64
,
i
,
preTerm
);
}
logStoreDestory
(
pLogStore
);
...
...
@@ -354,8 +354,8 @@ void test5() {
SyncIndex
preIndex
=
syncNodeGetPreIndex
(
pSyncNode
,
i
);
SyncTerm
preTerm
=
syncNodeGetPreTerm
(
pSyncNode
,
i
);
sTrace
(
"
"
PRId64
"'s
preIndex: %"
PRId64
,
i
,
preIndex
);
sTrace
(
"
"
PRId64
"'s
preTerm: %"
PRIu64
,
i
,
preTerm
);
sTrace
(
"
i: %"
PRId64
"
preIndex: %"
PRId64
,
i
,
preIndex
);
sTrace
(
"
i: %"
PRId64
"
preTerm: %"
PRIu64
,
i
,
preTerm
);
if
(
gAssert
)
{
SyncIndex
preIndexArr
[
12
]
=
{
9999
,
9999
,
9999
,
9999
,
9999
,
9999
,
5
,
6
,
7
,
8
,
9
,
10
};
...
...
source/libs/sync/test/syncReplicateTest.cpp
浏览文件 @
54dfc8cd
...
...
@@ -145,7 +145,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) {
pMsg
->
msgType
=
9999
;
pMsg
->
contLen
=
256
;
pMsg
->
pCont
=
rpcMallocCont
(
pMsg
->
contLen
);
snprintf
((
char
*
)(
pMsg
->
pCont
),
pMsg
->
contLen
,
"value-myIndex:%u-%d-%d-"
PRId64
,
myIndex
,
i
,
count
,
snprintf
((
char
*
)(
pMsg
->
pCont
),
pMsg
->
contLen
,
"value-myIndex:%u-%d-%d-
%
"
PRId64
,
myIndex
,
i
,
count
,
taosGetTimestampMs
());
return
pMsg
;
}
...
...
source/libs/sync/test/syncRespMgrTest.cpp
浏览文件 @
54dfc8cd
...
...
@@ -58,18 +58,18 @@ void syncRespMgrGetTest(uint64_t i) {
if
(
ret
==
1
)
{
printStub
(
&
stub
);
}
else
if
(
ret
==
0
)
{
printf
(
""
PRId64
" notFound
\n
"
,
i
);
printf
(
"
%
"
PRId64
" notFound
\n
"
,
i
);
}
}
void
syncRespMgrGetAndDelTest
(
uint64_t
i
)
{
printf
(
"------syncRespMgrGetAndDelTest-------"
PRIu64
"--
\n
"
,
i
);
printf
(
"------syncRespMgrGetAndDelTest-------
%
"
PRIu64
"--
\n
"
,
i
);
SRespStub
stub
;
int32_t
ret
=
syncRespMgrGetAndDel
(
pMgr
,
i
,
&
stub
);
if
(
ret
==
1
)
{
printStub
(
&
stub
);
}
else
if
(
ret
==
0
)
{
printf
(
""
PRId64
" notFound
\n
"
,
i
);
printf
(
"
%
"
PRId64
" notFound
\n
"
,
i
);
}
}
...
...
source/libs/sync/test/syncTestTool.cpp
浏览文件 @
54dfc8cd
...
...
@@ -154,7 +154,7 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_
void
RestoreFinishCb
(
struct
SSyncFSM
*
pFsm
)
{
sTrace
(
"==callback== ==RestoreFinishCb== pFsm:%p"
,
pFsm
);
}
void
ReConfigCb
(
struct
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SReConfigCbMeta
*
cbMeta
)
{
char
*
s
=
syncCfg2Str
(
&
(
cbMeta
.
newCfg
));
char
*
s
=
syncCfg2Str
(
&
(
cbMeta
->
newCfg
));
sTrace
(
"==callback== ==ReConfigCb== flag:0x%lX, index:%"
PRId64
", code:%d, currentTerm:%"
PRIu64
", term:%"
PRIu64
", newCfg:%s"
,
cbMeta
->
flag
,
cbMeta
->
index
,
cbMeta
->
code
,
cbMeta
->
currentTerm
,
cbMeta
->
term
,
s
);
...
...
@@ -308,7 +308,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) {
pMsg
->
msgType
=
TDMT_VND_SUBMIT
;
pMsg
->
contLen
=
256
;
pMsg
->
pCont
=
rpcMallocCont
(
pMsg
->
contLen
);
snprintf
((
char
*
)(
pMsg
->
pCont
),
pMsg
->
contLen
,
"value-myIndex:%u-%d-%d-"
PRId64
,
myIndex
,
i
,
count
,
snprintf
((
char
*
)(
pMsg
->
pCont
),
pMsg
->
contLen
,
"value-myIndex:%u-%d-%d-
%
"
PRId64
,
myIndex
,
i
,
count
,
taosGetTimestampMs
());
return
pMsg
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录