2021-12-12 15:02:34 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can use, redistribute, and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3
|
|
|
|
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
2021-12-20 03:02:08 +00:00
|
|
|
#include "stub.h"
|
2022-01-21 10:19:40 +00:00
|
|
|
|
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
|
#pragma GCC diagnostic ignored "-Wformat"
|
|
|
|
|
|
2022-03-03 16:04:57 +00:00
|
|
|
#include <addr_any.h>
|
2021-12-20 03:02:08 +00:00
|
|
|
|
2022-01-21 10:19:40 +00:00
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
|
|
2022-03-03 16:04:57 +00:00
|
|
|
#include "mockCatalog.h"
|
2021-12-13 09:54:45 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
void generateTestT1(MockCatalogService* mcs) {
|
2022-02-25 08:29:40 +00:00
|
|
|
ITableBuilder& builder = mcs->createTableBuilder("test", "t1", TSDB_NORMAL_TABLE, 6)
|
2021-12-13 09:54:45 +00:00
|
|
|
.setPrecision(TSDB_TIME_PRECISION_MILLI).setVgid(1).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
|
2022-02-25 08:29:40 +00:00
|
|
|
.addColumn("c1", TSDB_DATA_TYPE_INT).addColumn("c2", TSDB_DATA_TYPE_BINARY, 20).addColumn("c3", TSDB_DATA_TYPE_BIGINT)
|
|
|
|
|
.addColumn("c4", TSDB_DATA_TYPE_DOUBLE).addColumn("c5", TSDB_DATA_TYPE_DOUBLE);
|
2021-12-13 09:54:45 +00:00
|
|
|
builder.done();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void generateTestST1(MockCatalogService* mcs) {
|
2021-12-23 08:27:59 +00:00
|
|
|
ITableBuilder& builder = mcs->createTableBuilder("test", "st1", TSDB_SUPER_TABLE, 3, 2)
|
2021-12-13 09:54:45 +00:00
|
|
|
.setPrecision(TSDB_TIME_PRECISION_MILLI).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
|
2021-12-21 22:03:20 +00:00
|
|
|
.addTag("tag1", TSDB_DATA_TYPE_INT).addTag("tag2", TSDB_DATA_TYPE_BINARY, 20)
|
|
|
|
|
.addColumn("c1", TSDB_DATA_TYPE_INT).addColumn("c2", TSDB_DATA_TYPE_BINARY, 20);
|
2021-12-13 09:54:45 +00:00
|
|
|
builder.done();
|
2021-12-23 08:27:59 +00:00
|
|
|
mcs->createSubTable("test", "st1", "st1s1", 1);
|
|
|
|
|
mcs->createSubTable("test", "st1", "st1s2", 2);
|
2021-12-13 09:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-20 03:02:08 +00:00
|
|
|
int32_t __catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle) {
|
2021-12-22 05:39:11 +00:00
|
|
|
return 0;
|
2021-12-12 15:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-29 07:01:12 +00:00
|
|
|
int32_t __catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) {
|
|
|
|
|
return mockCatalogService->catalogGetTableMeta(pTableName, pTableMeta);
|
2021-12-22 05:39:11 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-29 07:01:12 +00:00
|
|
|
int32_t __catalogGetTableHashVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SVgroupInfo* vgInfo) {
|
|
|
|
|
return mockCatalogService->catalogGetTableHashVgroup(pTableName, vgInfo);
|
2021-12-12 15:02:34 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-04 14:48:15 +00:00
|
|
|
int32_t __catalogGetTableDistVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgList) {
|
|
|
|
|
return mockCatalogService->catalogGetTableDistVgInfo(pTableName, pVgList);
|
2022-03-05 23:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-19 20:46:54 +00:00
|
|
|
void initMetaDataEnv() {
|
|
|
|
|
mockCatalogService.reset(new MockCatalogService());
|
2021-12-20 03:02:08 +00:00
|
|
|
|
|
|
|
|
static Stub stub;
|
|
|
|
|
stub.set(catalogGetHandle, __catalogGetHandle);
|
|
|
|
|
stub.set(catalogGetTableMeta, __catalogGetTableMeta);
|
2021-12-22 05:39:11 +00:00
|
|
|
stub.set(catalogGetTableHashVgroup, __catalogGetTableHashVgroup);
|
2022-03-05 23:12:08 +00:00
|
|
|
stub.set(catalogGetTableDistVgInfo, __catalogGetTableDistVgInfo);
|
2021-12-20 03:02:08 +00:00
|
|
|
{
|
|
|
|
|
AddrAny any("libcatalog.so");
|
|
|
|
|
std::map<std::string,void*> result;
|
|
|
|
|
any.get_global_func_addr_dynsym("^catalogGetHandle$", result);
|
|
|
|
|
for (const auto& f : result) {
|
|
|
|
|
stub.set(f.second, __catalogGetHandle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
AddrAny any("libcatalog.so");
|
|
|
|
|
std::map<std::string,void*> result;
|
|
|
|
|
any.get_global_func_addr_dynsym("^catalogGetTableMeta$", result);
|
|
|
|
|
for (const auto& f : result) {
|
|
|
|
|
stub.set(f.second, __catalogGetTableMeta);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-22 05:39:11 +00:00
|
|
|
{
|
|
|
|
|
AddrAny any("libcatalog.so");
|
|
|
|
|
std::map<std::string,void*> result;
|
|
|
|
|
any.get_global_func_addr_dynsym("^catalogGetTableHashVgroup$", result);
|
|
|
|
|
for (const auto& f : result) {
|
|
|
|
|
stub.set(f.second, __catalogGetTableHashVgroup);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-05 23:12:08 +00:00
|
|
|
{
|
|
|
|
|
AddrAny any("libcatalog.so");
|
|
|
|
|
std::map<std::string,void*> result;
|
|
|
|
|
any.get_global_func_addr_dynsym("^catalogGetTableDistVgInfo$", result);
|
|
|
|
|
for (const auto& f : result) {
|
|
|
|
|
stub.set(f.second, __catalogGetTableDistVgInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-19 20:46:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void generateMetaData() {
|
|
|
|
|
generateTestT1(mockCatalogService.get());
|
|
|
|
|
generateTestST1(mockCatalogService.get());
|
|
|
|
|
mockCatalogService->showTables();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void destroyMetaDataEnv() {
|
|
|
|
|
mockCatalogService.reset();
|
2021-12-12 15:02:34 +00:00
|
|
|
}
|