| 50 | } |
| 51 | |
| 52 | TEST(CountersTest, Basic) { |
| 53 | ObjectPool pool; |
| 54 | RuntimeProfile* profile_a = RuntimeProfile::Create(&pool, "ProfileA"); |
| 55 | RuntimeProfile* profile_a1 = RuntimeProfile::Create(&pool, "ProfileA1"); |
| 56 | RuntimeProfile* profile_a2 = RuntimeProfile::Create(&pool, "ProfileAb"); |
| 57 | |
| 58 | TRuntimeProfileTree thrift_profile; |
| 59 | |
| 60 | profile_a->AddChild(profile_a1); |
| 61 | profile_a->AddChild(profile_a2); |
| 62 | |
| 63 | // Test Empty |
| 64 | profile_a->ToThrift(&thrift_profile); |
| 65 | EXPECT_EQ(thrift_profile.nodes.size(), 3); |
| 66 | thrift_profile.nodes.clear(); |
| 67 | |
| 68 | RuntimeProfile::Counter* counter_a; |
| 69 | RuntimeProfile::Counter* counter_b; |
| 70 | RuntimeProfile::Counter* counter_merged; |
| 71 | |
| 72 | // Updating/setting counter |
| 73 | counter_a = profile_a->AddCounter("A", TUnit::UNIT); |
| 74 | EXPECT_TRUE(counter_a != NULL); |
| 75 | counter_a->Add(10); |
| 76 | counter_a->Add(-5); |
| 77 | EXPECT_EQ(counter_a->value(), 5); |
| 78 | counter_a->Set(1); |
| 79 | EXPECT_EQ(counter_a->value(), 1); |
| 80 | |
| 81 | counter_b = profile_a2->AddCounter("B", TUnit::BYTES); |
| 82 | EXPECT_TRUE(counter_b != NULL); |
| 83 | |
| 84 | // Update status to be included in ExecSummary |
| 85 | TExecSummary exec_summary; |
| 86 | TStatus status; |
| 87 | status.__set_status_code(TErrorCode::CANCELLED); |
| 88 | exec_summary.__set_status(status); |
| 89 | profile_a->SetTExecSummary(exec_summary); |
| 90 | |
| 91 | // Serialize/deserialize to thrift |
| 92 | profile_a->ToThrift(&thrift_profile); |
| 93 | RuntimeProfile* from_thrift = RuntimeProfile::CreateFromThrift(&pool, thrift_profile); |
| 94 | counter_merged = from_thrift->GetCounter("A"); |
| 95 | EXPECT_EQ(counter_merged->value(), 1); |
| 96 | EXPECT_TRUE(from_thrift->GetCounter("Not there") == NULL); |
| 97 | EXPECT_TRUE(from_thrift->GetCounter("Not there") == nullptr); |
| 98 | TExecSummary exec_summary_result; |
| 99 | from_thrift->GetExecSummary(&exec_summary_result); |
| 100 | EXPECT_EQ(exec_summary_result.status, status); |
| 101 | |
| 102 | // Serialize/deserialize to archive string |
| 103 | string archive_str; |
| 104 | EXPECT_OK(profile_a->SerializeToArchiveString(&archive_str)); |
| 105 | TRuntimeProfileTree deserialized_thrift_profile; |
| 106 | EXPECT_OK(RuntimeProfile::DeserializeFromArchiveString( |
| 107 | archive_str, &deserialized_thrift_profile)); |
| 108 | RuntimeProfile* deserialized_profile = |
| 109 | RuntimeProfile::CreateFromThrift(&pool, deserialized_thrift_profile); |
nothing calls this directly
no test coverage detected