add more code

This commit is contained in:
hzcheng 2020-03-05 08:22:41 +00:00
parent a04663b7ee
commit 4eedfc40d6
11 changed files with 71 additions and 76 deletions

View File

@ -6,4 +6,4 @@ add_subdirectory(tsdb)
enable_testing()
add_subdirectory(tests)
# add_subdirectory(tests)

View File

@ -1,3 +0,0 @@
add_subdirectory(common)
add_subdirectory(tsdb)

View File

@ -1,14 +0,0 @@
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
message(STATUS "COMMON: ${SOURCE_LIST}")
add_executable(commonTests ${SOURCE_LIST})
target_link_libraries(commonTests gtest gtest_main pthread common)
add_test(
NAME
unit
COMMAND
${CMAKE_CURRENT_BINARY_DIR}/commonTests
)

View File

@ -1,7 +0,0 @@
#include <gtest/gtest.h>
#include "dataformat.h"
TEST(commonDataTests, createDataRow) {
EXPECT_EQ(1, 2/2);
}

View File

@ -1,9 +0,0 @@
#include <gtest/gtest.h>
#include <stdlib.h>
#include <stdio.h>
#include "schema.h"
TEST(commonSchemaTests, createSchema) {
EXPECT_EQ(1, 2/2);
}

View File

@ -1,37 +0,0 @@
#include <gtest/gtest.h>
#include <stdlib.h>
#include "tsdb.h"
TEST(TsdbTest, createTsdbRepo) {
STsdbCfg *pCfg = tsdbCreateDefaultCfg();
tsdb_repo_t *pRepo = tsdbCreateRepo("/root/mnt/test/vnode0", pCfg, NULL);
tsdbFreeCfg(pCfg);
ASSERT_NE(pRepo, nullptr);
STableCfg config;
config.tableId.tid = 0;
config.tableId.uid = 10889498868728187539;
config.numOfCols = 2;
config.schema = (SSchema *)malloc(sizeof(SSchema) + sizeof(SColumn) * config.numOfCols);
config.schema->version = 0;
config.schema->numOfCols = 2;
config.schema->numOfTags = 0;
config.schema->colIdCounter = 1;
for (int i = 0; i < config.numOfCols; i++) {
SColumn *pCol = config.schema->columns + i;
pCol->type = TD_DATATYPE_BIGINT;
pCol->colId = config.schema->colIdCounter++;
pCol->offset = 10;
pCol->colName = strdup("col1");
}
config.tagValues = NULL;
tsdbCreateTable(pRepo, &config);
tsdbCloseRepo(pRepo);
}

View File

@ -8,4 +8,6 @@ target_include_directories(tsdb
PUBLIC "${CMAKE_SOURCE_DIR}/src/inc"
PUBLIC "${CMAKE_SOURCE_DIR}/src/util/inc"
PUBLIC "${CMAKE_SOURCE_DIR}/src/os/linux/inc"
)
)
add_subdirectory(tests)

View File

@ -116,6 +116,7 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg);
int32_t tsdbDropTableImpl(STsdbMeta *pMeta, STableId tableId);
STable *tsdbIsValidTableToInsert(STsdbMeta *pMeta, STableId tableId);
int32_t tsdbInsertRowToTableImpl(SSkipListNode *pNode, STable *pTable);
STable *tsdbGetTableByUid(STsdbMeta *pMeta, int64_t uid);
#ifdef __cplusplus
}

View File

@ -12,7 +12,6 @@
static int tsdbFreeTable(STable *pTable);
static int32_t tsdbCheckTableCfg(STableCfg *pCfg);
static STable *tsdbGetTableByUid(STsdbMeta *pMeta, int64_t uid);
static int tsdbAddTableToMeta(STsdbMeta *pMeta, STable *pTable);
static int tsdbAddTableIntoMap(STsdbMeta *pMeta, STable *pTable);
static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable);
@ -206,7 +205,7 @@ static int32_t tsdbCheckTableCfg(STableCfg *pCfg) {
return 0;
}
static STable *tsdbGetTableByUid(STsdbMeta *pMeta, int64_t uid) {
STable *tsdbGetTableByUid(STsdbMeta *pMeta, int64_t uid) {
return (STable *)taosGetDataFromHashTable(pMeta->tableMap, (char *)(&uid), sizeof(uid));
}

View File

@ -1,7 +1,5 @@
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
message(STATUS "TSDB: ${SOURCE_LIST}")
add_executable(tsdbTests ${SOURCE_LIST})
target_link_libraries(tsdbTests gtest gtest_main pthread tsdb)

View File

@ -0,0 +1,65 @@
#include <gtest/gtest.h>
#include <stdlib.h>
#include "tsdbMeta.h"
TEST(TsdbTest, createTable) {
STsdbMeta *pMeta = tsdbCreateMeta(100);
ASSERT_NE(pMeta, nullptr);
STableCfg config;
config.tableId.tid = 0;
config.tableId.uid = 98868728187539L;
config.numOfCols = 2;
config.schema = (SSchema *)malloc(sizeof(SSchema) + sizeof(SColumn) * config.numOfCols);
config.schema->version = 0;
config.schema->numOfCols = 2;
config.schema->numOfTags = 0;
config.schema->colIdCounter = 1;
for (int i = 0; i < config.numOfCols; i++) {
SColumn *pCol = config.schema->columns + i;
pCol->type = TD_DATATYPE_BIGINT;
pCol->colId = config.schema->colIdCounter++;
pCol->offset = 10;
pCol->colName = strdup("col1");
}
config.tagValues = nullptr;
tsdbCreateTableImpl(pMeta, &config), 0;
STable *pTable = tsdbGetTableByUid(pMeta, config.tableId.uid);
ASSERT_NE(pTable, nullptr);
}
TEST(TsdbTest, DISABLED_createTsdbRepo) {
STsdbCfg *pCfg = tsdbCreateDefaultCfg();
tsdb_repo_t *pRepo = tsdbCreateRepo("/root/mnt/test/vnode0", pCfg, NULL);
tsdbFreeCfg(pCfg);
ASSERT_NE(pRepo, nullptr);
STableCfg config;
config.tableId.tid = 0;
config.tableId.uid = 10889498868728187539;
config.numOfCols = 2;
config.schema = (SSchema *)malloc(sizeof(SSchema) + sizeof(SColumn) * config.numOfCols);
config.schema->version = 0;
config.schema->numOfCols = 2;
config.schema->numOfTags = 0;
config.schema->colIdCounter = 1;
for (int i = 0; i < config.numOfCols; i++) {
SColumn *pCol = config.schema->columns + i;
pCol->type = TD_DATATYPE_BIGINT;
pCol->colId = config.schema->colIdCounter++;
pCol->offset = 10;
pCol->colName = strdup("col1");
}
config.tagValues = NULL;
tsdbCreateTable(pRepo, &config);
tsdbCloseRepo(pRepo);
}