This is an automated email from the ASF dual-hosted git repository. bmahler pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 831499b058b69d4030c3a121cef81e02b22ca2f6 Author: Benjamin Mahler <[email protected]> AuthorDate: Wed Oct 9 00:09:20 2019 -0400 Added a registrar test that invalid quota configs are rejected. Now that invalid quota configs are rejected during the update quota operation, this test ensures it works as expected. Review: https://reviews.apache.org/r/71598 --- src/tests/registrar_tests.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/tests/registrar_tests.cpp b/src/tests/registrar_tests.cpp index ff7f933..ab18138 100644 --- a/src/tests/registrar_tests.cpp +++ b/src/tests/registrar_tests.cpp @@ -73,6 +73,7 @@ using mesos::internal::log::Replica; using std::cout; using std::endl; using std::map; +using std::pair; using std::set; using std::string; using std::vector; @@ -84,6 +85,7 @@ using process::http::OK; using process::http::Response; using process::http::Unauthorized; +using google::protobuf::Map; using google::protobuf::RepeatedPtrField; using google::protobuf::util::MessageDifferencer; @@ -1707,6 +1709,49 @@ TEST_F(RegistrarTest, UpdateQuota) } +// Tests that updating quota with an invalid config fails. +TEST_F(RegistrarTest, UpdateQuotaInvalid) +{ + QuotaConfig config; + config.set_role("role1"); + + auto resourceMap = [](const vector<pair<string, double>>& vector) + -> Map<string, Value::Scalar> { + Map<string, Value::Scalar> result; + + foreachpair (const string& name, double value, vector) { + Value::Scalar scalar; + scalar.set_value(value); + result[name] = scalar; + } + + return result; + }; + + // The quota endpoint only allows memory / disk up to + // 1 exabyte (in megabytes) or 1 trillion cores/ports/other. + // For this test, we just check 1 invalid case via mem. + double largestMegabytes = 1024.0 * 1024.0 * 1024.0 * 1024.0; + + *config.mutable_limits() = resourceMap({{"mem", largestMegabytes + 1.0}}); + + Registrar registrar(flags, state); + Future<Registry> registry = registrar.recover(master); + AWAIT_READY(registry); + + EXPECT_EQ(0, registry->quota_configs().size()); + EXPECT_EQ(0, registry->minimum_capabilities().size()); + + // Store quota for a role with default quota. + RepeatedPtrField<QuotaConfig> configs; + *configs.Add() = config; + + AWAIT_FALSE( + registrar.apply(Owned<RegistryOperation>(new UpdateQuota(configs)))); + +} + + // Tests that updating weights in the registry works properly. TEST_F(RegistrarTest, UpdateWeights) {
