From 75f9f415e607fffa34a8ae2e9c2f9aea0cb0a2fa Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Sat, 23 Jul 2022 16:05:34 +0800 Subject: [PATCH] refactor(sync): add entry cache test --- source/libs/sync/test/syncEntryCacheTest.cpp | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/source/libs/sync/test/syncEntryCacheTest.cpp b/source/libs/sync/test/syncEntryCacheTest.cpp index 66b93563e7..1b3d68f959 100644 --- a/source/libs/sync/test/syncEntryCacheTest.cpp +++ b/source/libs/sync/test/syncEntryCacheTest.cpp @@ -6,6 +6,7 @@ #include "syncRaftStore.h" #include "syncUtil.h" #include "tskiplist.h" +#include "tref.h" void logTest() { sTrace("--- sync log test: trace"); @@ -121,6 +122,37 @@ void test3() { raftEntryCacheLog2((char*)"==test3 write 10 entries==", pCache); } + + +static void freeObj(void* param) { + SSyncRaftEntry* pEntry = (SSyncRaftEntry*)param; + syncEntryLog2((char*)"freeObj: ", pEntry); + syncEntryDestory(pEntry); +} + +void test4() { + int32_t testRefId = taosOpenRef(200, freeObj); + + SSyncRaftEntry* pEntry = createEntry(10); + ASSERT(pEntry != NULL); + + int64_t rid = taosAddRef(testRefId, pEntry); + sTrace("rid: %ld", rid); + + do { + SSyncRaftEntry* pAcquireEntry = (SSyncRaftEntry*)taosAcquireRef(testRefId, rid); + syncEntryLog2((char*)"acquire: ", pAcquireEntry); + + taosAcquireRef(testRefId, rid); + taosAcquireRef(testRefId, rid); + + taosReleaseRef(testRefId, rid); + //taosReleaseRef(testRefId, rid); + } while (0); + + taosRemoveRef(testRefId, rid); +} + int main(int argc, char** argv) { gRaftDetailLog = true; tsAsyncLog = 0; @@ -130,5 +162,7 @@ int main(int argc, char** argv) { test2(); test3(); + //test4(); + return 0; }