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

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

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

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

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

  STable *pTable = tsdbGetTableByUid(pMeta, config.tableId.uid);
  ASSERT_NE(pTable, nullptr);
H
hzcheng 已提交
28 29
}

H
hzcheng 已提交
30
TEST(TsdbTest, createRepo) {
H
hzcheng 已提交
31 32
  STsdbCfg *pCfg = tsdbCreateDefaultCfg();

H
hzcheng 已提交
33
  // Create a tsdb repository
H
hzcheng 已提交
34 35 36 37
  tsdb_repo_t *pRepo = tsdbCreateRepo("/root/mnt/test/vnode0", pCfg, NULL);
  ASSERT_NE(pRepo, nullptr);
  tsdbFreeCfg(pCfg);

H
hzcheng 已提交
38
  // create a normal table in this repository
H
hzcheng 已提交
39 40 41 42 43
  STableCfg config;
  config.tableId.tid = 0;
  config.tableId.uid = 98868728187539L;
  config.numOfCols = 5;
  config.schema = tdNewSchema(config.numOfCols);
H
hzcheng 已提交
44
  STColumn *pCol = tdNewCol(TSDB_DATA_TYPE_TIMESTAMP, 0, 0);
H
hzcheng 已提交
45 46 47
  tdColCpy(schemaColAt(config.schema, 0), pCol);
  tdFreeCol(pCol);
  for (int i = 1; i < schemaNCols(config.schema); i++) {
H
hzcheng 已提交
48
    pCol = tdNewCol(TSDB_DATA_TYPE_BIGINT, i, 0);
H
hzcheng 已提交
49 50 51 52 53
    tdColCpy(schemaColAt(config.schema, i), pCol);
    tdFreeCol(pCol);
  }

  tsdbCreateTable(pRepo, &config);
H
hzcheng 已提交
54
  // Write some data
H
hzcheng 已提交
55

H
hzcheng 已提交
56
  // int32_t size = sizeof(SSubmitMsg) + sizeof(SSubmitBlock) + tdMaxRowDataBytes(config.schema) * 10 + sizeof(int32_t);
H
hzcheng 已提交
57

H
hzcheng 已提交
58
  // tdUpdateSchema(config.schema);
H
hzcheng 已提交
59

H
hzcheng 已提交
60 61
  // SSubmitMsg *pMsg = (SSubmitMsg *)malloc(size);
  // pMsg->numOfTables = 1;  // TODO: use api
H
hzcheng 已提交
62

H
hzcheng 已提交
63 64 65 66
  // SSubmitBlock *pBlock = (SSubmitBlock *)pMsg->data;
  // pBlock->tableId = {.uid = 98868728187539L, .tid = 0};
  // pBlock->sversion = 0;
  // pBlock->len = sizeof(SSubmitBlock);
H
hzcheng 已提交
67

H
hzcheng 已提交
68 69
  // SDataRows rows = pBlock->data;
  // dataRowsInit(rows);
H
hzcheng 已提交
70

H
hzcheng 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83
  // SDataRow row = tdNewDataRow(tdMaxRowDataBytes(config.schema));
  // int64_t ttime = 1583508800000;
  // for (int i = 0; i < 10; i++) {  // loop over rows
  //   ttime += (10000 * i);
  //   tdDataRowReset(row);
  //   for (int j = 0; j < schemaNCols(config.schema); j++) {
  //     if (j == 0) {  // set time stamp
  //       tdAppendColVal(row, (void *)(&ttime), schemaColAt(config.schema, j), 40);
  //     } else {       // set other fields
  //       int32_t val = 10;
  //       tdAppendColVal(row, (void *)(&val), schemaColAt(config.schema, j), 40);
  //     }
  //   }
H
hzcheng 已提交
84

H
hzcheng 已提交
85 86
  //   tdDataRowsAppendRow(rows, row);
  // }
H
hzcheng 已提交
87

H
hzcheng 已提交
88
  // tsdbInsertData(pRepo, pMsg);
H
hzcheng 已提交
89

H
hzcheng 已提交
90
  // tdFreeDataRow(row);
H
hzcheng 已提交
91 92

  tdFreeSchema(config.schema);
H
hzcheng 已提交
93
  tsdbDropRepo(pRepo);
H
hzcheng 已提交
94
}