Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
48bed202
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看板
提交
48bed202
编写于
3月 01, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync encode test
上级
d5732003
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
103 addition
and
19 deletion
+103
-19
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+5
-2
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+24
-17
source/libs/sync/test/CMakeLists.txt
source/libs/sync/test/CMakeLists.txt
+14
-0
source/libs/sync/test/syncEncodeTest.cpp
source/libs/sync/test/syncEncodeTest.cpp
+60
-0
未找到文件。
source/libs/sync/inc/syncMessage.h
浏览文件 @
48bed202
...
...
@@ -23,6 +23,7 @@ extern "C" {
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "cJSON.h"
#include "sync.h"
#include "syncRaftEntry.h"
#include "taosdef.h"
...
...
@@ -52,7 +53,7 @@ typedef struct SyncPing {
SRaftId
srcId
;
SRaftId
destId
;
uint32_t
dataLen
;
char
*
data
;
char
data
[]
;
}
SyncPing
;
#define SYNC_PING_FIX_LEN (sizeof(uint32_t) + sizeof(uint32_t) + sizeof(SRaftId) + sizeof(SRaftId) + sizeof(uint32_t))
...
...
@@ -63,7 +64,7 @@ typedef struct SyncPingReply {
SRaftId
srcId
;
SRaftId
destId
;
uint32_t
dataLen
;
char
*
data
;
char
data
[]
;
}
SyncPingReply
;
typedef
struct
SyncClientRequest
{
...
...
@@ -128,6 +129,8 @@ void syncPingDeserialize(const char* buf, uint32_t len, SyncPing* pSyncPing);
void
syncPing2RpcMsg
(
const
SyncPing
*
pSyncPing
,
SRpcMsg
*
pRpcMsg
);
cJSON
*
syncPing2Json
(
const
SyncPing
*
pSyncPing
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
48bed202
...
...
@@ -41,9 +41,11 @@ void syncPingSerialize(const SyncPing* pSyncPing, char* buf, uint32_t bufLen) {
}
void
syncPingDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncPing
*
pSyncPing
)
{
/*
uint32_t* pU32 = (uint32_t*)buf;
uint32_t bytes = *pU32;
pSyncPing = (SyncPing*)malloc(bytes);
*/
memcpy
(
pSyncPing
,
buf
,
len
);
assert
(
len
==
pSyncPing
->
bytes
);
assert
(
pSyncPing
->
bytes
==
SYNC_PING_FIX_LEN
+
pSyncPing
->
dataLen
);
...
...
@@ -60,23 +62,28 @@ void syncPing2RpcMsg(const SyncPing* pSyncPing, SRpcMsg* pRpcMsg) {
free
(
buf
);
}
/*
typedef struct SRaftId {
SyncNodeId addr; // typedef uint64_t SyncNodeId;
SyncGroupId vgId; // typedef int32_t SyncGroupId;
} SRaftId;
typedef struct SyncPing {
uint32_t bytes;
uint32_t msgType;
SRaftId srcId;
SRaftId destId;
uint32_t dataLen;
char* data;
} SyncPing;
*/
cJSON
*
syncPing2Json
(
const
SyncPing
*
pSyncPing
)
{
cJSON
*
pRoot
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
pRoot
,
"bytes"
,
pSyncPing
->
bytes
);
cJSON_AddNumberToObject
(
pRoot
,
"msgType"
,
pSyncPing
->
msgType
);
/*
cJSON
*
pSrcId
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
pSrcId
,
"addr"
,
pSyncPing
->
srcId
.
addr
);
cJSON_AddNumberToObject
(
pSrcId
,
"vgId"
,
pSyncPing
->
srcId
.
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"srcId"
,
pSrcId
);
cJSON
*
pDestId
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
pDestId
,
"addr"
,
pSyncPing
->
destId
.
addr
);
cJSON_AddNumberToObject
(
pDestId
,
"vgId"
,
pSyncPing
->
destId
.
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"srcId"
,
pDestId
);
cJSON_AddNumberToObject
(
pRoot
,
"dataLen"
,
pSyncPing
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
pSyncPing
->
data
);
return
pRoot
;
}
#if 0
void syncPingSerialize(const SyncPing* pSyncPing, char** ppBuf, uint32_t* bufLen) {
*bufLen = sizeof(SyncPing) + pSyncPing->dataLen;
*ppBuf = (char*)malloc(*bufLen);
...
...
@@ -144,4 +151,4 @@ void syncPingDeserialize(const char* buf, uint32_t len, SyncPing* pSyncPing) {
pStart = taosDecodeFixedU32(pStart, &u32);
pSyncPing->dataLen = u32;
}
*/
\ No newline at end of file
#endif
\ No newline at end of file
source/libs/sync/test/CMakeLists.txt
浏览文件 @
48bed202
add_executable
(
syncTest
""
)
add_executable
(
syncEnvTest
""
)
add_executable
(
syncPingTest
""
)
add_executable
(
syncEncodeTest
""
)
target_sources
(
syncTest
...
...
@@ -15,6 +16,10 @@ target_sources(syncPingTest
PRIVATE
"syncPingTest.cpp"
)
target_sources
(
syncEncodeTest
PRIVATE
"syncEncodeTest.cpp"
)
target_include_directories
(
syncTest
...
...
@@ -32,6 +37,11 @@ target_include_directories(syncPingTest
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncEncodeTest
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_link_libraries
(
syncTest
...
...
@@ -46,6 +56,10 @@ target_link_libraries(syncPingTest
sync
gtest_main
)
target_link_libraries
(
syncEncodeTest
sync
gtest_main
)
enable_testing
()
...
...
source/libs/sync/test/syncEncodeTest.cpp
0 → 100644
浏览文件 @
48bed202
#include <stdio.h>
#include "syncEnv.h"
#include "syncIO.h"
#include "syncInt.h"
#include "syncMessage.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"
);
}
#define PING_MSG_LEN 20
int
main
()
{
// taosInitLog((char*)"syncPingTest.log", 100000, 10);
tsAsyncLog
=
0
;
sDebugFlag
=
143
+
64
;
char
msg
[
PING_MSG_LEN
];
snprintf
(
msg
,
sizeof
(
msg
),
"%s"
,
"test ping"
);
SyncPing
*
pSyncPing
=
syncPingBuild
(
PING_MSG_LEN
);
pSyncPing
->
srcId
.
addr
=
1
;
pSyncPing
->
srcId
.
vgId
=
2
;
pSyncPing
->
destId
.
addr
=
3
;
pSyncPing
->
destId
.
vgId
=
4
;
memcpy
(
pSyncPing
->
data
,
msg
,
PING_MSG_LEN
);
{
cJSON
*
pJson
=
syncPing2Json
(
pSyncPing
);
char
*
serialized
=
cJSON_Print
(
pJson
);
printf
(
"SyncPing:
\n
%s
\n\n
"
,
serialized
);
free
(
serialized
);
cJSON_Delete
(
pJson
);
}
uint32_t
bufLen
=
pSyncPing
->
bytes
;
char
*
buf
=
(
char
*
)
malloc
(
bufLen
);
syncPingSerialize
(
pSyncPing
,
buf
,
bufLen
);
SyncPing
*
pSyncPing2
=
(
SyncPing
*
)
malloc
(
pSyncPing
->
bytes
);
syncPingDeserialize
(
buf
,
bufLen
,
pSyncPing2
);
{
cJSON
*
pJson
=
syncPing2Json
(
pSyncPing2
);
char
*
serialized
=
cJSON_Print
(
pJson
);
printf
(
"SyncPing2:
\n
%s
\n\n
"
,
serialized
);
free
(
serialized
);
cJSON_Delete
(
pJson
);
}
syncPingDestroy
(
pSyncPing
);
syncPingDestroy
(
pSyncPing2
);
free
(
buf
);
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录