tsdbTests.cpp 1.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

H
hzcheng 已提交
7
TEST(TsdbTest, createRepo) {
H
hzcheng 已提交
8
  STsdbCfg config;
H
hzcheng 已提交
9

H
hzcheng 已提交
10
  // 1. Create a tsdb repository
H
hzcheng 已提交
11 12
  tsdbSetDefaultCfg(&config);
  tsdb_repo_t *pRepo = tsdbCreateRepo("/home/ubuntu/work/ttest/vnode0", &config, NULL);
H
hzcheng 已提交
13 14
  ASSERT_NE(pRepo, nullptr);

H
hzcheng 已提交
15 16 17 18 19
  // 2. Create a normal table
  STableCfg tCfg;
  ASSERT_EQ(tsdbInitTableCfg(&tCfg, TSDB_SUPER_TABLE, 987607499877672L, 0), -1);
  ASSERT_EQ(tsdbInitTableCfg(&tCfg, TSDB_NTABLE, 987607499877672L, 0), 0);

H
hzcheng 已提交
20
  int       nCols = 5;
H
hzcheng 已提交
21 22
  STSchema *schema = tdNewSchema(nCols);

H
hzcheng 已提交
23
  for (int i = 0; i < nCols; i++) {
H
hzcheng 已提交
24 25 26 27 28 29
    if (i == 0) {
      tdSchemaAppendCol(schema, TSDB_DATA_TYPE_TIMESTAMP, i, -1);
    } else {
      tdSchemaAppendCol(schema, TSDB_DATA_TYPE_INT, i, -1);
    }
  }
H
hzcheng 已提交
30

H
hzcheng 已提交
31
  tsdbTableSetSchema(&tCfg, schema, true);
H
hzcheng 已提交
32

H
hzcheng 已提交
33
  tsdbCreateTable(pRepo, &tCfg);
H
hzcheng 已提交
34

H
hzcheng 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
  // // 3. Loop to write some simple data
  // int nRows = 10;
  // SSubmitMsg *pMsg = (SSubmitMsg *)malloc(sizeof(SSubmitMsg) + sizeof(SSubmitBlk) + tdMaxRowBytesFromSchema(schema) * nRows);

  // SSubmitBlk *pBlock = pMsg->blocks;
  // pBlock->tableId = {.uid = 987607499877672L, .tid = 0};
  // pBlock->sversion = 0;
  // pBlock->len = 0;
  // int64_t start_time = 1584081000000;
  // for (int i = 0; i < nRows; i++) {
  //   int64_t ttime = start_time + 1000 * i;
  //   SDataRow row = (SDataRow)(pBlock->data + pBlock->len);
  //   dataRowInit(row);

  //   for (int j; j < schemaNCols(schema); j++) {
  //     if (j == 0) { // Just for timestamp
  //       tdAppendColVal(row, (void *)(&time), schemaColAt(schema, i), );
  //     } else { // For int

  //     }
  //   }

  //   pBlock->len += dataRowLen(row);
H
hzcheng 已提交
58
  // }
H
hzcheng 已提交
59 60
}