Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setters for all OptionsImpl fields. #3424

Merged
merged 3 commits into from
May 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions source/server/options_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,43 @@ class OptionsImpl : public Server::Options {
OptionsImpl(int argc, char** argv, const HotRestartVersionCb& hot_restart_version_cb,
spdlog::level::level_enum default_log_level);

// Setters for option fields. These are not part of the Options interface.
void setBaseId(uint64_t base_id) { base_id_ = base_id; };
void setConcurrency(uint32_t concurrency) { concurrency_ = concurrency; }
void setConfigPath(const std::string& config_path) { config_path_ = config_path; }
void setConfigYaml(const std::string& config_yaml) { config_yaml_ = config_yaml; }
void setV2ConfigOnly(bool v2_config_only) { v2_config_only_ = v2_config_only; }
void setAdminAddressPath(const std::string& admin_address_path) {
admin_address_path_ = admin_address_path;
}
void setLocalAddressIpVersion(Network::Address::IpVersion local_address_ip_version) {
local_address_ip_version_ = local_address_ip_version;
}
void setDrainTime(std::chrono::seconds drain_time) { drain_time_ = drain_time; }
void setLogLevel(spdlog::level::level_enum log_level) { log_level_ = log_level; }
void setLogFormat(const std::string& log_format) { log_format_ = log_format; }
void setLogPath(const std::string& log_path) { log_path_ = log_path; }
void setParentShutdownTime(std::chrono::seconds parent_shutdown_time) {
parent_shutdown_time_ = parent_shutdown_time;
}
void setRestartEpoch(uint64_t restart_epoch) { restart_epoch_ = restart_epoch; }
void setMode(Server::Mode mode) { mode_ = mode; }
void setFileFlushIntervalMsec(std::chrono::milliseconds file_flush_interval_msec) {
file_flush_interval_msec_ = file_flush_interval_msec;
}
void setServiceClusterName(const std::string& service_cluster) {
service_cluster_ = service_cluster;
}
void setServiceNodeName(const std::string& service_node) { service_node_ = service_node; }
void setServiceZone(const std::string& service_zone) { service_zone_ = service_zone; }
void setMaxStats(uint64_t max_stats) { max_stats_ = max_stats; }
void setMaxObjNameLength(uint64_t max_obj_name_length) {
max_obj_name_length_ = max_obj_name_length;
}
void setHotRestartDisabled(bool hot_restart_disabled) {
hot_restart_disabled_ = hot_restart_disabled;
}

// Server::Options
uint64_t baseId() const override { return base_id_; }
uint32_t concurrency() const override { return concurrency_; }
Expand Down
49 changes: 49 additions & 0 deletions test/server/options_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,55 @@ TEST(OptionsImplTest, All) {
EXPECT_EQ(true, options->hotRestartDisabled());
}

TEST(OptionsImplTest, SetAll) {
std::unique_ptr<OptionsImpl> options = createOptionsImpl("envoy -c hello");
bool v2_config_only = options->v2ConfigOnly();
bool hot_restart_disabled = options->v2ConfigOnly();
options->setBaseId(109876);
options->setConcurrency(42);
options->setConfigPath("foo");
options->setConfigYaml("bogus:");
options->setV2ConfigOnly(!options->v2ConfigOnly());
options->setAdminAddressPath("path");
options->setLocalAddressIpVersion(Network::Address::IpVersion::v6);
options->setDrainTime(std::chrono::seconds(42));
options->setLogLevel(spdlog::level::trace);
options->setLogFormat("%L %n %v");
options->setLogPath("/foo/bar");
options->setParentShutdownTime(std::chrono::seconds(43));
options->setRestartEpoch(44);
options->setFileFlushIntervalMsec(std::chrono::milliseconds(45));
options->setMode(Server::Mode::Validate);
options->setServiceClusterName("cluster_foo");
options->setServiceNodeName("node_foo");
options->setServiceZone("zone_foo");
options->setMaxStats(12345);
options->setMaxObjNameLength(54321);
options->setHotRestartDisabled(!options->hotRestartDisabled());

EXPECT_EQ(109876, options->baseId());
EXPECT_EQ(42U, options->concurrency());
EXPECT_EQ("foo", options->configPath());
EXPECT_EQ("bogus:", options->configYaml());
EXPECT_EQ(!v2_config_only, options->v2ConfigOnly());
EXPECT_EQ("path", options->adminAddressPath());
EXPECT_EQ(Network::Address::IpVersion::v6, options->localAddressIpVersion());
EXPECT_EQ(std::chrono::seconds(42), options->drainTime());
EXPECT_EQ(spdlog::level::trace, options->logLevel());
EXPECT_EQ("%L %n %v", options->logFormat());
EXPECT_EQ("/foo/bar", options->logPath());
EXPECT_EQ(std::chrono::seconds(43), options->parentShutdownTime());
EXPECT_EQ(44, options->restartEpoch());
EXPECT_EQ(std::chrono::milliseconds(45), options->fileFlushIntervalMsec());
EXPECT_EQ(Server::Mode::Validate, options->mode());
EXPECT_EQ("cluster_foo", options->serviceClusterName());
EXPECT_EQ("node_foo", options->serviceNodeName());
EXPECT_EQ("zone_foo", options->serviceZone());
EXPECT_EQ(12345U, options->maxStats());
EXPECT_EQ(54321U, options->maxObjNameLength());
EXPECT_EQ(!hot_restart_disabled, options->hotRestartDisabled());
}

TEST(OptionsImplTest, DefaultParams) {
std::unique_ptr<OptionsImpl> options = createOptionsImpl("envoy -c hello");
EXPECT_EQ(std::chrono::seconds(600), options->drainTime());
Expand Down