16 #include <aws/core/Aws.h> 17 #include <aws/monitoring/model/MetricDatum.h> 19 #include <gtest/gtest.h> 35 uint32_t send_metrics_call_count{};
43 this->last_metric_namespace =
"";
44 this->send_metrics_ret_val = Utils::CloudWatchMetricsStatus::SUCCESS;
45 this->send_metrics_call_count = 0;
49 const std::string & metric_namespace,
52 this->last_metric_namespace = metric_namespace;
53 this->last_metrics = metrics;
54 this->send_metrics_call_count++;
55 return this->send_metrics_ret_val;
69 std::shared_ptr<MockCloudWatchFacade>
mock_cw_;
74 mock_cw_ = std::make_shared<MockCloudWatchFacade>();
75 std::shared_ptr<Utils::CloudWatchMetricsFacade> cw = mock_cw_;
76 publisher_ = std::make_shared<MetricPublisher>(
"test_namespace", cw);
77 metrics_list_.emplace_back();
78 metrics_list_.emplace_back();
79 EXPECT_FALSE(metrics_list_.empty());
80 EXPECT_TRUE(publisher_->start());
85 EXPECT_TRUE(publisher_->shutdown());
97 EXPECT_EQ(Aws::DataFlow::UploadStatus::INVALID_DATA, publisher_->attemptPublish(test_list));
98 EXPECT_EQ(PublisherState::NOT_CONNECTED, publisher_->getPublisherState());
99 EXPECT_EQ(0u, mock_cw_->send_metrics_call_count);
104 EXPECT_EQ(Aws::DataFlow::UploadStatus::SUCCESS, publisher_->attemptPublish(metrics_list_));
105 EXPECT_EQ(PublisherState::CONNECTED, publisher_->getPublisherState());
106 EXPECT_EQ(1u, mock_cw_->send_metrics_call_count);
112 EXPECT_EQ(Aws::DataFlow::UploadStatus::SUCCESS, publisher_->attemptPublish(metrics_list_));
113 EXPECT_EQ(PublisherState::CONNECTED, publisher_->getPublisherState());
114 EXPECT_EQ(1u, mock_cw_->send_metrics_call_count);
116 EXPECT_EQ(Aws::DataFlow::UploadStatus::SUCCESS, publisher_->attemptPublish(metrics_list_));
117 EXPECT_EQ(PublisherState::CONNECTED, publisher_->getPublisherState());
118 EXPECT_EQ(2u, mock_cw_->send_metrics_call_count);
std::list< Aws::CloudWatch::Model::MetricDatum > MetricDatumCollection
std::string last_metric_namespace
TEST_F(TestMetricPublisherFixture, Sanity)
MetricDatumCollection metrics_list_
MetricDatumCollection last_metrics
Utils::CloudWatchMetricsStatus send_metrics_ret_val
This class is a simple Facade over the CloudWatch client. This class is a very small abstraction over...
std::shared_ptr< MetricPublisher > publisher_
std::shared_ptr< MockCloudWatchFacade > mock_cw_
Utils::CloudWatchMetricsStatus SendMetricsToCloudWatch(const std::string &metric_namespace, MetricDatumCollection &metrics) override
Sends a list of metrics to CloudWatch Used to send a list of metrics to CloudWatch.