Refactored metrics to support pull model.
MetricsGroup split into 3 groups, session, engine, and crypto. MetricsFrontEnd and Report removed. This is a merge from wvgerrit/28420 Bug: 36217927 Test: Added unit tests to cover modified code. Change-Id: I2f39f99ce88cc2229d6d1aa9459c67c5b86ccef4
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// Unit tests for EventMetric
|
||||
|
||||
#include "event_metric.h"
|
||||
#include "metric_publisher.h"
|
||||
#include "metric_serialization.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
@@ -15,22 +15,22 @@ using testing::NotNull;
|
||||
namespace wvcdm {
|
||||
namespace metrics {
|
||||
|
||||
class MockEventMetricNotification : public MetricNotification {
|
||||
class MockEventMetricSerializer : public MetricSerializer {
|
||||
public:
|
||||
MOCK_METHOD2(UpdateString, void(const std::string& metric_id,
|
||||
MOCK_METHOD2(SetString, void(const std::string& metric_id,
|
||||
const std::string& value));
|
||||
MOCK_METHOD2(UpdateInt32, void(const std::string& metric_id,
|
||||
MOCK_METHOD2(SetInt32, void(const std::string& metric_id,
|
||||
int32_t value));
|
||||
MOCK_METHOD2(UpdateInt64, void(const std::string& metric_id,
|
||||
MOCK_METHOD2(SetInt64, void(const std::string& metric_id,
|
||||
int64_t value));
|
||||
MOCK_METHOD2(UpdateDouble, void(const std::string& metric_id,
|
||||
MOCK_METHOD2(SetDouble, void(const std::string& metric_id,
|
||||
double value));
|
||||
};
|
||||
|
||||
class EventMetricTest : public ::testing::Test {
|
||||
public:
|
||||
void SetUp() {
|
||||
mock_notification_.reset(new MockEventMetricNotification());
|
||||
mock_serializer_.reset(new MockEventMetricSerializer());
|
||||
}
|
||||
protected:
|
||||
template<typename F1,
|
||||
@@ -44,7 +44,7 @@ class EventMetricTest : public ::testing::Test {
|
||||
return metric.value_map_;
|
||||
}
|
||||
|
||||
scoped_ptr<MockEventMetricNotification> mock_notification_;
|
||||
scoped_ptr<MockEventMetricSerializer> mock_serializer_;
|
||||
};
|
||||
|
||||
TEST_F(EventMetricTest, NoFieldsSuccessNullCallback) {
|
||||
@@ -60,19 +60,19 @@ TEST_F(EventMetricTest, NoFieldsSuccessNullCallback) {
|
||||
|
||||
TEST_F(EventMetricTest, NoFieldsSuccessWithCallback) {
|
||||
wvcdm::metrics::EventMetric<> metric("no/fields/metric");
|
||||
EXPECT_CALL(*mock_notification_,
|
||||
UpdateInt64("no/fields/metric/count", 1.0));
|
||||
EXPECT_CALL(*mock_notification_,
|
||||
UpdateDouble("no/fields/metric/mean", 10.0));
|
||||
EXPECT_CALL(*mock_notification_,
|
||||
UpdateDouble("no/fields/metric/variance", 0.0));
|
||||
EXPECT_CALL(*mock_notification_,
|
||||
UpdateDouble("no/fields/metric/min", 10.0));
|
||||
EXPECT_CALL(*mock_notification_,
|
||||
UpdateDouble("no/fields/metric/max", 10.0));
|
||||
EXPECT_CALL(*mock_serializer_,
|
||||
SetInt64("no/fields/metric/count", 1.0));
|
||||
EXPECT_CALL(*mock_serializer_,
|
||||
SetDouble("no/fields/metric/mean", 10.0));
|
||||
EXPECT_CALL(*mock_serializer_,
|
||||
SetDouble("no/fields/metric/variance", 0.0));
|
||||
EXPECT_CALL(*mock_serializer_,
|
||||
SetDouble("no/fields/metric/min", 10.0));
|
||||
EXPECT_CALL(*mock_serializer_,
|
||||
SetDouble("no/fields/metric/max", 10.0));
|
||||
|
||||
metric.Record(10);
|
||||
metric.Publish(mock_notification_.get());
|
||||
metric.Serialize(mock_serializer_.get());
|
||||
|
||||
std::map<std::string, Distribution*> value_map = GetValueMap(metric);
|
||||
ASSERT_EQ(1u, GetValueMap(metric).size());
|
||||
@@ -142,24 +142,24 @@ TEST_F(EventMetricTest, TwoFieldsSuccessWithCallback) {
|
||||
|
||||
// Callbacks from second record operation.
|
||||
EXPECT_CALL(
|
||||
*mock_notification_,
|
||||
UpdateInt64("two/fields/metric/count{error_code:11&pow2_size:16}", 2.0));
|
||||
*mock_serializer_,
|
||||
SetInt64("two/fields/metric/count{error_code:11&pow2_size:16}", 2.0));
|
||||
EXPECT_CALL(
|
||||
*mock_notification_,
|
||||
UpdateDouble("two/fields/metric/mean{error_code:11&pow2_size:16}", 3.5));
|
||||
*mock_serializer_,
|
||||
SetDouble("two/fields/metric/mean{error_code:11&pow2_size:16}", 3.5));
|
||||
EXPECT_CALL(
|
||||
*mock_notification_,
|
||||
UpdateDouble("two/fields/metric/variance{error_code:11&pow2_size:16}",
|
||||
*mock_serializer_,
|
||||
SetDouble("two/fields/metric/variance{error_code:11&pow2_size:16}",
|
||||
0.25));
|
||||
EXPECT_CALL(
|
||||
*mock_notification_,
|
||||
UpdateDouble("two/fields/metric/min{error_code:11&pow2_size:16}", 3.0));
|
||||
*mock_serializer_,
|
||||
SetDouble("two/fields/metric/min{error_code:11&pow2_size:16}", 3.0));
|
||||
EXPECT_CALL(
|
||||
*mock_notification_,
|
||||
UpdateDouble("two/fields/metric/max{error_code:11&pow2_size:16}", 4.0));
|
||||
*mock_serializer_,
|
||||
SetDouble("two/fields/metric/max{error_code:11&pow2_size:16}", 4.0));
|
||||
metric.Record(3, 11, Pow2Bucket(29));
|
||||
metric.Record(4, 11, Pow2Bucket(29));
|
||||
metric.Publish(mock_notification_.get());
|
||||
metric.Serialize(mock_serializer_.get());
|
||||
}
|
||||
|
||||
TEST_F(EventMetricTest, ThreeFieldsSuccess) {
|
||||
|
||||
Reference in New Issue
Block a user