tsdbTests.cpp 1.5 KB
Newer Older
H
hzcheng 已提交
1 2 3
#include <gtest/gtest.h>
#include <stdlib.h>

H
hzcheng 已提交
4
#include "tsdb.h"
H
hzcheng 已提交
5 6
#include "tsdbMeta.h"

H
hzcheng 已提交
7
TEST(TsdbTest, createTable)  {
H
hzcheng 已提交
8 9 10 11 12 13
    STsdbMeta *pMeta = tsdbCreateMeta(100);
    ASSERT_NE(pMeta, nullptr);

    STableCfg config;
    config.tableId.tid = 0;
    config.tableId.uid = 98868728187539L;
H
hzcheng 已提交
14 15 16 17 18 19
    config.numOfCols = 5;
    config.schema = tdNewSchema(config.numOfCols);
    for (int i = 0; i < schemaNCols(config.schema); i++) {
      SColumn *pCol = tdNewCol(TD_DATATYPE_BIGINT, i, 0);
      tdColCpy(schemaColAt(config.schema, i), pCol);
      tdFreeCol(pCol);
H
hzcheng 已提交
20 21 22
    }
    config.tagValues = nullptr;

H
hzcheng 已提交
23
    tsdbCreateTableImpl(pMeta, &config);
H
hzcheng 已提交
24 25 26

    STable *pTable = tsdbGetTableByUid(pMeta, config.tableId.uid);
    ASSERT_NE(pTable, nullptr);
H
hzcheng 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
}

TEST(TsdbTest, createRepo)  {
  STsdbCfg *pCfg = tsdbCreateDefaultCfg();

  tsdb_repo_t *pRepo = tsdbCreateRepo("/root/mnt/test/vnode0", pCfg, NULL);
  ASSERT_NE(pRepo, nullptr);
  tsdbFreeCfg(pCfg);

  STableCfg config;
  config.tableId.tid = 0;
  config.tableId.uid = 98868728187539L;
  config.numOfCols = 5;
  config.schema = tdNewSchema(config.numOfCols);
  SColumn *pCol = tdNewCol(TD_DATATYPE_TIMESTAMP, 0, 0);
  tdColCpy(schemaColAt(config.schema, 0), pCol);
  tdFreeCol(pCol);
  for (int i = 1; i < schemaNCols(config.schema); i++) {
    pCol = tdNewCol(TD_DATATYPE_BIGINT, i, 0);
    tdColCpy(schemaColAt(config.schema, i), pCol);
    tdFreeCol(pCol);
  }

  tsdbCreateTable(pRepo, &config);
  tdFreeSchema(config.schema);

  tsdbDropRepo(pRepo);
H
hzcheng 已提交
54
}