job_counters_ut.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include <yt/cpp/mapreduce/interface/job_counters.h>
  2. #include <yt/cpp/mapreduce/interface/operation.h>
  3. #include <library/cpp/yson/node/node_io.h>
  4. #include <library/cpp/testing/gtest/gtest.h>
  5. using namespace NYT;
  6. TEST(TJobCountersTest, Full)
  7. {
  8. const TString input = R"""(
  9. {
  10. "completed" = {
  11. "total" = 6;
  12. "non-interrupted" = 1;
  13. "interrupted" = {
  14. "whatever_interrupted" = 2;
  15. "whatever_else_interrupted" = 3;
  16. };
  17. };
  18. "aborted" = {
  19. "non_scheduled" = {
  20. "whatever_non_scheduled" = 4;
  21. "whatever_else_non_scheduled" = 5;
  22. };
  23. "scheduled" = {
  24. "whatever_scheduled" = 6;
  25. "whatever_else_scheduled" = 7;
  26. };
  27. "total" = 22;
  28. };
  29. "lost" = 8;
  30. "invalidated" = 9;
  31. "failed" = 10;
  32. "running" = 11;
  33. "suspended" = 12;
  34. "pending" = 13;
  35. "blocked" = 14;
  36. "total" = 105;
  37. })""";
  38. TJobCounters counters(NodeFromYsonString(input));
  39. EXPECT_EQ(counters.GetTotal(), 105u);
  40. EXPECT_EQ(counters.GetCompleted().GetTotal(), 6u);
  41. EXPECT_EQ(counters.GetCompletedNonInterrupted().GetTotal(), 1u);
  42. EXPECT_EQ(counters.GetCompletedInterrupted().GetTotal(), 5u);
  43. EXPECT_EQ(counters.GetAborted().GetTotal(), 22u);
  44. EXPECT_EQ(counters.GetAbortedNonScheduled().GetTotal(), 9u);
  45. EXPECT_EQ(counters.GetAbortedScheduled().GetTotal(), 13u);
  46. EXPECT_EQ(counters.GetLost().GetTotal(), 8u);
  47. EXPECT_EQ(counters.GetInvalidated().GetTotal(), 9u);
  48. EXPECT_EQ(counters.GetFailed().GetTotal(), 10u);
  49. EXPECT_EQ(counters.GetRunning().GetTotal(), 11u);
  50. EXPECT_EQ(counters.GetSuspended().GetTotal(), 12u);
  51. EXPECT_EQ(counters.GetPending().GetTotal(), 13u);
  52. EXPECT_EQ(counters.GetBlocked().GetTotal(), 14u);
  53. EXPECT_EQ(counters.GetCompletedInterrupted().GetValue("whatever_interrupted"), 2u);
  54. EXPECT_EQ(counters.GetCompletedInterrupted().GetValue("whatever_else_interrupted"), 3u);
  55. EXPECT_EQ(counters.GetAbortedNonScheduled().GetValue("whatever_non_scheduled"), 4u);
  56. EXPECT_EQ(counters.GetAbortedNonScheduled().GetValue("whatever_else_non_scheduled"), 5u);
  57. EXPECT_EQ(counters.GetAbortedScheduled().GetValue("whatever_scheduled"), 6u);
  58. EXPECT_EQ(counters.GetAbortedScheduled().GetValue("whatever_else_scheduled"), 7u);
  59. EXPECT_THROW(counters.GetCompletedInterrupted().GetValue("Nothingness"), yexception);
  60. }
  61. TEST(TJobCountersTest, Empty)
  62. {
  63. const TString input = "{}";
  64. TJobCounters counters(NodeFromYsonString(input));
  65. EXPECT_EQ(counters.GetTotal(), 0u);
  66. EXPECT_EQ(counters.GetCompleted().GetTotal(), 0u);
  67. EXPECT_EQ(counters.GetCompletedNonInterrupted().GetTotal(), 0u);
  68. EXPECT_EQ(counters.GetCompletedInterrupted().GetTotal(), 0u);
  69. EXPECT_EQ(counters.GetAborted().GetTotal(), 0u);
  70. EXPECT_EQ(counters.GetAbortedNonScheduled().GetTotal(), 0u);
  71. EXPECT_EQ(counters.GetAbortedScheduled().GetTotal(), 0u);
  72. EXPECT_EQ(counters.GetLost().GetTotal(), 0u);
  73. EXPECT_EQ(counters.GetInvalidated().GetTotal(), 0u);
  74. EXPECT_EQ(counters.GetFailed().GetTotal(), 0u);
  75. EXPECT_EQ(counters.GetRunning().GetTotal(), 0u);
  76. EXPECT_EQ(counters.GetSuspended().GetTotal(), 0u);
  77. EXPECT_EQ(counters.GetPending().GetTotal(), 0u);
  78. EXPECT_EQ(counters.GetBlocked().GetTotal(), 0u);
  79. }
  80. TEST(TJobCountersTest, Broken)
  81. {
  82. EXPECT_THROW_MESSAGE_HAS_SUBSTR((TJobCounters(TNode())), yexception, "TJobCounters");
  83. EXPECT_THROW_MESSAGE_HAS_SUBSTR((TJobCounters(TNode(1))), yexception, "TJobCounters");
  84. EXPECT_THROW_MESSAGE_HAS_SUBSTR((TJobCounters(TNode(1.0))), yexception, "TJobCounters");
  85. EXPECT_THROW_MESSAGE_HAS_SUBSTR((TJobCounters(TNode("Whatever"))), yexception, "TJobCounters");
  86. }