You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2016/12/09 04:08:40 UTC

mesos git commit: Added implicit role tests for multi-role frameworks.

Repository: mesos
Updated Branches:
  refs/heads/master 2e6bce694 -> f35f1a47c


Added implicit role tests for multi-role frameworks.

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


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

Branch: refs/heads/master
Commit: f35f1a47c5e8e092faabaa87b199721b64fb4ae4
Parents: 2e6bce6
Author: Jay Guo <gu...@gmail.com>
Authored: Thu Dec 8 20:07:58 2016 -0800
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Thu Dec 8 20:07:58 2016 -0800

----------------------------------------------------------------------
 src/tests/role_tests.cpp | 118 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 118 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f35f1a47/src/tests/role_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/role_tests.cpp b/src/tests/role_tests.cpp
index 1a67669..2ee7801 100644
--- a/src/tests/role_tests.cpp
+++ b/src/tests/role_tests.cpp
@@ -20,6 +20,7 @@
 #include <mesos/http.hpp>
 #include <mesos/roles.hpp>
 
+#include <process/clock.hpp>
 #include <process/owned.hpp>
 #include <process/pid.hpp>
 
@@ -36,6 +37,7 @@ using std::vector;
 
 using google::protobuf::RepeatedPtrField;
 
+using process::Clock;
 using process::Future;
 using process::Owned;
 using process::PID;
@@ -567,6 +569,122 @@ TEST_F(RoleTest, EndpointImplicitRolesQuotas)
 }
 
 
+// This test ensures that master adds/removes all roles of
+// a multi-role framework when it registers/terminates.
+TEST_F(RoleTest, AddAndRemoveFrameworkWithMultipleRoles)
+{
+  // When we test removeFramework later in this test, we have to
+  // be sure the teardown call is processed completely before
+  // sending request to `getRoles` API.
+  Clock::pause();
+
+  Try<Owned<cluster::Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  FrameworkInfo framework = DEFAULT_FRAMEWORK_INFO;
+  framework.add_roles("role1");
+  framework.add_roles("role2");
+  framework.add_capabilities()->set_type(
+      FrameworkInfo::Capability::MULTI_ROLE);
+
+  MockScheduler sched;
+  MesosSchedulerDriver driver(
+      &sched, framework, master.get()->pid, DEFAULT_CREDENTIAL);
+
+  Future<FrameworkID> frameworkId;
+  EXPECT_CALL(sched, registered(&driver, _, _))
+    .WillOnce(FutureArg<1>(&frameworkId));;
+
+  driver.start();
+
+  AWAIT_READY(frameworkId);
+
+  // Tests all roles of the multi-role framework are added.
+  {
+    Future<Response> response = process::http::get(
+        master.get()->pid,
+        "roles",
+        None(),
+        createBasicAuthHeaders(DEFAULT_CREDENTIAL));
+
+    AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
+      << response->body;
+
+    Try<JSON::Value> parse = JSON::parse(response->body);
+    ASSERT_SOME(parse);
+
+    Try<JSON::Value> expected = JSON::parse(
+        "{"
+        "  \"roles\": ["
+        "    {"
+        "      \"frameworks\": [\"" + frameworkId->value() + "\"],"
+        "      \"name\": \"role1\","
+        "      \"resources\": {"
+        "        \"cpus\": 0,"
+        "        \"disk\": 0,"
+        "        \"gpus\": 0,"
+        "        \"mem\":  0"
+        "      },"
+        "      \"weight\": 1.0"
+        "    },"
+        "    {"
+        "      \"frameworks\": [\"" + frameworkId->value() + "\"],"
+        "      \"name\": \"role2\","
+        "      \"resources\": {"
+        "        \"cpus\": 0,"
+        "        \"disk\": 0,"
+        "        \"gpus\": 0,"
+        "        \"mem\":  0"
+        "      },"
+        "      \"weight\": 1.0"
+        "    }"
+        "  ]"
+        "}");
+
+    ASSERT_SOME(expected);
+
+    EXPECT_EQ(expected.get(), parse.get());
+  }
+
+  // Set expectation that Master receives teardown call.
+  Future<mesos::scheduler::Call> teardownCall = FUTURE_CALL(
+      mesos::scheduler::Call(), mesos::scheduler::Call::TEARDOWN, _, _);
+
+  driver.stop();
+  driver.join();
+
+  // Wait for teardown call to be dispatched.
+  AWAIT_READY(teardownCall);
+
+  // Make sure the teardown call is processed completely.
+  Clock::settle();
+
+  // Tests all roles of multi-role framework are removed.
+  {
+    Future<Response> response = process::http::get(
+        master.get()->pid,
+        "roles",
+        None(),
+        createBasicAuthHeaders(DEFAULT_CREDENTIAL));
+
+    AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
+      << response.get().body;
+
+    Try<JSON::Value> parse = JSON::parse(response.get().body);
+    ASSERT_SOME(parse);
+
+    Try<JSON::Value> expected = JSON::parse(
+        "{"
+        "  \"roles\": []"
+        "}");
+
+    ASSERT_SOME(expected);
+
+    EXPECT_EQ(expected.get(), parse.get());
+  }
+}
+
+
 // This tests the parse function of roles.
 TEST(RolesTest, Parsing)
 {