Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7469d62f
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
7469d62f
编写于
3月 11, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync refactor
上级
a0a62227
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
385 addition
and
24 deletion
+385
-24
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+20
-4
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+125
-3
source/libs/sync/test/CMakeLists.txt
source/libs/sync/test/CMakeLists.txt
+38
-10
source/libs/sync/test/syncAppendEntriesReplyTest.cpp
source/libs/sync/test/syncAppendEntriesReplyTest.cpp
+96
-0
source/libs/sync/test/syncAppendEntriesTest.cpp
source/libs/sync/test/syncAppendEntriesTest.cpp
+98
-0
source/libs/sync/test/syncRequestVoteReplyTest.cpp
source/libs/sync/test/syncRequestVoteReplyTest.cpp
+8
-7
source/libs/sync/test/syncRequestVoteTest.cpp
source/libs/sync/test/syncRequestVoteTest.cpp
+0
-0
未找到文件。
source/libs/sync/inc/syncMessage.h
浏览文件 @
7469d62f
...
...
@@ -218,17 +218,23 @@ typedef struct SyncAppendEntries {
char
data
[];
}
SyncAppendEntries
;
#define SYNC_APPEND_ENTRIES_FIX_LEN \
(sizeof(uint32_t) + sizeof(uint32_t) + sizeof(SRaftId) + sizeof(SRaftId) + sizeof(SyncIndex) + sizeof(SyncTerm) + \
sizeof(SyncIndex) + sizeof(uint32_t))
SyncAppendEntries
*
syncAppendEntriesBuild
(
uint32_t
dataLen
);
void
syncAppendEntriesDestroy
(
SyncAppendEntries
*
pMsg
);
void
syncAppendEntriesSerialize
(
const
SyncAppendEntries
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncAppendEntriesDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncAppendEntries
*
pMsg
);
char
*
syncAppendEntriesSerialize2
(
const
SyncAppendEntries
*
pMsg
,
uint32_t
*
len
);
SyncAppendEntries
*
syncAppendEntriesDeserialize2
(
const
char
*
buf
,
uint32_t
len
);
void
syncAppendEntries2RpcMsg
(
const
SyncAppendEntries
*
pMsg
,
SRpcMsg
*
pRpcMsg
);
void
syncAppendEntriesFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncAppendEntries
*
pMsg
);
SyncAppendEntries
*
syncAppendEntriesFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
);
cJSON
*
syncAppendEntries2Json
(
const
SyncAppendEntries
*
pMsg
);
char
*
syncAppendEntries2Str
(
const
SyncAppendEntries
*
pMsg
);
// for debug ----------------------
void
syncAppendEntriesPrint
(
const
SyncAppendEntries
*
pMsg
);
void
syncAppendEntriesPrint2
(
char
*
s
,
const
SyncAppendEntries
*
pMsg
);
void
syncAppendEntriesLog
(
const
SyncAppendEntries
*
pMsg
);
void
syncAppendEntriesLog2
(
char
*
s
,
const
SyncAppendEntries
*
pMsg
);
// ---------------------------------------------
typedef
struct
SyncAppendEntriesReply
{
...
...
@@ -245,9 +251,19 @@ SyncAppendEntriesReply* syncAppendEntriesReplyBuild();
void
syncAppendEntriesReplyDestroy
(
SyncAppendEntriesReply
*
pMsg
);
void
syncAppendEntriesReplySerialize
(
const
SyncAppendEntriesReply
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncAppendEntriesReplyDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncAppendEntriesReply
*
pMsg
);
char
*
syncAppendEntriesReplySerialize2
(
const
SyncAppendEntriesReply
*
pMsg
,
uint32_t
*
len
);
SyncAppendEntriesReply
*
syncAppendEntriesReplyDeserialize2
(
const
char
*
buf
,
uint32_t
len
);
void
syncAppendEntriesReply2RpcMsg
(
const
SyncAppendEntriesReply
*
pMsg
,
SRpcMsg
*
pRpcMsg
);
void
syncAppendEntriesReplyFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncAppendEntriesReply
*
pMsg
);
SyncAppendEntriesReply
*
syncAppendEntriesReplyFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
);
cJSON
*
syncAppendEntriesReply2Json
(
const
SyncAppendEntriesReply
*
pMsg
);
char
*
syncAppendEntriesReply2Str
(
const
SyncAppendEntriesReply
*
pMsg
);
// for debug ----------------------
void
syncAppendEntriesReplyPrint
(
const
SyncAppendEntriesReply
*
pMsg
);
void
syncAppendEntriesReplyPrint2
(
char
*
s
,
const
SyncAppendEntriesReply
*
pMsg
);
void
syncAppendEntriesReplyLog
(
const
SyncAppendEntriesReply
*
pMsg
);
void
syncAppendEntriesReplyLog2
(
char
*
s
,
const
SyncAppendEntriesReply
*
pMsg
);
#ifdef __cplusplus
}
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
7469d62f
...
...
@@ -700,7 +700,7 @@ void syncRequestVoteReplyLog2(char* s, const SyncRequestVoteReply* pMsg) {
// ---- message process SyncAppendEntries----
SyncAppendEntries
*
syncAppendEntriesBuild
(
uint32_t
dataLen
)
{
uint32_t
bytes
=
SYNC_APPEND_ENTRIES_FIX_LEN
+
dataLen
;
uint32_t
bytes
=
sizeof
(
SyncAppendEntries
)
+
dataLen
;
SyncAppendEntries
*
pMsg
=
malloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
pMsg
->
bytes
=
bytes
;
...
...
@@ -723,7 +723,26 @@ void syncAppendEntriesSerialize(const SyncAppendEntries* pMsg, char* buf, uint32
void
syncAppendEntriesDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncAppendEntries
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
assert
(
len
==
pMsg
->
bytes
);
assert
(
pMsg
->
bytes
==
SYNC_APPEND_ENTRIES_FIX_LEN
+
pMsg
->
dataLen
);
assert
(
pMsg
->
bytes
==
sizeof
(
SyncAppendEntries
)
+
pMsg
->
dataLen
);
}
char
*
syncAppendEntriesSerialize2
(
const
SyncAppendEntries
*
pMsg
,
uint32_t
*
len
)
{
char
*
buf
=
malloc
(
pMsg
->
bytes
);
assert
(
buf
!=
NULL
);
syncAppendEntriesSerialize
(
pMsg
,
buf
,
pMsg
->
bytes
);
if
(
len
!=
NULL
)
{
*
len
=
pMsg
->
bytes
;
}
return
buf
;
}
SyncAppendEntries
*
syncAppendEntriesDeserialize2
(
const
char
*
buf
,
uint32_t
len
)
{
uint32_t
bytes
=
*
((
uint32_t
*
)
buf
);
SyncAppendEntries
*
pMsg
=
malloc
(
bytes
);
assert
(
pMsg
!=
NULL
);
syncAppendEntriesDeserialize
(
buf
,
len
,
pMsg
);
assert
(
len
==
pMsg
->
bytes
);
return
pMsg
;
}
void
syncAppendEntries2RpcMsg
(
const
SyncAppendEntries
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
...
...
@@ -738,6 +757,11 @@ void syncAppendEntriesFromRpcMsg(const SRpcMsg* pRpcMsg, SyncAppendEntries* pMsg
syncAppendEntriesDeserialize
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
pMsg
);
}
SyncAppendEntries
*
syncAppendEntriesFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
)
{
SyncAppendEntries
*
pMsg
=
syncAppendEntriesDeserialize2
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
return
pMsg
;
}
cJSON
*
syncAppendEntries2Json
(
const
SyncAppendEntries
*
pMsg
)
{
char
u64buf
[
128
];
...
...
@@ -785,13 +809,53 @@ cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) {
cJSON_AddStringToObject
(
pRoot
,
"commit_index"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"dataLen"
,
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
pMsg
->
data
);
char
*
s
;
s
=
syncUtilprintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
free
(
s
);
s
=
syncUtilprintBin2
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data2"
,
s
);
free
(
s
);
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncAppendEntries"
,
pRoot
);
return
pJson
;
}
char
*
syncAppendEntries2Str
(
const
SyncAppendEntries
*
pMsg
)
{
cJSON
*
pJson
=
syncAppendEntries2Json
(
pMsg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
// for debug ----------------------
void
syncAppendEntriesPrint
(
const
SyncAppendEntries
*
pMsg
)
{
char
*
serialized
=
syncAppendEntries2Str
(
pMsg
);
printf
(
"syncAppendEntriesPrint | len:%lu | %s
\n
"
,
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
syncAppendEntriesPrint2
(
char
*
s
,
const
SyncAppendEntries
*
pMsg
)
{
char
*
serialized
=
syncAppendEntries2Str
(
pMsg
);
printf
(
"syncAppendEntriesPrint2 | len:%lu | %s | %s
\n
"
,
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
syncAppendEntriesLog
(
const
SyncAppendEntries
*
pMsg
)
{
char
*
serialized
=
syncAppendEntries2Str
(
pMsg
);
sTrace
(
"syncAppendEntriesLog | len:%lu | %s"
,
strlen
(
serialized
),
serialized
);
free
(
serialized
);
}
void
syncAppendEntriesLog2
(
char
*
s
,
const
SyncAppendEntries
*
pMsg
)
{
char
*
serialized
=
syncAppendEntries2Str
(
pMsg
);
sTrace
(
"syncAppendEntriesLog2 | len:%lu | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
free
(
serialized
);
}
// ---- message process SyncAppendEntriesReply----
SyncAppendEntriesReply
*
syncAppendEntriesReplyBuild
()
{
uint32_t
bytes
=
sizeof
(
SyncAppendEntriesReply
);
...
...
@@ -818,6 +882,25 @@ void syncAppendEntriesReplyDeserialize(const char* buf, uint32_t len, SyncAppend
assert
(
len
==
pMsg
->
bytes
);
}
char
*
syncAppendEntriesReplySerialize2
(
const
SyncAppendEntriesReply
*
pMsg
,
uint32_t
*
len
)
{
char
*
buf
=
malloc
(
pMsg
->
bytes
);
assert
(
buf
!=
NULL
);
syncAppendEntriesReplySerialize
(
pMsg
,
buf
,
pMsg
->
bytes
);
if
(
len
!=
NULL
)
{
*
len
=
pMsg
->
bytes
;
}
return
buf
;
}
SyncAppendEntriesReply
*
syncAppendEntriesReplyDeserialize2
(
const
char
*
buf
,
uint32_t
len
)
{
uint32_t
bytes
=
*
((
uint32_t
*
)
buf
);
SyncAppendEntriesReply
*
pMsg
=
malloc
(
bytes
);
assert
(
pMsg
!=
NULL
);
syncAppendEntriesReplyDeserialize
(
buf
,
len
,
pMsg
);
assert
(
len
==
pMsg
->
bytes
);
return
pMsg
;
}
void
syncAppendEntriesReply2RpcMsg
(
const
SyncAppendEntriesReply
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
memset
(
pRpcMsg
,
0
,
sizeof
(
*
pRpcMsg
));
pRpcMsg
->
msgType
=
pMsg
->
msgType
;
...
...
@@ -830,6 +913,11 @@ void syncAppendEntriesReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncAppendEntriesR
syncAppendEntriesReplyDeserialize
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
pMsg
);
}
SyncAppendEntriesReply
*
syncAppendEntriesReplyFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
)
{
SyncAppendEntriesReply
*
pMsg
=
syncAppendEntriesReplyDeserialize2
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
return
pMsg
;
}
cJSON
*
syncAppendEntriesReply2Json
(
const
SyncAppendEntriesReply
*
pMsg
)
{
char
u64buf
[
128
];
...
...
@@ -874,4 +962,38 @@ cJSON* syncAppendEntriesReply2Json(const SyncAppendEntriesReply* pMsg) {
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncAppendEntriesReply"
,
pRoot
);
return
pJson
;
}
char
*
syncAppendEntriesReply2Str
(
const
SyncAppendEntriesReply
*
pMsg
)
{
cJSON
*
pJson
=
syncAppendEntriesReply2Json
(
pMsg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
// for debug ----------------------
void
syncAppendEntriesReplyPrint
(
const
SyncAppendEntriesReply
*
pMsg
)
{
char
*
serialized
=
syncAppendEntriesReply2Str
(
pMsg
);
printf
(
"syncAppendEntriesReplyPrint | len:%lu | %s
\n
"
,
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
syncAppendEntriesReplyPrint2
(
char
*
s
,
const
SyncAppendEntriesReply
*
pMsg
)
{
char
*
serialized
=
syncAppendEntriesReply2Str
(
pMsg
);
printf
(
"syncAppendEntriesReplyPrint2 | len:%lu | %s | %s
\n
"
,
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
syncAppendEntriesReplyLog
(
const
SyncAppendEntriesReply
*
pMsg
)
{
char
*
serialized
=
syncAppendEntriesReply2Str
(
pMsg
);
sTrace
(
"syncAppendEntriesReplyLog | len:%lu | %s"
,
strlen
(
serialized
),
serialized
);
free
(
serialized
);
}
void
syncAppendEntriesReplyLog2
(
char
*
s
,
const
SyncAppendEntriesReply
*
pMsg
)
{
char
*
serialized
=
syncAppendEntriesReply2Str
(
pMsg
);
sTrace
(
"syncAppendEntriesReplyLog2 | len:%lu | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
free
(
serialized
);
}
\ No newline at end of file
source/libs/sync/test/CMakeLists.txt
浏览文件 @
7469d62f
...
...
@@ -17,8 +17,10 @@ add_executable(syncVotesRespondTest "")
add_executable
(
syncIndexMgrTest
""
)
add_executable
(
syncLogStoreTest
""
)
add_executable
(
syncEntryTest
""
)
add_executable
(
syncRequestVote
""
)
add_executable
(
syncRequestVoteReply
""
)
add_executable
(
syncRequestVoteTest
""
)
add_executable
(
syncRequestVoteReplyTest
""
)
add_executable
(
syncAppendEntriesTest
""
)
add_executable
(
syncAppendEntriesReplyTest
""
)
target_sources
(
syncTest
...
...
@@ -97,13 +99,21 @@ target_sources(syncEntryTest
PRIVATE
"syncEntryTest.cpp"
)
target_sources
(
syncRequestVote
target_sources
(
syncRequestVote
Test
PRIVATE
"syncRequestVote.cpp"
"syncRequestVote
Test
.cpp"
)
target_sources
(
syncRequestVoteReply
target_sources
(
syncRequestVoteReply
Test
PRIVATE
"syncRequestVoteReply.cpp"
"syncRequestVoteReplyTest.cpp"
)
target_sources
(
syncAppendEntriesTest
PRIVATE
"syncAppendEntriesTest.cpp"
)
target_sources
(
syncAppendEntriesReplyTest
PRIVATE
"syncAppendEntriesReplyTest.cpp"
)
...
...
@@ -202,12 +212,22 @@ target_include_directories(syncEntryTest
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncRequestVote
target_include_directories
(
syncRequestVoteTest
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncRequestVoteReplyTest
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncAppendEntriesTest
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
sync
RequestVoteReply
target_include_directories
(
sync
AppendEntriesReplyTest
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
...
...
@@ -290,11 +310,19 @@ target_link_libraries(syncEntryTest
sync
gtest_main
)
target_link_libraries
(
syncRequestVote
target_link_libraries
(
syncRequestVoteTest
sync
gtest_main
)
target_link_libraries
(
syncRequestVoteReplyTest
sync
gtest_main
)
target_link_libraries
(
syncAppendEntriesTest
sync
gtest_main
)
target_link_libraries
(
sync
RequestVoteReply
target_link_libraries
(
sync
AppendEntriesReplyTest
sync
gtest_main
)
...
...
source/libs/sync/test/syncAppendEntriesReplyTest.cpp
0 → 100644
浏览文件 @
7469d62f
#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"
);
}
SyncAppendEntriesReply
*
createMsg
()
{
SyncAppendEntriesReply
*
pMsg
=
syncAppendEntriesReplyBuild
();
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
->
success
=
true
;
pMsg
->
matchIndex
=
77
;
}
void
test1
()
{
SyncAppendEntriesReply
*
pMsg
=
createMsg
();
syncAppendEntriesReplyPrint2
((
char
*
)
"test1:"
,
pMsg
);
syncAppendEntriesReplyDestroy
(
pMsg
);
}
void
test2
()
{
SyncAppendEntriesReply
*
pMsg
=
createMsg
();
uint32_t
len
=
pMsg
->
bytes
;
char
*
serialized
=
(
char
*
)
malloc
(
len
);
syncAppendEntriesReplySerialize
(
pMsg
,
serialized
,
len
);
SyncAppendEntriesReply
*
pMsg2
=
syncAppendEntriesReplyBuild
();
syncAppendEntriesReplyDeserialize
(
serialized
,
len
,
pMsg2
);
syncAppendEntriesReplyPrint2
((
char
*
)
"test2: syncAppendEntriesReplySerialize -> syncAppendEntriesReplyDeserialize "
,
pMsg2
);
free
(
serialized
);
syncAppendEntriesReplyDestroy
(
pMsg
);
syncAppendEntriesReplyDestroy
(
pMsg2
);
}
void
test3
()
{
SyncAppendEntriesReply
*
pMsg
=
createMsg
();
uint32_t
len
;
char
*
serialized
=
syncAppendEntriesReplySerialize2
(
pMsg
,
&
len
);
SyncAppendEntriesReply
*
pMsg2
=
syncAppendEntriesReplyDeserialize2
(
serialized
,
len
);
syncAppendEntriesReplyPrint2
((
char
*
)
"test3: syncAppendEntriesReplySerialize3 -> syncAppendEntriesReplyDeserialize2 "
,
pMsg2
);
free
(
serialized
);
syncAppendEntriesReplyDestroy
(
pMsg
);
syncAppendEntriesReplyDestroy
(
pMsg2
);
}
void
test4
()
{
SyncAppendEntriesReply
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
syncAppendEntriesReply2RpcMsg
(
pMsg
,
&
rpcMsg
);
SyncAppendEntriesReply
*
pMsg2
=
syncAppendEntriesReplyBuild
();
syncAppendEntriesReplyFromRpcMsg
(
&
rpcMsg
,
pMsg2
);
syncAppendEntriesReplyPrint2
((
char
*
)
"test4: syncAppendEntriesReply2RpcMsg -> syncAppendEntriesReplyFromRpcMsg "
,
pMsg2
);
syncAppendEntriesReplyDestroy
(
pMsg
);
syncAppendEntriesReplyDestroy
(
pMsg2
);
}
void
test5
()
{
SyncAppendEntriesReply
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
syncAppendEntriesReply2RpcMsg
(
pMsg
,
&
rpcMsg
);
SyncAppendEntriesReply
*
pMsg2
=
syncAppendEntriesReplyFromRpcMsg2
(
&
rpcMsg
);
syncAppendEntriesReplyPrint2
((
char
*
)
"test5: syncAppendEntriesReply2RpcMsg -> syncAppendEntriesReplyFromRpcMsg2 "
,
pMsg2
);
syncAppendEntriesReplyDestroy
(
pMsg
);
syncAppendEntriesReplyDestroy
(
pMsg2
);
}
int
main
()
{
// taosInitLog((char *)"syncTest.log", 100000, 10);
tsAsyncLog
=
0
;
sDebugFlag
=
143
+
64
;
logTest
();
test1
();
test2
();
test3
();
test4
();
test5
();
return
0
;
}
source/libs/sync/test/syncAppendEntriesTest.cpp
0 → 100644
浏览文件 @
7469d62f
#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
);
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
;
strcpy
(
pMsg
->
data
,
"hello world"
);
return
pMsg
;
}
void
test1
()
{
SyncAppendEntries
*
pMsg
=
createMsg
();
syncAppendEntriesPrint2
((
char
*
)
"test1:"
,
pMsg
);
syncAppendEntriesDestroy
(
pMsg
);
}
void
test2
()
{
SyncAppendEntries
*
pMsg
=
createMsg
();
uint32_t
len
=
pMsg
->
bytes
;
char
*
serialized
=
(
char
*
)
malloc
(
len
);
syncAppendEntriesSerialize
(
pMsg
,
serialized
,
len
);
SyncAppendEntries
*
pMsg2
=
syncAppendEntriesBuild
(
pMsg2
->
dataLen
);
syncAppendEntriesDeserialize
(
serialized
,
len
,
pMsg2
);
syncAppendEntriesPrint2
((
char
*
)
"test2: syncAppendEntriesSerialize -> syncAppendEntriesDeserialize "
,
pMsg2
);
free
(
serialized
);
syncAppendEntriesDestroy
(
pMsg
);
syncAppendEntriesDestroy
(
pMsg2
);
}
void
test3
()
{
SyncAppendEntries
*
pMsg
=
createMsg
();
uint32_t
len
;
char
*
serialized
=
syncAppendEntriesSerialize2
(
pMsg
,
&
len
);
SyncAppendEntries
*
pMsg2
=
syncAppendEntriesDeserialize2
(
serialized
,
len
);
syncAppendEntriesPrint2
((
char
*
)
"test3: syncAppendEntriesSerialize3 -> syncAppendEntriesDeserialize2 "
,
pMsg2
);
free
(
serialized
);
syncAppendEntriesDestroy
(
pMsg
);
syncAppendEntriesDestroy
(
pMsg2
);
}
void
test4
()
{
SyncAppendEntries
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
syncAppendEntries2RpcMsg
(
pMsg
,
&
rpcMsg
);
SyncAppendEntries
*
pMsg2
=
(
SyncAppendEntries
*
)
malloc
(
rpcMsg
.
contLen
);
syncAppendEntriesFromRpcMsg
(
&
rpcMsg
,
pMsg2
);
syncAppendEntriesPrint2
((
char
*
)
"test4: syncAppendEntries2RpcMsg -> syncAppendEntriesFromRpcMsg "
,
pMsg2
);
syncAppendEntriesDestroy
(
pMsg
);
syncAppendEntriesDestroy
(
pMsg2
);
}
void
test5
()
{
SyncAppendEntries
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
syncAppendEntries2RpcMsg
(
pMsg
,
&
rpcMsg
);
SyncAppendEntries
*
pMsg2
=
syncAppendEntriesFromRpcMsg2
(
&
rpcMsg
);
syncAppendEntriesPrint2
((
char
*
)
"test5: syncAppendEntries2RpcMsg -> syncAppendEntriesFromRpcMsg2 "
,
pMsg2
);
syncAppendEntriesDestroy
(
pMsg
);
syncAppendEntriesDestroy
(
pMsg2
);
}
int
main
()
{
// taosInitLog((char *)"syncTest.log", 100000, 10);
tsAsyncLog
=
0
;
sDebugFlag
=
143
+
64
;
logTest
();
test1
();
test2
();
test3
();
test4
();
test5
();
return
0
;
}
source/libs/sync/test/syncRequestVoteReply.cpp
→
source/libs/sync/test/syncRequestVoteReply
Test
.cpp
浏览文件 @
7469d62f
...
...
@@ -32,8 +32,8 @@ void test1() {
void
test2
()
{
SyncRequestVoteReply
*
pMsg
=
createMsg
();
uint32_t
len
=
pMsg
->
bytes
;
char
*
serialized
=
(
char
*
)
malloc
(
len
);
uint32_t
len
=
pMsg
->
bytes
;
char
*
serialized
=
(
char
*
)
malloc
(
len
);
syncRequestVoteReplySerialize
(
pMsg
,
serialized
,
len
);
SyncRequestVoteReply
*
pMsg2
=
syncRequestVoteReplyBuild
();
syncRequestVoteReplyDeserialize
(
serialized
,
len
,
pMsg2
);
...
...
@@ -46,10 +46,11 @@ void test2() {
void
test3
()
{
SyncRequestVoteReply
*
pMsg
=
createMsg
();
uint32_t
len
;
char
*
serialized
=
syncRequestVoteReplySerialize2
(
pMsg
,
&
len
);
uint32_t
len
;
char
*
serialized
=
syncRequestVoteReplySerialize2
(
pMsg
,
&
len
);
SyncRequestVoteReply
*
pMsg2
=
syncRequestVoteReplyDeserialize2
(
serialized
,
len
);
syncRequestVoteReplyPrint2
((
char
*
)
"test3: syncRequestVoteReplySerialize3 -> syncRequestVoteReplyDeserialize2 "
,
pMsg2
);
syncRequestVoteReplyPrint2
((
char
*
)
"test3: syncRequestVoteReplySerialize3 -> syncRequestVoteReplyDeserialize2 "
,
pMsg2
);
free
(
serialized
);
syncRequestVoteReplyDestroy
(
pMsg
);
...
...
@@ -58,7 +59,7 @@ void test3() {
void
test4
()
{
SyncRequestVoteReply
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
SRpcMsg
rpcMsg
;
syncRequestVoteReply2RpcMsg
(
pMsg
,
&
rpcMsg
);
SyncRequestVoteReply
*
pMsg2
=
syncRequestVoteReplyBuild
();
syncRequestVoteReplyFromRpcMsg
(
&
rpcMsg
,
pMsg2
);
...
...
@@ -70,7 +71,7 @@ void test4() {
void
test5
()
{
SyncRequestVoteReply
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
SRpcMsg
rpcMsg
;
syncRequestVoteReply2RpcMsg
(
pMsg
,
&
rpcMsg
);
SyncRequestVoteReply
*
pMsg2
=
syncRequestVoteReplyFromRpcMsg2
(
&
rpcMsg
);
syncRequestVoteReplyPrint2
((
char
*
)
"test5: syncRequestVoteReply2RpcMsg -> syncRequestVoteReplyFromRpcMsg2 "
,
pMsg2
);
...
...
source/libs/sync/test/syncRequestVote.cpp
→
source/libs/sync/test/syncRequestVote
Test
.cpp
浏览文件 @
7469d62f
文件已移动
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录