This is an automated email from the ASF dual-hosted git repository. haonan pushed a commit to branch cpp_1 in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 0339297305e65067d600bd56af2eb08e61370844 Author: Haonan <[email protected]> AuthorDate: Fri Dec 30 20:05:47 2022 +0800 Fix cpp SDK bug & enable cpp IT (#8680) --- .github/workflows/client-cpp.yml | 18 ++++- client-cpp/pom.xml | 71 +++++++++++-------- client-cpp/src/main/Session.cpp | 5 +- client-cpp/src/main/Session.h | 127 +++++++++++++++++++--------------- client-cpp/src/test/CMakeLists.txt | 1 + client-cpp/src/test/cpp/sessionIT.cpp | 94 +++++++++++++++++++------ 6 files changed, 206 insertions(+), 110 deletions(-) diff --git a/.github/workflows/client-cpp.yml b/.github/workflows/client-cpp.yml index 167f13ebc8..b9a40b62d7 100644 --- a/.github/workflows/client-cpp.yml +++ b/.github/workflows/client-cpp.yml @@ -62,8 +62,12 @@ jobs: path: ~/.m2 key: client-${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2- + - name: Build IoTDB server + run: mvn clean package -pl distribution -am -DskipTests - name: Test with Maven - run: mvn -B clean integration-test -P compile-cpp -Dtsfile.test.skip=true -Djdbc.test.skip=true -Diotdb.test.skip=true -Dconsensus.test.skip=true -Dcommons.test.skip=true -Dtest.port.closed=true -pl server,client-cpp,example/client-cpp-example -am + run: mvn clean verify -pl client-cpp -am -P compile-cpp -P cppTest + - name: Show test result + run: cat client-cpp/target/build/test/Testing/Temporary/LastTest_*.log build-win: strategy: @@ -101,6 +105,16 @@ jobs: - name: Add Flex and Bison Path and OpenSSL shell: bash run: cd /d/a/cpp && unzip win_flex_bison.zip && mv win_flex.exe flex.exe && mv win_bison.exe bison.exe && echo 'export PATH=/d/a/cpp:$PATH' >> ~/.bash_profile && source ~/.bash_profile + - name: Build IoTDB server + shell: bash + run: source ~/.bash_profile && mvn clean package -pl distribution -am -DskipTests - name: Test with Maven shell: bash - run: source ~/.bash_profile && mvn -B clean integration-test -P compile-cpp -Dboost.include.dir=/c/local/boost_1_78_0 -Dboost.library.dir=/c/local/boost_1_78_0/stage/lib -Dtsfile.test.skip=true -Djdbc.test.skip=true -Diotdb.test.skip=true -Dconsensus.test.skip=true -Dcommons.test.skip=true -Dtest.port.closed=true -Denforcer.skip=true -pl server,client-cpp,example/client-cpp-example -am -Dcmake.url="https://github.com/Kitware/CMake/releases/download/v3.21.6/cmake-3.21.6-windows-x8 [...] + run: source ~/.bash_profile && mvn clean verify -pl client-cpp -am -P compile-cpp -P cppTest -Dboost.include.dir=/c/local/boost_1_78_0 -Dboost.library.dir=/c/local/boost_1_78_0/stage/lib -Dcmake.url="https://github.com/Kitware/CMake/releases/download/v3.21.6/cmake-3.21.6-windows-x86_64.zip" -Dcmake.root.dir=/D/a/iotdb/iotdb/compile-tools/thrift/target/cmake-3.21.6-windows-x86_64/ -Dcmake.generator="Visual Studio 17 2022" + - name: Upload Artifact + if: failure() + uses: actions/upload-artifact@v3 + with: + name: cpp-IT-${{ runner.os }} + path: client-cpp/target/build/test/Testing + retention-days: 1 diff --git a/client-cpp/pom.xml b/client-cpp/pom.xml index 2bb64eb3e3..d366b942e4 100644 --- a/client-cpp/pom.xml +++ b/client-cpp/pom.xml @@ -39,7 +39,7 @@ <!-- Default value of cmake root --> <cmake.root.dir>${project.build.directory}/dependency/cmake/</cmake.root.dir> <cmake.build.type>Release</cmake.build.type> - <catch2.url>https://github.com/catchorg/Catch2/releases/download/v2.13.0/catch.hpp</catch2.url> + <catch2.url>https://github.com/catchorg/Catch2/releases/download/v2.13.7/catch.hpp</catch2.url> </properties> <modules> <module>../example/client-cpp-example</module> @@ -70,27 +70,29 @@ <cmake.generator>Unix Makefiles</cmake.generator> <cmake.root.dir>${project.parent.basedir}/compile-tools/thrift/target/cmake-${cmake-version}-Linux-x86_64/</cmake.root.dir> <thrift.exec.absolute.path>${project.parent.basedir}/compile-tools/thrift/target/build/compiler/cpp/bin/thrift</thrift.exec.absolute.path> - <iotdb.server.script>start-server.sh</iotdb.server.script> - </properties> - </profile> - <profile> - <id>os-unix-arm</id> - <activation> - <os> - <family>unix</family> - <arch>aarch64</arch> - </os> - </activation> - <properties> - <os.suffix>linux</os.suffix> - <os.classifier>linux-arm_32</os.classifier> - <!-- use Makefile as default cmake generator, users may specify other generators --> - <cmake.generator>Unix Makefiles</cmake.generator> - <cmake.root.dir>${project.parent.basedir}/compile-tools/thrift/target/cmake-3.21.2-linux-aarch64/</cmake.root.dir> - <thrift.exec.absolute.path>${project.parent.basedir}/compile-tools/thrift/target/build/compiler/cpp/bin/thrift</thrift.exec.absolute.path> - <iotdb.server.script>start-server.sh</iotdb.server.script> + <iotdb.start.script>start-standalone.sh</iotdb.start.script> + <iotdb.stop.script>stop-standalone.sh</iotdb.stop.script> </properties> </profile> + <!-- <profile>--> + <!-- <id>os-unix-arm</id>--> + <!-- <activation>--> + <!-- <os>--> + <!-- <family>unix</family>--> + <!-- <arch>aarch64</arch>--> + <!-- </os>--> + <!-- </activation>--> + <!-- <properties>--> + <!-- <os.suffix>linux</os.suffix>--> + <!-- <os.classifier>linux-arm_32</os.classifier>--> + <!-- <!– use Makefile as default cmake generator, users may specify other generators –>--> + <!-- <cmake.generator>Unix Makefiles</cmake.generator>--> + <!-- <cmake.root.dir>${project.parent.basedir}/compile-tools/thrift/target/cmake-3.21.2-linux-aarch64/</cmake.root.dir>--> + <!-- <thrift.exec.absolute.path>${project.parent.basedir}/compile-tools/thrift/target/build/compiler/cpp/bin/thrift</thrift.exec.absolute.path>--> + <!-- <iotdb.start.script>start-standalone.sh</iotdb.start.script>--> + <!-- <iotdb.stop.script>stop-standalone.sh</iotdb.stop.script>--> + <!-- </properties>--> + <!-- </profile>--> <profile> <id>os-mac</id> <activation> @@ -104,7 +106,8 @@ <cmake.generator>Unix Makefiles</cmake.generator> <cmake.root.dir>${project.parent.basedir}/compile-tools/thrift/target/cmake-${cmake-version}-Darwin-x86_64/CMake.app/Contents</cmake.root.dir> <thrift.exec.absolute.path>${project.parent.basedir}/compile-tools/thrift/target/build/compiler/cpp/bin/thrift</thrift.exec.absolute.path> - <iotdb.server.script>start-server.sh</iotdb.server.script> + <iotdb.start.script>start-standalone.sh</iotdb.start.script> + <iotdb.stop.script>stop-standalone.sh</iotdb.stop.script> </properties> </profile> <profile> @@ -120,7 +123,8 @@ <cmake.generator>Visual Studio 16 2019</cmake.generator> <cmake.root.dir>${project.parent.basedir}/compile-tools/thrift/target/cmake-${cmake-version}-win64-x64/</cmake.root.dir> <thrift.exec.absolute.path>${project.parent.basedir}/compile-tools/thrift/target/build/compiler/cpp/bin/${cmake.build.type}/thrift.exe</thrift.exec.absolute.path> - <iotdb.server.script>start-server.bat</iotdb.server.script> + <iotdb.start.script>start-standalone.bat</iotdb.start.script> + <iotdb.stop.script>stop-standalone.bat</iotdb.stop.script> <boost.include.dir/> <boost.library.dir/> </properties> @@ -363,7 +367,7 @@ <!-- Run the integration test cases --> <execution> <id>cmake-run-test</id> - <phase>test</phase> + <phase>integration-test</phase> <goals> <goal>test</goal> </goals> @@ -382,29 +386,40 @@ <!-- Start a local IoTDB server to run integration test cases --> <execution> <id>iotdb-process</id> - <phase>generate-test-resources</phase> + <phase>pre-integration-test</phase> <goals> <goal>start</goal> </goals> <configuration> - <name>start-iotdb</name> + <name>iotdb-server</name> <waitForInterrupt>false</waitForInterrupt> <!-- Maximum time in seconds to wait after launching IoTDB --> - <waitAfterLaunch>5</waitAfterLaunch> + <waitAfterLaunch>15</waitAfterLaunch> <!-- Redirect IoTDB server log to /dev/null --> <processLogFile>${project.build.directory}/build/test/test.log</processLogFile> <arguments> - <argument>${project.basedir}/../server/target/iotdb-server-${project.version}/sbin/${iotdb.server.script}</argument> + <argument>${project.basedir}/../distribution/target/apache-iotdb-${project.version}-all-bin/apache-iotdb-${project.version}-all-bin/sbin/${iotdb.start.script}</argument> </arguments> </configuration> </execution> <!-- Stop the IoTDB server when integration test finishes --> <execution> - <id>stop-all</id> + <id>stop-iotdb</id> <phase>post-integration-test</phase> <goals> <goal>stop-all</goal> </goals> + <configuration> + <name>iotdb-server</name> + <waitForInterrupt>false</waitForInterrupt> + <!-- Maximum time in seconds to wait after launching IoTDB --> + <waitAfterLaunch>5</waitAfterLaunch> + <!-- Redirect IoTDB server log to /dev/null --> + <processLogFile>${project.build.directory}/build/test/test1.log</processLogFile> + <arguments> + <argument>${project.basedir}/../distribution/target/apache-iotdb-${project.version}-all-bin/apache-iotdb-${project.version}-all-bin/sbin/${iotdb.stop.script}</argument> + </arguments> + </configuration> </execution> </executions> </plugin> diff --git a/client-cpp/src/main/Session.cpp b/client-cpp/src/main/Session.cpp index 54840a1b69..253c18039f 100644 --- a/client-cpp/src/main/Session.cpp +++ b/client-cpp/src/main/Session.cpp @@ -42,7 +42,8 @@ void RpcUtils::verifySuccess(const TSStatus &status) { verifySuccess(status.subStatus); return; } - if (status.code != TSStatusCode::SUCCESS_STATUS) { + if (status.code != TSStatusCode::SUCCESS_STATUS + && status.code != TSStatusCode::REDIRECTION_RECOMMEND) { throw ExecutionException(to_string(status.code) + ": " + status.message); } } @@ -1991,7 +1992,7 @@ bool Session::checkTemplateExists(const string& template_name) { return isExisted; } catch (const exception &e) { - if ( strstr(e.what(), "Undefined template name:") != NULL ) { + if ( strstr(e.what(), "get template info error") != NULL ) { return false; } log_debug(e.what()); diff --git a/client-cpp/src/main/Session.h b/client-cpp/src/main/Session.h index 9d9dc665f5..2f098be71a 100644 --- a/client-cpp/src/main/Session.h +++ b/client-cpp/src/main/Session.h @@ -176,60 +176,55 @@ namespace TSEncoding { namespace TSStatusCode { enum TSStatusCode { SUCCESS_STATUS = 200, - STILL_EXECUTING_STATUS = 201, - INVALID_HANDLE_STATUS = 202, - - NODE_DELETE_FAILED_ERROR = 298, - ALIAS_ALREADY_EXIST_ERROR = 299, - PATH_ALREADY_EXIST_ERROR = 300, - PATH_NOT_EXIST_ERROR = 301, - UNSUPPORTED_FETCH_METADATA_OPERATION_ERROR = 302, - METADATA_ERROR = 303, - OUT_OF_TTL_ERROR = 305, - CONFIG_ADJUSTER = 306, - MERGE_ERROR = 307, - SYSTEM_CHECK_ERROR = 308, - SYNC_DEVICE_OWNER_CONFLICT_ERROR = 309, - SYNC_CONNECTION_EXCEPTION = 310, - STORAGE_GROUP_PROCESSOR_ERROR = 311, - STORAGE_GROUP_ERROR = 312, - STORAGE_ENGINE_ERROR = 313, - TSFILE_PROCESSOR_ERROR = 314, - PATH_ILLEGAL = 315, - LOAD_FILE_ERROR = 316, - STORAGE_GROUP_NOT_READY = 317, - - EXECUTE_STATEMENT_ERROR = 400, - SQL_PARSE_ERROR = 401, - GENERATE_TIME_ZONE_ERROR = 402, - SET_TIME_ZONE_ERROR = 403, - NOT_STORAGE_GROUP_ERROR = 404, - QUERY_NOT_ALLOWED = 405, - AST_FORMAT_ERROR = 406, - LOGICAL_OPERATOR_ERROR = 407, - LOGICAL_OPTIMIZE_ERROR = 408, - UNSUPPORTED_FILL_TYPE_ERROR = 409, - PATH_ERROR = 410, - QUERY_PROCESS_ERROR = 411, - WRITE_PROCESS_ERROR = 412, - - INTERNAL_SERVER_ERROR = 500, - CLOSE_OPERATION_ERROR = 501, - READ_ONLY_SYSTEM_ERROR = 502, - DISK_SPACE_INSUFFICIENT_ERROR = 503, - START_UP_ERROR = 504, - SHUT_DOWN_ERROR = 505, - MULTIPLE_ERROR = 506, - WRONG_LOGIN_PASSWORD_ERROR = 600, - NOT_LOGIN_ERROR = 601, - NO_PERMISSION_ERROR = 602, - UNINITIALIZED_AUTH_ERROR = 603, - PARTITION_NOT_READY = 700, - TIME_OUT = 701, - NO_LEADER = 702, - UNSUPPORTED_OPERATION = 703, - NODE_READ_ONLY = 704, - INCOMPATIBLE_VERSION = 203, + + // System level + INCOMPATIBLE_VERSION = 201, + CONFIGURATION_ERROR = 202, + START_UP_ERROR = 203, + SHUT_DOWN_ERROR = 204, + + // General Error + UNSUPPORTED_OPERATION = 300, + EXECUTE_STATEMENT_ERROR = 301, + MULTIPLE_ERROR = 302, + ILLEGAL_PARAMETER = 303, + OVERLAP_WITH_EXISTING_TASK = 304, + INTERNAL_SERVER_ERROR = 305, + + // Client, + REDIRECTION_RECOMMEND = 400, + + // Schema Engine + DATABASE_NOT_EXIST = 500, + DATABASE_ALREADY_EXISTS = 501, + SERIES_OVERFLOW = 502, + TIMESERIES_ALREADY_EXIST = 503, + TIMESERIES_IN_BLACK_LIST = 504, + ALIAS_ALREADY_EXIST = 505, + PATH_ALREADY_EXIST = 506, + METADATA_ERROR = 507, + PATH_NOT_EXIST = 508, + ILLEGAL_PATH = 509, + CREATE_TEMPLATE_ERROR = 510, + DUPLICATED_TEMPLATE = 511, + UNDEFINED_TEMPLATE = 512, + TEMPLATE_NOT_SET = 513, + DIFFERENT_TEMPLATE = 514, + TEMPLATE_IS_IN_USE = 515, + TEMPLATE_INCOMPATIBLE = 516, + SEGMENT_NOT_FOUND = 517, + PAGE_OUT_OF_SPACE = 518, + RECORD_DUPLICATED=519, + SEGMENT_OUT_OF_SPACE = 520, + SCHEMA_FILE_NOT_EXISTS = 521, + OVERSIZE_RECORD = 522, + SCHEMA_FILE_REDO_LOG_BROKEN = 523, + TEMPLATE_NOT_ACTIVATED = 524, + + // Storage Engine + SYSTEM_READ_ONLY = 600, + STORAGE_ENGINE_ERROR = 601, + STORAGE_ENGINE_NOT_READY = 602, }; } @@ -294,7 +289,18 @@ public: } int64_t getInt64() { +#ifdef ARCH32 + const char *buf_addr = getOrderedByte(8); + if (reinterpret_cast<uint32_t>(buf_addr) % 4 == 0) { + return *(int64_t *)buf_addr; + } else { + char tmp_buf[8]; + memcpy(tmp_buf, buf_addr, 8); + return *(int64_t*)tmp_buf; + } +#else return *(int64_t *) getOrderedByte(8); +#endif } float getFloat() { @@ -302,7 +308,18 @@ public: } double getDouble() { +#ifdef ARCH32 + const char *buf_addr = getOrderedByte(8); + if (reinterpret_cast<uint32_t>(buf_addr) % 4 == 0) { + return *(double*)buf_addr; + } else { + char tmp_buf[8]; + memcpy(tmp_buf, buf_addr, 8); + return *(double*)tmp_buf; + } +#else return *(double *) getOrderedByte(8); +#endif } char getChar() { @@ -1194,4 +1211,4 @@ public: bool checkTemplateExists(const std::string &template_name); }; -#endif // IOTDB_SESSION_H +#endif // IOTDB_SESSION_H \ No newline at end of file diff --git a/client-cpp/src/test/CMakeLists.txt b/client-cpp/src/test/CMakeLists.txt index c5c969a049..7d6d18bcd5 100644 --- a/client-cpp/src/test/CMakeLists.txt +++ b/client-cpp/src/test/CMakeLists.txt @@ -22,6 +22,7 @@ SET(CMAKE_CXX_STANDARD 11) SET(CMAKE_CXX_STANDARD_REQUIRED ON) SET(TARGET_NAME session_tests) SET(TOOLS_DIR "${CMAKE_SOURCE_DIR}/../../../../compile-tools") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -g -O2") ENABLE_TESTING() # Add Boost include path for MacOS diff --git a/client-cpp/src/test/cpp/sessionIT.cpp b/client-cpp/src/test/cpp/sessionIT.cpp index 31f5daf0a9..b4330b82e8 100644 --- a/client-cpp/src/test/cpp/sessionIT.cpp +++ b/client-cpp/src/test/cpp/sessionIT.cpp @@ -35,7 +35,26 @@ void prepareTimeseries() { } } +static int global_test_id = 0; +class CaseReporter +{ +public: + CaseReporter(const char *caseNameArg) : caseName(caseNameArg) + { + test_id = global_test_id++; + std::cout << "Test " << test_id << ": " << caseName << std::endl; + } + ~CaseReporter() + { + std::cout << "Test " << test_id << ": " << caseName << " Done"<< std::endl << std::endl; + } +private: + const char *caseName; + int test_id; +}; + TEST_CASE("Create timeseries success", "[createTimeseries]") { + CaseReporter cr("createTimeseries"); if (!session->checkTimeseriesExists("root.test.d1.s1")) { session->createTimeseries("root.test.d1.s1", TSDataType::INT64, TSEncoding::RLE, CompressionType::SNAPPY); } @@ -44,6 +63,7 @@ TEST_CASE("Create timeseries success", "[createTimeseries]") { } TEST_CASE("Delete timeseries success", "[deleteTimeseries]") { + CaseReporter cr("deleteTimeseries"); if (!session->checkTimeseriesExists("root.test.d1.s1")) { session->createTimeseries("root.test.d1.s1", TSDataType::INT64, TSEncoding::RLE, CompressionType::SNAPPY); } @@ -53,6 +73,7 @@ TEST_CASE("Delete timeseries success", "[deleteTimeseries]") { } TEST_CASE("Test insertRecord by string", "[testInsertRecord]") { + CaseReporter cr("testInsertRecord"); prepareTimeseries(); string deviceId = "root.test.d1"; vector<string> measurements = {"s1", "s2", "s3"}; @@ -64,7 +85,7 @@ TEST_CASE("Test insertRecord by string", "[testInsertRecord]") { session->executeNonQueryStatement("insert into root.test.d1(timestamp,s1, s2, s3) values(100, 1,2,3)"); - unique_ptr<SessionDataSet> sessionDataSet = session->executeQueryStatement("select * from root.test.d1"); + unique_ptr<SessionDataSet> sessionDataSet = session->executeQueryStatement("select s1,s2,s3 from root.test.d1"); sessionDataSet->setBatchSize(1024); int count = 0; while (sessionDataSet->hasNext()) { @@ -79,6 +100,7 @@ TEST_CASE("Test insertRecord by string", "[testInsertRecord]") { } TEST_CASE("Test insertRecords ", "[testInsertRecords]") { + CaseReporter cr("testInsertRecords"); prepareTimeseries(); string deviceId = "root.test.d1"; vector<string> measurements = {"s1", "s2", "s3"}; @@ -87,7 +109,8 @@ TEST_CASE("Test insertRecords ", "[testInsertRecords]") { vector<vector<string>> valuesList; vector<int64_t> timestamps; - for (int64_t time = 0; time < 500; time++) { + int64_t COUNT = 500; + for (int64_t time = 1; time <= COUNT; time++) { vector<string> values = {"1", "2", "3"}; deviceIds.push_back(deviceId); @@ -103,9 +126,11 @@ TEST_CASE("Test insertRecords ", "[testInsertRecords]") { } } - session->insertRecords(deviceIds, timestamps, measurementsList, valuesList); + if (timestamps.size() > 0) { + session->insertRecords(deviceIds, timestamps, measurementsList, valuesList); + } - unique_ptr<SessionDataSet> sessionDataSet = session->executeQueryStatement("select * from root.test.d1"); + unique_ptr<SessionDataSet> sessionDataSet = session->executeQueryStatement("select s1,s2,s3 from root.test.d1"); sessionDataSet->setBatchSize(1024); int count = 0; while (sessionDataSet->hasNext()) { @@ -116,10 +141,11 @@ TEST_CASE("Test insertRecords ", "[testInsertRecords]") { index++; } } - REQUIRE(count == 500); + REQUIRE(count == COUNT); } TEST_CASE("Test insertRecord with types ", "[testTypedInsertRecord]") { + CaseReporter cr("testTypedInsertRecord"); vector<string> timeseries = {"root.test.d1.s1", "root.test.d1.s2", "root.test.d1.s3"}; vector<TSDataType::TSDataType> types = {TSDataType::INT32, TSDataType::DOUBLE, TSDataType::INT64}; @@ -151,6 +177,7 @@ TEST_CASE("Test insertRecord with types ", "[testTypedInsertRecord]") { } TEST_CASE("Test insertRecords with types ", "[testTypedInsertRecords]") { + CaseReporter cr("testTypedInsertRecords"); vector<string> timeseries = {"root.test.d1.s1", "root.test.d1.s2", "root.test.d1.s3"}; vector<TSDataType::TSDataType> types = {TSDataType::INT32, TSDataType::DOUBLE, TSDataType::INT64}; @@ -182,7 +209,7 @@ TEST_CASE("Test insertRecords with types ", "[testTypedInsertRecords]") { session->insertRecords(deviceIds, timestamps, measurementsList, typesList, valuesList); - unique_ptr<SessionDataSet> sessionDataSet = session->executeQueryStatement("select * from root.test.d1"); + unique_ptr<SessionDataSet> sessionDataSet = session->executeQueryStatement("select s1,s2,s3 from root.test.d1"); sessionDataSet->setBatchSize(1024); int count = 0; while (sessionDataSet->hasNext()) { @@ -193,6 +220,7 @@ TEST_CASE("Test insertRecords with types ", "[testTypedInsertRecords]") { } TEST_CASE("Test insertRecordsOfOneDevice", "[testInsertRecordsOfOneDevice]") { + CaseReporter cr("testInsertRecordsOfOneDevice"); vector<string> timeseries = {"root.test.d1.s1", "root.test.d1.s2", "root.test.d1.s3"}; vector<TSDataType::TSDataType> types = {TSDataType::INT32, TSDataType::DOUBLE, TSDataType::INT64}; @@ -233,6 +261,7 @@ TEST_CASE("Test insertRecordsOfOneDevice", "[testInsertRecordsOfOneDevice]") { } TEST_CASE("Test insertTablet ", "[testInsertTablet]") { + CaseReporter cr("testInsertTablet"); prepareTimeseries(); string deviceId = "root.test.d1"; vector<pair<string, TSDataType::TSDataType>> schemaList; @@ -244,9 +273,8 @@ TEST_CASE("Test insertTablet ", "[testInsertTablet]") { for (int64_t time = 0; time < 100; time++) { int row = tablet.rowSize++; tablet.timestamps[row] = time; - for (int i = 0; i < 3; i++) { - int64_t randVal = rand(); - tablet.addValue(i, row, &randVal); + for (int64_t i = 0; i < 3; i++) { + tablet.addValue(i, row, &i); } if (tablet.rowSize == tablet.maxRowNumber) { session->insertTablet(tablet); @@ -258,7 +286,7 @@ TEST_CASE("Test insertTablet ", "[testInsertTablet]") { session->insertTablet(tablet); tablet.reset(); } - unique_ptr<SessionDataSet> sessionDataSet = session->executeQueryStatement("select * from root.test.d1"); + unique_ptr<SessionDataSet> sessionDataSet = session->executeQueryStatement("select s1,s2,s3 from root.test.d1"); sessionDataSet->setBatchSize(1024); int count = 0; while (sessionDataSet->hasNext()) { @@ -273,6 +301,7 @@ TEST_CASE("Test insertTablet ", "[testInsertTablet]") { } TEST_CASE("Test Last query ", "[testLastQuery]") { + CaseReporter cr("testLastQuery"); prepareTimeseries(); string deviceId = "root.test.d1"; vector<string> measurements = {"s1", "s2", "s3"}; @@ -289,36 +318,55 @@ TEST_CASE("Test Last query ", "[testLastQuery]") { long index = 0; while (sessionDataSet->hasNext()) { vector<Field> fields = sessionDataSet->next()->fields; - REQUIRE(fields[0].stringV == deviceId + "." + measurements[index]); - REQUIRE(fields[1].stringV == measurementValues[index]); + REQUIRE("1" <= fields[1].stringV); + REQUIRE(fields[1].stringV <= "3"); index++; } } TEST_CASE("Test Huge query ", "[testHugeQuery]") { + CaseReporter cr("testHugeQuery"); prepareTimeseries(); string deviceId = "root.test.d1"; vector<string> measurements = {"s1", "s2", "s3"}; - vector<TSDataType::TSDataType> types = {TSDataType::INT32, TSDataType::INT32, TSDataType::INT32}; - int value1 = 1, value2 = 2, value3 = 3; + vector<TSDataType::TSDataType> types = {TSDataType::INT64, TSDataType::INT64, TSDataType::INT64}; + int64_t value1 = 1, value2 = 2, value3 = 3; vector<char*> values = {(char*)&value1, (char*)&value2, (char*)&value3}; - for (long time = 0; time < 1000000; time++) { + long total_count = 500000; + int print_count = 0; + std::cout.width(7); + std::cout << "inserting " << total_count << " rows:" << std::endl; + for (long time = 0; time < total_count; time++) { session->insertRecord(deviceId, time, measurements, types, values); + if (time != 0 && time % 1000 == 0) { + std::cout << time << "\t" << std::flush; + if (++print_count % 20 == 0) { + std::cout << std::endl; + } + } } - - unique_ptr<SessionDataSet> sessionDataSet = session->executeQueryStatement("select * from root.test.d1"); + + unique_ptr<SessionDataSet> sessionDataSet = session->executeQueryStatement("select s1,s2,s3 from root.test.d1"); sessionDataSet->setBatchSize(1024); RowRecord* rowRecord; int count = 0; + print_count = 0; + std::cout << "\n\niterating " << total_count << " rows:" << std::endl; while (sessionDataSet->hasNext()) { rowRecord = sessionDataSet->next(); REQUIRE(rowRecord->timestamp == count); - REQUIRE(rowRecord->fields[0].intV == 1); - REQUIRE(rowRecord->fields[1].intV == 2); - REQUIRE(rowRecord->fields[2].intV == 3); + REQUIRE(rowRecord->fields[0].longV== 1); + REQUIRE(rowRecord->fields[1].longV == 2); + REQUIRE(rowRecord->fields[2].longV == 3); count++; + if (count % 1000 == 0) { + std::cout << count << "\t" << std::flush; + if (++print_count % 20 == 0) { + std::cout << std::endl; + } + } } - - REQUIRE(count == 1000000); -} + + REQUIRE(count == total_count); +} \ No newline at end of file
