Repository: mesos
Updated Branches:
  refs/heads/master 9b9730493 -> bcf33f896


Quota: Added status endpoint validation tests.

Review: https://reviews.apache.org/r/39614/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/bcf33f89
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/bcf33f89
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/bcf33f89

Branch: refs/heads/master
Commit: bcf33f896b7f02d615e8edb9441cfbb96e3a5152
Parents: 9669945
Author: Joerg Schad <[email protected]>
Authored: Tue Jan 5 17:30:01 2016 -0800
Committer: Joris Van Remoortere <[email protected]>
Committed: Tue Jan 5 17:51:05 2016 -0800

----------------------------------------------------------------------
 src/tests/master_quota_tests.cpp | 96 +++++++++++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/bcf33f89/src/tests/master_quota_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_quota_tests.cpp b/src/tests/master_quota_tests.cpp
index 2f1bc3a..81f0386 100644
--- a/src/tests/master_quota_tests.cpp
+++ b/src/tests/master_quota_tests.cpp
@@ -48,6 +48,7 @@ using mesos::internal::master::Master;
 using mesos::internal::slave::Slave;
 
 using mesos::quota::QuotaInfo;
+using mesos::quota::QuotaStatus;
 
 using process::Future;
 using process::PID;
@@ -496,6 +497,101 @@ TEST_F(MasterQuotaTest, RemoveSingleQuota)
 }
 
 
+// Tests whether we can retrieve empty quota status (i.e. no quota set)
+// from /master/quota endpoint via a GET request against /quota.
+TEST_F(MasterQuotaTest, StatusNoQuotas)
+{
+  Try<PID<Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  // Query the master quota endpoint.
+  Future<Response> response = process::http::get(
+      master.get(),
+      "quota",
+      None(),
+      createBasicAuthHeaders(DEFAULT_CREDENTIAL));
+
+  AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response) << 
response.get().body;
+
+  EXPECT_SOME_EQ(
+      "application/json",
+      response.get().headers.get("Content-Type"));
+
+  const Try<JSON::Object> parse =
+    JSON::parse<JSON::Object>(response.get().body);
+
+  ASSERT_SOME(parse);
+
+  // Convert JSON response to `QuotaStatus` protobuf.
+  const Try<QuotaStatus> status = ::protobuf::parse<QuotaStatus>(parse.get());
+  ASSERT_FALSE(status.isError());
+
+  EXPECT_EQ(0, status.get().infos().size());
+
+  Shutdown();
+}
+
+
+// Tests whether we can retrieve the current quota status from
+// /master/quota endpoint via a GET request against /quota.
+TEST_F(MasterQuotaTest, StatusSingleQuota)
+{
+  TestAllocator<> allocator;
+  EXPECT_CALL(allocator, initialize(_, _, _, _));
+
+  Try<PID<Master>> master = StartMaster(&allocator);
+  ASSERT_SOME(master);
+
+  Future<Resources> agentTotalResources;
+  EXPECT_CALL(allocator, addSlave(_, _, _, _, _))
+    .WillOnce(DoAll(InvokeAddSlave(&allocator),
+                    FutureArg<3>(&agentTotalResources)));
+
+  // Start one agent and wait until it registers.
+  Try<PID<Slave>> agent = StartSlave();
+  ASSERT_SOME(agent);
+
+  AWAIT_READY(agentTotalResources);
+  EXPECT_EQ(defaultAgentResources, agentTotalResources.get());
+
+  // We request quota for a portion of resources available on the agents.
+  Resources quotaResources = Resources::parse("cpus:1;mem:512", ROLE1).get();
+
+  EXPECT_TRUE(agentTotalResources.get().contains(quotaResources.flatten()));
+
+  // Send a quota request for the specified role.
+  Future<Response> response = process::http::post(
+      master.get(),
+      "quota",
+      createBasicAuthHeaders(DEFAULT_CREDENTIAL),
+      createRequestBody(quotaResources));
+
+  AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response) << 
response.get().body;
+
+  // Query the master quota endpoint.
+  response = process::http::get(master.get(), "quota");
+  AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response) << 
response.get().body;
+
+  EXPECT_SOME_EQ(
+      "application/json",
+      response.get().headers.get("Content-Type"));
+
+  const Try<JSON::Object> parse =
+    JSON::parse<JSON::Object>(response.get().body);
+
+  ASSERT_SOME(parse);
+
+  // Convert JSON response to `QuotaStatus` protobuf.
+  const Try<QuotaStatus> status = ::protobuf::parse<QuotaStatus>(parse.get());
+  ASSERT_FALSE(status.isError());
+
+  ASSERT_EQ(1, status.get().infos().size());
+  EXPECT_EQ(quotaResources.flatten(), status.get().infos(0).guarantee());
+
+  Shutdown();
+}
+
+
 // These tests check whether a request makes sense in terms of current cluster
 // status. A quota request may be well-formed, but obviously infeasible, e.g.
 // request for 100 CPUs in a cluster with just 11 CPUs.

Reply via email to