mockCatalog.cpp 3.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * 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 "mockCatalog.h"

#include <iostream>

X
Xiaoyu Wang 已提交
20
#include "stub.h"
S
Shengliang Guan 已提交
21 22 23 24

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"

X
Xiaoyu Wang 已提交
25 26
#include "addr_any.h"

S
Shengliang Guan 已提交
27 28
#pragma GCC diagnostic pop

29 30 31
namespace {

void generateTestT1(MockCatalogService* mcs) {
X
Xiaoyu Wang 已提交
32
  ITableBuilder& builder = mcs->createTableBuilder("test", "t1", TSDB_NORMAL_TABLE, 6)
33
      .setPrecision(TSDB_TIME_PRECISION_MILLI).setVgid(1).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
X
Xiaoyu Wang 已提交
34 35
      .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);
36 37 38 39
  builder.done();
}

void generateTestST1(MockCatalogService* mcs) {
40
  ITableBuilder& builder = mcs->createTableBuilder("test", "st1", TSDB_SUPER_TABLE, 3, 2)
41
      .setPrecision(TSDB_TIME_PRECISION_MILLI).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
42 43
      .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);
44
  builder.done();
45 46
  mcs->createSubTable("test", "st1", "st1s1", 1);
  mcs->createSubTable("test", "st1", "st1s2", 2);
47 48 49 50
}

}

X
Xiaoyu Wang 已提交
51
int32_t __catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle) {
X
Xiaoyu Wang 已提交
52
  return 0;
53 54
}

H
Haojun Liao 已提交
55 56
int32_t __catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) {
  return mockCatalogService->catalogGetTableMeta(pTableName, pTableMeta);
X
Xiaoyu Wang 已提交
57 58
}

H
Haojun Liao 已提交
59 60
int32_t __catalogGetTableHashVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SVgroupInfo* vgInfo) {
  return mockCatalogService->catalogGetTableHashVgroup(pTableName, vgInfo);
61 62
}

63 64
void initMetaDataEnv() {
  mockCatalogService.reset(new MockCatalogService());
X
Xiaoyu Wang 已提交
65 66 67 68

  static Stub stub;
  stub.set(catalogGetHandle, __catalogGetHandle);
  stub.set(catalogGetTableMeta, __catalogGetTableMeta);
X
Xiaoyu Wang 已提交
69
  stub.set(catalogGetTableHashVgroup, __catalogGetTableHashVgroup);
X
Xiaoyu Wang 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
  {
    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);
    }
  }
X
Xiaoyu Wang 已提交
86 87 88 89 90 91 92 93
  {
    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);
    }
  }
94 95 96 97 98 99 100 101 102 103
}

void generateMetaData() {
  generateTestT1(mockCatalogService.get());
  generateTestST1(mockCatalogService.get());
  mockCatalogService->showTables();
}

void destroyMetaDataEnv() {
  mockCatalogService.reset();
104
}