add sync store test
This commit is contained in:
parent
700287508a
commit
8b71c4f5af
|
@ -17,10 +17,10 @@
|
||||||
#include "cJSON.h"
|
#include "cJSON.h"
|
||||||
#include "sync.h"
|
#include "sync.h"
|
||||||
|
|
||||||
char *serialized;
|
FileFd raftStoreFd;
|
||||||
|
|
||||||
void testJson() {
|
void testJson() {
|
||||||
FileFd raftStoreFd = taosOpenFileReadWrite("raft.store");
|
raftStoreFd = taosOpenFileReadWrite("raft.store");
|
||||||
|
|
||||||
uint64_t currentTerm = 100;
|
uint64_t currentTerm = 100;
|
||||||
uint64_t voteFor = 200;
|
uint64_t voteFor = 200;
|
||||||
|
@ -29,16 +29,22 @@ void testJson() {
|
||||||
cJSON_AddNumberToObject(pRoot, "current_term", currentTerm);
|
cJSON_AddNumberToObject(pRoot, "current_term", currentTerm);
|
||||||
cJSON_AddNumberToObject(pRoot, "vote_for", voteFor);
|
cJSON_AddNumberToObject(pRoot, "vote_for", voteFor);
|
||||||
|
|
||||||
serialized = cJSON_Print(pRoot);
|
char *serialized = cJSON_Print(pRoot);
|
||||||
int len = strlen(serialized);
|
int len = strlen(serialized);
|
||||||
printf("serialized: %s \n", serialized);
|
printf("serialized: %s \n", serialized);
|
||||||
|
|
||||||
taosWriteFile(raftStoreFd, serialized, len);
|
taosWriteFile(raftStoreFd, serialized, len);
|
||||||
taosCloseFile(raftStoreFd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void testJson2() {
|
void testJson2() {
|
||||||
cJSON *pRoot = cJSON_Parse(serialized);
|
taosLSeekFile(raftStoreFd, 0, SEEK_SET);
|
||||||
|
|
||||||
|
char buf[128];
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
taosReadFile(raftStoreFd, buf, sizeof(buf));
|
||||||
|
printf("read file: %s \n", buf);
|
||||||
|
|
||||||
|
cJSON *pRoot = cJSON_Parse(buf);
|
||||||
|
|
||||||
cJSON *pCurrentTerm = cJSON_GetObjectItem(pRoot, "current_term");
|
cJSON *pCurrentTerm = cJSON_GetObjectItem(pRoot, "current_term");
|
||||||
uint64_t currentTerm = pCurrentTerm->valueint;
|
uint64_t currentTerm = pCurrentTerm->valueint;
|
||||||
|
@ -47,6 +53,8 @@ void testJson2() {
|
||||||
uint64_t voteFor = pVoteFor->valueint;
|
uint64_t voteFor = pVoteFor->valueint;
|
||||||
|
|
||||||
printf("read json: currentTerm:%lu, voteFor:%lu \n", currentTerm, voteFor);
|
printf("read json: currentTerm:%lu, voteFor:%lu \n", currentTerm, voteFor);
|
||||||
|
|
||||||
|
taosCloseFile(raftStoreFd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t currentTerm(SyncTerm *pCurrentTerm) { return 0; }
|
int32_t currentTerm(SyncTerm *pCurrentTerm) { return 0; }
|
||||||
|
|
Loading…
Reference in New Issue