You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2016/03/16 14:17:00 UTC
[05/15] mesos git commit: Refactor MesosTest and remove cleanup logic.
Refactor MesosTest and remove cleanup logic.
Updates `StartMaster` and `StartSlave` test helpers to use the reworked
`cluster` helpers. Removes all `MesosTest` cleanup logic and as well as
the helpers that accept a `MockExecutor` pointer.
Review: https://reviews.apache.org/r/43614/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b377557c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b377557c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b377557c
Branch: refs/heads/master
Commit: b377557c2bfc35c894e87becb47122955540f133
Parents: 7bf6e4f
Author: Joseph Wu <jo...@mesosphere.io>
Authored: Tue Mar 15 18:51:09 2016 -0400
Committer: Michael Park <mp...@apache.org>
Committed: Wed Mar 16 08:19:10 2016 -0400
----------------------------------------------------------------------
src/tests/mesos.cpp | 227 ++++++++++-------------------------------------
src/tests/mesos.hpp | 107 +++++++---------------
2 files changed, 77 insertions(+), 257 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/b377557c/src/tests/mesos.cpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.cpp b/src/tests/mesos.cpp
index 7cca4ed..4be1248 100644
--- a/src/tests/mesos.cpp
+++ b/src/tests/mesos.cpp
@@ -73,16 +73,8 @@ ZooKeeperTestServer* MesosZooKeeperTest::server = NULL;
Option<zookeeper::URL> MesosZooKeeperTest::url;
#endif // MESOS_HAS_JAVA
-MesosTest::MesosTest(const Option<zookeeper::URL>& url) : cluster(url) {}
-
-
-void MesosTest::TearDown()
-{
- TemporaryDirectoryTest::TearDown();
-
- // TODO(benh): Fail the test if shutdown hasn't been called?
- Shutdown();
-}
+MesosTest::MesosTest(const Option<zookeeper::URL>& _zookeeperUrl)
+ : zookeeperUrl(_zookeeperUrl) {}
master::Flags MesosTest::CreateMasterFlags()
@@ -191,296 +183,169 @@ slave::Flags MesosTest::CreateSlaveFlags()
}
-Try<PID<master::Master>> MesosTest::StartMaster(
+Try<Owned<cluster::Master>> MesosTest::StartMaster(
const Option<master::Flags>& flags)
{
- return cluster.masters.start(
- flags.isNone() ? CreateMasterFlags() : flags.get());
+ return cluster::Master::start(
+ flags.isNone() ? CreateMasterFlags() : flags.get(),
+ zookeeperUrl);
}
-Try<PID<master::Master>> MesosTest::StartMaster(
+Try<Owned<cluster::Master>> MesosTest::StartMaster(
mesos::master::allocator::Allocator* allocator,
const Option<master::Flags>& flags)
{
- return cluster.masters.start(
+ return cluster::Master::start(
flags.isNone() ? CreateMasterFlags() : flags.get(),
+ zookeeperUrl,
allocator);
}
-Try<PID<master::Master>> MesosTest::StartMaster(
+Try<Owned<cluster::Master>> MesosTest::StartMaster(
Authorizer* authorizer,
const Option<master::Flags>& flags)
{
- return cluster.masters.start(
+ return cluster::Master::start(
flags.isNone() ? CreateMasterFlags() : flags.get(),
+ zookeeperUrl,
None(),
authorizer);
}
-Try<PID<master::Master>> MesosTest::StartMaster(
+Try<Owned<cluster::Master>> MesosTest::StartMaster(
const shared_ptr<MockRateLimiter>& slaveRemovalLimiter,
const Option<master::Flags>& flags)
{
- return cluster.masters.start(
+ return cluster::Master::start(
flags.isNone() ? CreateMasterFlags() : flags.get(),
+ zookeeperUrl,
None(),
None(),
slaveRemovalLimiter);
}
-Try<PID<slave::Slave>> MesosTest::StartSlave(
+Try<Owned<cluster::Slave>> MesosTest::StartSlave(
+ MasterDetector* detector,
const Option<slave::Flags>& flags)
{
- return cluster.slaves.start(
+ return cluster::Slave::start(
+ detector,
flags.isNone() ? CreateSlaveFlags() : flags.get());
}
-Try<PID<slave::Slave>> MesosTest::StartSlave(
- MockExecutor* executor,
- const Option<slave::Flags>& flags)
-{
- slave::Containerizer* containerizer = new TestContainerizer(executor);
-
- Try<PID<slave::Slave>> pid = StartSlave(containerizer, flags);
-
- if (pid.isError()) {
- delete containerizer;
- return pid;
- }
-
- containerizers[pid.get()] = containerizer;
-
- return pid;
-}
-
-
-Try<PID<slave::Slave>> MesosTest::StartSlave(
+Try<Owned<cluster::Slave>> MesosTest::StartSlave(
+ MasterDetector* detector,
slave::Containerizer* containerizer,
const Option<slave::Flags>& flags)
{
- return cluster.slaves.start(
+ return cluster::Slave::start(
+ detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
None(),
containerizer);
}
-Try<PID<slave::Slave>> MesosTest::StartSlave(
+Try<Owned<cluster::Slave>> MesosTest::StartSlave(
+ MasterDetector* detector,
slave::Containerizer* containerizer,
const std::string& id,
const Option<slave::Flags>& flags)
{
- return cluster.slaves.start(
+ return cluster::Slave::start(
+ detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
id,
containerizer);
}
-Try<PID<slave::Slave>> MesosTest::StartSlave(
- slave::Containerizer* containerizer,
- MasterDetector* detector,
- const Option<slave::Flags>& flags)
-{
- return cluster.slaves.start(
- flags.isNone() ? CreateSlaveFlags() : flags.get(),
- None(),
- containerizer,
- detector);
-}
-
-
-Try<PID<slave::Slave>> MesosTest::StartSlave(
- MasterDetector* detector,
- const Option<slave::Flags>& flags)
-{
- return cluster.slaves.start(
- flags.isNone() ? CreateSlaveFlags() : flags.get(),
- None(),
- None(),
- detector);
-}
-
-
-Try<PID<slave::Slave>> MesosTest::StartSlave(
+Try<Owned<cluster::Slave>> MesosTest::StartSlave(
MasterDetector* detector,
slave::GarbageCollector* gc,
const Option<slave::Flags>& flags)
{
- return cluster.slaves.start(
+ return cluster::Slave::start(
+ detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
None(),
None(),
- detector,
gc);
}
-Try<PID<slave::Slave>> MesosTest::StartSlave(
- MockExecutor* executor,
+Try<Owned<cluster::Slave>> MesosTest::StartSlave(
MasterDetector* detector,
- const Option<slave::Flags>& flags)
-{
- slave::Containerizer* containerizer = new TestContainerizer(executor);
-
- Try<PID<slave::Slave>> pid = cluster.slaves.start(
- flags.isNone() ? CreateSlaveFlags() : flags.get(),
- None(),
- containerizer,
- detector);
-
- if (pid.isError()) {
- delete containerizer;
- return pid;
- }
-
- containerizers[pid.get()] = containerizer;
-
- return pid;
-}
-
-
-Try<PID<slave::Slave>> MesosTest::StartSlave(
mesos::slave::ResourceEstimator* resourceEstimator,
const Option<slave::Flags>& flags)
{
- return cluster.slaves.start(
+ return cluster::Slave::start(
+ detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
None(),
None(),
None(),
None(),
- None(),
resourceEstimator);
}
-Try<PID<slave::Slave>> MesosTest::StartSlave(
- MockExecutor* executor,
+Try<Owned<cluster::Slave>> MesosTest::StartSlave(
+ MasterDetector* detector,
+ slave::Containerizer* containerizer,
mesos::slave::ResourceEstimator* resourceEstimator,
const Option<slave::Flags>& flags)
{
- slave::Containerizer* containerizer = new TestContainerizer(executor);
-
- Try<PID<slave::Slave>> pid = cluster.slaves.start(
- flags.isNone() ? CreateSlaveFlags() : flags.get(),
- None(),
- containerizer,
- None(),
- None(),
- None(),
- resourceEstimator);
-
- if (pid.isError()) {
- delete containerizer;
- return pid;
- }
-
- containerizers[pid.get()] = containerizer;
-
- return pid;
-}
-
-
-Try<PID<slave::Slave>> MesosTest::StartSlave(
- slave::Containerizer* containerizer,
- mesos::slave::ResourceEstimator* resourceEstimator,
- const Option<slave::Flags>& flags)
-{
- return cluster.slaves.start(
+ return cluster::Slave::start(
+ detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
None(),
containerizer,
None(),
None(),
- None(),
resourceEstimator);
}
-Try<PID<slave::Slave>> MesosTest::StartSlave(
+Try<Owned<cluster::Slave>> MesosTest::StartSlave(
+ MasterDetector* detector,
mesos::slave::QoSController* qoSController,
const Option<slave::Flags>& flags)
{
- return cluster.slaves.start(
+ return cluster::Slave::start(
+ detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
None(),
None(),
None(),
None(),
None(),
- None(),
qoSController);
}
-Try<PID<slave::Slave>> MesosTest::StartSlave(
+Try<Owned<cluster::Slave>> MesosTest::StartSlave(
+ MasterDetector* detector,
slave::Containerizer* containerizer,
mesos::slave::QoSController* qoSController,
const Option<slave::Flags>& flags)
{
- return cluster.slaves.start(
+ return cluster::Slave::start(
+ detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
None(),
containerizer,
None(),
None(),
None(),
- None(),
qoSController);
}
-
-void MesosTest::Stop(const PID<master::Master>& pid)
-{
- cluster.masters.stop(pid);
-}
-
-
-void MesosTest::Stop(const PID<slave::Slave>& pid, bool shutdown)
-{
- cluster.slaves.stop(pid, shutdown);
- if (containerizers.count(pid) > 0) {
- slave::Containerizer* containerizer = containerizers[pid];
- containerizers.erase(pid);
- delete containerizer;
- }
-}
-
-
-void MesosTest::Shutdown()
-{
- // TODO(arojas): Authenticators' lifetimes are tied to libprocess's lifetime.
- // Consider unsetting the authenticator in the master shutdown.
- // NOTE: This means that multiple masters in tests are not supported.
- process::http::authentication::unsetAuthenticator(
- master::DEFAULT_HTTP_AUTHENTICATION_REALM);
- ShutdownMasters();
- ShutdownSlaves();
-}
-
-
-void MesosTest::ShutdownMasters()
-{
- cluster.masters.shutdown();
-}
-
-
-void MesosTest::ShutdownSlaves()
-{
- cluster.slaves.shutdown();
-
- foreachvalue (slave::Containerizer* containerizer, containerizers) {
- delete containerizer;
- }
- containerizers.clear();
-}
-
// Although the constructors and destructors for mock classes are
// often trivial, defining them out-of-line (in a separate compilation
// unit) improves compilation time: see MESOS-3827.
http://git-wip-us.apache.org/repos/asf/mesos/blob/b377557c/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 908a53a..fc6011e 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -109,8 +109,6 @@ class MesosTest : public SSLTemporaryDirectoryTest
protected:
MesosTest(const Option<zookeeper::URL>& url = None());
- virtual void TearDown();
-
// Returns the flags used to create masters.
virtual master::Flags CreateMasterFlags();
@@ -118,23 +116,23 @@ protected:
virtual slave::Flags CreateSlaveFlags();
// Starts a master with the specified flags.
- virtual Try<process::PID<master::Master> > StartMaster(
+ virtual Try<process::Owned<cluster::Master>> StartMaster(
const Option<master::Flags>& flags = None());
// Starts a master with the specified allocator process and flags.
- virtual Try<process::PID<master::Master> > StartMaster(
+ virtual Try<process::Owned<cluster::Master>> StartMaster(
mesos::master::allocator::Allocator* allocator,
const Option<master::Flags>& flags = None());
// Starts a master with the specified authorizer and flags.
- // Waits for the master to detect a leader (could be itself) before
- // returning if 'wait' is set to true.
- virtual Try<process::PID<master::Master> > StartMaster(
+ virtual Try<process::Owned<cluster::Master>> StartMaster(
Authorizer* authorizer,
const Option<master::Flags>& flags = None());
// Starts a master with a slave removal rate limiter and flags.
- virtual Try<process::PID<master::Master> > StartMaster(
+ // NOTE: The `slaveRemovalLimiter` is a `shared_ptr` because the
+ // underlying `Master` process requires the pointer in this form.
+ virtual Try<process::Owned<cluster::Master>> StartMaster(
const std::shared_ptr<MockRateLimiter>& slaveRemovalLimiter,
const Option<master::Flags>& flags = None());
@@ -157,102 +155,59 @@ protected:
// injections.gc = gc;
// Try<PID<Slave> > slave = StartSlave(injections);
- // Starts a slave with the specified flags.
- virtual Try<process::PID<slave::Slave> > StartSlave(
- const Option<slave::Flags>& flags = None());
-
- // Starts a slave with the specified mock executor and flags.
- virtual Try<process::PID<slave::Slave> > StartSlave(
- MockExecutor* executor,
+ // Starts a slave with the specified detector and flags.
+ virtual Try<process::Owned<cluster::Slave>> StartSlave(
+ MasterDetector* detector,
const Option<slave::Flags>& flags = None());
- // Starts a slave with the specified containerizer and flags.
- virtual Try<process::PID<slave::Slave> > StartSlave(
+ // Starts a slave with the specified detector, containerizer, and flags.
+ virtual Try<process::Owned<cluster::Slave>> StartSlave(
+ MasterDetector* detector,
slave::Containerizer* containerizer,
const Option<slave::Flags>& flags = None());
- virtual Try<process::PID<slave::Slave> > StartSlave(
+ // Starts a slave with the specified detector, containerizer, id, and flags.
+ virtual Try<process::Owned<cluster::Slave>> StartSlave(
+ MasterDetector* detector,
slave::Containerizer* containerizer,
const std::string& id,
const Option<slave::Flags>& flags = None());
- // Starts a slave with the specified containerizer, detector and flags.
- virtual Try<process::PID<slave::Slave> > StartSlave(
- slave::Containerizer* containerizer,
- MasterDetector* detector,
- const Option<slave::Flags>& flags = None());
-
- // Starts a slave with the specified MasterDetector and flags.
- virtual Try<process::PID<slave::Slave> > StartSlave(
- MasterDetector* detector,
- const Option<slave::Flags>& flags = None());
-
- // Starts a slave with the specified MasterDetector, GC, and flags.
- virtual Try<process::PID<slave::Slave> > StartSlave(
+ // Starts a slave with the specified detector, GC, and flags.
+ virtual Try<process::Owned<cluster::Slave>> StartSlave(
MasterDetector* detector,
slave::GarbageCollector* gc,
const Option<slave::Flags>& flags = None());
- // Starts a slave with the specified mock executor, MasterDetector
- // and flags.
- virtual Try<process::PID<slave::Slave> > StartSlave(
- MockExecutor* executor,
+ // Starts a slave with the specified detector, resource estimator, and flags.
+ virtual Try<process::Owned<cluster::Slave>> StartSlave(
MasterDetector* detector,
- const Option<slave::Flags>& flags = None());
-
- // Starts a slave with the specified resource estimator and flags.
- virtual Try<process::PID<slave::Slave>> StartSlave(
mesos::slave::ResourceEstimator* resourceEstimator,
const Option<slave::Flags>& flags = None());
- // Starts a slave with the specified mock executor, resource
- // estimator and flags.
- virtual Try<process::PID<slave::Slave>> StartSlave(
- MockExecutor* executor,
- mesos::slave::ResourceEstimator* resourceEstimator,
- const Option<slave::Flags>& flags = None());
-
- // Starts a slave with the specified resource estimator,
- // containerizer and flags.
- virtual Try<process::PID<slave::Slave>> StartSlave(
+ // Starts a slave with the specified detector, containerizer,
+ // resource estimator, and flags.
+ virtual Try<process::Owned<cluster::Slave>> StartSlave(
+ MasterDetector* detector,
slave::Containerizer* containerizer,
mesos::slave::ResourceEstimator* resourceEstimator,
const Option<slave::Flags>& flags = None());
- // Starts a slave with the specified QoS Controller and flags.
- virtual Try<process::PID<slave::Slave>> StartSlave(
+ // Starts a slave with the specified detector, QoS Controller, and flags.
+ virtual Try<process::Owned<cluster::Slave>> StartSlave(
+ MasterDetector* detector,
mesos::slave::QoSController* qosController,
const Option<slave::Flags>& flags = None());
- // Starts a slave with the specified QoS Controller,
- // containerizer and flags.
- virtual Try<process::PID<slave::Slave>> StartSlave(
+ // Starts a slave with the specified detector, containerizer,
+ // QoS Controller, and flags.
+ virtual Try<process::Owned<cluster::Slave>> StartSlave(
+ MasterDetector* detector,
slave::Containerizer* containerizer,
mesos::slave::QoSController* qosController,
const Option<slave::Flags>& flags = None());
- // Stop the specified master.
- virtual void Stop(
- const process::PID<master::Master>& pid);
-
- // Stop the specified slave.
- virtual void Stop(
- const process::PID<slave::Slave>& pid,
- bool shutdown = false);
-
- // Stop all masters and slaves.
- virtual void Shutdown();
-
- // Stop all masters.
- virtual void ShutdownMasters();
-
- // Stop all slaves.
- virtual void ShutdownSlaves();
-
- Cluster cluster;
-
- // Containerizer(s) created during test that we need to cleanup.
- std::map<process::PID<slave::Slave>, slave::Containerizer*> containerizers;
+ Option<zookeeper::URL> zookeeperUrl;
const std::string defaultAgentResourcesString{
"cpus:2;mem:1024;disk:1024;ports:[31000-32000]"};