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:16:58 UTC

[03/15] mesos git commit: Especially updated tests to use the updated MesosTest helpers.

Especially updated tests to use the updated MesosTest helpers.

Continuation of https://reviews.apache.org/r/43615/ with a slightly
different pattern.

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


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

Branch: refs/heads/master
Commit: 56e9406763e8514a7557ab3862d2f352a61425d5
Parents: 75ca1e6
Author: Joseph Wu <jo...@mesosphere.io>
Authored: Wed Mar 16 08:17:46 2016 -0400
Committer: Michael Park <mp...@apache.org>
Committed: Wed Mar 16 08:19:10 2016 -0400

----------------------------------------------------------------------
 src/tests/dynamic_weights_tests.cpp | 108 ++--
 src/tests/fetcher_cache_tests.cpp   |  83 +--
 src/tests/resource_offers_tests.cpp |  56 +-
 src/tests/slave_recovery_tests.cpp  | 893 ++++++++++++++++---------------
 4 files changed, 573 insertions(+), 567 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/56e94067/src/tests/dynamic_weights_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/dynamic_weights_tests.cpp b/src/tests/dynamic_weights_tests.cpp
index a95663f..ee0c4b1 100644
--- a/src/tests/dynamic_weights_tests.cpp
+++ b/src/tests/dynamic_weights_tests.cpp
@@ -25,6 +25,7 @@
 #include <process/http.hpp>
 #include <process/id.hpp>
 #include <process/pid.hpp>
+#include <process/owned.hpp>
 
 #include <stout/format.hpp>
 #include <stout/protobuf.hpp>
@@ -46,6 +47,7 @@ using mesos::internal::slave::Slave;
 
 using process::Future;
 using process::PID;
+using process::Owned;
 using process::UPID;
 
 using process::http::BadRequest;
@@ -110,12 +112,12 @@ protected:
   }
 
   void checkWithRolesEndpoint(
-      const Try<PID<Master>>& master,
+      const PID<Master>& master,
       const Option<string>& weights = None())
   {
     Future<Response> response = process::http::request(
         process::http::createRequest(
-            master.get(),
+            master,
             "GET",
             false,
             "roles",
@@ -239,7 +241,7 @@ protected:
 // should return a '400 Bad Request'.
 TEST_F(DynamicWeightsTest, PutInvalidRequest)
 {
-  Try<PID<Master>> master = StartMaster();
+  Try<Owned<cluster::Master>> master = StartMaster();
   ASSERT_SOME(master);
 
   // Tests whether an update weights request with invalid JSON fails.
@@ -251,7 +253,7 @@ TEST_F(DynamicWeightsTest, PutInvalidRequest)
 
   Future<Response> response = process::http::request(
       process::http::createRequest(
-          master.get(),
+          master.get()->pid,
           "PUT",
           false,
           "weights",
@@ -261,7 +263,7 @@ TEST_F(DynamicWeightsTest, PutInvalidRequest)
   AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response)
     << response.get().body;
 
-  checkWithRolesEndpoint(master);
+  checkWithRolesEndpoint(master.get()->pid);
 
   // Tests whether an update weights request with an invalid field fails.
   // In this case, the correct field name should be 'role'.
@@ -273,7 +275,7 @@ TEST_F(DynamicWeightsTest, PutInvalidRequest)
 
   response = process::http::request(
       process::http::createRequest(
-          master.get(),
+          master.get()->pid,
           "PUT",
           false,
           "weights",
@@ -283,9 +285,7 @@ TEST_F(DynamicWeightsTest, PutInvalidRequest)
   AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response)
     << response.get().body;
 
-  checkWithRolesEndpoint(master);
-
-  ShutdownMasters();
+  checkWithRolesEndpoint(master.get()->pid);
 }
 
 
@@ -293,13 +293,13 @@ TEST_F(DynamicWeightsTest, PutInvalidRequest)
 // should return a '400 Bad Request'.
 TEST_F(DynamicWeightsTest, ZeroWeight)
 {
-  Try<PID<Master>> master = StartMaster();
+  Try<Owned<cluster::Master>> master = StartMaster();
   ASSERT_SOME(master);
 
   // Send a weight update request to update the weight of 'role1' to 0.
   Future<Response> response = process::http::request(
       process::http::createRequest(
-          master.get(),
+          master.get()->pid,
           "PUT",
           false,
           "weights",
@@ -309,9 +309,7 @@ TEST_F(DynamicWeightsTest, ZeroWeight)
   AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response)
     << response.get().body;
 
-  checkWithRolesEndpoint(master);
-
-  ShutdownMasters();
+  checkWithRolesEndpoint(master.get()->pid);
 }
 
 
@@ -319,13 +317,13 @@ TEST_F(DynamicWeightsTest, ZeroWeight)
 // should return a '400 Bad Request'.
 TEST_F(DynamicWeightsTest, NegativeWeight)
 {
-  Try<PID<Master>> master = StartMaster();
+  Try<Owned<cluster::Master>> master = StartMaster();
   ASSERT_SOME(master);
 
   // Send a weight update request to update the weight of 'role1' to -2.0.
   Future<Response> response = process::http::request(
       process::http::createRequest(
-          master.get(),
+          master.get()->pid,
           "PUT",
           false,
           "weights",
@@ -335,9 +333,7 @@ TEST_F(DynamicWeightsTest, NegativeWeight)
   AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response)
     << response.get().body;
 
-  checkWithRolesEndpoint(master);
-
-  ShutdownMasters();
+  checkWithRolesEndpoint(master.get()->pid);
 }
 
 
@@ -345,13 +341,13 @@ TEST_F(DynamicWeightsTest, NegativeWeight)
 // should return a '400 Bad Request'.
 TEST_F(DynamicWeightsTest, NonNumericWeight)
 {
-  Try<PID<Master>> master = StartMaster();
+  Try<Owned<cluster::Master>> master = StartMaster();
   ASSERT_SOME(master);
 
   // Send a weight update request to update the weight of 'role1' to 'two'
   Future<Response> response = process::http::request(
       process::http::createRequest(
-          master.get(),
+          master.get()->pid,
           "PUT",
           false,
           "weights",
@@ -361,9 +357,7 @@ TEST_F(DynamicWeightsTest, NonNumericWeight)
   AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response)
     << response.get().body;
 
-  checkWithRolesEndpoint(master);
-
-  ShutdownMasters();
+  checkWithRolesEndpoint(master.get()->pid);
 }
 
 
@@ -371,13 +365,13 @@ TEST_F(DynamicWeightsTest, NonNumericWeight)
 // and a missing role request should return a '400 Bad Request'.
 TEST_F(DynamicWeightsTest, MissingRole)
 {
-  Try<PID<Master>> master = StartMaster();
+  Try<Owned<cluster::Master>> master = StartMaster();
   ASSERT_SOME(master);
 
   // Send a missing role update request.
   Future<Response> response1 = process::http::request(
       process::http::createRequest(
-          master.get(),
+          master.get()->pid,
           "PUT",
           false,
           "weights",
@@ -387,12 +381,12 @@ TEST_F(DynamicWeightsTest, MissingRole)
   AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response1)
     << response1.get().body;
 
-  checkWithRolesEndpoint(master);
+  checkWithRolesEndpoint(master.get()->pid);
 
   // Send an empty role (only a space) update request.
   Future<Response> response2 = process::http::request(
       process::http::createRequest(
-          master.get(),
+          master.get()->pid,
           "PUT",
           false,
           "weights",
@@ -402,9 +396,7 @@ TEST_F(DynamicWeightsTest, MissingRole)
   AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response2)
     << response2.get().body;
 
-  checkWithRolesEndpoint(master);
-
-  ShutdownMasters();
+  checkWithRolesEndpoint(master.get()->pid);
 }
 
 
@@ -416,13 +408,13 @@ TEST_F(DynamicWeightsTest, UnknownRole)
   // Specify --roles whitelist when starting master.
   master::Flags flags = MesosTest::CreateMasterFlags();
   flags.roles = strings::join(",", ROLE1, ROLE2);
-  Try<PID<Master>> master = StartMaster(flags);
+  Try<Owned<cluster::Master>> master = StartMaster(flags);
   ASSERT_SOME(master);
 
   // Send a weight update request for 'unknown' role.
   Future<Response> response = process::http::request(
       process::http::createRequest(
-          master.get(),
+          master.get()->pid,
           "PUT",
           false,
           "weights",
@@ -432,9 +424,7 @@ TEST_F(DynamicWeightsTest, UnknownRole)
   AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response)
     << response.get().body;
 
-  checkWithRolesEndpoint(master, DEFAULT_WEIGHTS);
-
-  ShutdownMasters();
+  checkWithRolesEndpoint(master.get()->pid, DEFAULT_WEIGHTS);
 }
 
 
@@ -446,15 +436,15 @@ TEST_F(DynamicWeightsTest, UpdateWeightsWithExplictRoles)
   // Specify --roles whitelist when starting master.
   master::Flags flags = MesosTest::CreateMasterFlags();
   flags.roles = strings::join(",", ROLE1, ROLE2);
-  Try<PID<Master>> master = StartMaster(flags);
+  Try<Owned<cluster::Master>> master = StartMaster(flags);
   ASSERT_SOME(master);
 
-  checkWithRolesEndpoint(master, DEFAULT_WEIGHTS);
+  checkWithRolesEndpoint(master.get()->pid, DEFAULT_WEIGHTS);
 
   // Send a weight update request for the specified roles in UPDATED_WEIGHTS.
   Future<Response> response = process::http::request(
       process::http::createRequest(
-          master.get(),
+          master.get()->pid,
           "PUT",
           false,
           "weights",
@@ -464,9 +454,7 @@ TEST_F(DynamicWeightsTest, UpdateWeightsWithExplictRoles)
   AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
     << response.get().body;
 
-  checkWithRolesEndpoint(master, UPDATED_WEIGHTS);
-
-  ShutdownMasters();
+  checkWithRolesEndpoint(master.get()->pid, UPDATED_WEIGHTS);
 }
 
 
@@ -476,7 +464,7 @@ TEST_F(DynamicWeightsTest, UnauthenticatedUpdateWeightRequest)
 {
   // The master is configured so that only requests from `DEFAULT_CREDENTIAL`
   // are authenticated.
-  Try<PID<Master>> master = StartMaster();
+  Try<Owned<cluster::Master>> master = StartMaster();
   ASSERT_SOME(master);
 
   Credential credential;
@@ -486,7 +474,7 @@ TEST_F(DynamicWeightsTest, UnauthenticatedUpdateWeightRequest)
   // Send a weight update request for the specified roles in UPDATED_WEIGHTS.
   Future<Response> response1 = process::http::request(
       process::http::createRequest(
-          master.get(),
+          master.get()->pid,
           "PUT",
           false,
           "weights",
@@ -496,12 +484,12 @@ TEST_F(DynamicWeightsTest, UnauthenticatedUpdateWeightRequest)
   AWAIT_EXPECT_RESPONSE_STATUS_EQ(Unauthorized({}).status, response1)
     << response1.get().body;
 
-  checkWithRolesEndpoint(master);
+  checkWithRolesEndpoint(master.get()->pid);
 
   // The absence of credentials leads to authentication failure as well.
   Future<Response> response2 = process::http::request(
       process::http::createRequest(
-          master.get(),
+          master.get()->pid,
           "PUT",
           false,
           "weights",
@@ -511,9 +499,7 @@ TEST_F(DynamicWeightsTest, UnauthenticatedUpdateWeightRequest)
   AWAIT_EXPECT_RESPONSE_STATUS_EQ(Unauthorized({}).status, response2)
     << response2.get().body;
 
-  checkWithRolesEndpoint(master);
-
-  ShutdownMasters();
+  checkWithRolesEndpoint(master.get()->pid);
 }
 
 
@@ -532,13 +518,13 @@ TEST_F(DynamicWeightsTest, AuthorizedWeightUpdateRequest)
   master::Flags masterFlags = CreateMasterFlags();
   masterFlags.acls = acls;
 
-  Try<PID<Master>> master = StartMaster(masterFlags);
+  Try<Owned<cluster::Master>> master = StartMaster(masterFlags);
   ASSERT_SOME(master);
 
   // Send a weight update request for the specified roles in UPDATED_WEIGHTS.
   Future<Response> response = process::http::request(
       process::http::createRequest(
-          master.get(),
+          master.get()->pid,
           "PUT",
           false,
           "weights",
@@ -548,9 +534,7 @@ TEST_F(DynamicWeightsTest, AuthorizedWeightUpdateRequest)
   AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
     << response.get().body;
 
-  checkWithRolesEndpoint(master, UPDATED_WEIGHTS);
-
-  ShutdownMasters();
+  checkWithRolesEndpoint(master.get()->pid, UPDATED_WEIGHTS);
 }
 
 
@@ -573,13 +557,13 @@ TEST_F(DynamicWeightsTest, AuthorizedUpdateWeightRequestWithoutPrincipal)
   masterFlags.authenticate_http = false;
   masterFlags.acls = acls;
 
-  Try<PID<Master>> master = StartMaster(masterFlags);
+  Try<Owned<cluster::Master>> master = StartMaster(masterFlags);
   ASSERT_SOME(master);
 
   // Send a weight update request for the specified roles in UPDATED_WEIGHTS.
   Future<Response> response = process::http::request(
       process::http::createRequest(
-          master.get(),
+          master.get()->pid,
           "PUT",
           false,
           "weights",
@@ -589,9 +573,7 @@ TEST_F(DynamicWeightsTest, AuthorizedUpdateWeightRequestWithoutPrincipal)
   AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response)
     << response.get().body;
 
-  checkWithRolesEndpoint(master, UPDATED_WEIGHTS);
-
-  ShutdownMasters();
+  checkWithRolesEndpoint(master.get()->pid, UPDATED_WEIGHTS);
 }
 
 
@@ -606,13 +588,13 @@ TEST_F(DynamicWeightsTest, UnauthorizedWeightUpdateRequest)
   master::Flags masterFlags = CreateMasterFlags();
   masterFlags.acls = acls;
 
-  Try<PID<Master>> master = StartMaster(masterFlags);
+  Try<Owned<cluster::Master>> master = StartMaster(masterFlags);
   ASSERT_SOME(master);
 
   // Send a weight update request for the specified roles in UPDATED_WEIGHTS.
   Future<Response> response = process::http::request(
       process::http::createRequest(
-          master.get(),
+          master.get()->pid,
           "PUT",
           false,
           "weights",
@@ -622,9 +604,7 @@ TEST_F(DynamicWeightsTest, UnauthorizedWeightUpdateRequest)
   AWAIT_EXPECT_RESPONSE_STATUS_EQ(Forbidden().status, response)
     << response.get().body;
 
-  checkWithRolesEndpoint(master);
-
-  ShutdownMasters();
+  checkWithRolesEndpoint(master.get()->pid);
 }
 
 } // namespace tests {

http://git-wip-us.apache.org/repos/asf/mesos/blob/56e94067/src/tests/fetcher_cache_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/fetcher_cache_tests.cpp b/src/tests/fetcher_cache_tests.cpp
index 776c952..645dae2 100644
--- a/src/tests/fetcher_cache_tests.cpp
+++ b/src/tests/fetcher_cache_tests.cpp
@@ -151,18 +151,26 @@ protected:
   string assetsDirectory;
   string commandPath;
   string archivePath;
+  string cacheDirectory;
+
+  Owned<cluster::Master> master;
+  Owned<cluster::Slave> slave;
 
   slave::Flags flags;
-  MesosContainerizer* containerizer;
-  PID<Slave> slavePid;
   SlaveID slaveId;
-  string cacheDirectory;
+
+  Owned<MasterDetector> detector;
+  Owned<MesosContainerizer> containerizer;
+
+  // NOTE: This is technically owned by the `fetcher`, but we violate
+  // this ownership in the tests.
   MockFetcherProcess* fetcherProcess;
+
   MockScheduler scheduler;
-  MesosSchedulerDriver* driver;
+  Owned<MesosSchedulerDriver> driver;
 
 private:
-  Fetcher* fetcher;
+  Owned<Fetcher> fetcher;
 
   FrameworkID frameworkId;
 
@@ -185,27 +193,28 @@ void FetcherCacheTest::SetUp()
   setupCommandFileAsset();
   setupArchiveAsset();
 
-  Try<PID<Master>> master = StartMaster();
-  ASSERT_SOME(master);
+  Try<Owned<cluster::Master>> _master = StartMaster();
+  ASSERT_SOME(_master);
+  master = _master.get();
 
   fetcherProcess = new MockFetcherProcess();
-  fetcher = new Fetcher(Owned<FetcherProcess>(fetcherProcess));
+  fetcher.reset(new Fetcher(Owned<FetcherProcess>(fetcherProcess)));
 
   FrameworkInfo frameworkInfo;
   frameworkInfo.set_name("default");
   frameworkInfo.set_checkpoint(true);
 
-  driver = new MesosSchedulerDriver(
-    &scheduler, frameworkInfo, master.get(), DEFAULT_CREDENTIAL);
+  driver.reset(new MesosSchedulerDriver(
+    &scheduler, frameworkInfo, master->pid, DEFAULT_CREDENTIAL));
 
-  EXPECT_CALL(scheduler, registered(driver, _, _))
+  EXPECT_CALL(scheduler, registered(driver.get(), _, _))
     .Times(1);
 
   // This installs a temporary reaction to resourceOffers calls, which
   // must be in place BEFORE starting the scheduler driver. This
   // "cover" is necessary, because we only add relevant mock actions
   // in launchTask() and launchTasks() AFTER starting the driver.
-  EXPECT_CALL(scheduler, resourceOffers(driver, _))
+  EXPECT_CALL(scheduler, resourceOffers(driver.get(), _))
     .WillRepeatedly(DeclineOffers());
 }
 
@@ -260,9 +269,9 @@ void FetcherCacheTest::TearDown()
 
   driver->stop();
   driver->join();
-  delete driver;
 
-  delete fetcher;
+  master.reset();
+  slave.reset();
 
   MesosTest::TearDown();
 }
@@ -273,16 +282,20 @@ void FetcherCacheTest::TearDown()
 void FetcherCacheTest::startSlave()
 {
   Try<MesosContainerizer*> create = MesosContainerizer::create(
-      flags, true, fetcher);
+      flags, true, fetcher.get());
+
   ASSERT_SOME(create);
-  containerizer = create.get();
+  containerizer.reset(create.get());
 
   Future<SlaveRegisteredMessage> slaveRegisteredMessage =
     FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _);
 
-  Try<PID<Slave>> pid = StartSlave(containerizer, flags);
-  ASSERT_SOME(pid);
-  slavePid = pid.get();
+  detector = master->createDetector();
+
+  Try<Owned<cluster::Slave>> _slave =
+    StartSlave(detector.get(), containerizer.get(), flags);
+  ASSERT_SOME(_slave);
+  slave = _slave.get();
 
   AWAIT_READY(slaveRegisteredMessage);
   slaveId = slaveRegisteredMessage.get().slave_id();
@@ -292,13 +305,6 @@ void FetcherCacheTest::startSlave()
 }
 
 
-void FetcherCacheTest::stopSlave()
-{
-  Stop(slavePid);
-  delete containerizer;
-}
-
-
 void FetcherCacheTest::setupCommandFileAsset()
 {
   commandPath = path::join(assetsDirectory, COMMAND_NAME);
@@ -403,7 +409,7 @@ Try<FetcherCacheTest::Task> FetcherCacheTest::launchTask(
     const size_t taskIndex)
 {
   Future<vector<Offer>> offers;
-  EXPECT_CALL(scheduler, resourceOffers(driver, _))
+  EXPECT_CALL(scheduler, resourceOffers(driver.get(), _))
     .WillOnce(FutureArg<1>(&offers))
     .WillRepeatedly(DeclineOffers());
 
@@ -442,7 +448,7 @@ Try<FetcherCacheTest::Task> FetcherCacheTest::launchTask(
 
   Queue<TaskStatus> taskStatusQueue;
 
-  EXPECT_CALL(scheduler, statusUpdate(driver, _))
+  EXPECT_CALL(scheduler, statusUpdate(driver.get(), _))
     .WillRepeatedly(PushTaskStatus(taskStatusQueue));
 
   driver->launchTasks(offer.id(), tasks);
@@ -514,7 +520,7 @@ Try<vector<FetcherCacheTest::Task>> FetcherCacheTest::launchTasks(
               Invoke(fetcherProcess, &MockFetcherProcess::unmocked__fetch)));
 
   Future<vector<Offer>> offers;
-  EXPECT_CALL(scheduler, resourceOffers(driver, _))
+  EXPECT_CALL(scheduler, resourceOffers(driver.get(), _))
     .WillOnce(FutureArg<1>(&offers))
     .WillRepeatedly(DeclineOffers());
 
@@ -579,7 +585,7 @@ Try<vector<FetcherCacheTest::Task>> FetcherCacheTest::launchTasks(
     fetchContentionWaypoints.push_back(waypoint);
   }
 
-  EXPECT_CALL(scheduler, statusUpdate(driver, _))
+  EXPECT_CALL(scheduler, statusUpdate(driver.get(), _))
     .WillRepeatedly(PushIndexedTaskStatus<1>(result));
 
   driver->launchTasks(offer.id(), tasks);
@@ -1180,7 +1186,8 @@ TEST_F(FetcherCacheHttpTest, DISABLED_HttpCachedRecovery)
     EXPECT_EQ(2u, httpServer->countCommandRequests);
   }
 
-  stopSlave();
+  // Stop and destroy the current slave.
+  slave->terminate();
 
   // Start over.
   httpServer->resetCounts();
@@ -1189,19 +1196,21 @@ TEST_F(FetcherCacheHttpTest, DISABLED_HttpCachedRecovery)
   // stopping the slave.
   Fetcher fetcher2;
 
-  Try<MesosContainerizer*> c =
+  Try<MesosContainerizer*> _containerizer =
     MesosContainerizer::create(flags, true, &fetcher2);
-  CHECK_SOME(c);
-  containerizer = c.get();
+
+  ASSERT_SOME(_containerizer);
+  containerizer.reset(_containerizer.get());
 
   // Set up so we can wait until the new slave updates the container's
   // resources (this occurs after the executor has re-registered).
   Future<Nothing> update =
     FUTURE_DISPATCH(_, &MesosContainerizerProcess::update);
 
-  Try<PID<Slave>> pid = StartSlave(containerizer, flags);
-  CHECK_SOME(pid);
-  slavePid = pid.get();
+  Try<Owned<cluster::Slave>> _slave =
+    StartSlave(detector.get(), containerizer.get(), flags);
+  ASSERT_SOME(_slave);
+  slave = _slave.get();
 
   // Wait until the containerizer is updated.
   AWAIT_READY(update);

http://git-wip-us.apache.org/repos/asf/mesos/blob/56e94067/src/tests/resource_offers_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/resource_offers_tests.cpp b/src/tests/resource_offers_tests.cpp
index 0bad45d..1cf292e 100644
--- a/src/tests/resource_offers_tests.cpp
+++ b/src/tests/resource_offers_tests.cpp
@@ -21,6 +21,10 @@
 #include <mesos/executor.hpp>
 #include <mesos/scheduler.hpp>
 
+#include <process/future.hpp>
+#include <process/owned.hpp>
+#include <process/pid.hpp>
+
 #include <stout/strings.hpp>
 
 #include "master/master.hpp"
@@ -37,6 +41,7 @@ using mesos::internal::master::Master;
 using mesos::internal::slave::Slave;
 
 using process::Future;
+using process::Owned;
 using process::PID;
 
 using std::vector;
@@ -53,22 +58,26 @@ class ResourceOffersTest : public MesosTest {};
 
 TEST_F(ResourceOffersTest, ResourceOfferWithMultipleSlaves)
 {
-  Try<PID<Master>> master = StartMaster();
+  Try<Owned<cluster::Master>> master = StartMaster();
   ASSERT_SOME(master);
 
+  Owned<MasterDetector> detector = master.get()->createDetector();
+  vector<Owned<cluster::Slave>> slaves;
+
   // Start 10 slaves.
   for (int i = 0; i < 10; i++) {
     slave::Flags flags = CreateSlaveFlags();
 
     flags.resources = Option<std::string>("cpus:2;mem:1024");
 
-    Try<PID<Slave>> slave = StartSlave(flags);
+    Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), flags);
     ASSERT_SOME(slave);
+    slaves.push_back(slave.get());
   }
 
   MockScheduler sched;
   MesosSchedulerDriver driver(
-      &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);
+      &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
 
   EXPECT_CALL(sched, registered(&driver, _, _))
     .Times(1);
@@ -90,22 +99,21 @@ TEST_F(ResourceOffersTest, ResourceOfferWithMultipleSlaves)
 
   driver.stop();
   driver.join();
-
-  Shutdown();
 }
 
 
 TEST_F(ResourceOffersTest, ResourcesGetReofferedAfterFrameworkStops)
 {
-  Try<PID<Master>> master = StartMaster();
+  Try<Owned<cluster::Master>> master = StartMaster();
   ASSERT_SOME(master);
 
-  Try<PID<Slave>> slave = StartSlave();
+  Owned<MasterDetector> detector = master.get()->createDetector();
+  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get());
   ASSERT_SOME(slave);
 
   MockScheduler sched1;
   MesosSchedulerDriver driver1(
-      &sched1, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);
+      &sched1, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
 
   EXPECT_CALL(sched1, registered(&driver1, _, _))
     .Times(1);
@@ -124,7 +132,7 @@ TEST_F(ResourceOffersTest, ResourcesGetReofferedAfterFrameworkStops)
 
   MockScheduler sched2;
   MesosSchedulerDriver driver2(
-      &sched2, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);
+      &sched2, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
 
   EXPECT_CALL(sched2, registered(&driver2, _, _))
     .Times(1);
@@ -138,22 +146,21 @@ TEST_F(ResourceOffersTest, ResourcesGetReofferedAfterFrameworkStops)
 
   driver2.stop();
   driver2.join();
-
-  Shutdown();
 }
 
 
 TEST_F(ResourceOffersTest, ResourcesGetReofferedWhenUnused)
 {
-  Try<PID<Master>> master = StartMaster();
+  Try<Owned<cluster::Master>> master = StartMaster();
   ASSERT_SOME(master);
 
-  Try<PID<Slave>> slave = StartSlave();
+  Owned<MasterDetector> detector = master.get()->createDetector();
+  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get());
   ASSERT_SOME(slave);
 
   MockScheduler sched1;
   MesosSchedulerDriver driver1(
-      &sched1, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);
+      &sched1, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
 
   EXPECT_CALL(sched1, registered(&driver1, _, _))
     .Times(1);
@@ -172,7 +179,7 @@ TEST_F(ResourceOffersTest, ResourcesGetReofferedWhenUnused)
 
   MockScheduler sched2;
   MesosSchedulerDriver driver2(
-      &sched2, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);
+      &sched2, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
 
   EXPECT_CALL(sched2, registered(&driver2, _, _))
     .Times(1);
@@ -190,22 +197,21 @@ TEST_F(ResourceOffersTest, ResourcesGetReofferedWhenUnused)
 
   driver2.stop();
   driver2.join();
-
-  Shutdown();
 }
 
 
 TEST_F(ResourceOffersTest, ResourcesGetReofferedAfterTaskInfoError)
 {
-  Try<PID<Master>> master = StartMaster();
+  Try<Owned<cluster::Master>> master = StartMaster();
   ASSERT_SOME(master);
 
-  Try<PID<Slave>> slave = StartSlave();
+  Owned<MasterDetector> detector = master.get()->createDetector();
+  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get());
   ASSERT_SOME(slave);
 
   MockScheduler sched1;
   MesosSchedulerDriver driver1(
-      &sched1, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);
+      &sched1, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
 
   EXPECT_CALL(sched1, registered(&driver1, _, _))
     .Times(1);
@@ -255,7 +261,7 @@ TEST_F(ResourceOffersTest, ResourcesGetReofferedAfterTaskInfoError)
 
   MockScheduler sched2;
   MesosSchedulerDriver driver2(
-      &sched2, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);
+      &sched2, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
 
   EXPECT_CALL(sched2, registered(&driver2, _, _))
     .Times(1);
@@ -273,8 +279,6 @@ TEST_F(ResourceOffersTest, ResourcesGetReofferedAfterTaskInfoError)
 
   driver2.stop();
   driver2.join();
-
-  Shutdown();
 }
 
 
@@ -285,12 +289,12 @@ TEST_F(ResourceOffersTest, Request)
   EXPECT_CALL(allocator, initialize(_, _, _, _))
     .Times(1);
 
-  Try<PID<Master>> master = StartMaster(&allocator);
+  Try<Owned<cluster::Master>> master = StartMaster(&allocator);
   ASSERT_SOME(master);
 
   MockScheduler sched;
   MesosSchedulerDriver driver(
-      &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);
+      &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
 
   EXPECT_CALL(allocator, addFramework(_, _, _))
     .Times(1);
@@ -321,8 +325,6 @@ TEST_F(ResourceOffersTest, Request)
 
   driver.stop();
   driver.join();
-
-  Shutdown();
 }
 
 } // namespace tests {