提交 ac7a543b 编写于 作者: S Shengliang Guan

TD-10431 acct test

上级 c8a74657
# add_subdirectory(acct) add_subdirectory(acct)
# add_subdirectory(auth) # add_subdirectory(auth)
# add_subdirectory(balance) # add_subdirectory(balance)
# add_subdirectory(cluster) # add_subdirectory(cluster)
......
add_executable(dndTestAcct "") add_executable(dnode_test_acct "")
target_sources(dndTestAcct target_sources(dnode_test_acct
PRIVATE PRIVATE
"acct.cpp" "acct.cpp"
"../sut/deploy.cpp" "../sut/deploy.cpp"
) )
target_link_libraries( target_link_libraries(
dndTestAcct dnode_test_acct
PUBLIC dnode PUBLIC dnode
PUBLIC util PUBLIC util
PUBLIC os PUBLIC os
PUBLIC gtest_main PUBLIC gtest_main
) )
target_include_directories(dndTestAcct target_include_directories(dnode_test_acct
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt" "${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
...@@ -24,6 +24,6 @@ target_include_directories(dndTestAcct ...@@ -24,6 +24,6 @@ target_include_directories(dndTestAcct
enable_testing() enable_testing()
add_test( add_test(
NAME dndTestAcct NAME dnode_test_acct
COMMAND dndTestAcct COMMAND dnode_test_acct
) )
...@@ -17,24 +17,27 @@ ...@@ -17,24 +17,27 @@
class DndTestAcct : public ::testing::Test { class DndTestAcct : public ::testing::Test {
protected: protected:
void SetUp() override {} static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
void TearDown() override {} SServer* pServer = createServer(path, fqdn, port, firstEp);
ASSERT(pServer);
return pServer;
}
static void SetUpTestSuite() { static void SetUpTestSuite() {
const char* user = "root"; initLog("/tmp/tdlog");
const char* pass = "taosdata";
const char* path = "/tmp/dndTestAcct";
const char* fqdn = "localhost";
uint16_t port = 9520;
pServer = createServer(path, fqdn, port); const char* fqdn = "localhost";
ASSERT(pServer); const char* firstEp = "localhost:9012";
pClient = createClient(user, pass, fqdn, port); pServer = CreateServer("/tmp/dnode_test_user", fqdn, 9012, firstEp);
pClient = createClient("root", "taosdata", fqdn, 9012);
taosMsleep(300);
} }
static void TearDownTestSuite() { static void TearDownTestSuite() {
stopServer(pServer); stopServer(pServer);
dropClient(pClient); dropClient(pClient);
pServer = NULL;
pClient = NULL;
} }
static SServer* pServer; static SServer* pServer;
......
...@@ -182,7 +182,7 @@ SServer* DndTestDb::pServer; ...@@ -182,7 +182,7 @@ SServer* DndTestDb::pServer;
SClient* DndTestDb::pClient; SClient* DndTestDb::pClient;
int32_t DndTestDb::connId; int32_t DndTestDb::connId;
TEST_F(DndTestDb, ShowDb) { TEST_F(DndTestDb, 01_ShowDb) {
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 16); SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 16);
CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN - 1 + VARSTR_HEADER_SIZE, "name"); CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN - 1 + VARSTR_HEADER_SIZE, "name");
CheckSchema(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create time"); CheckSchema(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create time");
...@@ -204,7 +204,7 @@ TEST_F(DndTestDb, ShowDb) { ...@@ -204,7 +204,7 @@ TEST_F(DndTestDb, ShowDb) {
SendThenCheckShowRetrieveMsg(0); SendThenCheckShowRetrieveMsg(0);
} }
TEST_F(DndTestDb, CreateDb_01) { TEST_F(DndTestDb, 02_CreateDb) {
{ {
SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(sizeof(SCreateDbMsg)); SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(sizeof(SCreateDbMsg));
strcpy(pReq->db, "1.d1"); strcpy(pReq->db, "1.d1");
...@@ -258,65 +258,51 @@ TEST_F(DndTestDb, CreateDb_01) { ...@@ -258,65 +258,51 @@ TEST_F(DndTestDb, CreateDb_01) {
CheckInt8(0); // update CheckInt8(0); // update
} }
#if 0 TEST_F(DndTestDb, 03_AlterDb) {
TEST_F(DndTestDb, AlterUser_01) { {
SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(sizeof(SAlterUserMsg)); SAlterDbMsg* pReq = (SAlterDbMsg*)rpcMallocCont(sizeof(SAlterDbMsg));
strcpy(pReq->user, "u1"); strcpy(pReq->db, "1.d1");
strcpy(pReq->pass, "p2"); pReq->totalBlocks = htonl(12);
pReq->daysToKeep0 = htonl(300);
SRpcMsg rpcMsg = {0}; pReq->daysToKeep1 = htonl(400);
rpcMsg.pCont = pReq; pReq->daysToKeep2 = htonl(500);
rpcMsg.contLen = sizeof(SAlterUserMsg); pReq->fsyncPeriod = htonl(4000);
rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_USER; pReq->walLevel = 2;
pReq->quorum = 2;
sendMsg(pClient, &rpcMsg); pReq->cacheLastRow = 1;
SRpcMsg* pMsg = pClient->pRsp;
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
SendThenCheckShowRetrieveMsg(3);
CheckBinary("u1", TSDB_USER_LEN);
CheckBinary("root", TSDB_USER_LEN);
CheckBinary("u2", TSDB_USER_LEN);
CheckBinary("normal", 10);
CheckBinary("super", 10);
CheckBinary("normal", 10);
CheckTimestamp();
CheckTimestamp();
CheckTimestamp();
CheckBinary("root", TSDB_USER_LEN);
CheckBinary("root", TSDB_USER_LEN);
CheckBinary("root", TSDB_USER_LEN);
}
TEST_F(DndTestDb, DropUser_01) {
SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(sizeof(SDropUserMsg));
strcpy(pReq->user, "u1");
SRpcMsg rpcMsg = {0}; SRpcMsg rpcMsg = {0};
rpcMsg.pCont = pReq; rpcMsg.pCont = pReq;
rpcMsg.contLen = sizeof(SDropUserMsg); rpcMsg.contLen = sizeof(SAlterDbMsg);
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_USER; rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_DB;
sendMsg(pClient, &rpcMsg); sendMsg(pClient, &rpcMsg);
SRpcMsg* pMsg = pClient->pRsp; SRpcMsg* pMsg = pClient->pRsp;
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pMsg->code, 0);
}
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4); SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 16);
SendThenCheckShowRetrieveMsg(2); SendThenCheckShowRetrieveMsg(1);
CheckBinary("root", TSDB_USER_LEN); CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
CheckBinary("u2", TSDB_USER_LEN);
CheckBinary("super", 10);
CheckBinary("normal", 10);
CheckTimestamp();
CheckTimestamp(); CheckTimestamp();
CheckBinary("root", TSDB_USER_LEN); CheckInt16(1); // replica
CheckBinary("root", TSDB_USER_LEN); CheckInt16(2); // quorum
CheckInt16(10); // days
CheckBinary("300,400,500", 24); // days
CheckInt32(16); // cache
CheckInt32(12); // blocks
CheckInt32(100); // minrows
CheckInt32(4096); // maxrows
CheckInt8(2); // wallevel
CheckInt32(4000); // fsync
CheckInt8(2); // comp
CheckInt8(1); // cachelast
CheckBinary("ms", 3); // precision
CheckInt8(0); // update
} }
TEST_F(DndTestDb, RestartDnode) { TEST_F(DndTestDb, 04_RestartDnode) {
stopServer(pServer); stopServer(pServer);
pServer = NULL; pServer = NULL;
...@@ -328,16 +314,42 @@ TEST_F(DndTestDb, RestartDnode) { ...@@ -328,16 +314,42 @@ TEST_F(DndTestDb, RestartDnode) {
uInfo("all server is running"); uInfo("all server is running");
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4); SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 16);
SendThenCheckShowRetrieveMsg(2); SendThenCheckShowRetrieveMsg(1);
CheckBinary("root", TSDB_USER_LEN); CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
CheckBinary("u2", TSDB_USER_LEN);
CheckBinary("super", 10);
CheckBinary("normal", 10);
CheckTimestamp();
CheckTimestamp(); CheckTimestamp();
CheckBinary("root", TSDB_USER_LEN); CheckInt16(1); // replica
CheckBinary("root", TSDB_USER_LEN); CheckInt16(2); // quorum
CheckInt16(10); // days
CheckBinary("300,400,500", 24); // days
CheckInt32(16); // cache
CheckInt32(12); // blocks
CheckInt32(100); // minrows
CheckInt32(4096); // maxrows
CheckInt8(2); // wallevel
CheckInt32(4000); // fsync
CheckInt8(2); // comp
CheckInt8(1); // cachelast
CheckBinary("ms", 3); // precision
CheckInt8(0); // update
} }
#endif TEST_F(DndTestDb, 05_DropDb) {
\ No newline at end of file {
SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(sizeof(SAlterDbMsg));
strcpy(pReq->db, "1.d1");
SRpcMsg rpcMsg = {0};
rpcMsg.pCont = pReq;
rpcMsg.contLen = sizeof(SDropDbMsg);
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_DB;
sendMsg(pClient, &rpcMsg);
SRpcMsg* pMsg = pClient->pRsp;
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
}
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 16);
SendThenCheckShowRetrieveMsg(0);
}
\ No newline at end of file
...@@ -24,7 +24,7 @@ class DndTestDnode : public ::testing::Test { ...@@ -24,7 +24,7 @@ class DndTestDnode : public ::testing::Test {
} }
static void SetUpTestSuite() { static void SetUpTestSuite() {
initLog("/tmp/dnode_test_dnode"); initLog("/tmp/tdlog");
const char* fqdn = "localhost"; const char* fqdn = "localhost";
const char* firstEp = "localhost:9041"; const char* firstEp = "localhost:9041";
...@@ -188,7 +188,7 @@ SServer* DndTestDnode::pServer4; ...@@ -188,7 +188,7 @@ SServer* DndTestDnode::pServer4;
SServer* DndTestDnode::pServer5; SServer* DndTestDnode::pServer5;
SClient* DndTestDnode::pClient; SClient* DndTestDnode::pClient;
TEST_F(DndTestDnode, ShowDnode) { TEST_F(DndTestDnode, 01_ShowDnode) {
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7); SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
CheckSchema(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); CheckSchema(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
CheckSchema(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "end point"); CheckSchema(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "end point");
...@@ -208,7 +208,7 @@ TEST_F(DndTestDnode, ShowDnode) { ...@@ -208,7 +208,7 @@ TEST_F(DndTestDnode, ShowDnode) {
CheckBinary("", 24); CheckBinary("", 24);
} }
TEST_F(DndTestDnode, ConfigDnode_01) { TEST_F(DndTestDnode, 02_ConfigDnode) {
SCfgDnodeMsg* pReq = (SCfgDnodeMsg*)rpcMallocCont(sizeof(SCfgDnodeMsg)); SCfgDnodeMsg* pReq = (SCfgDnodeMsg*)rpcMallocCont(sizeof(SCfgDnodeMsg));
pReq->dnodeId = htonl(1); pReq->dnodeId = htonl(1);
strcpy(pReq->config, "ddebugflag 131"); strcpy(pReq->config, "ddebugflag 131");
...@@ -224,7 +224,7 @@ TEST_F(DndTestDnode, ConfigDnode_01) { ...@@ -224,7 +224,7 @@ TEST_F(DndTestDnode, ConfigDnode_01) {
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pMsg->code, 0);
} }
TEST_F(DndTestDnode, CreateDnode_01) { TEST_F(DndTestDnode, 03_CreateDnode) {
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg)); SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg));
strcpy(pReq->ep, "localhost:9042"); strcpy(pReq->ep, "localhost:9042");
...@@ -257,7 +257,7 @@ TEST_F(DndTestDnode, CreateDnode_01) { ...@@ -257,7 +257,7 @@ TEST_F(DndTestDnode, CreateDnode_01) {
CheckBinary("", 24); CheckBinary("", 24);
} }
TEST_F(DndTestDnode, DropDnode_01) { TEST_F(DndTestDnode, 04_DropDnode) {
SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(sizeof(SDropDnodeMsg)); SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(sizeof(SDropDnodeMsg));
pReq->dnodeId = htonl(2); pReq->dnodeId = htonl(2);
...@@ -282,7 +282,7 @@ TEST_F(DndTestDnode, DropDnode_01) { ...@@ -282,7 +282,7 @@ TEST_F(DndTestDnode, DropDnode_01) {
CheckBinary("", 24); CheckBinary("", 24);
} }
TEST_F(DndTestDnode, CreateDnode_02) { TEST_F(DndTestDnode, 05_CreateDnode) {
{ {
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg)); SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg));
strcpy(pReq->ep, "localhost:9043"); strcpy(pReq->ep, "localhost:9043");
...@@ -361,7 +361,7 @@ TEST_F(DndTestDnode, CreateDnode_02) { ...@@ -361,7 +361,7 @@ TEST_F(DndTestDnode, CreateDnode_02) {
CheckBinary("", 24); CheckBinary("", 24);
} }
TEST_F(DndTestDnode, RestartDnode_01) { TEST_F(DndTestDnode, 06_RestartDnode) {
uInfo("stop all server"); uInfo("stop all server");
stopServer(pServer1); stopServer(pServer1);
stopServer(pServer2); stopServer(pServer2);
......
...@@ -170,7 +170,7 @@ SServer* DndTestUser::pServer; ...@@ -170,7 +170,7 @@ SServer* DndTestUser::pServer;
SClient* DndTestUser::pClient; SClient* DndTestUser::pClient;
int32_t DndTestUser::connId; int32_t DndTestUser::connId;
TEST_F(DndTestUser, ShowUser) { TEST_F(DndTestUser, 01_ShowUser) {
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4); SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "name"); CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "name");
CheckSchema(1, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "privilege"); CheckSchema(1, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "privilege");
...@@ -184,7 +184,7 @@ TEST_F(DndTestUser, ShowUser) { ...@@ -184,7 +184,7 @@ TEST_F(DndTestUser, ShowUser) {
CheckBinary("root", TSDB_USER_LEN); CheckBinary("root", TSDB_USER_LEN);
} }
TEST_F(DndTestUser, CreateUser_01) { TEST_F(DndTestUser, 02_CreateUser) {
{ {
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(sizeof(SCreateUserMsg)); SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(sizeof(SCreateUserMsg));
strcpy(pReq->user, "u1"); strcpy(pReq->user, "u1");
...@@ -233,7 +233,7 @@ TEST_F(DndTestUser, CreateUser_01) { ...@@ -233,7 +233,7 @@ TEST_F(DndTestUser, CreateUser_01) {
CheckBinary("root", TSDB_USER_LEN); CheckBinary("root", TSDB_USER_LEN);
} }
TEST_F(DndTestUser, AlterUser_01) { TEST_F(DndTestUser, 03_AlterUser) {
SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(sizeof(SAlterUserMsg)); SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(sizeof(SAlterUserMsg));
strcpy(pReq->user, "u1"); strcpy(pReq->user, "u1");
strcpy(pReq->pass, "p2"); strcpy(pReq->pass, "p2");
...@@ -264,7 +264,7 @@ TEST_F(DndTestUser, AlterUser_01) { ...@@ -264,7 +264,7 @@ TEST_F(DndTestUser, AlterUser_01) {
CheckBinary("root", TSDB_USER_LEN); CheckBinary("root", TSDB_USER_LEN);
} }
TEST_F(DndTestUser, DropUser_01) { TEST_F(DndTestUser, 04_DropUser) {
SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(sizeof(SDropUserMsg)); SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(sizeof(SDropUserMsg));
strcpy(pReq->user, "u1"); strcpy(pReq->user, "u1");
...@@ -290,7 +290,7 @@ TEST_F(DndTestUser, DropUser_01) { ...@@ -290,7 +290,7 @@ TEST_F(DndTestUser, DropUser_01) {
CheckBinary("root", TSDB_USER_LEN); CheckBinary("root", TSDB_USER_LEN);
} }
TEST_F(DndTestUser, RestartDnode) { TEST_F(DndTestUser, 05_RestartDnode) {
stopServer(pServer); stopServer(pServer);
pServer = NULL; pServer = NULL;
......
...@@ -646,7 +646,6 @@ static int32_t mndProcessDropDbMsg(SMnodeMsg *pMsg) { ...@@ -646,7 +646,6 @@ static int32_t mndProcessDropDbMsg(SMnodeMsg *pMsg) {
mndReleaseDb(pMnode, pDb); mndReleaseDb(pMnode, pDb);
if (code != 0) { if (code != 0) {
terrno = code;
mError("db:%s, failed to drop since %s", pDrop->db, terrstr()); mError("db:%s, failed to drop since %s", pDrop->db, terrstr());
return code; return code;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册