forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_resource_monitor.h
51 lines (39 loc) · 1.55 KB
/
fake_resource_monitor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once
#include "envoy/server/resource_monitor.h"
#include "envoy/server/resource_monitor_config.h"
#include "test/common/config/dummy_config.pb.h"
namespace Envoy {
class FakeResourceMonitorFactory;
class FakeResourceMonitor : public Server::ResourceMonitor {
public:
FakeResourceMonitor(Event::Dispatcher& dispatcher, FakeResourceMonitorFactory& factory)
: dispatcher_(dispatcher), factory_(factory), pressure_(0.0) {}
// Server::ResourceMonitor
~FakeResourceMonitor() override;
void updateResourceUsage(Server::ResourceUpdateCallbacks& callbacks) override;
void setResourcePressure(double pressure) {
dispatcher_.post([this, pressure] { pressure_ = pressure; });
}
private:
Event::Dispatcher& dispatcher_;
FakeResourceMonitorFactory& factory_;
double pressure_;
};
class FakeResourceMonitorFactory : public Server::Configuration::ResourceMonitorFactory {
public:
// Server::Configuration::ResourceMonitorFactory
Server::ResourceMonitorPtr
createResourceMonitor(const Protobuf::Message& config,
Server::Configuration::ResourceMonitorFactoryContext& context) override;
ProtobufTypes::MessagePtr createEmptyConfigProto() override {
return std::make_unique<test::common::config::DummyConfig>();
}
std::string name() const override {
return "envoy.resource_monitors.testonly.fake_resource_monitor";
}
FakeResourceMonitor* monitor() const { return monitor_; }
void onMonitorDestroyed(FakeResourceMonitor* monitor);
private:
FakeResourceMonitor* monitor_{nullptr};
};
} // namespace Envoy