Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d7a3a975
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d7a3a975
编写于
6月 30, 2021
作者:
W
wpan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
restore files
上级
45cd731d
变更
7
展开全部
显示空白变更内容
内联
并排
Showing
7 changed file
with
1804 addition
and
6 deletion
+1804
-6
src/query/tests/CMakeLists.txt
src/query/tests/CMakeLists.txt
+6
-6
src/query/tests/astTest.cpp
src/query/tests/astTest.cpp
+635
-0
src/query/tests/histogramTest.cpp
src/query/tests/histogramTest.cpp
+142
-0
src/query/tests/patternMatchTest.cpp
src/query/tests/patternMatchTest.cpp
+86
-0
src/query/tests/percentileTest.cpp
src/query/tests/percentileTest.cpp
+257
-0
src/query/tests/resultBufferTest.cpp
src/query/tests/resultBufferTest.cpp
+163
-0
src/query/tests/tsBufTest.cpp
src/query/tests/tsBufTest.cpp
+515
-0
未找到文件。
src/query/tests/CMakeLists.txt
浏览文件 @
d7a3a975
...
...
@@ -20,10 +20,10 @@ IF (HEADER_GTEST_INCLUDE_DIR AND LIB_GTEST_STATIC_DIR)
TARGET_LINK_LIBRARIES
(
queryTest taos query gtest pthread
)
ENDIF
()
#
SET_SOURCE_FILES_PROPERTIES(./astTest.cpp PROPERTIES COMPILE_FLAGS -w)
#
SET_SOURCE_FILES_PROPERTIES(./histogramTest.cpp PROPERTIES COMPILE_FLAGS -w)
#
SET_SOURCE_FILES_PROPERTIES(./percentileTest.cpp PROPERTIES COMPILE_FLAGS -w)
#
SET_SOURCE_FILES_PROPERTIES(./resultBufferTest.cpp PROPERTIES COMPILE_FLAGS -w)
#
SET_SOURCE_FILES_PROPERTIES(./tsBufTest.cpp PROPERTIES COMPILE_FLAGS -w)
#
SET_SOURCE_FILES_PROPERTIES(./unitTest.cpp PROPERTIES COMPILE_FLAGS -w)
SET_SOURCE_FILES_PROPERTIES
(
./astTest.cpp PROPERTIES COMPILE_FLAGS -w
)
SET_SOURCE_FILES_PROPERTIES
(
./histogramTest.cpp PROPERTIES COMPILE_FLAGS -w
)
SET_SOURCE_FILES_PROPERTIES
(
./percentileTest.cpp PROPERTIES COMPILE_FLAGS -w
)
SET_SOURCE_FILES_PROPERTIES
(
./resultBufferTest.cpp PROPERTIES COMPILE_FLAGS -w
)
SET_SOURCE_FILES_PROPERTIES
(
./tsBufTest.cpp PROPERTIES COMPILE_FLAGS -w
)
SET_SOURCE_FILES_PROPERTIES
(
./unitTest.cpp PROPERTIES COMPILE_FLAGS -w
)
SET_SOURCE_FILES_PROPERTIES
(
./rangeMergeTest.cpp PROPERTIES COMPILE_FLAGS -w
)
src/query/tests/astTest.cpp
0 → 100644
浏览文件 @
d7a3a975
此差异已折叠。
点击以展开。
src/query/tests/histogramTest.cpp
0 → 100644
浏览文件 @
d7a3a975
#include <gtest/gtest.h>
#include <sys/time.h>
#include <cassert>
#include <iostream>
#include "taos.h"
#include "qHistogram.h"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
namespace
{
void
doHistogramAddTest
()
{
SHistogramInfo
*
pHisto
=
NULL
;
/**
* use arrayList, elapsed time is:
* before:
* 10,000,000 45sec, bin:1000 (-O0) / 17sec. bin:1000, (-O3)
*
* after:
*
*/
struct
timeval
systemTime
;
gettimeofday
(
&
systemTime
,
NULL
);
int64_t
st
=
(
int64_t
)
systemTime
.
tv_sec
*
1000L
+
(
uint64_t
)
systemTime
.
tv_usec
/
1000
;
for
(
int32_t
i
=
0
;
i
<
10000
;
++
i
)
{
tHistogramAdd
(
&
pHisto
,
i
);
// tHistogramPrint(pHisto);
}
//
gettimeofday
(
&
systemTime
,
NULL
);
int64_t
et
=
(
int64_t
)
systemTime
.
tv_sec
*
1000L
+
(
uint64_t
)
systemTime
.
tv_usec
/
1000
;
printf
(
"total elapsed time: %ld
\n
"
,
et
-
st
);
printf
(
"elements: %d, slot:%d
\n
"
,
pHisto
->
numOfElems
,
pHisto
->
numOfEntries
);
tHistogramPrint
(
pHisto
);
printf
(
"%ld
\n
"
,
tHistogramSum
(
pHisto
,
1.5
));
printf
(
"%ld
\n
"
,
tHistogramSum
(
pHisto
,
2
));
printf
(
"%ld
\n
"
,
tHistogramSum
(
pHisto
,
3
));
printf
(
"%ld
\n
"
,
tHistogramSum
(
pHisto
,
4
));
printf
(
"%ld
\n
"
,
tHistogramSum
(
pHisto
,
5
));
printf
(
"%ld
\n
"
,
tHistogramSum
(
pHisto
,
6
));
for
(
int32_t
i
=
399
;
i
<
400
;
++
i
)
{
printf
(
"val:%d, %ld
\n
"
,
i
,
tHistogramSum
(
pHisto
,
i
));
}
double
ratio
[]
=
{
0
/
100
,
20.0
/
100
,
88.0
/
100
,
100
/
100
};
double
*
res
=
tHistogramUniform
(
pHisto
,
ratio
,
4
);
for
(
int32_t
i
=
0
;
i
<
4
;
++
i
)
{
printf
(
"%f
\n
"
,
res
[
i
]);
}
SHistogramInfo
*
pHisto1
=
NULL
;
for
(
int32_t
i
=
(
90000
-
1
);
i
>=
80000
;
--
i
)
{
tHistogramAdd
(
&
pHisto1
,
i
);
}
tHistogramPrint
(
pHisto1
);
SHistogramInfo
*
pRes
=
tHistogramMerge
(
pHisto1
,
pHisto
,
MAX_HISTOGRAM_BIN
);
assert
(
pRes
->
numOfElems
==
pHisto
->
numOfElems
+
pHisto1
->
numOfElems
);
tHistogramPrint
(
pRes
);
tHistogramDestroy
(
&
pHisto
);
tHistogramDestroy
(
&
pHisto1
);
tHistogramDestroy
(
&
pRes
);
free
(
res
);
}
void
doHistogramRepeatTest
()
{
SHistogramInfo
*
pHisto
=
NULL
;
struct
timeval
systemTime
;
gettimeofday
(
&
systemTime
,
NULL
);
int64_t
st
=
(
int64_t
)
systemTime
.
tv_sec
*
1000L
+
(
uint64_t
)
systemTime
.
tv_usec
/
1000
;
for
(
int32_t
i
=
0
;
i
<
1000
;
++
i
)
{
tHistogramAdd
(
&
pHisto
,
-
24
+
i
);
// tHistogramPrint(pHisto);
}
tHistogramDestroy
(
&
pHisto
);
}
}
/* test validate the names for table/database */
TEST
(
testCase
,
histogram_binary_search
)
{
SHistogramInfo
*
pHisto
=
tHistogramCreate
(
MAX_HISTOGRAM_BIN
);
pHisto
->
numOfEntries
=
10
;
for
(
int32_t
i
=
0
;
i
<
10
;
++
i
)
{
pHisto
->
elems
[
i
].
num
=
1
;
pHisto
->
elems
[
i
].
val
=
i
;
}
int32_t
idx
=
histoBinarySearch
(
pHisto
->
elems
,
pHisto
->
numOfEntries
,
1
);
assert
(
idx
==
1
);
idx
=
histoBinarySearch
(
pHisto
->
elems
,
pHisto
->
numOfEntries
,
9
);
assert
(
idx
==
9
);
idx
=
histoBinarySearch
(
pHisto
->
elems
,
pHisto
->
numOfEntries
,
20
);
assert
(
idx
==
10
);
idx
=
histoBinarySearch
(
pHisto
->
elems
,
pHisto
->
numOfEntries
,
-
1
);
assert
(
idx
==
0
);
idx
=
histoBinarySearch
(
pHisto
->
elems
,
pHisto
->
numOfEntries
,
3.9
);
assert
(
idx
==
4
);
free
(
pHisto
);
}
TEST
(
testCase
,
histogram_add
)
{
doHistogramAddTest
();
doHistogramRepeatTest
();
}
TEST
(
testCase
,
heapsort
)
{
// int32_t num = 20;
//
// SHeapEntry* pEntry = tHeapCreate(num);
//
// for(int32_t i=0; i<num; ++i) {
// pEntry[i].val = num - 1 - i;
// }
//
// tHeapSort(pEntry, num);
//
// for(int32_t i=0; i<num; ++i) {
// printf("%lf, ", pEntry[i].val);
// }
//
// printf("\n");
//
// free(pEntry);
}
src/query/tests/patternMatchTest.cpp
0 → 100644
浏览文件 @
d7a3a975
#include <gtest/gtest.h>
#include <sys/time.h>
#include <cassert>
#include <iostream>
#include "qAggMain.h"
#include "tcompare.h"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
TEST
(
testCase
,
patternMatchTest
)
{
SPatternCompareInfo
info
=
PATTERN_COMPARE_INFO_INITIALIZER
;
const
char
*
str
=
"abcdef"
;
int32_t
ret
=
patternMatch
(
"a%b%"
,
str
,
strlen
(
str
),
&
info
);
EXPECT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
str
=
"tm01"
;
ret
=
patternMatch
(
"tm__"
,
str
,
strlen
(
str
),
&
info
);
EXPECT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
str
=
"tkm1"
;
ret
=
patternMatch
(
"t%m1"
,
str
,
strlen
(
str
),
&
info
);
EXPECT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
str
=
"tkm1"
;
ret
=
patternMatch
(
"%m1"
,
str
,
strlen
(
str
),
&
info
);
EXPECT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
str
=
""
;
ret
=
patternMatch
(
"%_"
,
str
,
strlen
(
str
),
&
info
);
EXPECT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
str
=
"1"
;
ret
=
patternMatch
(
"%__"
,
str
,
strlen
(
str
),
&
info
);
EXPECT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
str
=
""
;
ret
=
patternMatch
(
"%"
,
str
,
strlen
(
str
),
&
info
);
EXPECT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
str
=
" "
;
ret
=
patternMatch
(
"_"
,
str
,
strlen
(
str
),
&
info
);
EXPECT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
str
=
"!"
;
ret
=
patternMatch
(
"%_"
,
str
,
strlen
(
str
),
&
info
);
EXPECT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
str
=
"abcdefg"
;
ret
=
patternMatch
(
"abc%fg"
,
str
,
strlen
(
str
),
&
info
);
EXPECT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
str
=
"abcdefgabcdeju"
;
ret
=
patternMatch
(
"abc%fg"
,
str
,
7
,
&
info
);
EXPECT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
str
=
"abcdefgabcdeju"
;
ret
=
patternMatch
(
"abc%f_"
,
str
,
6
,
&
info
);
EXPECT_EQ
(
ret
,
TSDB_PATTERN_NOWILDCARDMATCH
);
str
=
"abcdefgabcdeju"
;
ret
=
patternMatch
(
"abc%f_"
,
str
,
1
,
&
info
);
// pattern string is longe than the size
EXPECT_EQ
(
ret
,
TSDB_PATTERN_NOMATCH
);
str
=
"abcdefgabcdeju"
;
ret
=
patternMatch
(
"ab"
,
str
,
2
,
&
info
);
EXPECT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
str
=
"abcdefgabcdeju"
;
ret
=
patternMatch
(
"a%"
,
str
,
2
,
&
info
);
EXPECT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
str
=
"abcdefgabcdeju"
;
ret
=
patternMatch
(
"a__"
,
str
,
2
,
&
info
);
EXPECT_EQ
(
ret
,
TSDB_PATTERN_NOMATCH
);
str
=
"carzero"
;
ret
=
patternMatch
(
"%o"
,
str
,
strlen
(
str
),
&
info
);
EXPECT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
str
=
"19"
;
ret
=
patternMatch
(
"%9"
,
str
,
2
,
&
info
);
EXPECT_EQ
(
ret
,
TSDB_PATTERN_MATCH
);
}
src/query/tests/percentileTest.cpp
0 → 100644
浏览文件 @
d7a3a975
#include <gtest/gtest.h>
#include <iostream>
#include "qResultbuf.h"
#include "taos.h"
#include "taosdef.h"
#include "qPercentile.h"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
namespace
{
tMemBucket
*
createBigIntDataBucket
(
int32_t
start
,
int32_t
end
)
{
tMemBucket
*
pBucket
=
tMemBucketCreate
(
sizeof
(
int64_t
),
TSDB_DATA_TYPE_BIGINT
,
start
,
end
);
for
(
int32_t
i
=
start
;
i
<=
end
;
++
i
)
{
int64_t
val
=
i
;
tMemBucketPut
(
pBucket
,
&
val
,
1
);
}
return
pBucket
;
}
tMemBucket
*
createIntDataBucket
(
int32_t
start
,
int32_t
end
)
{
tMemBucket
*
pBucket
=
tMemBucketCreate
(
sizeof
(
int32_t
),
TSDB_DATA_TYPE_INT
,
start
,
end
);
for
(
int32_t
i
=
start
;
i
<=
end
;
++
i
)
{
int32_t
val
=
i
;
tMemBucketPut
(
pBucket
,
&
val
,
1
);
}
return
pBucket
;
}
tMemBucket
*
createDoubleDataBucket
(
int32_t
start
,
int32_t
end
)
{
tMemBucket
*
pBucket
=
tMemBucketCreate
(
sizeof
(
double
),
TSDB_DATA_TYPE_DOUBLE
,
start
,
end
);
for
(
int32_t
i
=
start
;
i
<=
end
;
++
i
)
{
double
val
=
i
;
int32_t
ret
=
tMemBucketPut
(
pBucket
,
&
val
,
1
);
if
(
ret
!=
0
)
{
printf
(
"value out of range:%f"
,
val
);
}
}
return
pBucket
;
}
tMemBucket
*
createUnsignedDataBucket
(
int32_t
start
,
int32_t
end
,
int32_t
type
)
{
tMemBucket
*
pBucket
=
tMemBucketCreate
(
tDataTypes
[
type
].
bytes
,
type
,
start
,
end
);
for
(
int32_t
i
=
start
;
i
<=
end
;
++
i
)
{
uint64_t
k
=
i
;
int32_t
ret
=
tMemBucketPut
(
pBucket
,
&
k
,
1
);
if
(
ret
!=
0
)
{
printf
(
"value out of range:%"
PRId64
,
k
);
}
}
return
pBucket
;
}
void
intDataTest
()
{
printf
(
"running %s
\n
"
,
__FUNCTION__
);
tMemBucket
*
pBucket
=
NULL
;
double
result
=
0.
;
pBucket
=
createIntDataBucket
(
0
,
0
);
result
=
getPercentile
(
pBucket
,
0
);
ASSERT_DOUBLE_EQ
(
result
,
0
);
tMemBucketDestroy
(
pBucket
);
pBucket
=
createIntDataBucket
(
0
,
1
);
result
=
getPercentile
(
pBucket
,
100
);
ASSERT_DOUBLE_EQ
(
result
,
1
);
result
=
getPercentile
(
pBucket
,
0
);
ASSERT_DOUBLE_EQ
(
result
,
0
);
tMemBucketDestroy
(
pBucket
);
pBucket
=
createIntDataBucket
(
-
1
,
1
);
result
=
getPercentile
(
pBucket
,
50
);
ASSERT_DOUBLE_EQ
(
result
,
0
);
result
=
getPercentile
(
pBucket
,
0
);
ASSERT_DOUBLE_EQ
(
result
,
-
1
);
result
=
getPercentile
(
pBucket
,
75
);
ASSERT_DOUBLE_EQ
(
result
,
0.5
);
result
=
getPercentile
(
pBucket
,
100
);
ASSERT_DOUBLE_EQ
(
result
,
1
);
tMemBucketDestroy
(
pBucket
);
pBucket
=
createIntDataBucket
(
0
,
99999
);
result
=
getPercentile
(
pBucket
,
50
);
ASSERT_DOUBLE_EQ
(
result
,
49999.5
);
tMemBucketDestroy
(
pBucket
);
}
void
bigintDataTest
()
{
printf
(
"running %s
\n
"
,
__FUNCTION__
);
tMemBucket
*
pBucket
=
NULL
;
double
result
=
0.0
;
pBucket
=
createBigIntDataBucket
(
-
1000
,
1000
);
result
=
getPercentile
(
pBucket
,
50
);
ASSERT_DOUBLE_EQ
(
result
,
0.
);
tMemBucketDestroy
(
pBucket
);
pBucket
=
createBigIntDataBucket
(
-
10000
,
10000
);
result
=
getPercentile
(
pBucket
,
100
);
ASSERT_DOUBLE_EQ
(
result
,
10000.0
);
tMemBucketDestroy
(
pBucket
);
pBucket
=
createBigIntDataBucket
(
-
10000
,
10000
);
result
=
getPercentile
(
pBucket
,
75
);
ASSERT_DOUBLE_EQ
(
result
,
5000.0
);
tMemBucketDestroy
(
pBucket
);
}
void
doubleDataTest
()
{
printf
(
"running %s
\n
"
,
__FUNCTION__
);
tMemBucket
*
pBucket
=
NULL
;
double
result
=
0
;
pBucket
=
createDoubleDataBucket
(
-
10
,
10
);
result
=
getPercentile
(
pBucket
,
0
);
ASSERT_DOUBLE_EQ
(
result
,
-
10.0
);
printf
(
"result is: %lf
\n
"
,
result
);
tMemBucketDestroy
(
pBucket
);
pBucket
=
createDoubleDataBucket
(
-
100000
,
100000
);
result
=
getPercentile
(
pBucket
,
25
);
ASSERT_DOUBLE_EQ
(
result
,
-
50000
);
printf
(
"result is: %lf
\n
"
,
result
);
tMemBucketDestroy
(
pBucket
);
pBucket
=
createDoubleDataBucket
(
-
100000
,
100000
);
result
=
getPercentile
(
pBucket
,
50
);
ASSERT_DOUBLE_EQ
(
result
,
0
);
tMemBucketDestroy
(
pBucket
);
pBucket
=
createDoubleDataBucket
(
-
100000
,
100000
);
result
=
getPercentile
(
pBucket
,
75
);
ASSERT_DOUBLE_EQ
(
result
,
50000
);
tMemBucketDestroy
(
pBucket
);
pBucket
=
createDoubleDataBucket
(
-
100000
,
100000
);
result
=
getPercentile
(
pBucket
,
100
);
ASSERT_DOUBLE_EQ
(
result
,
100000.0
);
printf
(
"result is: %lf
\n
"
,
result
);
tMemBucketDestroy
(
pBucket
);
}
/*
* large data test, we employ 0.1billion double data to calculated the percentile
* which is 800MB data
*/
void
largeDataTest
()
{
printf
(
"running : %s
\n
"
,
__FUNCTION__
);
tMemBucket
*
pBucket
=
NULL
;
double
result
=
0
;
struct
timeval
tv
;
gettimeofday
(
&
tv
,
NULL
);
int64_t
start
=
tv
.
tv_sec
;
printf
(
"start time: %"
PRId64
"
\n
"
,
tv
.
tv_sec
);
pBucket
=
createDoubleDataBucket
(
0
,
100000000
);
result
=
getPercentile
(
pBucket
,
50
);
ASSERT_DOUBLE_EQ
(
result
,
50000000
);
gettimeofday
(
&
tv
,
NULL
);
printf
(
"total elapsed time: %"
PRId64
" sec."
,
-
start
+
tv
.
tv_sec
);
printf
(
"the result of %d is: %lf
\n
"
,
50
,
result
);
tMemBucketDestroy
(
pBucket
);
}
void
qsortTest
()
{
printf
(
"running : %s
\n
"
,
__FUNCTION__
);
SSchema
field
[
1
]
=
{
{
TSDB_DATA_TYPE_INT
,
"k"
,
sizeof
(
int32_t
)},
};
const
int32_t
num
=
2000
;
int32_t
*
d
=
(
int32_t
*
)
malloc
(
sizeof
(
int32_t
)
*
num
);
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
d
[
i
]
=
i
%
4
;
}
const
int32_t
numOfOrderCols
=
1
;
int32_t
orderColIdx
=
0
;
SColumnModel
*
pModel
=
createColumnModel
(
field
,
1
,
1000
);
tOrderDescriptor
*
pDesc
=
tOrderDesCreate
(
&
orderColIdx
,
numOfOrderCols
,
pModel
,
1
);
tColDataQSort
(
pDesc
,
num
,
0
,
num
-
1
,
(
char
*
)
d
,
1
);
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
printf
(
"%d
\t
"
,
d
[
i
]);
}
printf
(
"
\n
"
);
destroyColumnModel
(
pModel
);
}
void
unsignedDataTest
()
{
printf
(
"running %s
\n
"
,
__FUNCTION__
);
tMemBucket
*
pBucket
=
NULL
;
double
result
=
0.0
;
pBucket
=
createUnsignedDataBucket
(
0
,
1000
,
TSDB_DATA_TYPE_UINT
);
result
=
getPercentile
(
pBucket
,
50
);
ASSERT_DOUBLE_EQ
(
result
,
500.0
);
tMemBucketDestroy
(
pBucket
);
pBucket
=
createUnsignedDataBucket
(
0
,
10000
,
TSDB_DATA_TYPE_UBIGINT
);
result
=
getPercentile
(
pBucket
,
100
);
ASSERT_DOUBLE_EQ
(
result
,
10000.0
);
result
=
getPercentile
(
pBucket
,
0
);
ASSERT_DOUBLE_EQ
(
result
,
0.0
);
result
=
getPercentile
(
pBucket
,
50
);
ASSERT_DOUBLE_EQ
(
result
,
5000
);
result
=
getPercentile
(
pBucket
,
75
);
ASSERT_DOUBLE_EQ
(
result
,
7500
);
tMemBucketDestroy
(
pBucket
);
}
}
// namespace
TEST
(
testCase
,
percentileTest
)
{
// qsortTest();
intDataTest
();
bigintDataTest
();
doubleDataTest
();
unsignedDataTest
();
largeDataTest
();
}
src/query/tests/resultBufferTest.cpp
0 → 100644
浏览文件 @
d7a3a975
#include <gtest/gtest.h>
#include <cassert>
#include <iostream>
#include "qResultbuf.h"
#include "taos.h"
#include "tsdb.h"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
namespace
{
// simple test
void
simpleTest
()
{
SDiskbasedResultBuf
*
pResultBuf
=
NULL
;
int32_t
ret
=
createDiskbasedResultBuffer
(
&
pResultBuf
,
1024
,
4096
,
1
);
int32_t
pageId
=
0
;
int32_t
groupId
=
0
;
tFilePage
*
pBufPage
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
ASSERT_TRUE
(
pBufPage
!=
NULL
);
ASSERT_EQ
(
getResBufSize
(
pResultBuf
),
1024
);
SIDList
list
=
getDataBufPagesIdList
(
pResultBuf
,
groupId
);
ASSERT_EQ
(
taosArrayGetSize
(
list
),
1
);
ASSERT_EQ
(
getNumOfResultBufGroupId
(
pResultBuf
),
1
);
releaseResBufPage
(
pResultBuf
,
pBufPage
);
tFilePage
*
pBufPage1
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t
=
getResBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t
==
pBufPage1
);
tFilePage
*
pBufPage2
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t1
=
getResBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t1
==
pBufPage2
);
tFilePage
*
pBufPage3
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t2
=
getResBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t2
==
pBufPage3
);
tFilePage
*
pBufPage4
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t3
=
getResBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t3
==
pBufPage4
);
tFilePage
*
pBufPage5
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t4
=
getResBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t4
==
pBufPage5
);
destroyResultBuf
(
pResultBuf
);
}
void
writeDownTest
()
{
SDiskbasedResultBuf
*
pResultBuf
=
NULL
;
int32_t
ret
=
createDiskbasedResultBuffer
(
&
pResultBuf
,
1024
,
4
*
1024
,
1
);
int32_t
pageId
=
0
;
int32_t
writePageId
=
0
;
int32_t
groupId
=
0
;
int32_t
nx
=
12345
;
tFilePage
*
pBufPage
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
ASSERT_TRUE
(
pBufPage
!=
NULL
);
*
(
int32_t
*
)(
pBufPage
->
data
)
=
nx
;
writePageId
=
pageId
;
releaseResBufPage
(
pResultBuf
,
pBufPage
);
tFilePage
*
pBufPage1
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t1
=
getResBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t1
==
pBufPage1
);
ASSERT_TRUE
(
pageId
==
1
);
tFilePage
*
pBufPage2
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t2
=
getResBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t2
==
pBufPage2
);
ASSERT_TRUE
(
pageId
==
2
);
tFilePage
*
pBufPage3
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t3
=
getResBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t3
==
pBufPage3
);
ASSERT_TRUE
(
pageId
==
3
);
tFilePage
*
pBufPage4
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t4
=
getResBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t4
==
pBufPage4
);
ASSERT_TRUE
(
pageId
==
4
);
releaseResBufPage
(
pResultBuf
,
t4
);
// flush the written page to disk, and read it out again
tFilePage
*
pBufPagex
=
getResBufPage
(
pResultBuf
,
writePageId
);
ASSERT_EQ
(
*
(
int32_t
*
)
pBufPagex
->
data
,
nx
);
SArray
*
pa
=
getDataBufPagesIdList
(
pResultBuf
,
groupId
);
ASSERT_EQ
(
taosArrayGetSize
(
pa
),
5
);
destroyResultBuf
(
pResultBuf
);
}
void
recyclePageTest
()
{
SDiskbasedResultBuf
*
pResultBuf
=
NULL
;
int32_t
ret
=
createDiskbasedResultBuffer
(
&
pResultBuf
,
1024
,
4
*
1024
,
1
);
int32_t
pageId
=
0
;
int32_t
writePageId
=
0
;
int32_t
groupId
=
0
;
int32_t
nx
=
12345
;
tFilePage
*
pBufPage
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
ASSERT_TRUE
(
pBufPage
!=
NULL
);
releaseResBufPage
(
pResultBuf
,
pBufPage
);
tFilePage
*
pBufPage1
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t1
=
getResBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t1
==
pBufPage1
);
ASSERT_TRUE
(
pageId
==
1
);
tFilePage
*
pBufPage2
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t2
=
getResBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t2
==
pBufPage2
);
ASSERT_TRUE
(
pageId
==
2
);
tFilePage
*
pBufPage3
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t3
=
getResBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t3
==
pBufPage3
);
ASSERT_TRUE
(
pageId
==
3
);
tFilePage
*
pBufPage4
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t4
=
getResBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t4
==
pBufPage4
);
ASSERT_TRUE
(
pageId
==
4
);
releaseResBufPage
(
pResultBuf
,
t4
);
tFilePage
*
pBufPage5
=
getNewDataBuf
(
pResultBuf
,
groupId
,
&
pageId
);
tFilePage
*
t5
=
getResBufPage
(
pResultBuf
,
pageId
);
ASSERT_TRUE
(
t5
==
pBufPage5
);
ASSERT_TRUE
(
pageId
==
5
);
// flush the written page to disk, and read it out again
tFilePage
*
pBufPagex
=
getResBufPage
(
pResultBuf
,
writePageId
);
*
(
int32_t
*
)(
pBufPagex
->
data
)
=
nx
;
writePageId
=
pageId
;
// update the data
releaseResBufPage
(
pResultBuf
,
pBufPagex
);
tFilePage
*
pBufPagex1
=
getResBufPage
(
pResultBuf
,
1
);
SArray
*
pa
=
getDataBufPagesIdList
(
pResultBuf
,
groupId
);
ASSERT_EQ
(
taosArrayGetSize
(
pa
),
6
);
destroyResultBuf
(
pResultBuf
);
}
}
// namespace
TEST
(
testCase
,
resultBufferTest
)
{
srand
(
time
(
NULL
));
simpleTest
();
writeDownTest
();
recyclePageTest
();
}
src/query/tests/tsBufTest.cpp
0 → 100644
浏览文件 @
d7a3a975
#include "os.h"
#include <gtest/gtest.h>
#include <cassert>
#include <iostream>
#include "qTsbuf.h"
#include "taos.h"
#include "tsdb.h"
#include "ttoken.h"
#include "tutil.h"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
namespace
{
/**
*
* @param num total number
* @param step gap between two consecutive ts
* @return
*/
int64_t
*
createTsList
(
int32_t
num
,
int64_t
start
,
int32_t
step
)
{
int64_t
*
pList
=
(
int64_t
*
)
malloc
(
num
*
sizeof
(
int64_t
));
for
(
int64_t
i
=
0
;
i
<
num
;
++
i
)
{
pList
[
i
]
=
start
+
i
*
step
;
}
return
pList
;
}
// simple test
void
simpleTest
()
{
STSBuf
*
pTSBuf
=
tsBufCreate
(
true
,
TSDB_ORDER_ASC
);
// write 10 ts points
int32_t
num
=
10
;
tVariant
t
=
{
0
};
t
.
nType
=
TSDB_DATA_TYPE_BIGINT
;
t
.
i64
=
1
;
int64_t
*
list
=
createTsList
(
10
,
10000000
,
30
);
tsBufAppend
(
pTSBuf
,
0
,
&
t
,
(
const
char
*
)
list
,
num
*
sizeof
(
int64_t
));
EXPECT_EQ
(
pTSBuf
->
tsOrder
,
TSDB_ORDER_ASC
);
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
sizeof
(
int64_t
)
*
num
);
EXPECT_EQ
(
tVariantCompare
(
&
pTSBuf
->
block
.
tag
,
&
t
),
0
);
EXPECT_EQ
(
pTSBuf
->
numOfGroups
,
1
);
tsBufFlush
(
pTSBuf
);
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
0
);
EXPECT_EQ
(
pTSBuf
->
block
.
numOfElem
,
num
);
tsBufDestroy
(
pTSBuf
);
free
(
list
);
}
// one large list of ts, the ts list need to be split into several small blocks
void
largeTSTest
()
{
STSBuf
*
pTSBuf
=
tsBufCreate
(
true
,
TSDB_ORDER_ASC
);
// write 10 ts points
int32_t
num
=
1000000
;
tVariant
t
=
{
0
};
t
.
nType
=
TSDB_DATA_TYPE_BIGINT
;
t
.
i64
=
1
;
int64_t
*
list
=
createTsList
(
num
,
10000000
,
30
);
tsBufAppend
(
pTSBuf
,
0
,
&
t
,
(
const
char
*
)
list
,
num
*
sizeof
(
int64_t
));
// the data has been flush to disk, no data in cache
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
0
);
EXPECT_EQ
(
tVariantCompare
(
&
pTSBuf
->
block
.
tag
,
&
t
),
0
);
EXPECT_EQ
(
pTSBuf
->
numOfGroups
,
1
);
EXPECT_EQ
(
pTSBuf
->
tsOrder
,
TSDB_ORDER_ASC
);
tsBufFlush
(
pTSBuf
);
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
0
);
EXPECT_EQ
(
pTSBuf
->
block
.
numOfElem
,
num
);
tsBufDestroy
(
pTSBuf
);
free
(
list
);
}
void
multiTagsTest
()
{
STSBuf
*
pTSBuf
=
tsBufCreate
(
true
,
TSDB_ORDER_ASC
);
int32_t
num
=
10000
;
tVariant
t
=
{
0
};
t
.
nType
=
TSDB_DATA_TYPE_BIGINT
;
int64_t
start
=
10000000
;
int32_t
numOfTags
=
50
;
int32_t
step
=
30
;
for
(
int32_t
i
=
0
;
i
<
numOfTags
;
++
i
)
{
int64_t
*
list
=
createTsList
(
num
,
start
,
step
);
t
.
i64
=
i
;
tsBufAppend
(
pTSBuf
,
0
,
&
t
,
(
const
char
*
)
list
,
num
*
sizeof
(
int64_t
));
free
(
list
);
start
+=
step
*
num
;
}
EXPECT_EQ
(
pTSBuf
->
tsOrder
,
TSDB_ORDER_ASC
);
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
num
*
sizeof
(
int64_t
));
EXPECT_EQ
(
pTSBuf
->
block
.
tag
.
i64
,
numOfTags
-
1
);
EXPECT_EQ
(
pTSBuf
->
numOfGroups
,
1
);
tsBufFlush
(
pTSBuf
);
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
0
);
EXPECT_EQ
(
pTSBuf
->
block
.
numOfElem
,
num
);
tsBufDestroy
(
pTSBuf
);
}
void
multiVnodeTagsTest
()
{
STSBuf
*
pTSBuf
=
tsBufCreate
(
true
,
TSDB_ORDER_ASC
);
int32_t
num
=
10000
;
int64_t
start
=
10000000
;
int32_t
numOfTags
=
50
;
int32_t
step
=
30
;
// 2000 vnodes
for
(
int32_t
j
=
0
;
j
<
20
;
++
j
)
{
// vnodeId:0
start
=
10000000
;
tVariant
t
=
{
0
};
t
.
nType
=
TSDB_DATA_TYPE_BIGINT
;
for
(
int32_t
i
=
0
;
i
<
numOfTags
;
++
i
)
{
int64_t
*
list
=
createTsList
(
num
,
start
,
step
);
t
.
i64
=
i
;
tsBufAppend
(
pTSBuf
,
j
,
&
t
,
(
const
char
*
)
list
,
num
*
sizeof
(
int64_t
));
free
(
list
);
start
+=
step
*
num
;
}
EXPECT_EQ
(
pTSBuf
->
numOfGroups
,
j
+
1
);
}
EXPECT_EQ
(
pTSBuf
->
tsOrder
,
TSDB_ORDER_ASC
);
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
num
*
sizeof
(
int64_t
));
EXPECT_EQ
(
pTSBuf
->
block
.
tag
.
i64
,
numOfTags
-
1
);
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
num
*
sizeof
(
int64_t
));
EXPECT_EQ
(
pTSBuf
->
block
.
tag
.
i64
,
numOfTags
-
1
);
tsBufFlush
(
pTSBuf
);
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
0
);
EXPECT_EQ
(
pTSBuf
->
block
.
numOfElem
,
num
);
tsBufDestroy
(
pTSBuf
);
}
void
loadDataTest
()
{
STSBuf
*
pTSBuf
=
tsBufCreate
(
true
,
TSDB_ORDER_ASC
);
int32_t
num
=
10000
;
int64_t
oldStart
=
10000000
;
int32_t
numOfTags
=
50
;
int32_t
step
=
30
;
int32_t
numOfVnode
=
200
;
// 10000 vnodes
for
(
int32_t
j
=
0
;
j
<
numOfVnode
;
++
j
)
{
// vnodeId:0
int64_t
start
=
10000000
;
tVariant
t
=
{
0
};
t
.
nType
=
TSDB_DATA_TYPE_BIGINT
;
for
(
int32_t
i
=
0
;
i
<
numOfTags
;
++
i
)
{
int64_t
*
list
=
createTsList
(
num
,
start
,
step
);
t
.
i64
=
i
;
tsBufAppend
(
pTSBuf
,
j
,
&
t
,
(
const
char
*
)
list
,
num
*
sizeof
(
int64_t
));
printf
(
"%d - %"
PRIu64
"
\n
"
,
i
,
list
[
0
]);
free
(
list
);
start
+=
step
*
num
;
}
EXPECT_EQ
(
pTSBuf
->
numOfGroups
,
j
+
1
);
}
EXPECT_EQ
(
pTSBuf
->
tsOrder
,
TSDB_ORDER_ASC
);
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
num
*
sizeof
(
int64_t
));
EXPECT_EQ
(
pTSBuf
->
block
.
tag
.
i64
,
numOfTags
-
1
);
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
num
*
sizeof
(
int64_t
));
EXPECT_EQ
(
pTSBuf
->
block
.
tag
.
i64
,
numOfTags
-
1
);
tsBufFlush
(
pTSBuf
);
EXPECT_EQ
(
pTSBuf
->
tsData
.
len
,
0
);
EXPECT_EQ
(
pTSBuf
->
block
.
numOfElem
,
num
);
// create from exists file
STSBuf
*
pNewBuf
=
tsBufCreateFromFile
(
pTSBuf
->
path
,
false
);
EXPECT_EQ
(
pNewBuf
->
tsOrder
,
pTSBuf
->
tsOrder
);
EXPECT_EQ
(
pNewBuf
->
numOfGroups
,
numOfVnode
);
EXPECT_EQ
(
pNewBuf
->
fileSize
,
pTSBuf
->
fileSize
);
EXPECT_EQ
(
pNewBuf
->
pData
[
0
].
info
.
offset
,
pTSBuf
->
pData
[
0
].
info
.
offset
);
EXPECT_EQ
(
pNewBuf
->
pData
[
0
].
info
.
numOfBlocks
,
pTSBuf
->
pData
[
0
].
info
.
numOfBlocks
);
EXPECT_EQ
(
pNewBuf
->
pData
[
0
].
info
.
compLen
,
pTSBuf
->
pData
[
0
].
info
.
compLen
);
EXPECT_STREQ
(
pNewBuf
->
path
,
pTSBuf
->
path
);
tsBufResetPos
(
pNewBuf
);
int64_t
s
=
taosGetTimestampUs
();
printf
(
"start:%"
PRIu64
"
\n
"
,
s
);
int32_t
x
=
0
;
while
(
tsBufNextPos
(
pNewBuf
))
{
STSElem
elem
=
tsBufGetElem
(
pNewBuf
);
if
(
++
x
==
100000000
)
{
break
;
}
// printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag, elem.ts);
}
int64_t
e
=
taosGetTimestampUs
();
printf
(
"end:%"
PRIu64
", elapsed:%"
PRIu64
", total obj:%d
\n
"
,
e
,
e
-
s
,
x
);
tsBufDestroy
(
pTSBuf
);
tsBufDestroy
(
pNewBuf
);
}
void
randomIncTsTest
()
{}
void
TSTraverse
()
{
// 10000 vnodes
int32_t
num
=
200000
;
int64_t
oldStart
=
10000000
;
int32_t
numOfTags
=
3
;
int32_t
step
=
30
;
int32_t
numOfVnode
=
2
;
STSBuf
*
pTSBuf
=
tsBufCreate
(
true
,
TSDB_ORDER_ASC
);
for
(
int32_t
j
=
0
;
j
<
numOfVnode
;
++
j
)
{
// vnodeId:0
int64_t
start
=
10000000
;
tVariant
t
=
{
0
};
t
.
nType
=
TSDB_DATA_TYPE_BIGINT
;
for
(
int32_t
i
=
0
;
i
<
numOfTags
;
++
i
)
{
int64_t
*
list
=
createTsList
(
num
,
start
,
step
);
t
.
i64
=
i
;
tsBufAppend
(
pTSBuf
,
j
,
&
t
,
(
const
char
*
)
list
,
num
*
sizeof
(
int64_t
));
printf
(
"%d - %d - %"
PRIu64
", %"
PRIu64
"
\n
"
,
j
,
i
,
list
[
0
],
list
[
num
-
1
]);
free
(
list
);
start
+=
step
*
num
;
list
=
createTsList
(
num
,
start
,
step
);
tsBufAppend
(
pTSBuf
,
j
,
&
t
,
(
const
char
*
)
list
,
num
*
sizeof
(
int64_t
));
printf
(
"%d - %d - %"
PRIu64
", %"
PRIu64
"
\n
"
,
j
,
i
,
list
[
0
],
list
[
num
-
1
]);
free
(
list
);
start
+=
step
*
num
;
}
EXPECT_EQ
(
pTSBuf
->
numOfGroups
,
j
+
1
);
}
tsBufResetPos
(
pTSBuf
);
////////////////////////////////////////////////////////////////////////////////////////
// reverse traverse
int64_t
s
=
taosGetTimestampUs
();
printf
(
"start:%"
PRIu64
"
\n
"
,
s
);
pTSBuf
->
cur
.
order
=
TSDB_ORDER_DESC
;
// complete reverse traverse
int32_t
x
=
0
;
while
(
tsBufNextPos
(
pTSBuf
))
{
STSElem
elem
=
tsBufGetElem
(
pTSBuf
);
// printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag, elem.ts);
}
// specify the data block with vnode and tags value
tsBufResetPos
(
pTSBuf
);
pTSBuf
->
cur
.
order
=
TSDB_ORDER_DESC
;
int32_t
startVnode
=
1
;
int32_t
startTag
=
2
;
tVariant
t
=
{
0
};
t
.
nType
=
TSDB_DATA_TYPE_BIGINT
;
t
.
i64
=
startTag
;
tsBufGetElemStartPos
(
pTSBuf
,
startVnode
,
&
t
);
int32_t
totalOutput
=
10
;
while
(
1
)
{
STSElem
elem
=
tsBufGetElem
(
pTSBuf
);
printf
(
"%d-%"
PRIu64
"-%"
PRIu64
"
\n
"
,
elem
.
id
,
elem
.
tag
->
i64
,
elem
.
ts
);
if
(
!
tsBufNextPos
(
pTSBuf
))
{
break
;
}
if
(
--
totalOutput
<=
0
)
{
totalOutput
=
10
;
startTag
-=
1
;
t
.
i64
=
startTag
;
tsBufGetElemStartPos
(
pTSBuf
,
startVnode
,
&
t
);
if
(
startTag
==
0
)
{
startVnode
-=
1
;
startTag
=
3
;
}
if
(
startVnode
<
0
)
{
break
;
}
}
}
/////////////////////////////////////////////////////////////////////////////////
// traverse
pTSBuf
->
cur
.
order
=
TSDB_ORDER_ASC
;
tsBufResetPos
(
pTSBuf
);
// complete forwards traverse
while
(
tsBufNextPos
(
pTSBuf
))
{
STSElem
elem
=
tsBufGetElem
(
pTSBuf
);
// printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag, elem.ts);
}
// specify the data block with vnode and tags value
tsBufResetPos
(
pTSBuf
);
pTSBuf
->
cur
.
order
=
TSDB_ORDER_ASC
;
startVnode
=
1
;
startTag
=
2
;
t
.
i64
=
startTag
;
tsBufGetElemStartPos
(
pTSBuf
,
startVnode
,
&
t
);
totalOutput
=
10
;
while
(
1
)
{
STSElem
elem
=
tsBufGetElem
(
pTSBuf
);
printf
(
"%d-%"
PRIu64
"-%"
PRIu64
"
\n
"
,
elem
.
id
,
elem
.
tag
->
i64
,
elem
.
ts
);
if
(
!
tsBufNextPos
(
pTSBuf
))
{
break
;
}
if
(
--
totalOutput
<=
0
)
{
totalOutput
=
10
;
startTag
-=
1
;
t
.
i64
=
startTag
;
tsBufGetElemStartPos
(
pTSBuf
,
startVnode
,
&
t
);
if
(
startTag
<
0
)
{
startVnode
-=
1
;
startTag
=
3
;
}
if
(
startVnode
<
0
)
{
break
;
}
}
}
tsBufDestroy
(
pTSBuf
);
}
void
performanceTest
()
{}
void
emptyTagTest
()
{}
void
invalidFileTest
()
{
const
char
*
cmd
=
"touch /tmp/test"
;
// create empty file
system
(
cmd
);
STSBuf
*
pNewBuf
=
tsBufCreateFromFile
(
"/tmp/test"
,
true
);
EXPECT_TRUE
(
pNewBuf
==
NULL
);
tsBufDestroy
(
pNewBuf
);
pNewBuf
=
tsBufCreateFromFile
(
"/tmp/911"
,
true
);
EXPECT_TRUE
(
pNewBuf
==
NULL
);
tsBufDestroy
(
pNewBuf
);
}
void
mergeDiffVnodeBufferTest
()
{
STSBuf
*
pTSBuf1
=
tsBufCreate
(
true
,
TSDB_ORDER_ASC
);
STSBuf
*
pTSBuf2
=
tsBufCreate
(
true
,
TSDB_ORDER_ASC
);
int32_t
step
=
30
;
int32_t
num
=
1000
;
int32_t
numOfTags
=
10
;
tVariant
t
=
{
0
};
t
.
nType
=
TSDB_DATA_TYPE_BIGINT
;
// vnodeId:0
int64_t
start
=
10000000
;
for
(
int32_t
i
=
0
;
i
<
numOfTags
;
++
i
)
{
int64_t
*
list
=
createTsList
(
num
,
start
,
step
);
t
.
i64
=
i
;
tsBufAppend
(
pTSBuf1
,
1
,
&
t
,
(
const
char
*
)
list
,
num
*
sizeof
(
int64_t
));
tsBufAppend
(
pTSBuf2
,
9
,
&
t
,
(
const
char
*
)
list
,
num
*
sizeof
(
int64_t
));
free
(
list
);
start
+=
step
*
num
;
}
tsBufFlush
(
pTSBuf2
);
tsBufMerge
(
pTSBuf1
,
pTSBuf2
);
EXPECT_EQ
(
pTSBuf1
->
numOfGroups
,
2
);
EXPECT_EQ
(
pTSBuf1
->
numOfTotal
,
numOfTags
*
2
*
num
);
tsBufDisplay
(
pTSBuf1
);
tsBufDestroy
(
pTSBuf2
);
tsBufDestroy
(
pTSBuf1
);
}
void
mergeIdenticalVnodeBufferTest
()
{
STSBuf
*
pTSBuf1
=
tsBufCreate
(
true
,
TSDB_ORDER_ASC
);
STSBuf
*
pTSBuf2
=
tsBufCreate
(
true
,
TSDB_ORDER_ASC
);
tVariant
t
=
{
0
};
t
.
nType
=
TSDB_DATA_TYPE_BIGINT
;
int32_t
step
=
30
;
int32_t
num
=
1000
;
int32_t
numOfTags
=
10
;
// vnodeId:0
int64_t
start
=
10000000
;
for
(
int32_t
i
=
0
;
i
<
numOfTags
;
++
i
)
{
int64_t
*
list
=
createTsList
(
num
,
start
,
step
);
t
.
i64
=
i
;
tsBufAppend
(
pTSBuf1
,
12
,
&
t
,
(
const
char
*
)
list
,
num
*
sizeof
(
int64_t
));
free
(
list
);
start
+=
step
*
num
;
}
for
(
int32_t
i
=
numOfTags
;
i
<
numOfTags
*
2
;
++
i
)
{
int64_t
*
list
=
createTsList
(
num
,
start
,
step
);
t
.
i64
=
i
;
tsBufAppend
(
pTSBuf2
,
77
,
&
t
,
(
const
char
*
)
list
,
num
*
sizeof
(
int64_t
));
free
(
list
);
start
+=
step
*
num
;
}
tsBufFlush
(
pTSBuf2
);
tsBufMerge
(
pTSBuf1
,
pTSBuf2
);
EXPECT_EQ
(
pTSBuf1
->
numOfGroups
,
2
);
EXPECT_EQ
(
pTSBuf1
->
numOfTotal
,
numOfTags
*
2
*
num
);
tsBufResetPos
(
pTSBuf1
);
int32_t
count
=
0
;
while
(
tsBufNextPos
(
pTSBuf1
))
{
STSElem
elem
=
tsBufGetElem
(
pTSBuf1
);
if
(
count
++
<
numOfTags
*
num
)
{
EXPECT_EQ
(
elem
.
id
,
12
);
}
else
{
EXPECT_EQ
(
elem
.
id
,
77
);
}
printf
(
"%d-%"
PRIu64
"-%"
PRIu64
"
\n
"
,
elem
.
id
,
elem
.
tag
->
i64
,
elem
.
ts
);
}
tsBufDestroy
(
pTSBuf1
);
tsBufDestroy
(
pTSBuf2
);
}
}
// namespace
//TODO add binary tag value test case
TEST
(
testCase
,
tsBufTest
)
{
simpleTest
();
largeTSTest
();
multiTagsTest
();
multiVnodeTagsTest
();
loadDataTest
();
invalidFileTest
();
// randomIncTsTest();
TSTraverse
();
mergeDiffVnodeBufferTest
();
mergeIdenticalVnodeBufferTest
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录