aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/http_client/ut/raw_batch_request_ut.cpp
diff options
context:
space:
mode:
authorhiddenpath <hiddenpath@yandex-team.com>2025-01-22 08:47:22 +0300
committerhiddenpath <hiddenpath@yandex-team.com>2025-01-22 09:04:11 +0300
commit044fc00c5520ec73b6146427ce9f1cf80ec6a95f (patch)
tree6d8b56e510374542ad49e5588c25d95701d7cf02 /yt/cpp/mapreduce/http_client/ut/raw_batch_request_ut.cpp
parent8f9ae59afa6108d373d287e973a7597c0a89143e (diff)
downloadydb-044fc00c5520ec73b6146427ce9f1cf80ec6a95f.tar.gz
YT-23616: Rename raw_client to http_client
commit_hash:df330f3a0c0ca36d9bcf801fd96b964f1be6383a
Diffstat (limited to 'yt/cpp/mapreduce/http_client/ut/raw_batch_request_ut.cpp')
-rw-r--r--yt/cpp/mapreduce/http_client/ut/raw_batch_request_ut.cpp121
1 files changed, 121 insertions, 0 deletions
diff --git a/yt/cpp/mapreduce/http_client/ut/raw_batch_request_ut.cpp b/yt/cpp/mapreduce/http_client/ut/raw_batch_request_ut.cpp
new file mode 100644
index 0000000000..f185b5a606
--- /dev/null
+++ b/yt/cpp/mapreduce/http_client/ut/raw_batch_request_ut.cpp
@@ -0,0 +1,121 @@
+#include <yt/cpp/mapreduce/http_client/raw_batch_request.h>
+
+#include <yt/cpp/mapreduce/http/context.h>
+#include <yt/cpp/mapreduce/interface/client_method_options.h>
+#include <yt/cpp/mapreduce/interface/errors.h>
+#include <yt/cpp/mapreduce/common/retry_lib.h>
+
+#include <library/cpp/testing/gtest/gtest.h>
+
+using namespace NYT;
+using namespace NYT::NDetail;
+using namespace NYT::NDetail::NRawClient;
+
+
+class TTestRetryPolicy
+ : public IRequestRetryPolicy
+{
+private:
+ static constexpr int RetriableCode = 904;
+
+public:
+ void NotifyNewAttempt() override
+ { }
+
+ TMaybe<TDuration> OnGenericError(const std::exception& /*e*/) override
+ {
+ return TDuration::Seconds(42);
+ }
+
+ void OnIgnoredError(const TErrorResponse& /*e*/) override
+ { }
+
+ TMaybe<TDuration> OnRetriableError(const TErrorResponse& e) override
+ {
+ if (e.GetError().GetCode() == RetriableCode) {
+ return TDuration::Seconds(e.GetError().GetAttributes().at("retry_interval").AsUint64());
+ } else {
+ return Nothing();
+ }
+ }
+
+ TString GetAttemptDescription() const override
+ {
+ return "attempt";
+ }
+
+ static TNode GenerateRetriableError(TDuration retryDuration)
+ {
+ Y_ABORT_UNLESS(retryDuration - TDuration::Seconds(retryDuration.Seconds()) == TDuration::Zero());
+
+ return TNode()
+ ("code", RetriableCode)
+ ("attributes",
+ TNode()
+ ("retry_interval", retryDuration.Seconds()));
+ }
+};
+
+
+TString GetPathFromRequest(const TNode& params)
+{
+ return params.AsMap().at("parameters").AsMap().at("path").AsString();
+}
+
+TVector<TString> GetAllPathsFromRequestList(const TNode& requestList)
+{
+ TVector<TString> result;
+ for (const auto& request : requestList.AsList()) {
+ result.push_back(GetPathFromRequest(request)); }
+ return result;
+}
+
+
+TEST(TBatchRequestImplTest, ParseResponse) {
+ TClientContext context;
+ THttpRawBatchRequest batchRequest(context, /*retryPolicy*/ nullptr);
+
+ EXPECT_EQ(batchRequest.BatchSize(), 0u);
+
+ auto get1 = batchRequest.Get(
+ TTransactionId(),
+ "//getOk",
+ TGetOptions());
+
+ auto get2 = batchRequest.Get(
+ TTransactionId(),
+ "//getError-3",
+ TGetOptions());
+
+ auto get3 = batchRequest.Get(
+ TTransactionId(),
+ "//getError-5",
+ TGetOptions());
+
+ EXPECT_EQ(batchRequest.BatchSize(), 3u);
+
+ auto testRetryPolicy = MakeIntrusive<TTestRetryPolicy>();
+ const TInstant now = TInstant::Seconds(100500);
+
+ batchRequest.ParseResponse(
+ TNode()
+ .Add(TNode()("output", 5))
+ .Add(TNode()("error",
+ TTestRetryPolicy::GenerateRetriableError(TDuration::Seconds(3))))
+ .Add(TNode()("error",
+ TTestRetryPolicy::GenerateRetriableError(TDuration::Seconds(5)))),
+ "<no-request-id>",
+ testRetryPolicy,
+ now);
+
+ EXPECT_EQ(batchRequest.BatchSize(), 2u);
+
+ TNode retryParameterList;
+ TInstant nextTry;
+ batchRequest.FillParameterList(3, &retryParameterList, &nextTry);
+ EXPECT_EQ(
+ GetAllPathsFromRequestList(retryParameterList),
+ TVector<TString>({"//getError-3", "//getError-5"}));
+
+ EXPECT_EQ(nextTry, now + TDuration::Seconds(5));
+}