|
12 | 12 | #include <ydb/core/wrappers/ut_helpers/s3_mock.h> |
13 | 13 | #include <ydb/core/metering/metering.h> |
14 | 14 | #include <ydb/core/ydb_convert/table_description.h> |
| 15 | +#include <ydb/public/api/protos/ydb_import.pb.h> |
15 | 16 |
|
16 | 17 | #include <contrib/libs/zstd/include/zstd.h> |
17 | 18 | #include <library/cpp/string_utils/quote/quote.h> |
@@ -2949,6 +2950,162 @@ Y_UNIT_TEST_SUITE(TImportTests) { |
2949 | 2950 | env.TestWaitNotification(runtime, importId); |
2950 | 2951 | } |
2951 | 2952 |
|
| 2953 | + Y_UNIT_TEST(ImportStartTime) { |
| 2954 | + TTestBasicRuntime runtime; |
| 2955 | + TTestEnv env(runtime, TTestEnvOptions()); |
| 2956 | + ui64 txId = 100; |
| 2957 | + |
| 2958 | + const auto data = GenerateTestData(R"( |
| 2959 | + columns { |
| 2960 | + name: "key" |
| 2961 | + type { optional_type { item { type_id: UTF8 } } } |
| 2962 | + } |
| 2963 | + columns { |
| 2964 | + name: "value" |
| 2965 | + type { optional_type { item { type_id: UTF8 } } } |
| 2966 | + } |
| 2967 | + primary_key: "key" |
| 2968 | + )", {{"a", 1}}); |
| 2969 | + |
| 2970 | + TPortManager portManager; |
| 2971 | + const ui16 port = portManager.GetPort(); |
| 2972 | + |
| 2973 | + TS3Mock s3Mock(ConvertTestData(data), TS3Mock::TSettings(port)); |
| 2974 | + UNIT_ASSERT(s3Mock.Start()); |
| 2975 | + |
| 2976 | + TestImport(runtime, ++txId, "/MyRoot", Sprintf(R"( |
| 2977 | + ImportFromS3Settings { |
| 2978 | + endpoint: "localhost:%d" |
| 2979 | + scheme: HTTP |
| 2980 | + items { |
| 2981 | + source_prefix: "" |
| 2982 | + destination_path: "/MyRoot/Table" |
| 2983 | + } |
| 2984 | + } |
| 2985 | + )", port)); |
| 2986 | + |
| 2987 | + const auto desc = TestGetImport(runtime, txId, "/MyRoot"); |
| 2988 | + const auto& entry = desc.GetResponse().GetEntry(); |
| 2989 | + UNIT_ASSERT_VALUES_EQUAL(entry.GetProgress(), Ydb::Import::ImportProgress::PROGRESS_PREPARING); |
| 2990 | + UNIT_ASSERT(entry.HasStartTime()); |
| 2991 | + UNIT_ASSERT(!entry.HasEndTime()); |
| 2992 | + } |
| 2993 | + |
| 2994 | + Y_UNIT_TEST(CompletedImportEndTime) { |
| 2995 | + TTestBasicRuntime runtime; |
| 2996 | + TTestEnv env(runtime, TTestEnvOptions()); |
| 2997 | + ui64 txId = 100; |
| 2998 | + |
| 2999 | + const auto data = GenerateTestData(R"( |
| 3000 | + columns { |
| 3001 | + name: "key" |
| 3002 | + type { optional_type { item { type_id: UTF8 } } } |
| 3003 | + } |
| 3004 | + columns { |
| 3005 | + name: "value" |
| 3006 | + type { optional_type { item { type_id: UTF8 } } } |
| 3007 | + } |
| 3008 | + primary_key: "key" |
| 3009 | + )", {{"a", 1}}); |
| 3010 | + |
| 3011 | + TPortManager portManager; |
| 3012 | + const ui16 port = portManager.GetPort(); |
| 3013 | + |
| 3014 | + TS3Mock s3Mock(ConvertTestData(data), TS3Mock::TSettings(port)); |
| 3015 | + UNIT_ASSERT(s3Mock.Start()); |
| 3016 | + |
| 3017 | + TestImport(runtime, ++txId, "/MyRoot", Sprintf(R"( |
| 3018 | + ImportFromS3Settings { |
| 3019 | + endpoint: "localhost:%d" |
| 3020 | + scheme: HTTP |
| 3021 | + items { |
| 3022 | + source_prefix: "" |
| 3023 | + destination_path: "/MyRoot/Table" |
| 3024 | + } |
| 3025 | + } |
| 3026 | + )", port)); |
| 3027 | + |
| 3028 | + runtime.AdvanceCurrentTime(TDuration::Seconds(30)); // doing import |
| 3029 | + |
| 3030 | + env.TestWaitNotification(runtime, txId); |
| 3031 | + |
| 3032 | + const auto desc = TestGetImport(runtime, txId, "/MyRoot"); |
| 3033 | + const auto& entry = desc.GetResponse().GetEntry(); |
| 3034 | + UNIT_ASSERT_VALUES_EQUAL(entry.GetProgress(), Ydb::Import::ImportProgress::PROGRESS_DONE); |
| 3035 | + UNIT_ASSERT(entry.HasStartTime()); |
| 3036 | + UNIT_ASSERT(entry.HasEndTime()); |
| 3037 | + UNIT_ASSERT_LT(entry.GetStartTime().seconds(), entry.GetEndTime().seconds()); |
| 3038 | + } |
| 3039 | + |
| 3040 | + Y_UNIT_TEST(CancelledImportEndTime) { |
| 3041 | + TTestBasicRuntime runtime; |
| 3042 | + TTestEnv env(runtime, TTestEnvOptions()); |
| 3043 | + ui64 txId = 100; |
| 3044 | + |
| 3045 | + const auto data = GenerateTestData(R"( |
| 3046 | + columns { |
| 3047 | + name: "key" |
| 3048 | + type { optional_type { item { type_id: UTF8 } } } |
| 3049 | + } |
| 3050 | + columns { |
| 3051 | + name: "value" |
| 3052 | + type { optional_type { item { type_id: UTF8 } } } |
| 3053 | + } |
| 3054 | + primary_key: "key" |
| 3055 | + )", {{"a", 1}}); |
| 3056 | + |
| 3057 | + TPortManager portManager; |
| 3058 | + const ui16 port = portManager.GetPort(); |
| 3059 | + |
| 3060 | + TS3Mock s3Mock(ConvertTestData(data), TS3Mock::TSettings(port)); |
| 3061 | + UNIT_ASSERT(s3Mock.Start()); |
| 3062 | + |
| 3063 | + auto delayFunc = [](TAutoPtr<IEventHandle>& ev) { |
| 3064 | + if (ev->GetTypeRewrite() != TEvSchemeShard::EvModifySchemeTransaction) { |
| 3065 | + return false; |
| 3066 | + } |
| 3067 | + |
| 3068 | + return ev->Get<TEvSchemeShard::TEvModifySchemeTransaction>()->Record |
| 3069 | + .GetTransaction(0).GetOperationType() == NKikimrSchemeOp::ESchemeOpRestore; |
| 3070 | + }; |
| 3071 | + |
| 3072 | + THolder<IEventHandle> delayed; |
| 3073 | + auto prevObserver = SetDelayObserver(runtime, delayed, delayFunc); |
| 3074 | + |
| 3075 | + TestImport(runtime, ++txId, "/MyRoot", Sprintf(R"( |
| 3076 | + ImportFromS3Settings { |
| 3077 | + endpoint: "localhost:%d" |
| 3078 | + scheme: HTTP |
| 3079 | + items { |
| 3080 | + source_prefix: "" |
| 3081 | + destination_path: "/MyRoot/Table" |
| 3082 | + } |
| 3083 | + } |
| 3084 | + )", port)); |
| 3085 | + const ui64 importId = txId; |
| 3086 | + |
| 3087 | + runtime.AdvanceCurrentTime(TDuration::Seconds(30)); // doing import |
| 3088 | + |
| 3089 | + WaitForDelayed(runtime, delayed, prevObserver); |
| 3090 | + |
| 3091 | + TestCancelImport(runtime, ++txId, "/MyRoot", importId); |
| 3092 | + |
| 3093 | + auto desc = TestGetImport(runtime, importId, "/MyRoot"); |
| 3094 | + auto entry = desc.GetResponse().GetEntry(); |
| 3095 | + UNIT_ASSERT_VALUES_EQUAL(entry.GetProgress(), Ydb::Import::ImportProgress::PROGRESS_CANCELLATION); |
| 3096 | + UNIT_ASSERT(entry.HasStartTime()); |
| 3097 | + UNIT_ASSERT(!entry.HasEndTime()); |
| 3098 | + |
| 3099 | + runtime.Send(delayed.Release(), 0, true); |
| 3100 | + env.TestWaitNotification(runtime, importId); |
| 3101 | + |
| 3102 | + desc = TestGetImport(runtime, importId, "/MyRoot", Ydb::StatusIds::CANCELLED); |
| 3103 | + entry = desc.GetResponse().GetEntry(); |
| 3104 | + UNIT_ASSERT_VALUES_EQUAL(entry.GetProgress(), Ydb::Import::ImportProgress::PROGRESS_CANCELLED); |
| 3105 | + UNIT_ASSERT(entry.HasStartTime()); |
| 3106 | + UNIT_ASSERT(entry.HasEndTime()); |
| 3107 | + UNIT_ASSERT_LT(entry.GetStartTime().seconds(), entry.GetEndTime().seconds()); |
| 3108 | + } |
2952 | 3109 | } |
2953 | 3110 |
|
2954 | 3111 | Y_UNIT_TEST_SUITE(TImportWithRebootsTests) { |
|
0 commit comments