You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by me...@apache.org on 2015/12/19 10:21:05 UTC
[3/5] mesos git commit: Added test cases for role behavior.
Added test cases for role behavior.
Review: https://reviews.apache.org/r/40995/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/47aa47ca
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/47aa47ca
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/47aa47ca
Branch: refs/heads/master
Commit: 47aa47ca7cdfa4211ca80990b676ad813c14a48c
Parents: b0285c4
Author: Neil Conway <ne...@gmail.com>
Authored: Fri Dec 18 15:31:40 2015 -0800
Committer: Adam B <ad...@mesosphere.io>
Committed: Fri Dec 18 23:35:56 2015 -0800
----------------------------------------------------------------------
src/Makefile.am | 1 +
src/tests/reservation_tests.cpp | 2 +-
src/tests/role_tests.cpp | 180 +++++++++++++++++++++++++++++++++++
3 files changed, 182 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/47aa47ca/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 08ee83c..cf7f950 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1736,6 +1736,7 @@ mesos_tests_SOURCES = \
tests/reservation_tests.cpp \
tests/resource_offers_tests.cpp \
tests/resources_tests.cpp \
+ tests/role_tests.cpp \
tests/scheduler_driver_tests.cpp \
tests/scheduler_event_call_tests.cpp \
tests/scheduler_http_api_tests.cpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/47aa47ca/src/tests/reservation_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/reservation_tests.cpp b/src/tests/reservation_tests.cpp
index f429472..69ddf90 100644
--- a/src/tests/reservation_tests.cpp
+++ b/src/tests/reservation_tests.cpp
@@ -52,8 +52,8 @@ using mesos::internal::master::Master;
using mesos::internal::slave::Slave;
-using process::PID;
using process::Future;
+using process::PID;
using std::map;
using std::string;
http://git-wip-us.apache.org/repos/asf/mesos/blob/47aa47ca/src/tests/role_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/role_tests.cpp b/src/tests/role_tests.cpp
new file mode 100644
index 0000000..240017c
--- /dev/null
+++ b/src/tests/role_tests.cpp
@@ -0,0 +1,180 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <process/pid.hpp>
+
+#include "tests/mesos.hpp"
+
+using mesos::internal::master::Master;
+using mesos::internal::slave::Slave;
+
+using process::Future;
+using process::PID;
+
+using std::vector;
+
+namespace mesos {
+namespace internal {
+namespace tests {
+
+class RoleTest : public MesosTest {};
+
+
+// This test checks that a framework cannot register with a role that
+// is not in the configured list.
+TEST_F(RoleTest, BadRegister)
+{
+ FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
+ frameworkInfo.set_role("invalid");
+
+ master::Flags masterFlags = CreateMasterFlags();
+ masterFlags.roles = "foo,bar";
+
+ Try<PID<Master>> master = StartMaster(masterFlags);
+ ASSERT_SOME(master);
+
+ MockScheduler sched;
+ MesosSchedulerDriver driver(
+ &sched, frameworkInfo, master.get(), DEFAULT_CREDENTIAL);
+
+ Future<Nothing> error;
+ EXPECT_CALL(sched, error(&driver, _))
+ .WillOnce(FutureSatisfy(&error));
+
+ driver.start();
+
+ // Scheduler should get error message from the master.
+ AWAIT_READY(error);
+
+ driver.stop();
+ driver.join();
+
+ Shutdown();
+}
+
+
+// This test checks that the "/roles" endpoint returns the expected
+// information when there are no active roles.
+TEST_F(RoleTest, EndpointEmpty)
+{
+ Try<PID<Master>> master = StartMaster();
+ ASSERT_SOME(master);
+
+ Future<process::http::Response> response =
+ process::http::get(master.get(), "roles");
+
+ AWAIT_READY(response);
+
+ EXPECT_SOME_EQ(
+ "application/json",
+ response.get().headers.get("Content-Type"));
+
+ Try<JSON::Value> parse = JSON::parse(response.get().body);
+ ASSERT_SOME(parse);
+
+ Try<JSON::Value> expected = JSON::parse(
+ "{"
+ " \"roles\": ["
+ " {"
+ " \"frameworks\": [],"
+ " \"name\": \"*\","
+ " \"resources\": {"
+ " \"cpus\": 0,"
+ " \"disk\": 0,"
+ " \"mem\": 0"
+ " },"
+ " \"weight\": 1.0"
+ " }"
+ " ]"
+ "}");
+
+ ASSERT_SOME(expected);
+ EXPECT_EQ(expected.get(), parse.get());
+
+ Shutdown();
+}
+
+
+// This test checks that the "/roles" endpoint returns the expected
+// information when there are configured weights and explicit roles,
+// but no active frameworks.
+TEST_F(RoleTest, EndpointNoFrameworks)
+{
+ master::Flags masterFlags = CreateMasterFlags();
+ masterFlags.roles = "role1,role2";
+ masterFlags.weights = "role1=5";
+
+ Try<PID<Master>> master = StartMaster(masterFlags);
+ ASSERT_SOME(master);
+
+ Future<process::http::Response> response =
+ process::http::get(master.get(), "roles");
+
+ AWAIT_READY(response);
+
+ EXPECT_SOME_EQ(
+ "application/json",
+ response.get().headers.get("Content-Type"));
+
+ Try<JSON::Value> parse = JSON::parse(response.get().body);
+ ASSERT_SOME(parse);
+
+ Try<JSON::Value> expected = JSON::parse(
+ "{"
+ " \"roles\": ["
+ " {"
+ " \"frameworks\": [],"
+ " \"name\": \"*\","
+ " \"resources\": {"
+ " \"cpus\": 0,"
+ " \"disk\": 0,"
+ " \"mem\": 0"
+ " },"
+ " \"weight\": 1.0"
+ " },"
+ " {"
+ " \"frameworks\": [],"
+ " \"name\": \"role1\","
+ " \"resources\": {"
+ " \"cpus\": 0,"
+ " \"disk\": 0,"
+ " \"mem\": 0"
+ " },"
+ " \"weight\": 5.0"
+ " },"
+ " {"
+ " \"frameworks\": [],"
+ " \"name\": \"role2\","
+ " \"resources\": {"
+ " \"cpus\": 0,"
+ " \"disk\": 0,"
+ " \"mem\": 0"
+ " },"
+ " \"weight\": 1.0"
+ " }"
+ " ]"
+ "}");
+
+ ASSERT_SOME(expected);
+ EXPECT_EQ(expected.get(), parse.get());
+
+ Shutdown();
+}
+
+
+} // namespace tests {
+} // namespace internal {
+} // namespace mesos {