metaTests.cpp 2.5 KB
Newer Older
H
refact  
Hongze Cheng 已提交
1
#include <gtest/gtest.h>
H
Hongze Cheng 已提交
2
#include <string.h>
H
refact  
Hongze Cheng 已提交
3 4 5 6
#include <iostream>

#include "meta.h"

H
more  
Hongze Cheng 已提交
7 8
static STSchema *metaGetSimpleSchema() {
  STSchema *      pSchema = NULL;
H
more  
Hongze Cheng 已提交
9
  STSchemaBuilder sb = {0};
H
more  
Hongze Cheng 已提交
10 11 12 13 14 15 16 17 18 19 20

  tdInitTSchemaBuilder(&sb, 0);
  tdAddColToSchema(&sb, TSDB_DATA_TYPE_TIMESTAMP, 0, 8);
  tdAddColToSchema(&sb, TSDB_DATA_TYPE_INT, 1, 4);

  pSchema = tdGetSchemaFromBuilder(&sb);
  tdDestroyTSchemaBuilder(&sb);

  return pSchema;
}

H
more  
Hongze Cheng 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
static SKVRow metaGetSimpleTags() {
  SKVRowBuilder kvrb = {0};
  SKVRow        row;

  tdInitKVRowBuilder(&kvrb);
  int64_t ts = 1634287978000;
  int32_t a = 10;

  tdAddColToKVRow(&kvrb, 0, TSDB_DATA_TYPE_TIMESTAMP, (void *)(&ts));
  tdAddColToKVRow(&kvrb, 0, TSDB_DATA_TYPE_INT, (void *)(&a));

  row = tdGetKVRowFromBuilder(&kvrb);

  tdDestroyKVRowBuilder(&kvrb);

  return row;
}

TEST(MetaTest, DISABLED_meta_create_1m_normal_tables_test) {
H
Hongze Cheng 已提交
40
  // Open Meta
H
Hongze Cheng 已提交
41 42 43
  SMeta *meta = metaOpen(NULL);
  std::cout << "Meta is opened!" << std::endl;

H
more  
Hongze Cheng 已提交
44
  // Create 1000000 normal tables
H
more  
Hongze Cheng 已提交
45
  META_TABLE_OPTS_DECLARE(tbOpts);
H
more  
Hongze Cheng 已提交
46 47
  STSchema *pSchema = metaGetSimpleSchema();
  char      tbname[128];
H
Hongze Cheng 已提交
48

H
more  
Hongze Cheng 已提交
49 50 51
  for (size_t i = 0; i < 1000000; i++) {
    sprintf(tbname, "ntb%ld", i);
    metaNormalTableOptsInit(&tbOpts, tbname, pSchema);
H
more  
Hongze Cheng 已提交
52
    metaCreateTable(meta, &tbOpts);
H
more  
Hongze Cheng 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    metaTableOptsClear(&tbOpts);
  }

  tdFreeSchema(pSchema);

  // Close Meta
  metaClose(meta);
  std::cout << "Meta is closed!" << std::endl;

  // Destroy Meta
  metaDestroy("meta");
  std::cout << "Meta is destroyed!" << std::endl;
}

TEST(MetaTest, meta_create_1m_child_tables_test) {
  // Open Meta
  SMeta *meta = metaOpen(NULL);
  std::cout << "Meta is opened!" << std::endl;

  // Create a super tables
  tb_uid_t uid = 477529885843758ul;
  META_TABLE_OPTS_DECLARE(tbOpts);
  STSchema *pSchema = metaGetSimpleSchema();
  STSchema *pTagSchema = metaGetSimpleSchema();

  metaSuperTableOptsInit(&tbOpts, "st", uid, pSchema, pTagSchema);
  metaCreateTable(meta, &tbOpts);
  metaTableOptsClear(&tbOpts);

  tdFreeSchema(pSchema);
  tdFreeSchema(pTagSchema);

  // Create 1000000 child tables
  char   name[128];
  SKVRow row = metaGetSimpleTags();
  for (size_t i = 0; i < 1000000; i++) {
    sprintf(name, "ctb%ld", i);
    metaChildTableOptsInit(&tbOpts, name, uid, row);
    metaCreateTable(meta, &tbOpts);
    metaTableOptsClear(&tbOpts);
H
more  
Hongze Cheng 已提交
93
  }
H
more  
Hongze Cheng 已提交
94
  kvRowFree(row);
H
Hongze Cheng 已提交
95 96

  // Close Meta
H
Hongze Cheng 已提交
97 98
  metaClose(meta);
  std::cout << "Meta is closed!" << std::endl;
H
more  
Hongze Cheng 已提交
99

H
more  
Hongze Cheng 已提交
100 101 102
  // Destroy Meta
  metaDestroy("meta");
  std::cout << "Meta is destroyed!" << std::endl;
H
refact  
Hongze Cheng 已提交
103
}