raw_requests_ut.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #include <yt/cpp/mapreduce/raw_client/raw_requests.h>
  2. #include <library/cpp/yson/node/node_io.h>
  3. #include <library/cpp/testing/gtest/gtest.h>
  4. using namespace NYT;
  5. using namespace NYT::NDetail;
  6. using namespace NYT::NDetail::NRawClient;
  7. TEST(TOperationsApiParsingTest, ParseOperationAttributes)
  8. {
  9. auto response = TStringBuf(R"""({
  10. "id" = "1-2-3-4";
  11. "authenticated_user" = "some-user";
  12. "start_time" = "2018-01-01T00:00:00.0Z";
  13. "weight" = 1.;
  14. "state" = "completed";
  15. "suspended" = %false;
  16. "finish_time" = "2018-01-02T00:00:00.0Z";
  17. "brief_progress" = {
  18. "jobs" = {
  19. "lost" = 0;
  20. "pending" = 0;
  21. "failed" = 1;
  22. "aborted" = 0;
  23. "total" = 84;
  24. "running" = 0;
  25. "completed" = 84;
  26. };
  27. };
  28. "result" = {
  29. "error" = {
  30. "attributes" = {};
  31. "code" = 0;
  32. "message" = "";
  33. };
  34. };
  35. "brief_spec" = {
  36. "input_table_paths" = <
  37. "count" = 1;
  38. > [
  39. "//some-input";
  40. ];
  41. "pool" = "some-pool";
  42. "scheduling_info_per_pool_tree" = {
  43. "physical" = {
  44. "pool" = "some-pool";
  45. };
  46. };
  47. "title" = "some-title";
  48. "output_table_paths" = <
  49. "count" = 1;
  50. > [
  51. "//some-output";
  52. ];
  53. "mapper" = {
  54. "command" = "some-command";
  55. };
  56. };
  57. "type" = "map";
  58. "pool" = "some-pool";
  59. "progress" = {
  60. "build_time" = "2018-01-01T00:00:00.000000Z";
  61. "job_statistics" = {
  62. "data" = {
  63. "input" = {
  64. "row_count" = {
  65. "$" = {
  66. "failed" = {
  67. "map" = {
  68. "max" = 1;
  69. "count" = 1;
  70. "sum" = 1;
  71. "min" = 1;
  72. };
  73. };
  74. "completed" = {
  75. "map" = {
  76. "max" = 1;
  77. "count" = 84;
  78. "sum" = 84;
  79. "min" = 1;
  80. };
  81. };
  82. };
  83. };
  84. };
  85. };
  86. };
  87. "total_job_counter" = {
  88. "completed" = {
  89. "total" = 3;
  90. "non-interrupted" = 1;
  91. "interrupted" = {
  92. "whatever_interrupted" = 2;
  93. };
  94. };
  95. "aborted" = {
  96. "non_scheduled" = {
  97. "whatever_non_scheduled" = 3;
  98. };
  99. "scheduled" = {
  100. "whatever_scheduled" = 4;
  101. };
  102. "total" = 7;
  103. };
  104. "lost" = 5;
  105. "invalidated" = 6;
  106. "failed" = 7;
  107. "running" = 8;
  108. "suspended" = 9;
  109. "pending" = 10;
  110. "blocked" = 11;
  111. "total" = 66;
  112. };
  113. };
  114. "events" = [
  115. {"state" = "pending"; "time" = "2018-01-01T00:00:00.000000Z";};
  116. {"state" = "materializing"; "time" = "2018-01-02T00:00:00.000000Z";};
  117. {"state" = "running"; "time" = "2018-01-03T00:00:00.000000Z";};
  118. ];
  119. })""");
  120. auto attrs = ParseOperationAttributes(NodeFromYsonString(response));
  121. EXPECT_TRUE(attrs.Id);
  122. EXPECT_EQ(GetGuidAsString(*attrs.Id), "1-2-3-4");
  123. EXPECT_TRUE(attrs.Type);
  124. EXPECT_EQ(*attrs.Type, EOperationType::Map);
  125. EXPECT_TRUE(attrs.State);
  126. EXPECT_EQ(*attrs.State, "completed");
  127. EXPECT_TRUE(attrs.BriefState);
  128. EXPECT_EQ(*attrs.BriefState, EOperationBriefState::Completed);
  129. EXPECT_TRUE(attrs.AuthenticatedUser);
  130. EXPECT_EQ(*attrs.AuthenticatedUser, "some-user");
  131. EXPECT_TRUE(attrs.StartTime);
  132. EXPECT_TRUE(attrs.FinishTime);
  133. EXPECT_EQ(*attrs.FinishTime - *attrs.StartTime, TDuration::Days(1));
  134. EXPECT_TRUE(attrs.BriefProgress);
  135. EXPECT_EQ(attrs.BriefProgress->Completed, 84u);
  136. EXPECT_EQ(attrs.BriefProgress->Failed, 1u);
  137. EXPECT_TRUE(attrs.BriefSpec);
  138. EXPECT_EQ((*attrs.BriefSpec)["title"].AsString(), "some-title");
  139. EXPECT_TRUE(attrs.Suspended);
  140. EXPECT_EQ(*attrs.Suspended, false);
  141. EXPECT_TRUE(attrs.Result);
  142. EXPECT_TRUE(!attrs.Result->Error);
  143. EXPECT_TRUE(attrs.Progress);
  144. EXPECT_EQ(attrs.Progress->JobStatistics.JobState({}).GetStatistics("data/input/row_count").Sum(), 85u);
  145. EXPECT_EQ(attrs.Progress->JobCounters.GetCompletedInterrupted().GetTotal(), 2u);
  146. EXPECT_EQ(attrs.Progress->JobCounters.GetAbortedNonScheduled().GetTotal(), 3u);
  147. EXPECT_EQ(attrs.Progress->JobCounters.GetAbortedScheduled().GetTotal(), 4u);
  148. EXPECT_EQ(attrs.Progress->JobCounters.GetAborted().GetTotal(), 7u);
  149. EXPECT_EQ(attrs.Progress->JobCounters.GetFailed().GetTotal(), 7u);
  150. EXPECT_EQ(attrs.Progress->JobCounters.GetTotal(), 66u);
  151. EXPECT_EQ(*attrs.Progress->BuildTime, TInstant::ParseIso8601("2018-01-01T00:00:00.000000Z"));
  152. EXPECT_TRUE(attrs.Events);
  153. EXPECT_EQ((*attrs.Events)[1].State, "materializing");
  154. EXPECT_EQ((*attrs.Events)[1].Time, TInstant::ParseIso8601("2018-01-02T00:00:00.000000Z"));
  155. }
  156. TEST(TOperationsApiParsingTest, EmptyProgress)
  157. {
  158. auto response = TStringBuf(R"""({
  159. "id" = "1-2-3-4";
  160. "brief_progress" = {};
  161. "progress" = {};
  162. })""");
  163. auto attrs = ParseOperationAttributes(NodeFromYsonString(response));
  164. EXPECT_TRUE(attrs.Id);
  165. EXPECT_EQ(GetGuidAsString(*attrs.Id), "1-2-3-4");
  166. EXPECT_TRUE(!attrs.BriefProgress);
  167. EXPECT_TRUE(attrs.Progress);
  168. EXPECT_EQ(attrs.Progress->JobStatistics.JobState({}).GetStatisticsNames(), TVector<TString>{});
  169. EXPECT_EQ(attrs.Progress->JobCounters.GetTotal(), 0u);
  170. EXPECT_TRUE(!attrs.Progress->BuildTime);
  171. }