16 #include <aws/core/Aws.h> 17 #include <aws/core/client/AWSClient.h> 18 #include <aws/core/NoResult.h> 22 #include <gtest/gtest.h> 34 std::list<Aws::CloudWatchLogs::Model::InputLogEvent>
logs_list_;
36 std::shared_ptr<CloudWatchLogsFacade>
facade_;
43 logs_list_.emplace_back();
44 logs_list_.emplace_back();
46 Aws::InitAPI(options_);
47 mock_client = std::make_shared<CloudWatchLogsClientMock>();
48 mock_client_p = mock_client.get();
49 facade_ = std::make_shared<CloudWatchLogsFacade>(mock_client);
55 Aws::ShutdownAPI(options_);
58 std::chrono::milliseconds
Now()
const {
59 return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch());
68 std::list<Aws::CloudWatchLogs::Model::InputLogEvent> empty_logs_list;
69 Aws::String nextToken;
71 facade_->SendLogsToCloudWatch(nextToken,
"",
"", empty_logs_list));
76 Aws::CloudWatchLogs::Model::PutLogEventsOutcome failedOutcome;
77 EXPECT_CALL(*mock_client_p, PutLogEvents(testing::_))
78 .WillOnce(testing::Return(failedOutcome));
79 Aws::String nextToken;
82 facade_->SendLogsToCloudWatch(nextToken,
"",
"", logs_list_));
87 Aws::CloudWatchLogs::Model::PutLogEventsResult successResult;
88 Aws::CloudWatchLogs::Model::PutLogEventsOutcome successOutcome(successResult);
89 EXPECT_CALL(*mock_client_p, PutLogEvents(testing::_))
90 .WillOnce(testing::Return(successOutcome));
91 Aws::String nextToken;
94 facade_->SendLogsToCloudWatch(nextToken,
"",
"", logs_list_));
99 Aws::CloudWatchLogs::Model::PutLogEventsResult successResult;
100 Aws::CloudWatchLogs::Model::PutLogEventsOutcome successOutcome(successResult);
101 EXPECT_CALL(*mock_client_p, PutLogEvents(testing::_))
103 .WillRepeatedly(testing::Return(successOutcome));
105 Aws::String nextToken;
106 std::list<Aws::CloudWatchLogs::Model::InputLogEvent> logs_list;
107 for (
int i=0;i<200;i++) {
108 logs_list.emplace_back();
112 facade_->SendLogsToCloudWatch(nextToken,
"",
"", logs_list));
117 Aws::CloudWatchLogs::Model::PutLogEventsResult successResult;
118 Aws::CloudWatchLogs::Model::PutLogEventsOutcome successOutcome(successResult);
119 EXPECT_CALL(*mock_client_p, PutLogEvents(testing::_))
120 .WillRepeatedly(testing::Return(successOutcome));
122 const size_t count = 20;
126 const double expect_seconds = (count - 1) / 5.0;
127 const std::chrono::milliseconds min_time(
int(expect_seconds * 1000));
129 Aws::String nextToken;
130 const auto start = Now();
131 for (
int i = 0; i < 20; i++) {
133 facade_->SendLogsToCloudWatch(nextToken,
"",
"", logs_list_));
135 const auto end = Now();
137 EXPECT_GE((end - start).count(), min_time.count());
147 Aws::CloudWatchLogs::Model::CreateLogGroupOutcome* successOutcome =
148 new Aws::CloudWatchLogs::Model::CreateLogGroupOutcome(Aws::NoResult());
150 EXPECT_CALL(*mock_client_p, CreateLogGroup(testing::_))
151 .WillOnce(testing::Return(*successOutcome));
159 auto* failedOutcome =
160 new Aws::CloudWatchLogs::Model::CreateLogGroupOutcome();
162 EXPECT_CALL(*mock_client_p, CreateLogGroup(testing::_))
163 .WillOnce(testing::Return(*failedOutcome));
171 Aws::Client::AWSError<Aws::CloudWatchLogs::CloudWatchLogsErrors> error
172 (Aws::CloudWatchLogs::CloudWatchLogsErrors::RESOURCE_ALREADY_EXISTS,
false);
174 auto* failedOutcome =
175 new Aws::CloudWatchLogs::Model::CreateLogGroupOutcome(error);
177 EXPECT_CALL(*mock_client_p, CreateLogGroup(testing::_))
178 .WillOnce(testing::Return(*failedOutcome));
190 Aws::CloudWatchLogs::Model::DescribeLogGroupsOutcome failedOutcome;
191 EXPECT_CALL(*mock_client_p, DescribeLogGroups(testing::_))
192 .WillOnce(testing::Return(failedOutcome));
200 Aws::CloudWatchLogs::Model::LogGroup TestGroup;
202 Aws::CloudWatchLogs::Model::DescribeLogGroupsResult existsResult;
203 existsResult.AddLogGroups(TestGroup);
204 existsResult.SetNextToken(
"token");
205 Aws::CloudWatchLogs::Model::DescribeLogGroupsOutcome existsOutcome(existsResult);
206 EXPECT_CALL(*mock_client_p, DescribeLogGroups(testing::_))
207 .WillOnce(testing::Return(existsOutcome));
214 { Aws::CloudWatchLogs::Model::LogGroup TestGroup;
216 Aws::CloudWatchLogs::Model::DescribeLogGroupsResult doesntExistResult;
217 doesntExistResult.AddLogGroups(TestGroup);
218 doesntExistResult.SetNextToken(
"");
219 Aws::CloudWatchLogs::Model::DescribeLogGroupsOutcome doesntExistOutcome(doesntExistResult);
220 EXPECT_CALL(*mock_client_p, DescribeLogGroups(testing::_))
221 .WillOnce(testing::Return(doesntExistOutcome));
233 Aws::CloudWatchLogs::Model::CreateLogStreamOutcome* successOutcome =
234 new Aws::CloudWatchLogs::Model::CreateLogStreamOutcome(Aws::NoResult());
236 EXPECT_CALL(*mock_client_p, CreateLogStream(testing::_))
237 .WillOnce(testing::Return(*successOutcome));
247 Aws::Client::AWSError<Aws::CloudWatchLogs::CloudWatchLogsErrors> error(
248 Aws::CloudWatchLogs::CloudWatchLogsErrors::INTERNAL_FAILURE,
false);
250 auto* failedOutcome =
new Aws::CloudWatchLogs::Model::CreateLogStreamOutcome(error);
252 EXPECT_CALL(*mock_client_p, CreateLogStream(testing::_))
253 .WillOnce(testing::Return(*failedOutcome));
261 Aws::Client::AWSError<Aws::CloudWatchLogs::CloudWatchLogsErrors> error
262 (Aws::CloudWatchLogs::CloudWatchLogsErrors::RESOURCE_ALREADY_EXISTS,
false);
264 auto* failedOutcome =
265 new Aws::CloudWatchLogs::Model::CreateLogStreamOutcome(error);
267 EXPECT_CALL(*mock_client_p, CreateLogStream(testing::_))
268 .WillOnce(testing::Return(*failedOutcome));
280 Aws::CloudWatchLogs::Model::DescribeLogStreamsOutcome failedOutcome;
281 Aws::CloudWatchLogs::Model::LogStream * log_stream_object =
nullptr;
282 EXPECT_CALL(*mock_client_p, DescribeLogStreams(testing::_))
283 .WillOnce(testing::Return(failedOutcome));
291 Aws::CloudWatchLogs::Model::LogStream TestStream;
293 Aws::CloudWatchLogs::Model::DescribeLogStreamsResult existsResult;
294 existsResult.AddLogStreams(TestStream);
295 existsResult.SetNextToken(
"token");
296 Aws::CloudWatchLogs::Model::DescribeLogStreamsOutcome existsOutcome(existsResult);
297 EXPECT_CALL(*mock_client_p, DescribeLogStreams(testing::_))
298 .WillOnce(testing::Return(existsOutcome));
300 auto * log_stream_object =
new Aws::CloudWatchLogs::Model::LogStream();
307 { Aws::CloudWatchLogs::Model::LogStream TestStream;
309 Aws::CloudWatchLogs::Model::DescribeLogStreamsResult doesntExistResult;
310 doesntExistResult.AddLogStreams(TestStream);
311 Aws::CloudWatchLogs::Model::DescribeLogStreamsOutcome doesntExistOutcome(doesntExistResult);
312 EXPECT_CALL(*mock_client_p, DescribeLogStreams(testing::_))
313 .WillOnce(testing::Return(doesntExistOutcome));
315 Aws::CloudWatchLogs::Model::LogStream * log_stream_object =
nullptr;
std::shared_ptr< CloudWatchLogsFacade > facade_
constexpr char LOG_GROUP_NAME2[]
constexpr char LOG_STREAM_NAME1[]
TEST_F(TestCloudWatchFacade, TestCWLogsFacade_SendLogsToCloudWatch_EmptyLogs)
constexpr char LOG_STREAM_NAME2[]
Contains Error handling functionality for ROS AWS CloudWatch Logs libraries.
std::chrono::milliseconds Now() const
constexpr char LOG_GROUP_NAME1[]
std::shared_ptr< CloudWatchLogsClientMock > mock_client
std::list< Aws::CloudWatchLogs::Model::InputLogEvent > logs_list_