file_manager_test.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #include <iostream>
17 #include <fstream>
18 #include <cstdio>
19 #include <experimental/filesystem>
20 
21 #include <gtest/gtest.h>
22 #include <gmock/gmock.h>
23 #include <aws/monitoring/model/MetricDatum.h>
24 #include <aws/core/utils/memory/stl/AWSString.h>
25 #include <aws/core/utils/logging/ConsoleLogSystem.h>
26 #include <aws/core/utils/logging/AWSLogging.h>
27 
31 
32 
33 using namespace Aws::CloudWatchMetrics::Utils;
34 using namespace Aws::FileManagement;
35 
36 class FileManagerTest : public ::testing::Test {
37 public:
38  void SetUp() override
39  {
40  }
41 
42  void TearDown() override
43  {
44  std::experimental::filesystem::path storage_path(options.storage_directory);
45  std::experimental::filesystem::remove_all(storage_path);
46  }
47 
48 protected:
49  FileManagerStrategyOptions options{"test", "metric_tests/", ".metrics", 1024*1024, 1024*1024};
50 };
51 
55 TEST_F(FileManagerTest, file_manager_write) {
56  std::shared_ptr<FileManagerStrategy> file_manager_strategy = std::make_shared<FileManagerStrategy>(options);
57  std::shared_ptr<StatusMonitor> status_monitor = std::make_shared<StatusMonitor>();
58  MetricFileManager file_manager(file_manager_strategy);
59  file_manager.setStatusMonitor(status_monitor);
60  file_manager.start();
61  MetricDatumCollection metric_data;
63  input_event.AddCounts(2);
64  input_event.SetMetricName("MetricName");
65  metric_data.push_back(input_event);
66  file_manager.write(metric_data);
67  std::string line;
68  auto batch = file_manager.readBatch(1);
69  ASSERT_EQ(1u, batch.batch_data.size());
70  auto result = *batch.batch_data.begin();
71  EXPECT_EQ(input_event.GetCounts(), result.GetCounts());
72  EXPECT_EQ(input_event.GetMetricName(), result.GetMetricName());
73 }
std::list< Aws::CloudWatch::Model::MetricDatum > MetricDatumCollection
Definition: definitions.h:23
void SetUp() override
TEST_F(FileManagerTest, file_manager_write)
Aws::CloudWatch::Model::MetricDatum MetricDatum
Definition: definitions.h:22
void TearDown() override


cloudwatch_metrics_common
Author(s): AWS RoboMaker
autogenerated on Fri May 7 2021 02:18:25