From 46af79b90cd1d229e1733d16fa31b8727d9fe812 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 28 Apr 2022 09:55:31 +0800 Subject: [PATCH] test: add unitest for sdb --- source/dnode/mnode/impl/test/sdb/sdbTest.cpp | 47 +++++++++++++++++--- source/dnode/mnode/sdb/src/sdb.c | 2 +- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/source/dnode/mnode/impl/test/sdb/sdbTest.cpp b/source/dnode/mnode/impl/test/sdb/sdbTest.cpp index 21913375d6..4da414e274 100644 --- a/source/dnode/mnode/impl/test/sdb/sdbTest.cpp +++ b/source/dnode/mnode/impl/test/sdb/sdbTest.cpp @@ -23,6 +23,12 @@ class MndTestSdb : public ::testing::Test { void TearDown() override {} }; +typedef struct SMnode { + int32_t v100; + int32_t v200; + SSdb *pSdb; +} SMnode; + typedef struct SStrObj { char key[24]; int8_t v8; @@ -95,8 +101,39 @@ SSdbRaw *strDecode(SStrObj *pObj) { return pRaw; } +int32_t strInsert(SSdb *pSdb, SStrObj *pObj) { return 0; } + +int32_t strDelete(SSdb *pSdb, SStrObj *pObj, bool callFunc) { return 0; } + +int32_t strUpdate(SSdb *pSdb, SStrObj *pOld, SStrObj *pNew) { + pOld->v8 = pNew->v8; + pOld->v16 = pNew->v16; + pOld->v32 = pNew->v32; + pOld->v64 = pNew->v64; + return 0; +} + +int32_t strDefault(SMnode *pMnode) { + SStrObj strObj = {0}; + strcpy(strObj.key, "k1000"); + strObj.v8 = 1; + strObj.v16 = 1; + strObj.v32 = 1000; + strObj.v64 = 1000; + strcpy(strObj.vstr, "v1000"); + + SSdbRaw *pRaw = strEncode(&strObj); + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + return sdbWrite(pMnode->pSdb, pRaw); +} + TEST_F(MndTestSdb, 01_Basic) { + SMnode mnode; + mnode.v100 = 100; + mnode.v200 = 200; + SSdbOpt opt = {0}; + opt.pMnode = &mnode; opt.path = "/tmp/mnode_test_sdb"; SSdb *pSdb = sdbInit(&opt); @@ -106,11 +143,11 @@ TEST_F(MndTestSdb, 01_Basic) { .sdbType = SDB_USER, .keyType = SDB_KEY_BINARY, .deployFp = (SdbDeployFp)strEncode, - .encodeFp = (SdbEncodeFp)strDecode, - .decodeFp = (SdbDecodeFp)NULL, - .insertFp = (SdbInsertFp)NULL, - .updateFp = (SdbUpdateFp)NULL, - .deleteFp = (SdbDeleteFp)NULL, + .encodeFp = (SdbEncodeFp)strEncode, + .decodeFp = (SdbDecodeFp)strDecode, + .insertFp = (SdbInsertFp)strInsert, + .updateFp = (SdbUpdateFp)strDelete, + .deleteFp = (SdbDeleteFp)strUpdate, }; sdbSetTable(pSdb, strTable); diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index f85ff7a26e..d180271175 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -141,7 +141,7 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) { } static int32_t sdbCreateDir(SSdb *pSdb) { - if (taosMkDir(pSdb->currDir) != 0) { + if (taosMulMkDir(pSdb->currDir) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); mError("failed to create dir:%s since %s", pSdb->currDir, terrstr()); return -1; -- GitLab