OSDN Git Service

Set the metric name for alerts in fake config and add a test to make sure the fake...
authorYangster-mac <yanglu@google.com>
Wed, 22 Nov 2017 05:58:44 +0000 (21:58 -0800)
committerYangster-mac <yanglu@google.com>
Wed, 22 Nov 2017 21:43:25 +0000 (13:43 -0800)
Test: unit test passed.
Change-Id: I1879fc523cca9fc6c672332ab4ac383f21dc16fc

cmds/statsd/src/config/ConfigManager.cpp
cmds/statsd/src/config/ConfigManager.h
cmds/statsd/src/metrics/MetricsManager.h
cmds/statsd/tests/ConfigManager_test.cpp

index 0c9252e..408eeda 100644 (file)
@@ -30,8 +30,6 @@ namespace statsd {
 
 #define STATS_SERVICE_DIR "/data/system/stats-service"
 
-static StatsdConfig build_fake_config();
-
 using android::base::StringPrintf;
 using std::unique_ptr;
 
@@ -229,7 +227,7 @@ void ConfigManager::update_saved_configs(const ConfigKey& key, const StatsdConfi
     }
 }
 
-static StatsdConfig build_fake_config() {
+StatsdConfig build_fake_config() {
     // HACK: Hard code a test metric for counting screen on events...
     StatsdConfig config;
     config.set_name("CONFIG_12345");
index 01d7fb9..74a1574 100644 (file)
@@ -34,6 +34,9 @@ using std::unordered_map;
 using std::vector;
 using std::pair;
 
+// Util function to Hard code a test metric for counting screen on events.
+StatsdConfig build_fake_config();
+
 /**
  * Keeps track of which configurations have been set from various sources.
  *
index 59ade7c..a6054e3 100644 (file)
@@ -101,7 +101,7 @@ private:
     // maps from ConditionTracker to MetricProducer
     std::unordered_map<int, std::vector<int>> mConditionToMetricMap;
 
-    bool mConfigValid;
+    bool mConfigValid = false;
 };
 
 }  // namespace statsd
index f570522..3b52991 100644 (file)
@@ -13,6 +13,7 @@
 // limitations under the License.
 
 #include "src/config/ConfigManager.h"
+#include "src/metrics/MetricsManager.h"
 
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
@@ -60,6 +61,11 @@ MATCHER_P(StatsdConfigEq, name, "") {
     return arg.name() == name;
 }
 
+TEST(ConfigManagerTest, TestFakeConfig) {
+    auto metricsManager = std::make_unique<MetricsManager>(build_fake_config());
+    EXPECT_TRUE(metricsManager->isConfigValid());
+}
+
 /**
  * Test the addOrUpdate and remove methods
  */