From 7e21747c4ff962fd1e4864fe3678514ba5596491 Mon Sep 17 00:00:00 2001 From: 54liuyao <54liuyao@163.com> Date: Tue, 24 Dec 2024 14:17:37 +0800 Subject: [PATCH] ci(test):add slice state ut --- source/libs/stream/src/streamSliceState.c | 2 + .../libs/stream/test/streamSliceStateTest.cpp | 75 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 source/libs/stream/test/streamSliceStateTest.cpp diff --git a/source/libs/stream/src/streamSliceState.c b/source/libs/stream/src/streamSliceState.c index eefe046878..976f806032 100644 --- a/source/libs/stream/src/streamSliceState.c +++ b/source/libs/stream/src/streamSliceState.c @@ -112,6 +112,7 @@ void clearSearchBuff(SStreamFileState* pFileState) { } } +#ifdef BUILD_NO_CALL int32_t getStateFromRocksdbByCur(SStreamFileState* pFileState, SStreamStateCur* pCur, SWinKey* pResKey, SRowBuffPos** ppPos, int32_t* pVLen, int32_t* pWinCode) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; @@ -135,6 +136,7 @@ _end: } return code; } +#endif int32_t getHashSortNextRow(SStreamFileState* pFileState, const SWinKey* pKey, SWinKey* pResKey, void** ppVal, int32_t* pVLen, int32_t* pWinCode) { diff --git a/source/libs/stream/test/streamSliceStateTest.cpp b/source/libs/stream/test/streamSliceStateTest.cpp new file mode 100644 index 0000000000..1d62b8ca7b --- /dev/null +++ b/source/libs/stream/test/streamSliceStateTest.cpp @@ -0,0 +1,75 @@ +#include +#include "tstream.h" +#include "streamInt.h" +#include "tcs.h" +#include "tglobal.h" +#include "streamState.h" + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wwrite-strings" +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wsign-compare" +#pragma GCC diagnostic ignored "-Wformat" +#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" +#pragma GCC diagnostic ignored "-Wpointer-arith" + + +SStreamState *stateCreate2(const char *path) { + SStreamTask *pTask = (SStreamTask *)taosMemoryCalloc(1, sizeof(SStreamTask)); + pTask->ver = 1024; + pTask->id.streamId = 1023; + pTask->id.taskId = 1111111; + SStreamMeta *pMeta = NULL; + + int32_t code = streamMetaOpen((path), NULL, NULL, NULL, 0, 0, NULL, &pMeta); + pTask->pMeta = pMeta; + + SStreamState *p = streamStateOpen((char *)path, pTask, 0, 0); + ASSERT(p != NULL); + return p; +} +void *backendOpen2() { + streamMetaInit(); + const char *path = "/tmp/streamslicestate/"; + SStreamState *p = stateCreate2(path); + ASSERT(p != NULL); + return p; +} + +TSKEY compareTs1(void* pKey) { + SWinKey* pWinKey = (SWinKey*)pKey; + return pWinKey->ts; +} + +TEST(getHashSortNextRowFn, getHashSortNextRowTest) { + void *pState = backendOpen2(); + SStreamFileState *pFileState = NULL; + int32_t code = streamFileStateInit(1024, sizeof(SWinKey), 10, 0, compareTs1, pState, INT64_MAX, "aaa", 123, + STREAM_STATE_BUFF_HASH, &pFileState); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + + SWinKey key1; + key1.groupId = 123; + key1.ts = 456; + char str[] = "abc"; + code = streamStateFillPut_rocksdb((SStreamState*)pState, &key1, str, sizeof(str)); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + + SWinKey key2; + key2.groupId = 123; + key2.ts = 460; + code = streamStateFillPut_rocksdb((SStreamState*)pState, &key2, str, sizeof(str)); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + + SWinKey key3; + key3.groupId = 123; + void* pVal = NULL; + int32_t len = 0; + int32_t wincode = 0; + code = getHashSortNextRow(pFileState, &key1, &key3, &pVal, &len, &wincode); + ASSERT_EQ(code, TSDB_CODE_SUCCESS); + + ASSERT_EQ(key3.ts, key2.ts); +}