You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2015/11/09 14:14:29 UTC
[1/2] mesos git commit: Moved implementation of tests::Cluster to cpp
file.
Repository: mesos
Updated Branches:
refs/heads/master 73deb1cd1 -> b4c4f9050
Moved implementation of tests::Cluster to cpp file.
This helps reduce the dependency on hierarchical.hpp.
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b4c4f905
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b4c4f905
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b4c4f905
Branch: refs/heads/master
Commit: b4c4f9050b3a98b43b581d062be4b9ebb75ba23f
Parents: 2a9a5c1
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Mon Nov 9 09:36:05 2015 +0100
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon Nov 9 14:12:54 2015 +0100
----------------------------------------------------------------------
src/Makefile.am | 1 +
src/tests/cluster.cpp | 492 ++++++++++++++++++++++++++
src/tests/cluster.hpp | 461 ------------------------
src/tests/fault_tolerance_tests.cpp | 2 +
src/tests/master_authorization_tests.cpp | 2 +
src/tests/master_tests.cpp | 2 +
src/tests/partition_tests.cpp | 2 +
src/tests/rate_limiting_tests.cpp | 2 +
8 files changed, 503 insertions(+), 461 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/b4c4f905/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index e3a206c..1dc545b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1741,6 +1741,7 @@ mesos_tests_SOURCES = \
tests/attributes_tests.cpp \
tests/authentication_tests.cpp \
tests/authorization_tests.cpp \
+ tests/cluster.cpp \
tests/containerizer.cpp \
tests/cram_md5_authentication_tests.cpp \
tests/credentials_tests.cpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/b4c4f905/src/tests/cluster.cpp
----------------------------------------------------------------------
diff --git a/src/tests/cluster.cpp b/src/tests/cluster.cpp
new file mode 100644
index 0000000..ba5a10d
--- /dev/null
+++ b/src/tests/cluster.cpp
@@ -0,0 +1,492 @@
+/**
+ * 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 "tests/cluster.hpp"
+
+#include <process/clock.hpp>
+#include <process/future.hpp>
+#include <process/gmock.hpp>
+#include <process/gtest.hpp>
+#include <process/limiter.hpp>
+#include <process/owned.hpp>
+#include <process/pid.hpp>
+#include <process/process.hpp>
+
+#include <stout/duration.hpp>
+#include <stout/error.hpp>
+#include <stout/foreach.hpp>
+#include <stout/none.hpp>
+#include <stout/nothing.hpp>
+#include <stout/option.hpp>
+#include <stout/path.hpp>
+#include <stout/strings.hpp>
+#include <stout/try.hpp>
+
+#include "master/allocator/mesos/hierarchical.hpp"
+
+namespace mesos {
+namespace internal {
+namespace tests {
+
+Cluster::Masters::Masters(
+ Cluster* _cluster,
+ const Option<zookeeper::URL>& _url)
+ : cluster(_cluster),
+ url(_url) {}
+
+
+Cluster::Masters::~Masters()
+{
+ shutdown();
+}
+
+
+void Cluster::Masters::shutdown()
+{
+ // TODO(benh): Use utils::copy from stout once namespaced.
+ std::map<process::PID<master::Master>, Master> copy(masters);
+ foreachkey (const process::PID<master::Master>& pid, copy) {
+ stop(pid);
+ }
+ masters.clear();
+}
+
+
+Try<process::PID<master::Master>> Cluster::Masters::start(
+ const master::Flags& flags,
+ const Option<mesos::master::allocator::Allocator*>& allocator,
+ const Option<Authorizer*>& authorizer,
+ const Option<std::shared_ptr<process::RateLimiter>>& slaveRemovalLimiter)
+{
+ // Disallow multiple masters when not using ZooKeeper.
+ if (!masters.empty() && url.isNone()) {
+ return Error("Can not start multiple masters when not using ZooKeeper");
+ }
+
+ Master master;
+
+ if (allocator.isSome()) {
+ master.allocator = allocator.get();
+ } else {
+ // If allocator is not provided, fall back to the default one,
+ // managed by Cluster::Masters.
+ Try<mesos::master::allocator::Allocator*> allocator_ =
+ master::allocator::HierarchicalDRFAllocator::create();
+ if (allocator_.isError()) {
+ return Error(
+ "Failed to create an instance of HierarchicalDRFAllocator: " +
+ allocator_.error());
+ }
+
+ master.allocator = allocator_.get();
+ master.createdAllocator = true;
+ }
+
+ if (flags.registry == "in_memory") {
+ if (flags.registry_strict) {
+ return Error(
+ "Cannot use '--registry_strict' when using in-memory storage based"
+ " registry");
+ }
+ master.storage.reset(new state::InMemoryStorage());
+ } else if (flags.registry == "replicated_log") {
+ if (flags.work_dir.isNone()) {
+ return Error(
+ "Need to specify --work_dir for replicated log based registry");
+ }
+
+ if (url.isSome()) {
+ // Use ZooKeeper based replicated log.
+ if (flags.quorum.isNone()) {
+ return Error(
+ "Need to specify --quorum for replicated log based registry"
+ " when using ZooKeeper");
+ }
+ master.log.reset(new log::Log(
+ flags.quorum.get(),
+ path::join(flags.work_dir.get(), "replicated_log"),
+ url.get().servers,
+ flags.zk_session_timeout,
+ path::join(url.get().path, "log_replicas"),
+ url.get().authentication,
+ flags.log_auto_initialize));
+ } else {
+ master.log.reset(new log::Log(
+ 1,
+ path::join(flags.work_dir.get(), "replicated_log"),
+ std::set<process::UPID>(),
+ flags.log_auto_initialize));
+ }
+
+ master.storage.reset(new state::LogStorage(master.log.get()));
+ } else {
+ return Error("'" + flags.registry + "' is not a supported option for"
+ " registry persistence");
+ }
+
+ CHECK_NOTNULL(master.storage.get());
+
+ master.state.reset(new state::protobuf::State(master.storage.get()));
+ master.registrar.reset(new master::Registrar(flags, master.state.get()));
+ master.repairer.reset(new master::Repairer());
+
+ if (url.isSome()) {
+ master.contender.reset(new ZooKeeperMasterContender(url.get()));
+ master.detector.reset(new ZooKeeperMasterDetector(url.get()));
+ } else {
+ master.contender.reset(new StandaloneMasterContender());
+ master.detector.reset(new StandaloneMasterDetector());
+ }
+
+ if (authorizer.isSome()) {
+ CHECK_NOTNULL(authorizer.get());
+ } else if (flags.acls.isSome()) {
+ Try<Authorizer*> local = Authorizer::create(master::DEFAULT_AUTHORIZER);
+
+ if (local.isError()) {
+ EXIT(EXIT_FAILURE)
+ << "Failed to instantiate the local authorizer: "
+ << local.error();
+ }
+
+ Try<Nothing> initialized = local.get()->initialize(flags.acls.get());
+
+ if (initialized.isError()) {
+ return Error("Failed to initialize the authorizer: " +
+ initialized.error() + " (see --acls flag)");
+ }
+
+ master.authorizer.reset(local.get());
+ }
+
+ if (slaveRemovalLimiter.isNone() &&
+ flags.slave_removal_rate_limit.isSome()) {
+ // Parse the flag value.
+ // TODO(vinod): Move this parsing logic to flags once we have a
+ // 'Rate' abstraction in stout.
+ std::vector<std::string> tokens =
+ strings::tokenize(flags.slave_removal_rate_limit.get(), "/");
+
+ if (tokens.size() != 2) {
+ EXIT(1) << "Invalid slave_removal_rate_limit: "
+ << flags.slave_removal_rate_limit.get()
+ << ". Format is <Number of slaves>/<Duration>";
+ }
+
+ Try<int> permits = numify<int>(tokens[0]);
+ if (permits.isError()) {
+ EXIT(1) << "Invalid slave_removal_rate_limit: "
+ << flags.slave_removal_rate_limit.get()
+ << ". Format is <Number of slaves>/<Duration>"
+ << ": " << permits.error();
+ }
+
+ Try<Duration> duration = Duration::parse(tokens[1]);
+ if (duration.isError()) {
+ EXIT(1) << "Invalid slave_removal_rate_limit: "
+ << flags.slave_removal_rate_limit.get()
+ << ". Format is <Number of slaves>/<Duration>"
+ << ": " << duration.error();
+ }
+
+ master.slaveRemovalLimiter = std::shared_ptr<process::RateLimiter>(
+ new process::RateLimiter(permits.get(), duration.get()));
+ }
+
+ master.master = new master::Master(
+ master.allocator,
+ master.registrar.get(),
+ master.repairer.get(),
+ &cluster->files,
+ master.contender.get(),
+ master.detector.get(),
+ authorizer.isSome()
+ ? authorizer : master.authorizer.get(),
+ slaveRemovalLimiter.isSome()
+ ? slaveRemovalLimiter : master.slaveRemovalLimiter,
+ flags);
+
+ if (url.isNone()) {
+ // This means we are using the StandaloneMasterDetector.
+ StandaloneMasterDetector* detector_ = CHECK_NOTNULL(
+ dynamic_cast<StandaloneMasterDetector*>(master.detector.get()));
+
+ detector_->appoint(master.master->info());
+ }
+
+ process::Future<Nothing> _recover =
+ FUTURE_DISPATCH(master.master->self(), &master::Master::_recover);
+
+ process::PID<master::Master> pid = process::spawn(master.master);
+
+ masters[pid] = master;
+
+ // Speed up the tests by ensuring that the Master is recovered
+ // before the test proceeds. Otherwise, authentication and
+ // registration messages may be dropped, causing delayed retries.
+ // NOTE: We use process::internal::await() to avoid awaiting a
+ // Future forever when the Clock is paused.
+ if (!process::internal::await(
+ _recover,
+ flags.registry_fetch_timeout + flags.registry_store_timeout)) {
+ LOG(FATAL) << "Failed to wait for _recover";
+ }
+
+ bool paused = process::Clock::paused();
+
+ // Need to settle the Clock to ensure that the Master finishes
+ // executing _recover() before we return.
+ process::Clock::pause();
+ process::Clock::settle();
+
+ // Return the Clock to its original state.
+ if (!paused) {
+ process::Clock::resume();
+ }
+
+ return pid;
+}
+
+
+Try<Nothing> Cluster::Masters::stop(
+ const process::PID<master::Master>& pid)
+{
+ if (masters.count(pid) == 0) {
+ return Error("No master found to stop");
+ }
+
+ Master master = masters[pid];
+
+ process::terminate(master.master);
+ process::wait(master.master);
+ delete master.master;
+
+ if (master.createdAllocator) {
+ delete master.allocator;
+ }
+
+ masters.erase(pid);
+
+ return Nothing();
+}
+
+
+process::Owned<MasterDetector> Cluster::Masters::detector()
+{
+ if (url.isSome()) {
+ return process::Owned<MasterDetector>(
+ new ZooKeeperMasterDetector(url.get()));
+ }
+
+ CHECK(masters.size() == 1);
+
+ return process::Owned<MasterDetector>(
+ new StandaloneMasterDetector(masters.begin()->first));
+}
+
+
+Cluster::Slaves::Slaves(Cluster* _cluster, Masters* _masters)
+ : cluster(_cluster), masters(_masters) {}
+
+
+Cluster::Slaves::~Slaves()
+{
+ shutdown();
+}
+
+
+void Cluster::Slaves::shutdown()
+{
+ // TODO(benh): Use utils::copy from stout once namespaced.
+ std::map<process::PID<slave::Slave>, Slave> copy(slaves);
+ foreachpair (const process::PID<slave::Slave>& pid,
+ const Slave& slave,
+ copy) {
+ // Destroy the existing containers on the slave. Note that some
+ // containers may terminate while we are doing this, so we ignore
+ // any 'wait' failures and ensure that there are no containers
+ // when we're done destroying.
+ process::Future<hashset<ContainerID>> containers =
+ slave.containerizer->containers();
+ AWAIT_READY(containers);
+
+ foreach (const ContainerID& containerId, containers.get()) {
+ process::Future<containerizer::Termination> wait =
+ slave.containerizer->wait(containerId);
+
+ slave.containerizer->destroy(containerId);
+
+ AWAIT(wait);
+ }
+
+ containers = slave.containerizer->containers();
+ AWAIT_READY(containers);
+
+ ASSERT_TRUE(containers.get().empty())
+ << "Failed to destroy containers: " << stringify(containers.get());
+
+ stop(pid);
+ }
+ slaves.clear();
+}
+
+
+Try<process::PID<slave::Slave>> Cluster::Slaves::start(
+ const slave::Flags& flags,
+ const Option<slave::Containerizer*>& containerizer,
+ const Option<MasterDetector*>& detector,
+ const Option<slave::GarbageCollector*>& gc,
+ const Option<slave::StatusUpdateManager*>& statusUpdateManager,
+ const Option<mesos::slave::ResourceEstimator*>& resourceEstimator,
+ const Option<mesos::slave::QoSController*>& qosController)
+{
+ // TODO(benh): Create a work directory if using the default.
+
+ Slave slave;
+
+ if (containerizer.isSome()) {
+ slave.containerizer = containerizer.get();
+ } else {
+ // Create a new fetcher.
+ slave.fetcher.reset(new slave::Fetcher());
+
+ Try<slave::Containerizer*> containerizer =
+ slave::Containerizer::create(flags, true, slave.fetcher.get());
+
+ CHECK_SOME(containerizer);
+
+ slave.containerizer = containerizer.get();
+ slave.createdContainerizer = true;
+ }
+
+ if (resourceEstimator.isNone()) {
+ Try<mesos::slave::ResourceEstimator*> _resourceEstimator =
+ mesos::slave::ResourceEstimator::create(flags.resource_estimator);
+
+ CHECK_SOME(_resourceEstimator);
+ slave.resourceEstimator.reset(_resourceEstimator.get());
+ }
+
+ if (qosController.isNone()) {
+ Try<mesos::slave::QoSController*> _qosController =
+ mesos::slave::QoSController::create(flags.qos_controller);
+
+ CHECK_SOME(_qosController);
+ slave.qosController.reset(_qosController.get());
+ }
+
+ // Get a detector for the master(s) if one wasn't provided.
+ if (detector.isNone()) {
+ slave.detector = masters->detector();
+ }
+
+ // Create a garbage collector if one wasn't provided.
+ if (gc.isNone()) {
+ slave.gc.reset(new slave::GarbageCollector());
+ }
+
+ // Create a status update manager if one wasn't provided.
+ if (statusUpdateManager.isNone()) {
+ slave.statusUpdateManager.reset(new slave::StatusUpdateManager(flags));
+ }
+
+ slave.flags = flags;
+
+ slave.slave = new slave::Slave(
+ flags,
+ detector.getOrElse(slave.detector.get()),
+ slave.containerizer,
+ &cluster->files,
+ gc.getOrElse(slave.gc.get()),
+ statusUpdateManager.getOrElse(slave.statusUpdateManager.get()),
+ resourceEstimator.getOrElse(slave.resourceEstimator.get()),
+ qosController.getOrElse(slave.qosController.get()));
+
+ process::PID<slave::Slave> pid = process::spawn(slave.slave);
+
+ slaves[pid] = slave;
+
+ return pid;
+}
+
+
+Try<Nothing> Cluster::Slaves::stop(
+ const process::PID<slave::Slave>& pid,
+ bool shutdown)
+{
+ if (slaves.count(pid) == 0) {
+ return Error("No slave found to stop");
+ }
+
+ Slave slave = slaves[pid];
+
+ if (shutdown) {
+ process::dispatch(slave.slave,
+ &slave::Slave::shutdown,
+ process::UPID(),
+ "");
+ } else {
+ process::terminate(slave.slave);
+ }
+ process::wait(slave.slave);
+ delete slave.slave;
+
+ if (slave.createdContainerizer) {
+ delete slave.containerizer;
+ }
+
+#ifdef __linux__
+ // Remove all of this processes threads into the root cgroups - this
+ // simulates the slave process terminating and permits a new slave to start
+ // when the --slave_subsystems flag is used.
+ if (slave.flags.slave_subsystems.isSome()) {
+ foreach (const std::string& subsystem,
+ strings::tokenize(slave.flags.slave_subsystems.get(), ",")) {
+ std::string hierarchy = path::join(
+ slave.flags.cgroups_hierarchy, subsystem);
+
+ std::string cgroup = path::join(slave.flags.cgroups_root, "slave");
+
+ Try<bool> exists = cgroups::exists(hierarchy, cgroup);
+ if (exists.isError() || !exists.get()) {
+ EXIT(1) << "Failed to find cgroup " << cgroup
+ << " for subsystem " << subsystem
+ << " under hierarchy " << hierarchy
+ << " for slave: " + exists.error();
+ }
+
+ // Move all of our threads into the root cgroup.
+ Try<Nothing> assign = cgroups::assign(hierarchy, "", getpid());
+ if (assign.isError()) {
+ EXIT(1) << "Failed to move slave threads into cgroup " << cgroup
+ << " for subsystem " << subsystem
+ << " under hierarchy " << hierarchy
+ << " for slave: " + assign.error();
+ }
+ }
+ }
+#endif // __linux__
+
+ slaves.erase(pid);
+
+ return Nothing();
+}
+
+} // namespace tests {
+} // namespace internal {
+} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/b4c4f905/src/tests/cluster.hpp
----------------------------------------------------------------------
diff --git a/src/tests/cluster.hpp b/src/tests/cluster.hpp
index 032fcdd..cb701a3 100644
--- a/src/tests/cluster.hpp
+++ b/src/tests/cluster.hpp
@@ -32,23 +32,11 @@
#include <mesos/slave/resource_estimator.hpp>
-#include <process/clock.hpp>
-#include <process/future.hpp>
-#include <process/gmock.hpp>
-#include <process/gtest.hpp>
-#include <process/limiter.hpp>
#include <process/owned.hpp>
#include <process/pid.hpp>
-#include <process/process.hpp>
-#include <stout/duration.hpp>
-#include <stout/error.hpp>
-#include <stout/foreach.hpp>
#include <stout/none.hpp>
-#include <stout/nothing.hpp>
#include <stout/option.hpp>
-#include <stout/path.hpp>
-#include <stout/strings.hpp>
#include <stout/try.hpp>
#include "authorizer/local/authorizer.hpp"
@@ -61,8 +49,6 @@
#include "log/log.hpp"
-#include "log/tool/initialize.hpp"
-
#include "master/constants.hpp"
#include "master/contender.hpp"
#include "master/detector.hpp"
@@ -71,8 +57,6 @@
#include "master/registrar.hpp"
#include "master/repairer.hpp"
-#include "master/allocator/mesos/hierarchical.hpp"
-
#include "slave/flags.hpp"
#include "slave/gc.hpp"
#include "slave/slave.hpp"
@@ -270,451 +254,6 @@ private:
Cluster& operator=(const Cluster&);
};
-
-inline Cluster::Masters::Masters(
- Cluster* _cluster,
- const Option<zookeeper::URL>& _url)
- : cluster(_cluster),
- url(_url) {}
-
-
-inline Cluster::Masters::~Masters()
-{
- shutdown();
-}
-
-
-inline void Cluster::Masters::shutdown()
-{
- // TODO(benh): Use utils::copy from stout once namespaced.
- std::map<process::PID<master::Master>, Master> copy(masters);
- foreachkey (const process::PID<master::Master>& pid, copy) {
- stop(pid);
- }
- masters.clear();
-}
-
-
-inline Try<process::PID<master::Master>> Cluster::Masters::start(
- const master::Flags& flags,
- const Option<mesos::master::allocator::Allocator*>& allocator,
- const Option<Authorizer*>& authorizer,
- const Option<std::shared_ptr<process::RateLimiter>>& slaveRemovalLimiter)
-{
- // Disallow multiple masters when not using ZooKeeper.
- if (!masters.empty() && url.isNone()) {
- return Error("Can not start multiple masters when not using ZooKeeper");
- }
-
- Master master;
-
- if (allocator.isSome()) {
- master.allocator = allocator.get();
- } else {
- // If allocator is not provided, fall back to the default one,
- // managed by Cluster::Masters.
- Try<mesos::master::allocator::Allocator*> allocator_ =
- master::allocator::HierarchicalDRFAllocator::create();
- if (allocator_.isError()) {
- return Error(
- "Failed to create an instance of HierarchicalDRFAllocator: " +
- allocator_.error());
- }
-
- master.allocator = allocator_.get();
- master.createdAllocator = true;
- }
-
- if (flags.registry == "in_memory") {
- if (flags.registry_strict) {
- return Error(
- "Cannot use '--registry_strict' when using in-memory storage based"
- " registry");
- }
- master.storage.reset(new state::InMemoryStorage());
- } else if (flags.registry == "replicated_log") {
- if (flags.work_dir.isNone()) {
- return Error(
- "Need to specify --work_dir for replicated log based registry");
- }
-
- if (url.isSome()) {
- // Use ZooKeeper based replicated log.
- if (flags.quorum.isNone()) {
- return Error(
- "Need to specify --quorum for replicated log based registry"
- " when using ZooKeeper");
- }
- master.log.reset(new log::Log(
- flags.quorum.get(),
- path::join(flags.work_dir.get(), "replicated_log"),
- url.get().servers,
- flags.zk_session_timeout,
- path::join(url.get().path, "log_replicas"),
- url.get().authentication,
- flags.log_auto_initialize));
- } else {
- master.log.reset(new log::Log(
- 1,
- path::join(flags.work_dir.get(), "replicated_log"),
- std::set<process::UPID>(),
- flags.log_auto_initialize));
- }
-
- master.storage.reset(new state::LogStorage(master.log.get()));
- } else {
- return Error("'" + flags.registry + "' is not a supported option for"
- " registry persistence");
- }
-
- CHECK_NOTNULL(master.storage.get());
-
- master.state.reset(new state::protobuf::State(master.storage.get()));
- master.registrar.reset(new master::Registrar(flags, master.state.get()));
- master.repairer.reset(new master::Repairer());
-
- if (url.isSome()) {
- master.contender.reset(new ZooKeeperMasterContender(url.get()));
- master.detector.reset(new ZooKeeperMasterDetector(url.get()));
- } else {
- master.contender.reset(new StandaloneMasterContender());
- master.detector.reset(new StandaloneMasterDetector());
- }
-
- if (authorizer.isSome()) {
- CHECK_NOTNULL(authorizer.get());
- } else if (flags.acls.isSome()) {
- Try<Authorizer*> local = Authorizer::create(master::DEFAULT_AUTHORIZER);
-
- if (local.isError()) {
- EXIT(EXIT_FAILURE)
- << "Failed to instantiate the local authorizer: "
- << local.error();
- }
-
- Try<Nothing> initialized = local.get()->initialize(flags.acls.get());
-
- if (initialized.isError()) {
- return Error("Failed to initialize the authorizer: " +
- initialized.error() + " (see --acls flag)");
- }
-
- master.authorizer.reset(local.get());
- }
-
- if (slaveRemovalLimiter.isNone() &&
- flags.slave_removal_rate_limit.isSome()) {
- // Parse the flag value.
- // TODO(vinod): Move this parsing logic to flags once we have a
- // 'Rate' abstraction in stout.
- std::vector<std::string> tokens =
- strings::tokenize(flags.slave_removal_rate_limit.get(), "/");
-
- if (tokens.size() != 2) {
- EXIT(1) << "Invalid slave_removal_rate_limit: "
- << flags.slave_removal_rate_limit.get()
- << ". Format is <Number of slaves>/<Duration>";
- }
-
- Try<int> permits = numify<int>(tokens[0]);
- if (permits.isError()) {
- EXIT(1) << "Invalid slave_removal_rate_limit: "
- << flags.slave_removal_rate_limit.get()
- << ". Format is <Number of slaves>/<Duration>"
- << ": " << permits.error();
- }
-
- Try<Duration> duration = Duration::parse(tokens[1]);
- if (duration.isError()) {
- EXIT(1) << "Invalid slave_removal_rate_limit: "
- << flags.slave_removal_rate_limit.get()
- << ". Format is <Number of slaves>/<Duration>"
- << ": " << duration.error();
- }
-
- master.slaveRemovalLimiter = std::shared_ptr<process::RateLimiter>(
- new process::RateLimiter(permits.get(), duration.get()));
- }
-
- master.master = new master::Master(
- master.allocator,
- master.registrar.get(),
- master.repairer.get(),
- &cluster->files,
- master.contender.get(),
- master.detector.get(),
- authorizer.isSome()
- ? authorizer : master.authorizer.get(),
- slaveRemovalLimiter.isSome()
- ? slaveRemovalLimiter : master.slaveRemovalLimiter,
- flags);
-
- if (url.isNone()) {
- // This means we are using the StandaloneMasterDetector.
- StandaloneMasterDetector* detector_ = CHECK_NOTNULL(
- dynamic_cast<StandaloneMasterDetector*>(master.detector.get()));
-
- detector_->appoint(master.master->info());
- }
-
- process::Future<Nothing> _recover =
- FUTURE_DISPATCH(master.master->self(), &master::Master::_recover);
-
- process::PID<master::Master> pid = process::spawn(master.master);
-
- masters[pid] = master;
-
- // Speed up the tests by ensuring that the Master is recovered
- // before the test proceeds. Otherwise, authentication and
- // registration messages may be dropped, causing delayed retries.
- // NOTE: We use process::internal::await() to avoid awaiting a
- // Future forever when the Clock is paused.
- if (!process::internal::await(
- _recover,
- flags.registry_fetch_timeout + flags.registry_store_timeout)) {
- LOG(FATAL) << "Failed to wait for _recover";
- }
-
- bool paused = process::Clock::paused();
-
- // Need to settle the Clock to ensure that the Master finishes
- // executing _recover() before we return.
- process::Clock::pause();
- process::Clock::settle();
-
- // Return the Clock to its original state.
- if (!paused) {
- process::Clock::resume();
- }
-
- return pid;
-}
-
-
-inline Try<Nothing> Cluster::Masters::stop(
- const process::PID<master::Master>& pid)
-{
- if (masters.count(pid) == 0) {
- return Error("No master found to stop");
- }
-
- Master master = masters[pid];
-
- process::terminate(master.master);
- process::wait(master.master);
- delete master.master;
-
- if (master.createdAllocator) {
- delete master.allocator;
- }
-
- masters.erase(pid);
-
- return Nothing();
-}
-
-
-inline process::Owned<MasterDetector> Cluster::Masters::detector()
-{
- if (url.isSome()) {
- return process::Owned<MasterDetector>(
- new ZooKeeperMasterDetector(url.get()));
- }
-
- CHECK(masters.size() == 1);
-
- return process::Owned<MasterDetector>(
- new StandaloneMasterDetector(masters.begin()->first));
-}
-
-
-inline Cluster::Slaves::Slaves(Cluster* _cluster, Masters* _masters)
- : cluster(_cluster), masters(_masters) {}
-
-
-inline Cluster::Slaves::~Slaves()
-{
- shutdown();
-}
-
-
-inline void Cluster::Slaves::shutdown()
-{
- // TODO(benh): Use utils::copy from stout once namespaced.
- std::map<process::PID<slave::Slave>, Slave> copy(slaves);
- foreachpair (const process::PID<slave::Slave>& pid,
- const Slave& slave,
- copy) {
- // Destroy the existing containers on the slave. Note that some
- // containers may terminate while we are doing this, so we ignore
- // any 'wait' failures and ensure that there are no containers
- // when we're done destroying.
- process::Future<hashset<ContainerID>> containers =
- slave.containerizer->containers();
- AWAIT_READY(containers);
-
- foreach (const ContainerID& containerId, containers.get()) {
- process::Future<containerizer::Termination> wait =
- slave.containerizer->wait(containerId);
-
- slave.containerizer->destroy(containerId);
-
- AWAIT(wait);
- }
-
- containers = slave.containerizer->containers();
- AWAIT_READY(containers);
-
- ASSERT_TRUE(containers.get().empty())
- << "Failed to destroy containers: " << stringify(containers.get());
-
- stop(pid);
- }
- slaves.clear();
-}
-
-
-inline Try<process::PID<slave::Slave>> Cluster::Slaves::start(
- const slave::Flags& flags,
- const Option<slave::Containerizer*>& containerizer,
- const Option<MasterDetector*>& detector,
- const Option<slave::GarbageCollector*>& gc,
- const Option<slave::StatusUpdateManager*>& statusUpdateManager,
- const Option<mesos::slave::ResourceEstimator*>& resourceEstimator,
- const Option<mesos::slave::QoSController*>& qosController)
-{
- // TODO(benh): Create a work directory if using the default.
-
- Slave slave;
-
- if (containerizer.isSome()) {
- slave.containerizer = containerizer.get();
- } else {
- // Create a new fetcher.
- slave.fetcher.reset(new slave::Fetcher());
-
- Try<slave::Containerizer*> containerizer =
- slave::Containerizer::create(flags, true, slave.fetcher.get());
-
- CHECK_SOME(containerizer);
-
- slave.containerizer = containerizer.get();
- slave.createdContainerizer = true;
- }
-
- if (resourceEstimator.isNone()) {
- Try<mesos::slave::ResourceEstimator*> _resourceEstimator =
- mesos::slave::ResourceEstimator::create(flags.resource_estimator);
-
- CHECK_SOME(_resourceEstimator);
- slave.resourceEstimator.reset(_resourceEstimator.get());
- }
-
- if (qosController.isNone()) {
- Try<mesos::slave::QoSController*> _qosController =
- mesos::slave::QoSController::create(flags.qos_controller);
-
- CHECK_SOME(_qosController);
- slave.qosController.reset(_qosController.get());
- }
-
- // Get a detector for the master(s) if one wasn't provided.
- if (detector.isNone()) {
- slave.detector = masters->detector();
- }
-
- // Create a garbage collector if one wasn't provided.
- if (gc.isNone()) {
- slave.gc.reset(new slave::GarbageCollector());
- }
-
- // Create a status update manager if one wasn't provided.
- if (statusUpdateManager.isNone()) {
- slave.statusUpdateManager.reset(new slave::StatusUpdateManager(flags));
- }
-
- slave.flags = flags;
-
- slave.slave = new slave::Slave(
- flags,
- detector.getOrElse(slave.detector.get()),
- slave.containerizer,
- &cluster->files,
- gc.getOrElse(slave.gc.get()),
- statusUpdateManager.getOrElse(slave.statusUpdateManager.get()),
- resourceEstimator.getOrElse(slave.resourceEstimator.get()),
- qosController.getOrElse(slave.qosController.get()));
-
- process::PID<slave::Slave> pid = process::spawn(slave.slave);
-
- slaves[pid] = slave;
-
- return pid;
-}
-
-
-inline Try<Nothing> Cluster::Slaves::stop(
- const process::PID<slave::Slave>& pid,
- bool shutdown)
-{
- if (slaves.count(pid) == 0) {
- return Error("No slave found to stop");
- }
-
- Slave slave = slaves[pid];
-
- if (shutdown) {
- process::dispatch(slave.slave,
- &slave::Slave::shutdown,
- process::UPID(),
- "");
- } else {
- process::terminate(slave.slave);
- }
- process::wait(slave.slave);
- delete slave.slave;
-
- if (slave.createdContainerizer) {
- delete slave.containerizer;
- }
-
-#ifdef __linux__
- // Remove all of this processes threads into the root cgroups - this
- // simulates the slave process terminating and permits a new slave to start
- // when the --slave_subsystems flag is used.
- if (slave.flags.slave_subsystems.isSome()) {
- foreach (const std::string& subsystem,
- strings::tokenize(slave.flags.slave_subsystems.get(), ",")) {
- std::string hierarchy = path::join(
- slave.flags.cgroups_hierarchy, subsystem);
-
- std::string cgroup = path::join(slave.flags.cgroups_root, "slave");
-
- Try<bool> exists = cgroups::exists(hierarchy, cgroup);
- if (exists.isError() || !exists.get()) {
- EXIT(1) << "Failed to find cgroup " << cgroup
- << " for subsystem " << subsystem
- << " under hierarchy " << hierarchy
- << " for slave: " + exists.error();
- }
-
- // Move all of our threads into the root cgroup.
- Try<Nothing> assign = cgroups::assign(hierarchy, "", getpid());
- if (assign.isError()) {
- EXIT(1) << "Failed to move slave threads into cgroup " << cgroup
- << " for subsystem " << subsystem
- << " under hierarchy " << hierarchy
- << " for slave: " + assign.error();
- }
- }
- }
-#endif // __linux__
-
- slaves.erase(pid);
-
- return Nothing();
-}
-
} // namespace tests {
} // namespace internal {
} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/b4c4f905/src/tests/fault_tolerance_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/fault_tolerance_tests.cpp b/src/tests/fault_tolerance_tests.cpp
index cadc32e..3e353e4 100644
--- a/src/tests/fault_tolerance_tests.cpp
+++ b/src/tests/fault_tolerance_tests.cpp
@@ -47,6 +47,8 @@
#include "master/master.hpp"
+#include "master/allocator/mesos/allocator.hpp"
+
#include "sched/constants.hpp"
#include "slave/constants.hpp"
http://git-wip-us.apache.org/repos/asf/mesos/blob/b4c4f905/src/tests/master_authorization_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_authorization_tests.cpp b/src/tests/master_authorization_tests.cpp
index f3f0cc8..0d1f2b5 100644
--- a/src/tests/master_authorization_tests.cpp
+++ b/src/tests/master_authorization_tests.cpp
@@ -35,6 +35,8 @@
#include "master/master.hpp"
+#include "master/allocator/mesos/allocator.hpp"
+
#include "messages/messages.hpp"
#include "slave/slave.hpp"
http://git-wip-us.apache.org/repos/asf/mesos/blob/b4c4f905/src/tests/master_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_tests.cpp b/src/tests/master_tests.cpp
index 348bbef..a754e3b 100644
--- a/src/tests/master_tests.cpp
+++ b/src/tests/master_tests.cpp
@@ -53,6 +53,8 @@
#include "master/flags.hpp"
#include "master/master.hpp"
+#include "master/allocator/mesos/allocator.hpp"
+
#include "slave/constants.hpp"
#include "slave/gc.hpp"
#include "slave/flags.hpp"
http://git-wip-us.apache.org/repos/asf/mesos/blob/b4c4f905/src/tests/partition_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/partition_tests.cpp b/src/tests/partition_tests.cpp
index 9a87d9f..6a6524e 100644
--- a/src/tests/partition_tests.cpp
+++ b/src/tests/partition_tests.cpp
@@ -32,6 +32,8 @@
#include "master/master.hpp"
+#include "master/allocator/mesos/allocator.hpp"
+
#include "slave/constants.hpp"
#include "slave/flags.hpp"
#include "slave/slave.hpp"
http://git-wip-us.apache.org/repos/asf/mesos/blob/b4c4f905/src/tests/rate_limiting_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/rate_limiting_tests.cpp b/src/tests/rate_limiting_tests.cpp
index e512aa6..0658816 100644
--- a/src/tests/rate_limiting_tests.cpp
+++ b/src/tests/rate_limiting_tests.cpp
@@ -32,6 +32,8 @@
#include "master/flags.hpp"
#include "master/master.hpp"
+#include "master/allocator/mesos/allocator.hpp"
+
#include "tests/mesos.hpp"
#include "tests/utils.hpp"
[2/2] mesos git commit: Refactored mock allocator into a separate
header file.
Posted by jo...@apache.org.
Refactored mock allocator into a separate header file.
Refactored mock allocator into a separate header file.
Review: https://reviews.apache.org/r/39947
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2a9a5c12
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2a9a5c12
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2a9a5c12
Branch: refs/heads/master
Commit: 2a9a5c12b9a6621975b766c45b78740d9d3fbba8
Parents: 73deb1c
Author: Neil Conway <ne...@gmail.com>
Authored: Mon Nov 9 09:36:50 2015 +0100
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon Nov 9 14:12:54 2015 +0100
----------------------------------------------------------------------
src/Makefile.am | 1 +
src/tests/allocator.hpp | 415 ++++++++++++++++++++++++
src/tests/hierarchical_allocator_tests.cpp | 1 +
src/tests/master_allocator_tests.cpp | 1 +
src/tests/mesos.hpp | 374 ---------------------
src/tests/reservation_endpoints_tests.cpp | 1 +
src/tests/reservation_tests.cpp | 1 +
src/tests/resource_offers_tests.cpp | 1 +
src/tests/slave_recovery_tests.cpp | 1 +
9 files changed, 422 insertions(+), 374 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/2a9a5c12/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 3263991..e3a206c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -890,6 +890,7 @@ libmesos_no_3rdparty_la_SOURCES += \
slave/containerizer/mesos/provisioner/docker/token_manager.hpp \
slave/qos_controllers/noop.hpp \
slave/resource_estimators/noop.hpp \
+ tests/allocator.hpp \
tests/cluster.hpp \
tests/containerizer.hpp \
tests/environment.hpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/2a9a5c12/src/tests/allocator.hpp
----------------------------------------------------------------------
diff --git a/src/tests/allocator.hpp b/src/tests/allocator.hpp
new file mode 100644
index 0000000..4ab4766
--- /dev/null
+++ b/src/tests/allocator.hpp
@@ -0,0 +1,415 @@
+/**
+ * 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.
+ */
+
+#ifndef __TESTS_ALLOCATOR_HPP__
+#define __TESTS_ALLOCATOR_HPP__
+
+#include <gmock/gmock.h>
+
+#include <mesos/master/allocator.hpp>
+
+#include <process/future.hpp>
+#include <process/gmock.hpp>
+#include <process/owned.hpp>
+
+#include "master/allocator/mesos/hierarchical.hpp"
+
+using ::testing::_;
+using ::testing::An;
+using ::testing::DoDefault;
+using ::testing::Invoke;
+using ::testing::Return;
+
+namespace mesos {
+namespace internal {
+namespace tests {
+
+// The following actions make up for the fact that DoDefault
+// cannot be used inside a DoAll, for example:
+// EXPECT_CALL(allocator, addFramework(_, _, _))
+// .WillOnce(DoAll(InvokeAddFramework(&allocator),
+// FutureSatisfy(&addFramework)));
+
+ACTION_P(InvokeInitialize, allocator)
+{
+ allocator->real->initialize(arg0, arg1, arg2, arg3);
+}
+
+
+ACTION_P(InvokeAddFramework, allocator)
+{
+ allocator->real->addFramework(arg0, arg1, arg2);
+}
+
+
+ACTION_P(InvokeRemoveFramework, allocator)
+{
+ allocator->real->removeFramework(arg0);
+}
+
+
+ACTION_P(InvokeActivateFramework, allocator)
+{
+ allocator->real->activateFramework(arg0);
+}
+
+
+ACTION_P(InvokeDeactivateFramework, allocator)
+{
+ allocator->real->deactivateFramework(arg0);
+}
+
+
+ACTION_P(InvokeUpdateFramework, allocator)
+{
+ allocator->real->updateFramework(arg0, arg1);
+}
+
+
+ACTION_P(InvokeAddSlave, allocator)
+{
+ allocator->real->addSlave(arg0, arg1, arg2, arg3, arg4);
+}
+
+
+ACTION_P(InvokeRemoveSlave, allocator)
+{
+ allocator->real->removeSlave(arg0);
+}
+
+
+ACTION_P(InvokeUpdateSlave, allocator)
+{
+ allocator->real->updateSlave(arg0, arg1);
+}
+
+
+ACTION_P(InvokeActivateSlave, allocator)
+{
+ allocator->real->activateSlave(arg0);
+}
+
+
+ACTION_P(InvokeDeactivateSlave, allocator)
+{
+ allocator->real->deactivateSlave(arg0);
+}
+
+
+ACTION_P(InvokeUpdateWhitelist, allocator)
+{
+ allocator->real->updateWhitelist(arg0);
+}
+
+
+ACTION_P(InvokeRequestResources, allocator)
+{
+ allocator->real->requestResources(arg0, arg1);
+}
+
+
+ACTION_P(InvokeUpdateAllocation, allocator)
+{
+ allocator->real->updateAllocation(arg0, arg1, arg2);
+}
+
+
+ACTION_P(InvokeUpdateResources, allocator)
+{
+ return allocator->real->updateAvailable(arg0, arg1);
+}
+
+
+ACTION_P(InvokeUpdateUnavailability, allocator)
+{
+ return allocator->real->updateUnavailability(arg0, arg1);
+}
+
+
+ACTION_P(InvokeUpdateInverseOffer, allocator)
+{
+ return allocator->real->updateInverseOffer(arg0, arg1, arg2, arg3, arg4);
+}
+
+
+ACTION_P(InvokeGetInverseOfferStatuses, allocator)
+{
+ return allocator->real->getInverseOfferStatuses();
+}
+
+
+ACTION_P(InvokeRecoverResources, allocator)
+{
+ allocator->real->recoverResources(arg0, arg1, arg2, arg3);
+}
+
+
+ACTION_P2(InvokeRecoverResourcesWithFilters, allocator, timeout)
+{
+ Filters filters;
+ filters.set_refuse_seconds(timeout);
+
+ allocator->real->recoverResources(arg0, arg1, arg2, filters);
+}
+
+
+ACTION_P(InvokeSuppressOffers, allocator)
+{
+ allocator->real->suppressOffers(arg0);
+}
+
+
+ACTION_P(InvokeReviveOffers, allocator)
+{
+ allocator->real->reviveOffers(arg0);
+}
+
+
+template <typename T = master::allocator::HierarchicalDRFAllocator>
+mesos::master::allocator::Allocator* createAllocator()
+{
+ // T represents the allocator type. It can be a default built-in
+ // allocator, or one provided by an allocator module.
+ Try<mesos::master::allocator::Allocator*> instance = T::create();
+ CHECK_SOME(instance);
+ return CHECK_NOTNULL(instance.get());
+}
+
+template <typename T = master::allocator::HierarchicalDRFAllocator>
+class TestAllocator : public mesos::master::allocator::Allocator
+{
+public:
+ // Actual allocation is done by an instance of real allocator,
+ // which is specified by the template parameter.
+ TestAllocator() : real(createAllocator<T>())
+ {
+ // We use 'ON_CALL' and 'WillByDefault' here to specify the
+ // default actions (call in to the real allocator). This allows
+ // the tests to leverage the 'DoDefault' action.
+ // However, 'ON_CALL' results in a "Uninteresting mock function
+ // call" warning unless each test puts expectations in place.
+ // As a result, we also use 'EXPECT_CALL' and 'WillRepeatedly'
+ // to get the best of both worlds: the ability to use 'DoDefault'
+ // and no warnings when expectations are not explicit.
+
+ ON_CALL(*this, initialize(_, _, _, _))
+ .WillByDefault(InvokeInitialize(this));
+ EXPECT_CALL(*this, initialize(_, _, _, _))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, addFramework(_, _, _))
+ .WillByDefault(InvokeAddFramework(this));
+ EXPECT_CALL(*this, addFramework(_, _, _))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, removeFramework(_))
+ .WillByDefault(InvokeRemoveFramework(this));
+ EXPECT_CALL(*this, removeFramework(_))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, activateFramework(_))
+ .WillByDefault(InvokeActivateFramework(this));
+ EXPECT_CALL(*this, activateFramework(_))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, deactivateFramework(_))
+ .WillByDefault(InvokeDeactivateFramework(this));
+ EXPECT_CALL(*this, deactivateFramework(_))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, updateFramework(_, _))
+ .WillByDefault(InvokeUpdateFramework(this));
+ EXPECT_CALL(*this, updateFramework(_, _))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, addSlave(_, _, _, _, _))
+ .WillByDefault(InvokeAddSlave(this));
+ EXPECT_CALL(*this, addSlave(_, _, _, _, _))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, removeSlave(_))
+ .WillByDefault(InvokeRemoveSlave(this));
+ EXPECT_CALL(*this, removeSlave(_))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, updateSlave(_, _))
+ .WillByDefault(InvokeUpdateSlave(this));
+ EXPECT_CALL(*this, updateSlave(_, _))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, activateSlave(_))
+ .WillByDefault(InvokeActivateSlave(this));
+ EXPECT_CALL(*this, activateSlave(_))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, deactivateSlave(_))
+ .WillByDefault(InvokeDeactivateSlave(this));
+ EXPECT_CALL(*this, deactivateSlave(_))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, updateWhitelist(_))
+ .WillByDefault(InvokeUpdateWhitelist(this));
+ EXPECT_CALL(*this, updateWhitelist(_))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, requestResources(_, _))
+ .WillByDefault(InvokeRequestResources(this));
+ EXPECT_CALL(*this, requestResources(_, _))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, updateAllocation(_, _, _))
+ .WillByDefault(InvokeUpdateAllocation(this));
+ EXPECT_CALL(*this, updateAllocation(_, _, _))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, updateAvailable(_, _))
+ .WillByDefault(InvokeUpdateResources(this));
+ EXPECT_CALL(*this, updateAvailable(_, _))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, updateUnavailability(_, _))
+ .WillByDefault(InvokeUpdateUnavailability(this));
+ EXPECT_CALL(*this, updateUnavailability(_, _))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, updateInverseOffer(_, _, _, _, _))
+ .WillByDefault(InvokeUpdateInverseOffer(this));
+ EXPECT_CALL(*this, updateInverseOffer(_, _, _, _, _))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, getInverseOfferStatuses())
+ .WillByDefault(InvokeGetInverseOfferStatuses(this));
+ EXPECT_CALL(*this, getInverseOfferStatuses())
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, recoverResources(_, _, _, _))
+ .WillByDefault(InvokeRecoverResources(this));
+ EXPECT_CALL(*this, recoverResources(_, _, _, _))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, reviveOffers(_))
+ .WillByDefault(InvokeReviveOffers(this));
+ EXPECT_CALL(*this, reviveOffers(_))
+ .WillRepeatedly(DoDefault());
+
+ ON_CALL(*this, suppressOffers(_))
+ .WillByDefault(InvokeSuppressOffers(this));
+ EXPECT_CALL(*this, suppressOffers(_))
+ .WillRepeatedly(DoDefault());
+ }
+
+ virtual ~TestAllocator() {}
+
+ MOCK_METHOD4(initialize, void(
+ const Duration&,
+ const lambda::function<
+ void(const FrameworkID&,
+ const hashmap<SlaveID, Resources>&)>&,
+ const lambda::function<
+ void(const FrameworkID&,
+ const hashmap<SlaveID, UnavailableResources>&)>&,
+ const hashmap<std::string, mesos::master::RoleInfo>&));
+
+ MOCK_METHOD3(addFramework, void(
+ const FrameworkID&,
+ const FrameworkInfo&,
+ const hashmap<SlaveID, Resources>&));
+
+ MOCK_METHOD1(removeFramework, void(
+ const FrameworkID&));
+
+ MOCK_METHOD1(activateFramework, void(
+ const FrameworkID&));
+
+ MOCK_METHOD1(deactivateFramework, void(
+ const FrameworkID&));
+
+ MOCK_METHOD2(updateFramework, void(
+ const FrameworkID&,
+ const FrameworkInfo&));
+
+ MOCK_METHOD5(addSlave, void(
+ const SlaveID&,
+ const SlaveInfo&,
+ const Option<Unavailability>&,
+ const Resources&,
+ const hashmap<FrameworkID, Resources>&));
+
+ MOCK_METHOD1(removeSlave, void(
+ const SlaveID&));
+
+ MOCK_METHOD2(updateSlave, void(
+ const SlaveID&,
+ const Resources&));
+
+ MOCK_METHOD1(activateSlave, void(
+ const SlaveID&));
+
+ MOCK_METHOD1(deactivateSlave, void(
+ const SlaveID&));
+
+ MOCK_METHOD1(updateWhitelist, void(
+ const Option<hashset<std::string> >&));
+
+ MOCK_METHOD2(requestResources, void(
+ const FrameworkID&,
+ const std::vector<Request>&));
+
+ MOCK_METHOD3(updateAllocation, void(
+ const FrameworkID&,
+ const SlaveID&,
+ const std::vector<Offer::Operation>&));
+
+ MOCK_METHOD2(updateAvailable, process::Future<Nothing>(
+ const SlaveID&,
+ const std::vector<Offer::Operation>&));
+
+ MOCK_METHOD2(updateUnavailability, void(
+ const SlaveID&,
+ const Option<Unavailability>&));
+
+ MOCK_METHOD5(updateInverseOffer, void(
+ const SlaveID&,
+ const FrameworkID&,
+ const Option<UnavailableResources>&,
+ const Option<mesos::master::InverseOfferStatus>&,
+ const Option<Filters>&));
+
+ MOCK_METHOD0(getInverseOfferStatuses, process::Future<
+ hashmap<SlaveID, hashmap<
+ FrameworkID,
+ mesos::master::InverseOfferStatus>>>());
+
+ MOCK_METHOD4(recoverResources, void(
+ const FrameworkID&,
+ const SlaveID&,
+ const Resources&,
+ const Option<Filters>& filters));
+
+ MOCK_METHOD1(reviveOffers, void(const FrameworkID&));
+
+ MOCK_METHOD1(suppressOffers, void(const FrameworkID&));
+
+ process::Owned<mesos::master::allocator::Allocator> real;
+};
+
+} // namespace tests {
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __TESTS_ALLOCATOR_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/2a9a5c12/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index 505b9de..d422448 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -45,6 +45,7 @@
#include "master/allocator/mesos/hierarchical.hpp"
+#include "tests/allocator.hpp"
#include "tests/mesos.hpp"
using mesos::internal::master::MIN_CPUS;
http://git-wip-us.apache.org/repos/asf/mesos/blob/2a9a5c12/src/tests/master_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_allocator_tests.cpp b/src/tests/master_allocator_tests.cpp
index 1fe3757..52fa472 100644
--- a/src/tests/master_allocator_tests.cpp
+++ b/src/tests/master_allocator_tests.cpp
@@ -45,6 +45,7 @@
#include "master/allocator/mesos/hierarchical.hpp"
+#include "tests/allocator.hpp"
#include "tests/containerizer.hpp"
#include "tests/mesos.hpp"
#include "tests/module.hpp"
http://git-wip-us.apache.org/repos/asf/mesos/blob/2a9a5c12/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 71eba8b..25074a0 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -32,8 +32,6 @@
#include <mesos/authorizer/authorizer.hpp>
-#include <mesos/master/allocator.hpp>
-
#include <mesos/fetcher/fetcher.hpp>
#include <mesos/slave/qos_controller.hpp>
@@ -66,8 +64,6 @@
#include "master/detector.hpp"
#include "master/master.hpp"
-#include "master/allocator/mesos/hierarchical.hpp"
-
#include "slave/slave.hpp"
#include "slave/containerizer/containerizer.hpp"
@@ -1261,376 +1257,6 @@ public:
};
-// The following actions make up for the fact that DoDefault
-// cannot be used inside a DoAll, for example:
-// EXPECT_CALL(allocator, addFramework(_, _, _))
-// .WillOnce(DoAll(InvokeAddFramework(&allocator),
-// FutureSatisfy(&addFramework)));
-
-ACTION_P(InvokeInitialize, allocator)
-{
- allocator->real->initialize(arg0, arg1, arg2, arg3);
-}
-
-
-ACTION_P(InvokeAddFramework, allocator)
-{
- allocator->real->addFramework(arg0, arg1, arg2);
-}
-
-
-ACTION_P(InvokeRemoveFramework, allocator)
-{
- allocator->real->removeFramework(arg0);
-}
-
-
-ACTION_P(InvokeActivateFramework, allocator)
-{
- allocator->real->activateFramework(arg0);
-}
-
-
-ACTION_P(InvokeDeactivateFramework, allocator)
-{
- allocator->real->deactivateFramework(arg0);
-}
-
-
-ACTION_P(InvokeUpdateFramework, allocator)
-{
- allocator->real->updateFramework(arg0, arg1);
-}
-
-
-ACTION_P(InvokeAddSlave, allocator)
-{
- allocator->real->addSlave(arg0, arg1, arg2, arg3, arg4);
-}
-
-
-ACTION_P(InvokeRemoveSlave, allocator)
-{
- allocator->real->removeSlave(arg0);
-}
-
-
-ACTION_P(InvokeUpdateSlave, allocator)
-{
- allocator->real->updateSlave(arg0, arg1);
-}
-
-
-ACTION_P(InvokeActivateSlave, allocator)
-{
- allocator->real->activateSlave(arg0);
-}
-
-
-ACTION_P(InvokeDeactivateSlave, allocator)
-{
- allocator->real->deactivateSlave(arg0);
-}
-
-
-ACTION_P(InvokeUpdateWhitelist, allocator)
-{
- allocator->real->updateWhitelist(arg0);
-}
-
-
-ACTION_P(InvokeRequestResources, allocator)
-{
- allocator->real->requestResources(arg0, arg1);
-}
-
-
-ACTION_P(InvokeUpdateAllocation, allocator)
-{
- allocator->real->updateAllocation(arg0, arg1, arg2);
-}
-
-
-ACTION_P(InvokeUpdateResources, allocator)
-{
- return allocator->real->updateAvailable(arg0, arg1);
-}
-
-
-ACTION_P(InvokeUpdateUnavailability, allocator)
-{
- return allocator->real->updateUnavailability(arg0, arg1);
-}
-
-
-ACTION_P(InvokeUpdateInverseOffer, allocator)
-{
- return allocator->real->updateInverseOffer(arg0, arg1, arg2, arg3, arg4);
-}
-
-
-ACTION_P(InvokeGetInverseOfferStatuses, allocator)
-{
- return allocator->real->getInverseOfferStatuses();
-}
-
-
-ACTION_P(InvokeRecoverResources, allocator)
-{
- allocator->real->recoverResources(arg0, arg1, arg2, arg3);
-}
-
-
-ACTION_P2(InvokeRecoverResourcesWithFilters, allocator, timeout)
-{
- Filters filters;
- filters.set_refuse_seconds(timeout);
-
- allocator->real->recoverResources(arg0, arg1, arg2, filters);
-}
-
-
-ACTION_P(InvokeSuppressOffers, allocator)
-{
- allocator->real->suppressOffers(arg0);
-}
-
-
-ACTION_P(InvokeReviveOffers, allocator)
-{
- allocator->real->reviveOffers(arg0);
-}
-
-
-template <typename T = master::allocator::HierarchicalDRFAllocator>
-mesos::master::allocator::Allocator* createAllocator()
-{
- // T represents the allocator type. It can be a default built-in
- // allocator, or one provided by an allocator module.
- Try<mesos::master::allocator::Allocator*> instance = T::create();
- CHECK_SOME(instance);
- return CHECK_NOTNULL(instance.get());
-}
-
-template <typename T = master::allocator::HierarchicalDRFAllocator>
-class TestAllocator : public mesos::master::allocator::Allocator
-{
-public:
- // Actual allocation is done by an instance of real allocator,
- // which is specified by the template parameter.
- TestAllocator() : real(createAllocator<T>())
- {
- // We use 'ON_CALL' and 'WillByDefault' here to specify the
- // default actions (call in to the real allocator). This allows
- // the tests to leverage the 'DoDefault' action.
- // However, 'ON_CALL' results in a "Uninteresting mock function
- // call" warning unless each test puts expectations in place.
- // As a result, we also use 'EXPECT_CALL' and 'WillRepeatedly'
- // to get the best of both worlds: the ability to use 'DoDefault'
- // and no warnings when expectations are not explicit.
-
- ON_CALL(*this, initialize(_, _, _, _))
- .WillByDefault(InvokeInitialize(this));
- EXPECT_CALL(*this, initialize(_, _, _, _))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, addFramework(_, _, _))
- .WillByDefault(InvokeAddFramework(this));
- EXPECT_CALL(*this, addFramework(_, _, _))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, removeFramework(_))
- .WillByDefault(InvokeRemoveFramework(this));
- EXPECT_CALL(*this, removeFramework(_))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, activateFramework(_))
- .WillByDefault(InvokeActivateFramework(this));
- EXPECT_CALL(*this, activateFramework(_))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, deactivateFramework(_))
- .WillByDefault(InvokeDeactivateFramework(this));
- EXPECT_CALL(*this, deactivateFramework(_))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, updateFramework(_, _))
- .WillByDefault(InvokeUpdateFramework(this));
- EXPECT_CALL(*this, updateFramework(_, _))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, addSlave(_, _, _, _, _))
- .WillByDefault(InvokeAddSlave(this));
- EXPECT_CALL(*this, addSlave(_, _, _, _, _))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, removeSlave(_))
- .WillByDefault(InvokeRemoveSlave(this));
- EXPECT_CALL(*this, removeSlave(_))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, updateSlave(_, _))
- .WillByDefault(InvokeUpdateSlave(this));
- EXPECT_CALL(*this, updateSlave(_, _))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, activateSlave(_))
- .WillByDefault(InvokeActivateSlave(this));
- EXPECT_CALL(*this, activateSlave(_))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, deactivateSlave(_))
- .WillByDefault(InvokeDeactivateSlave(this));
- EXPECT_CALL(*this, deactivateSlave(_))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, updateWhitelist(_))
- .WillByDefault(InvokeUpdateWhitelist(this));
- EXPECT_CALL(*this, updateWhitelist(_))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, requestResources(_, _))
- .WillByDefault(InvokeRequestResources(this));
- EXPECT_CALL(*this, requestResources(_, _))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, updateAllocation(_, _, _))
- .WillByDefault(InvokeUpdateAllocation(this));
- EXPECT_CALL(*this, updateAllocation(_, _, _))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, updateAvailable(_, _))
- .WillByDefault(InvokeUpdateResources(this));
- EXPECT_CALL(*this, updateAvailable(_, _))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, updateUnavailability(_, _))
- .WillByDefault(InvokeUpdateUnavailability(this));
- EXPECT_CALL(*this, updateUnavailability(_, _))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, updateInverseOffer(_, _, _, _, _))
- .WillByDefault(InvokeUpdateInverseOffer(this));
- EXPECT_CALL(*this, updateInverseOffer(_, _, _, _, _))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, getInverseOfferStatuses())
- .WillByDefault(InvokeGetInverseOfferStatuses(this));
- EXPECT_CALL(*this, getInverseOfferStatuses())
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, recoverResources(_, _, _, _))
- .WillByDefault(InvokeRecoverResources(this));
- EXPECT_CALL(*this, recoverResources(_, _, _, _))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, reviveOffers(_))
- .WillByDefault(InvokeReviveOffers(this));
- EXPECT_CALL(*this, reviveOffers(_))
- .WillRepeatedly(DoDefault());
-
- ON_CALL(*this, suppressOffers(_))
- .WillByDefault(InvokeSuppressOffers(this));
- EXPECT_CALL(*this, suppressOffers(_))
- .WillRepeatedly(DoDefault());
- }
-
- virtual ~TestAllocator() {}
-
- MOCK_METHOD4(initialize, void(
- const Duration&,
- const lambda::function<
- void(const FrameworkID&,
- const hashmap<SlaveID, Resources>&)>&,
- const lambda::function<
- void(const FrameworkID&,
- const hashmap<SlaveID, UnavailableResources>&)>&,
- const hashmap<std::string, mesos::master::RoleInfo>&));
-
- MOCK_METHOD3(addFramework, void(
- const FrameworkID&,
- const FrameworkInfo&,
- const hashmap<SlaveID, Resources>&));
-
- MOCK_METHOD1(removeFramework, void(
- const FrameworkID&));
-
- MOCK_METHOD1(activateFramework, void(
- const FrameworkID&));
-
- MOCK_METHOD1(deactivateFramework, void(
- const FrameworkID&));
-
- MOCK_METHOD2(updateFramework, void(
- const FrameworkID&,
- const FrameworkInfo&));
-
- MOCK_METHOD5(addSlave, void(
- const SlaveID&,
- const SlaveInfo&,
- const Option<Unavailability>&,
- const Resources&,
- const hashmap<FrameworkID, Resources>&));
-
- MOCK_METHOD1(removeSlave, void(
- const SlaveID&));
-
- MOCK_METHOD2(updateSlave, void(
- const SlaveID&,
- const Resources&));
-
- MOCK_METHOD1(activateSlave, void(
- const SlaveID&));
-
- MOCK_METHOD1(deactivateSlave, void(
- const SlaveID&));
-
- MOCK_METHOD1(updateWhitelist, void(
- const Option<hashset<std::string> >&));
-
- MOCK_METHOD2(requestResources, void(
- const FrameworkID&,
- const std::vector<Request>&));
-
- MOCK_METHOD3(updateAllocation, void(
- const FrameworkID&,
- const SlaveID&,
- const std::vector<Offer::Operation>&));
-
- MOCK_METHOD2(updateAvailable, process::Future<Nothing>(
- const SlaveID&,
- const std::vector<Offer::Operation>&));
-
- MOCK_METHOD2(updateUnavailability, void(
- const SlaveID&,
- const Option<Unavailability>&));
-
- MOCK_METHOD5(updateInverseOffer, void(
- const SlaveID&,
- const FrameworkID&,
- const Option<UnavailableResources>&,
- const Option<mesos::master::InverseOfferStatus>&,
- const Option<Filters>&));
-
- MOCK_METHOD0(getInverseOfferStatuses, process::Future<
- hashmap<SlaveID, hashmap<
- FrameworkID,
- mesos::master::InverseOfferStatus>>>());
-
- MOCK_METHOD4(recoverResources, void(
- const FrameworkID&,
- const SlaveID&,
- const Resources&,
- const Option<Filters>& filters));
-
- MOCK_METHOD1(reviveOffers, void(const FrameworkID&));
-
- MOCK_METHOD1(suppressOffers, void(const FrameworkID&));
-
- process::Owned<mesos::master::allocator::Allocator> real;
-};
-
-
class OfferEqMatcher
: public ::testing::MatcherInterface<const std::vector<Offer>& >
{
http://git-wip-us.apache.org/repos/asf/mesos/blob/2a9a5c12/src/tests/reservation_endpoints_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/reservation_endpoints_tests.cpp b/src/tests/reservation_endpoints_tests.cpp
index 33f51d8..1552e45 100644
--- a/src/tests/reservation_endpoints_tests.cpp
+++ b/src/tests/reservation_endpoints_tests.cpp
@@ -36,6 +36,7 @@
#include "master/flags.hpp"
#include "master/master.hpp"
+#include "tests/allocator.hpp"
#include "tests/mesos.hpp"
#include "tests/utils.hpp"
http://git-wip-us.apache.org/repos/asf/mesos/blob/2a9a5c12/src/tests/reservation_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/reservation_tests.cpp b/src/tests/reservation_tests.cpp
index 6b7c43c..4bc2b31 100644
--- a/src/tests/reservation_tests.cpp
+++ b/src/tests/reservation_tests.cpp
@@ -44,6 +44,7 @@
#include "master/allocator/mesos/hierarchical.hpp"
+#include "tests/allocator.hpp"
#include "tests/containerizer.hpp"
#include "tests/mesos.hpp"
http://git-wip-us.apache.org/repos/asf/mesos/blob/2a9a5c12/src/tests/resource_offers_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/resource_offers_tests.cpp b/src/tests/resource_offers_tests.cpp
index af40a07..bf2fe3a 100644
--- a/src/tests/resource_offers_tests.cpp
+++ b/src/tests/resource_offers_tests.cpp
@@ -31,6 +31,7 @@
#include "slave/slave.hpp"
+#include "tests/allocator.hpp"
#include "tests/mesos.hpp"
using mesos::internal::master::Master;
http://git-wip-us.apache.org/repos/asf/mesos/blob/2a9a5c12/src/tests/slave_recovery_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/slave_recovery_tests.cpp b/src/tests/slave_recovery_tests.cpp
index a50960c..648babe 100644
--- a/src/tests/slave_recovery_tests.cpp
+++ b/src/tests/slave_recovery_tests.cpp
@@ -58,6 +58,7 @@
#include "messages/messages.hpp"
+#include "tests/allocator.hpp"
#include "tests/containerizer.hpp"
#include "tests/mesos.hpp"
#include "tests/utils.hpp"