job_counters_ut.cpp 4.7 KB

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