diff options
author | d-mokhnatkin <d-mokhnatkin@ydb.tech> | 2022-08-01 18:34:46 +0300 |
---|---|---|
committer | d-mokhnatkin <d-mokhnatkin@ydb.tech> | 2022-08-01 18:34:46 +0300 |
commit | 41e73b0260fb91fbeadbdd05d6ab2a8e5dd1587b (patch) | |
tree | eb7cfc80168f61e9cc0a5a61cf8c351313c4612a | |
parent | 636f550d7e66cc88bfbf06b8218bed4d08a775f3 (diff) | |
download | ydb-41e73b0260fb91fbeadbdd05d6ab2a8e5dd1587b.tar.gz |
Revert "Temporary remove ut again"
This reverts commit 0128a9a084018b44ea20ff44ae720ba35f7f9d2b, reversing
changes made to 32bab2c8cafd60816061e4d747e87337c6497458.
-rw-r--r-- | CMakeLists.darwin.txt | 1 | ||||
-rw-r--r-- | CMakeLists.linux.txt | 1 | ||||
-rw-r--r-- | ydb/library/yql/providers/dq/actors/grouped_issues_ut.cpp | 83 | ||||
-rw-r--r-- | ydb/library/yql/providers/dq/actors/ut/CMakeLists.darwin.txt | 46 | ||||
-rw-r--r-- | ydb/library/yql/providers/dq/actors/ut/CMakeLists.linux.txt | 50 | ||||
-rw-r--r-- | ydb/library/yql/providers/dq/actors/ut/CMakeLists.txt | 13 |
6 files changed, 194 insertions, 0 deletions
diff --git a/CMakeLists.darwin.txt b/CMakeLists.darwin.txt index f93658dc331..6301e267269 100644 --- a/CMakeLists.darwin.txt +++ b/CMakeLists.darwin.txt @@ -1382,6 +1382,7 @@ add_subdirectory(ydb/public/sdk/cpp/examples/ttl) add_subdirectory(ydb/library/yql/providers/common/codec/ut) add_subdirectory(ydb/library/yql/providers/common/http_gateway/mock) add_subdirectory(ydb/library/yql/providers/common/structured_token/ut) +add_subdirectory(ydb/library/yql/providers/dq/actors/ut) add_subdirectory(ydb/library/yql/providers/pq/gateway/dummy) add_subdirectory(ydb/library/yql/providers/s3/path_generator/ut) add_subdirectory(ydb/library/yql/providers/s3/range_helpers/ut) diff --git a/CMakeLists.linux.txt b/CMakeLists.linux.txt index 49fb1cec4e1..bf46e5d3a90 100644 --- a/CMakeLists.linux.txt +++ b/CMakeLists.linux.txt @@ -1404,6 +1404,7 @@ add_subdirectory(ydb/public/sdk/cpp/examples/ttl) add_subdirectory(ydb/library/yql/providers/common/codec/ut) add_subdirectory(ydb/library/yql/providers/common/http_gateway/mock) add_subdirectory(ydb/library/yql/providers/common/structured_token/ut) +add_subdirectory(ydb/library/yql/providers/dq/actors/ut) add_subdirectory(ydb/library/yql/providers/pq/gateway/dummy) add_subdirectory(ydb/library/yql/providers/s3/path_generator/ut) add_subdirectory(ydb/library/yql/providers/s3/range_helpers/ut) diff --git a/ydb/library/yql/providers/dq/actors/grouped_issues_ut.cpp b/ydb/library/yql/providers/dq/actors/grouped_issues_ut.cpp new file mode 100644 index 00000000000..dc148c5e100 --- /dev/null +++ b/ydb/library/yql/providers/dq/actors/grouped_issues_ut.cpp @@ -0,0 +1,83 @@ +#include <ydb/library/yql/providers/dq/actors/grouped_issues.h> + +#include <library/cpp/testing/unittest/registar.h> +#include <library/cpp/time_provider/time_provider.h> + + +namespace NYq { + +using namespace NYql; + +struct AgileTimeProvider: ITimeProvider { + AgileTimeProvider(ui64 secs): Value(TInstant::Seconds(secs)) { + } + + void IncreaseTime(ui64 secs_to_add) { + Value = TInstant::Seconds(Value.Seconds() + secs_to_add); + } + + TInstant Now() { + return Value; + } + + TInstant Value = Now(); +}; + +TIntrusivePtr<AgileTimeProvider> CreateAgileTimeProvider(ui64 initial) { + return TIntrusivePtr<AgileTimeProvider>(new AgileTimeProvider(initial)); +} + +Y_UNIT_TEST_SUITE(TestIssuesGrouping) { + Y_UNIT_TEST(ShouldCountEveryIssue) { + int iterations = 4; + int issueTypes = 4; + int expectedNumberOfIssues[issueTypes]; + + for (int i = 0; i < iterations; ++i) { + NDq::GroupedIssues holder(CreateDefaultTimeProvider()); + for (int j = 0; j < issueTypes; ++j) { + expectedNumberOfIssues[j] = rand() % 100; + for (int k = 0; k < expectedNumberOfIssues[j]; ++k) { + holder.AddIssue(TIssue(ToString(j))); + } + } + UNIT_ASSERT(holder.Issues.size() == 4); + for (int j = 0; j < issueTypes; ++j) { + int encounters = holder.Issues[TIssue(ToString(j))].EncountersNumber; + UNIT_ASSERT_C(encounters == expectedNumberOfIssues[j], + "expected " << expectedNumberOfIssues[j] << " got " << encounters << " at index " << j << " at iteration " << i); + } + } + } + + Y_UNIT_TEST(ShouldRemoveOldIssues) { + TIntrusivePtr<AgileTimeProvider> timeProvider = CreateAgileTimeProvider(1); + NDq::GroupedIssues holder(timeProvider); + holder.IssueExpiration = TDuration::Seconds(5); + holder.AddIssue(TIssue("a")); + timeProvider->IncreaseTime(10); + holder.AddIssue(TIssue("b")); + UNIT_ASSERT_C(holder.Issues.size() < 2, "old issue is not removed"); + } + + Y_UNIT_TEST(ShouldRemoveIfMoreThanMaxIssues) { + NDq::GroupedIssues holder(CreateDefaultTimeProvider()); + for (int i = 0; i < 30; ++i) { + holder.AddIssue(TIssue(ToString(i))); + } + UNIT_ASSERT_C(holder.Issues.size() <= holder.MaxIssues, "overflow issues are not removed"); + } + + Y_UNIT_TEST(ShouldRemoveTheOldestIfMoreThanMaxIssues) { + TIntrusivePtr<AgileTimeProvider> timeProvider = CreateAgileTimeProvider(1); + NDq::GroupedIssues holder(timeProvider); + auto eldery = TIssue("there is a simple honor in poverty"); + holder.AddIssue(eldery); + timeProvider->IncreaseTime(1); + for (int i = 0; i < 20; ++i) { + holder.AddIssue(TIssue(ToString(i))); + } + UNIT_ASSERT_C(!holder.Issues.contains(eldery), "the oldest issue is not removed"); + } +} +} // namespace NYq diff --git a/ydb/library/yql/providers/dq/actors/ut/CMakeLists.darwin.txt b/ydb/library/yql/providers/dq/actors/ut/CMakeLists.darwin.txt new file mode 100644 index 00000000000..c19c1242341 --- /dev/null +++ b/ydb/library/yql/providers/dq/actors/ut/CMakeLists.darwin.txt @@ -0,0 +1,46 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_executable(ydb-library-yql-providers-dq-actors-ut) +target_include_directories(ydb-library-yql-providers-dq-actors-ut PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/library/yql/providers/dq/actors +) +target_link_libraries(ydb-library-yql-providers-dq-actors-ut PUBLIC + contrib-libs-cxxsupp + yutil + library-cpp-cpuid_check + cpp-testing-unittest_main + providers-dq-actors + cpp-testing-unittest + library-cpp-time_provider + udf-service-stub +) +target_link_options(ydb-library-yql-providers-dq-actors-ut PRIVATE + -Wl,-no_deduplicate + -Wl,-sdk_version,10.15 + -fPIC + -fPIC + -framework + CoreFoundation +) +target_sources(ydb-library-yql-providers-dq-actors-ut PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/library/yql/providers/dq/actors/grouped_issues_ut.cpp +) +add_test( + NAME + ydb-library-yql-providers-dq-actors-ut + COMMAND + ydb-library-yql-providers-dq-actors-ut + --print-before-suite + --print-before-test + --fork-tests + --print-times + --show-fails +) +vcs_info(ydb-library-yql-providers-dq-actors-ut) diff --git a/ydb/library/yql/providers/dq/actors/ut/CMakeLists.linux.txt b/ydb/library/yql/providers/dq/actors/ut/CMakeLists.linux.txt new file mode 100644 index 00000000000..d0d1136979d --- /dev/null +++ b/ydb/library/yql/providers/dq/actors/ut/CMakeLists.linux.txt @@ -0,0 +1,50 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_executable(ydb-library-yql-providers-dq-actors-ut) +target_include_directories(ydb-library-yql-providers-dq-actors-ut PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/library/yql/providers/dq/actors +) +target_link_libraries(ydb-library-yql-providers-dq-actors-ut PUBLIC + contrib-libs-cxxsupp + yutil + cpp-malloc-tcmalloc + libs-tcmalloc-no_percpu_cache + library-cpp-cpuid_check + cpp-testing-unittest_main + providers-dq-actors + cpp-testing-unittest + library-cpp-time_provider + udf-service-stub +) +target_link_options(ydb-library-yql-providers-dq-actors-ut PRIVATE + -ldl + -lrt + -Wl,--no-as-needed + -fPIC + -fPIC + -lpthread + -lrt + -ldl +) +target_sources(ydb-library-yql-providers-dq-actors-ut PRIVATE + ${CMAKE_SOURCE_DIR}/ydb/library/yql/providers/dq/actors/grouped_issues_ut.cpp +) +add_test( + NAME + ydb-library-yql-providers-dq-actors-ut + COMMAND + ydb-library-yql-providers-dq-actors-ut + --print-before-suite + --print-before-test + --fork-tests + --print-times + --show-fails +) +vcs_info(ydb-library-yql-providers-dq-actors-ut) diff --git a/ydb/library/yql/providers/dq/actors/ut/CMakeLists.txt b/ydb/library/yql/providers/dq/actors/ut/CMakeLists.txt new file mode 100644 index 00000000000..fc7b1ee73ce --- /dev/null +++ b/ydb/library/yql/providers/dq/actors/ut/CMakeLists.txt @@ -0,0 +1,13 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + +if (APPLE) + include(CMakeLists.darwin.txt) +elseif (UNIX AND NOT APPLE) + include(CMakeLists.linux.txt) +endif() |