-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- MockNighthawkServiceClient - MockMetricsEvaluator - MockAdaptiveLoadSessionSpecProtoHelper Part 8 of splitting PR #483. Signed-off-by: eric846 <[email protected]>
- Loading branch information
Showing
8 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
load( | ||
"@envoy//bazel:envoy_build_system.bzl", | ||
"envoy_cc_mock", | ||
"envoy_package", | ||
) | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
envoy_package() | ||
|
||
envoy_cc_mock( | ||
name = "mock_metrics_evaluator", | ||
srcs = ["mock_metrics_evaluator.cc"], | ||
hdrs = ["mock_metrics_evaluator.h"], | ||
repository = "@envoy", | ||
deps = [ | ||
"//include/nighthawk/adaptive_load:metrics_evaluator", | ||
], | ||
) | ||
|
||
envoy_cc_mock( | ||
name = "mock_session_spec_proto_helper", | ||
srcs = ["mock_session_spec_proto_helper.cc"], | ||
hdrs = ["mock_session_spec_proto_helper.h"], | ||
repository = "@envoy", | ||
deps = [ | ||
"//include/nighthawk/adaptive_load:session_spec_proto_helper", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "test/mocks/adaptive_load/mock_metrics_evaluator.h" | ||
|
||
namespace Nighthawk { | ||
|
||
MockMetricsEvaluator::MockMetricsEvaluator() = default; | ||
|
||
} // namespace Nighthawk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#pragma once | ||
|
||
#include "nighthawk/adaptive_load/metrics_evaluator.h" | ||
|
||
#include "gmock/gmock.h" | ||
|
||
namespace Nighthawk { | ||
|
||
/** | ||
* A mock MetricsEvaluator that returns empty values from all methods. | ||
* | ||
* Typical usage: | ||
* | ||
* MockMetricsEvaluator mock_metrics_evaluator; | ||
* BenchmarkResult benchmark_result; | ||
* // (set benchmark_result fields here) | ||
* EXPECT_CALL(mock_metrics_evaluator, AnalyzeNighthawkBenchmark(_, _, _)) | ||
* .WillRepeatedly(Return(benchmark_result)); | ||
*/ | ||
class MockMetricsEvaluator : public MetricsEvaluator { | ||
public: | ||
/** | ||
* Empty constructor. | ||
*/ | ||
MockMetricsEvaluator(); | ||
|
||
MOCK_CONST_METHOD3(EvaluateMetric, | ||
absl::StatusOr<nighthawk::adaptive_load::MetricEvaluation>( | ||
const nighthawk::adaptive_load::MetricSpec& metric_spec, | ||
MetricsPlugin& metrics_plugin, | ||
const nighthawk::adaptive_load::ThresholdSpec* threshold_spec)); | ||
|
||
MOCK_CONST_METHOD1(ExtractMetricSpecs, | ||
const std::vector<std::pair<const nighthawk::adaptive_load::MetricSpec*, | ||
const nighthawk::adaptive_load::ThresholdSpec*>>( | ||
const nighthawk::adaptive_load::AdaptiveLoadSessionSpec& spec)); | ||
|
||
MOCK_CONST_METHOD3( | ||
AnalyzeNighthawkBenchmark, | ||
absl::StatusOr<nighthawk::adaptive_load::BenchmarkResult>( | ||
const nighthawk::client::ExecutionResponse& execution_response, | ||
const nighthawk::adaptive_load::AdaptiveLoadSessionSpec& spec, | ||
const absl::flat_hash_map<std::string, MetricsPluginPtr>& name_to_custom_plugin_map)); | ||
}; | ||
|
||
} // namespace Nighthawk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "test/mocks/adaptive_load/mock_session_spec_proto_helper.h" | ||
|
||
namespace Nighthawk { | ||
|
||
MockAdaptiveLoadSessionSpecProtoHelper::MockAdaptiveLoadSessionSpecProtoHelper() = default; | ||
|
||
} // namespace Nighthawk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include "nighthawk/adaptive_load/session_spec_proto_helper.h" | ||
|
||
#include "gmock/gmock.h" | ||
|
||
namespace Nighthawk { | ||
|
||
/** | ||
* A mock AdaptiveLoadSessionSpecProtoHelper that returns empty values or success from all methods | ||
* by default. | ||
* | ||
* In particular, SetSessionSpecDefaults does not pass its input value through to its output; | ||
* regardless of the output, it returns an empty proto, unless explicitly configured (see below). If | ||
* you don't need to inspect calls to the spec proto helper, it may be easier to use the real | ||
* AdaptiveLoadSessionSpecProtoHelperImpl in tests instead. | ||
* | ||
* Typical usage: | ||
* | ||
* NiceMock<MockAdaptiveLoadSessionSpecProtoHelper> mock_spec_proto_helper; | ||
* EXPECT_CALL(mock_spec_proto_helper, CheckSessionSpec(_)) | ||
* .WillOnce(Return(absl::OkStatus())); | ||
* AdaptiveLoadSessionSpec spec; | ||
* // Set spec fields here, including providing all defaults yourself. | ||
* EXPECT_CALL(mock_spec_proto_helper, SetSessionSpecDefaults(_)) | ||
* .WillOnce(Return(spec)); | ||
*/ | ||
class MockAdaptiveLoadSessionSpecProtoHelper : public AdaptiveLoadSessionSpecProtoHelper { | ||
public: | ||
/** | ||
* Empty constructor. | ||
*/ | ||
MockAdaptiveLoadSessionSpecProtoHelper(); | ||
|
||
MOCK_CONST_METHOD1(SetSessionSpecDefaults, | ||
nighthawk::adaptive_load::AdaptiveLoadSessionSpec( | ||
const nighthawk::adaptive_load::AdaptiveLoadSessionSpec spec)); | ||
MOCK_CONST_METHOD1(CheckSessionSpec, | ||
absl::Status(const nighthawk::adaptive_load::AdaptiveLoadSessionSpec& spec)); | ||
}; | ||
|
||
} // namespace Nighthawk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "test/mocks/common/mock_nighthawk_service_client.h" | ||
|
||
namespace Nighthawk { | ||
|
||
MockNighthawkServiceClient::MockNighthawkServiceClient() = default; | ||
|
||
} // namespace Nighthawk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include "nighthawk/common/nighthawk_service_client.h" | ||
|
||
#include "gmock/gmock.h" | ||
|
||
namespace Nighthawk { | ||
|
||
/** | ||
* A mock NighthawkServiceClient that returns an empty response by default. | ||
* | ||
* Typical usage: | ||
* | ||
* NiceMock<MockNighthawkServiceClient> mock_nighthawk_service_client; | ||
* nighthawk::client::ExecutionResponse nighthawk_response; | ||
* EXPECT_CALL(mock_nighthawk_service_client, PerformNighthawkBenchmark(_, _)) | ||
* .WillRepeatedly(Return(nighthawk_response)); | ||
*/ | ||
class MockNighthawkServiceClient : public NighthawkServiceClient { | ||
public: | ||
/** | ||
* Empty constructor. | ||
*/ | ||
MockNighthawkServiceClient(); | ||
|
||
MOCK_CONST_METHOD2(PerformNighthawkBenchmark, | ||
absl::StatusOr<nighthawk::client::ExecutionResponse>( | ||
nighthawk::client::NighthawkService::StubInterface* stub, | ||
const nighthawk::client::CommandLineOptions& options)); | ||
}; | ||
|
||
} // namespace Nighthawk |