You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2012/08/20 23:41:03 UTC
svn commit: r1375239 [2/2] - in /incubator/mesos/trunk/src: ./ local/
master/ tests/
Added: incubator/mesos/trunk/src/tests/allocator_zookeeper_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/allocator_zookeeper_tests.cpp?rev=1375239&view=auto
==============================================================================
--- incubator/mesos/trunk/src/tests/allocator_zookeeper_tests.cpp (added)
+++ incubator/mesos/trunk/src/tests/allocator_zookeeper_tests.cpp Mon Aug 20 21:41:02 2012
@@ -0,0 +1,367 @@
+/**
+ * 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 <gmock/gmock.h>
+
+#include "detector/detector.hpp"
+
+#include "master/allocator.hpp"
+#include "master/master.hpp"
+
+#include "tests/base_zookeeper_test.hpp"
+#include "tests/utils.hpp"
+
+using namespace mesos;
+using namespace mesos::internal;
+using namespace mesos::internal::test;
+
+using mesos::internal::master::AllocatorProcess;
+using mesos::internal::master::Master;
+
+using mesos::internal::slave::Slave;
+
+using process::PID;
+
+using std::map;
+using std::string;
+using std::vector;
+
+using testing::DoAll;
+using testing::DoDefault;
+using testing::Eq;
+using testing::_;
+using testing::Return;
+using testing::SaveArg;
+
+
+template <typename T = AllocatorProcess>
+class AllocatorZooKeeperTest : public BaseZooKeeperTest
+{
+public:
+ static void SetUpTestCase() {
+ BaseZooKeeperTest::SetUpTestCase();
+ }
+
+protected:
+ T allocator1;
+ MockAllocator<T> allocator2;
+};
+
+
+// Runs TYPED_TEST(AllocatorZooKeeperTest, ...) on all AllocatorTypes.
+TYPED_TEST_CASE(AllocatorZooKeeperTest, AllocatorTypes);
+
+
+TYPED_TEST(AllocatorZooKeeperTest, FrameworkReregistersFirst)
+{
+ EXPECT_CALL(this->allocator2, initialize(_, _));
+
+ trigger frameworkAddedTrigger;
+ EXPECT_CALL(this->allocator2, frameworkAdded(_, _, _))
+ .WillOnce(DoAll(InvokeFrameworkAdded(&this->allocator2),
+ Trigger(&frameworkAddedTrigger)));
+
+ EXPECT_CALL(this->allocator2, frameworkDeactivated(_));
+
+ EXPECT_CALL(this->allocator2, frameworkRemoved(_));
+
+ EXPECT_CALL(this->allocator2, slaveAdded(_, _, _));
+
+ trigger slaveRemovedTrigger;
+ EXPECT_CALL(this->allocator2, slaveRemoved(_))
+ .WillOnce(Trigger(&slaveRemovedTrigger));
+
+ EXPECT_CALL(this->allocator2, resourcesRecovered(_, _, _))
+ .WillRepeatedly(DoDefault());
+
+ MockFilter filter;
+ process::filter(&filter);
+
+ trigger shutdownMessageTrigger;
+ EXPECT_MESSAGE(filter, Eq(ShutdownMessage().GetTypeName()), _, _)
+ .WillRepeatedly(DoAll(Trigger(&shutdownMessageTrigger),
+ Return(true)));
+
+ EXPECT_MESSAGE(filter, Eq(ReregisterSlaveMessage().GetTypeName()), _, _)
+ .WillRepeatedly(Return(true));
+
+ Master m(&this->allocator1);
+ PID<Master> master1 = process::spawn(&m);
+
+ string zk = "zk://" + this->zks->connectString() + "/znode";
+ Try<MasterDetector*> detector =
+ MasterDetector::create(zk, master1, true, true);
+ CHECK(!detector.isError())
+ << "Failed to create a master detector: " << detector.error();
+
+ MockExecutor exec;
+
+ EXPECT_CALL(exec, registered(_, _, _, _));
+
+ EXPECT_CALL(exec, launchTask(_, _))
+ .WillOnce(SendStatusUpdateFromTask(TASK_RUNNING));
+
+ trigger shutdownTrigger;
+ EXPECT_CALL(exec, shutdown(_))
+ .WillOnce(Trigger(&shutdownTrigger));
+
+ map<ExecutorID, Executor*> execs;
+ execs[DEFAULT_EXECUTOR_ID] = &exec;
+
+ TestingIsolationModule isolationModule(execs);
+ Resources resources = Resources::parse("cpus:2;mem:1024");
+ Slave s(resources, true, &isolationModule);
+ PID<Slave> slave = process::spawn(&s);
+
+ Try<MasterDetector*> slave_detector =
+ MasterDetector::create(zk, slave, false, true);
+ CHECK(!slave_detector.isError())
+ << "Failed to create a master detector: " << slave_detector.error();
+
+ MockScheduler sched;
+ MesosSchedulerDriver driver(&sched, DEFAULT_FRAMEWORK_INFO,zk);
+
+ EXPECT_CALL(sched, registered(&driver, _, _))
+ .Times(2);
+
+ vector<Offer> offers, offers2;
+ trigger resourceOffersTrigger, resourceOffersTrigger2;
+ EXPECT_CALL(sched, resourceOffers(&driver, _))
+ .WillOnce(DoAll(SaveArg<1>(&offers),
+ LaunchTasks(1, 1, 512),
+ Trigger(&resourceOffersTrigger)))
+ .WillRepeatedly(DoAll(SaveArg<1>(&offers2),
+ Trigger(&resourceOffersTrigger2)));
+
+ TaskStatus status;
+ trigger statusUpdateTrigger;
+ EXPECT_CALL(sched, statusUpdate(&driver, _))
+ .WillOnce(DoAll(SaveArg<1>(&status),
+ Trigger(&statusUpdateTrigger)));
+
+ EXPECT_CALL(sched, disconnected(_))
+ .WillRepeatedly(DoDefault());
+
+ driver.start();
+
+ WAIT_UNTIL(resourceOffersTrigger);
+
+ EXPECT_THAT(offers, OfferEq(2, 1024));
+
+ Resources launchedResources = Resources::parse("cpus:1;mem:512");
+ trigger resourcesChangedTrigger;
+ EXPECT_CALL(isolationModule,
+ resourcesChanged(_, _, Resources(launchedResources)))
+ .WillOnce(Trigger(&resourcesChangedTrigger));
+
+ WAIT_UNTIL(statusUpdateTrigger);
+
+ EXPECT_EQ(TASK_RUNNING, status.state());
+
+ WAIT_UNTIL(resourcesChangedTrigger);
+
+ process::terminate(master1);
+ process::wait(master1);
+ MasterDetector::destroy(detector.get());
+
+ WAIT_UNTIL(shutdownMessageTrigger);
+
+ Master m2(&(this->allocator2));
+ PID<Master> master2 = process::spawn(m2);
+
+ Try<MasterDetector*> detector2 =
+ MasterDetector::create(zk, master2, true, true);
+ CHECK(!detector2.isError())
+ << "Failed to create a master detector: " << detector2.error();
+
+ WAIT_UNTIL(frameworkAddedTrigger);
+
+ resourceOffersTrigger2.value = false;
+
+ // We kill the filter so that ReregisterSlaveMessages can get
+ // to the master now that the framework has been added, ensuring
+ // that the slave reregisters after the framework.
+ process::filter(NULL);
+
+ WAIT_UNTIL(resourceOffersTrigger2);
+
+ EXPECT_THAT(offers2, OfferEq(1, 512));
+
+ driver.stop();
+ driver.join();
+
+ WAIT_UNTIL(shutdownTrigger); // Ensures MockExecutor can be deallocated.
+
+ process::terminate(slave);
+ process::wait(slave);
+
+ WAIT_UNTIL(slaveRemovedTrigger);
+
+ process::terminate(master2);
+ process::wait(master2);
+}
+
+
+TYPED_TEST(AllocatorZooKeeperTest, SlaveReregisterFirst)
+{
+ EXPECT_CALL(this->allocator2, initialize(_, _));
+
+ EXPECT_CALL(this->allocator2, frameworkAdded(_, _, _));
+
+ EXPECT_CALL(this->allocator2, frameworkDeactivated(_));
+
+ EXPECT_CALL(this->allocator2, frameworkRemoved(_));
+
+ trigger slaveAddedTrigger;
+ EXPECT_CALL(this->allocator2, slaveAdded(_, _, _))
+ .WillOnce(DoAll(InvokeSlaveAdded(&this->allocator2),
+ Trigger(&slaveAddedTrigger)));
+
+ trigger slaveRemovedTrigger;
+ EXPECT_CALL(this->allocator2, slaveRemoved(_))
+ .WillOnce(Trigger(&slaveRemovedTrigger));
+
+ EXPECT_CALL(this->allocator2, resourcesRecovered(_, _, _))
+ .WillRepeatedly(DoDefault());
+
+ MockFilter filter;
+ process::filter(&filter);
+
+ trigger shutdownMessageTrigger;
+ EXPECT_MESSAGE(filter, Eq(ShutdownMessage().GetTypeName()), _, _)
+ .WillRepeatedly(DoAll(Trigger(&shutdownMessageTrigger),
+ Return(true)));
+
+ EXPECT_MESSAGE(filter, Eq(ReregisterFrameworkMessage().GetTypeName()), _, _)
+ .WillRepeatedly(Return(true));
+
+ Master m(&this->allocator1);
+ PID<Master> master1 = process::spawn(&m);
+
+ string zk = "zk://" + this->zks->connectString() + "/znode";
+ Try<MasterDetector*> detector =
+ MasterDetector::create(zk, master1, true, true);
+ CHECK(!detector.isError())
+ << "Failed to create a master detector: " << detector.error();
+
+ MockExecutor exec;
+
+ EXPECT_CALL(exec, registered(_, _, _, _));
+
+ EXPECT_CALL(exec, launchTask(_, _))
+ .WillOnce(SendStatusUpdateFromTask(TASK_RUNNING));
+
+ trigger shutdownTrigger;
+ EXPECT_CALL(exec, shutdown(_))
+ .WillOnce(Trigger(&shutdownTrigger));
+
+ map<ExecutorID, Executor*> execs;
+ execs[DEFAULT_EXECUTOR_ID] = &exec;
+
+ TestingIsolationModule isolationModule(execs);
+ Resources resources = Resources::parse("cpus:2;mem:1024");
+ Slave s(resources, true, &isolationModule);
+ PID<Slave> slave = process::spawn(&s);
+
+ Try<MasterDetector*> slave_detector =
+ MasterDetector::create(zk, slave, false, true);
+ CHECK(!slave_detector.isError())
+ << "Failed to create a master detector: " << slave_detector.error();
+
+ MockScheduler sched;
+ MesosSchedulerDriver driver(&sched, DEFAULT_FRAMEWORK_INFO,zk);
+
+ EXPECT_CALL(sched, registered(&driver, _, _))
+ .Times(2);
+
+ vector<Offer> offers, offers2;
+ trigger resourceOffersTrigger, resourceOffersTrigger2;
+ EXPECT_CALL(sched, resourceOffers(&driver, _))
+ .WillOnce(DoAll(SaveArg<1>(&offers),
+ LaunchTasks(1, 1, 512),
+ Trigger(&resourceOffersTrigger)))
+ .WillRepeatedly(DoAll(SaveArg<1>(&offers2),
+ Trigger(&resourceOffersTrigger2)));
+
+ TaskStatus status;
+ trigger statusUpdateTrigger;
+ EXPECT_CALL(sched, statusUpdate(&driver, _))
+ .WillOnce(DoAll(SaveArg<1>(&status),
+ Trigger(&statusUpdateTrigger)));
+
+ EXPECT_CALL(sched, disconnected(_))
+ .WillRepeatedly(DoDefault());
+
+ driver.start();
+
+ WAIT_UNTIL(resourceOffersTrigger);
+
+ EXPECT_THAT(offers, OfferEq(2, 1024));
+
+ Resources launchedResources = Resources::parse("cpus:1;mem:512");
+ trigger resourcesChangedTrigger;
+ EXPECT_CALL(isolationModule,
+ resourcesChanged(_, _, Resources(launchedResources)))
+ .WillOnce(Trigger(&resourcesChangedTrigger));
+
+ WAIT_UNTIL(statusUpdateTrigger);
+
+ EXPECT_EQ(TASK_RUNNING, status.state());
+
+ WAIT_UNTIL(resourcesChangedTrigger);
+
+ process::terminate(master1);
+ process::wait(master1);
+ MasterDetector::destroy(detector.get());
+
+ WAIT_UNTIL(shutdownMessageTrigger);
+
+ Master m2(&(this->allocator2));
+ PID<Master> master2 = process::spawn(m2);
+
+ Try<MasterDetector*> detector2 =
+ MasterDetector::create(zk, master2, true, true);
+ CHECK(!detector2.isError())
+ << "Failed to create a master detector: " << detector2.error();
+
+ WAIT_UNTIL(slaveAddedTrigger);
+
+ resourceOffersTrigger2.value = false;
+
+ // We kill the filter so that ReregisterFrameworkMessages can get
+ // to the master now that the slave has been added, ensuring
+ // that the framework reregisters after the slave.
+ process::filter(NULL);
+
+ WAIT_UNTIL(resourceOffersTrigger2);
+
+ EXPECT_THAT(offers2, OfferEq(1, 512));
+
+ driver.stop();
+ driver.join();
+
+ WAIT_UNTIL(shutdownTrigger); // Ensures MockExecutor can be deallocated.
+
+ process::terminate(slave);
+ process::wait(slave);
+
+ WAIT_UNTIL(slaveRemovedTrigger);
+
+ process::terminate(master2);
+ process::wait(master2);
+}
Modified: incubator/mesos/trunk/src/tests/fault_tolerance_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/fault_tolerance_tests.cpp?rev=1375239&r1=1375238&r2=1375239&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/fault_tolerance_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/fault_tolerance_tests.cpp Mon Aug 20 21:41:02 2012
@@ -29,7 +29,6 @@
#include "local/local.hpp"
-#include "master/dominant_share_allocator.hpp"
#include "master/master.hpp"
#include "slave/process_based_isolation_module.hpp"
@@ -42,7 +41,6 @@ using namespace mesos::internal;
using namespace mesos::internal::test;
using mesos::internal::master::Master;
-using mesos::internal::master::DominantShareAllocator;
using mesos::internal::slave::ProcessBasedIsolationModule;
using mesos::internal::slave::Slave;
@@ -70,7 +68,7 @@ TEST(FaultToleranceTest, SlaveLost)
{
ASSERT_TRUE(GTEST_IS_THREADSAFE);
- DominantShareAllocator a;
+ TestAllocatorProcess a;
Master m(&a);
PID<Master> master = process::spawn(&m);
@@ -396,7 +394,7 @@ TEST(FaultToleranceTest, DISABLED_TaskLo
EXPECT_MESSAGE(filter, _, _, _)
.WillRepeatedly(Return(false));
- DominantShareAllocator a;
+ TestAllocatorProcess a;
Master m(&a);
PID<Master> master = process::spawn(&m);
@@ -500,7 +498,7 @@ TEST(FaultToleranceTest, SchedulerFailov
EXPECT_MESSAGE(filter, _, _, _)
.WillRepeatedly(Return(false));
- DominantShareAllocator a;
+ TestAllocatorProcess a;
Master m(&a);
PID<Master> master = process::spawn(&m);
@@ -632,7 +630,7 @@ TEST(FaultToleranceTest, SchedulerFailov
{
ASSERT_TRUE(GTEST_IS_THREADSAFE);
- DominantShareAllocator a;
+ TestAllocatorProcess a;
Master m(&a);
PID<Master> master = process::spawn(&m);
@@ -754,7 +752,7 @@ TEST(FaultToleranceTest, SchedulerExit)
EXPECT_MESSAGE(filter, _, _, _)
.WillRepeatedly(Return(false));
- DominantShareAllocator a;
+ TestAllocatorProcess a;
Master m(&a);
PID<Master> master = process::spawn(&m);
@@ -879,7 +877,7 @@ TEST(FaultToleranceTest, SlaveReliableRe
.WillOnce(DoAll(Trigger(&slaveRegisteredMsg), Return(true)))
.WillRepeatedly(Return(false));
- DominantShareAllocator a;
+ TestAllocatorProcess a;
Master m(&a);
PID<Master> master = process::spawn(&m);
@@ -937,7 +935,7 @@ TEST(FaultToleranceTest, SlaveReregister
EXPECT_MESSAGE(filter, _, _, _)
.WillRepeatedly(Return(false));
- DominantShareAllocator a;
+ TestAllocatorProcess a;
Master m(&a);
PID<Master> master = process::spawn(&m);
Modified: incubator/mesos/trunk/src/tests/gc_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/gc_tests.cpp?rev=1375239&r1=1375238&r2=1375239&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/gc_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/gc_tests.cpp Mon Aug 20 21:41:02 2012
@@ -34,7 +34,6 @@
#include "local/local.hpp"
#include "master/master.hpp"
-#include "master/dominant_share_allocator.hpp"
#include "slave/constants.hpp"
#include "slave/flags.hpp"
@@ -47,7 +46,6 @@ using namespace mesos::internal;
using namespace mesos::internal::test;
using mesos::internal::master::Master;
-using mesos::internal::master::DominantShareAllocator;
using mesos::internal::slave::Slave;
@@ -83,7 +81,7 @@ protected:
EXPECT_MESSAGE(filter, _, _, _)
.WillRepeatedly(Return(false));
- a = new DominantShareAllocator();
+ a = new TestAllocatorProcess();
m = new Master(a);
master = process::spawn(m);
@@ -166,7 +164,7 @@ protected:
launchTask(DEFAULT_EXECUTOR_INFO);
}
- DominantShareAllocator* a;
+ TestAllocatorProcess* a;
Master* m;
TestingIsolationModule* isolationModule;
Slave* s;
Modified: incubator/mesos/trunk/src/tests/master_detector_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/master_detector_tests.cpp?rev=1375239&r1=1375238&r2=1375239&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/master_detector_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/master_detector_tests.cpp Mon Aug 20 21:41:02 2012
@@ -31,7 +31,6 @@
#include "detector/detector.hpp"
-#include "master/dominant_share_allocator.hpp"
#include "master/master.hpp"
#include "slave/slave.hpp"
@@ -43,7 +42,6 @@ using namespace mesos::internal;
using namespace mesos::internal::test;
using mesos::internal::master::Master;
-using mesos::internal::master::DominantShareAllocator;
using mesos::internal::slave::Slave;
@@ -59,7 +57,7 @@ TEST(MasterDetector, File)
{
ASSERT_TRUE(GTEST_IS_THREADSAFE);
- DominantShareAllocator a;
+ TestAllocatorProcess a;
Master m(&a);
PID<Master> master = process::spawn(&m);
Modified: incubator/mesos/trunk/src/tests/master_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/master_tests.cpp?rev=1375239&r1=1375238&r2=1375239&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/master_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/master_tests.cpp Mon Aug 20 21:41:02 2012
@@ -32,7 +32,6 @@
#include "flags/flags.hpp"
-#include "master/dominant_share_allocator.hpp"
#include "master/flags.hpp"
#include "master/frameworks_manager.hpp"
#include "master/master.hpp"
@@ -52,7 +51,6 @@ using mesos::internal::master::Framework
using mesos::internal::master::FrameworksStorage;
using mesos::internal::master::Master;
-using mesos::internal::master::DominantShareAllocator;
using mesos::internal::slave::Slave;
@@ -76,7 +74,7 @@ TEST(MasterTest, TaskRunning)
{
ASSERT_TRUE(GTEST_IS_THREADSAFE);
- DominantShareAllocator a;
+ TestAllocatorProcess a;
Master m(&a);
PID<Master> master = process::spawn(&m);
@@ -169,7 +167,7 @@ TEST(MasterTest, KillTask)
{
ASSERT_TRUE(GTEST_IS_THREADSAFE);
- DominantShareAllocator a;
+ TestAllocatorProcess a;
Master m(&a);
PID<Master> master = process::spawn(&m);
@@ -266,7 +264,7 @@ TEST(MasterTest, RecoverResources)
{
ASSERT_TRUE(GTEST_IS_THREADSAFE);
- DominantShareAllocator a;
+ TestAllocatorProcess a;
Master m(&a);
PID<Master> master = process::spawn(&m);
@@ -400,7 +398,7 @@ TEST(MasterTest, FrameworkMessage)
{
ASSERT_TRUE(GTEST_IS_THREADSAFE);
- DominantShareAllocator a;
+ TestAllocatorProcess a;
Master m(&a);
PID<Master> master = process::spawn(&m);
@@ -520,7 +518,7 @@ TEST(MasterTest, MultipleExecutors)
{
ASSERT_TRUE(GTEST_IS_THREADSAFE);
- DominantShareAllocator a;
+ TestAllocatorProcess a;
Master m(&a);
PID<Master> master = process::spawn(&m);
@@ -665,7 +663,7 @@ TEST(MasterTest, MasterInfo)
EXPECT_MESSAGE(filter, _, _, _)
.WillRepeatedly(Return(false));
- DominantShareAllocator a;
+ TestAllocatorProcess a;
Master m(&a);
PID<Master> master = process::spawn(&m);
@@ -727,7 +725,7 @@ TEST(MasterTest, MasterInfoOnReElection)
EXPECT_MESSAGE(filter, _, _, _)
.WillRepeatedly(Return(false));
- DominantShareAllocator a;
+ TestAllocatorProcess a;
Master m(&a);
PID<Master> master = process::spawn(&m);
@@ -828,7 +826,7 @@ TEST_F(WhitelistFixture, WhitelistSlave)
string hosts = hostname.get() + "\n" + "dummy-slave";
CHECK (os::write(path, hosts).isSome()) << "Error writing whitelist";
- DominantShareAllocator a;
+ TestAllocatorProcess a;
flags::Flags<logging::Flags, master::Flags> flags;
flags.whitelist = "file://" + path;
Master m(&a, flags);
@@ -911,7 +909,7 @@ TEST(MasterTest, MasterLost)
EXPECT_MESSAGE(filter, _, _, _)
.WillRepeatedly(Return(false));
- DominantShareAllocator a;
+ TestAllocatorProcess a;
Master m(&a);
PID<Master> master = process::spawn(&m);
Modified: incubator/mesos/trunk/src/tests/resource_offers_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/resource_offers_tests.cpp?rev=1375239&r1=1375238&r2=1375239&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/resource_offers_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/resource_offers_tests.cpp Mon Aug 20 21:41:02 2012
@@ -29,7 +29,6 @@
#include "local/local.hpp"
-#include "master/dominant_share_allocator.hpp"
#include "master/master.hpp"
#include "slave/slave.hpp"
@@ -41,7 +40,6 @@ using namespace mesos::internal;
using namespace mesos::internal::test;
using mesos::internal::master::Master;
-using mesos::internal::master::DominantShareAllocator;
using mesos::internal::slave::Slave;
@@ -455,7 +453,7 @@ TEST(ResourceOffersTest, Request)
ASSERT_TRUE(GTEST_IS_THREADSAFE);
MockScheduler sched;
- MockAllocator<DominantShareAllocator> allocator;
+ MockAllocator<TestAllocatorProcess > allocator;
EXPECT_CALL(allocator, initialize(_, _))
.WillOnce(Return());
@@ -519,7 +517,7 @@ TEST(ResourceOffersTest, TasksExecutorIn
{
ASSERT_TRUE(GTEST_IS_THREADSAFE);
- DominantShareAllocator a;
+ TestAllocatorProcess a;
Master m(&a);
PID<Master> master = process::spawn(&m);
Modified: incubator/mesos/trunk/src/tests/utils.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/utils.hpp?rev=1375239&r1=1375238&r2=1375239&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/utils.hpp (original)
+++ incubator/mesos/trunk/src/tests/utils.hpp Mon Aug 20 21:41:02 2012
@@ -36,6 +36,8 @@
#include "common/type_utils.hpp"
+#include "master/drf_sorter.hpp"
+#include "master/hierarchical_allocator_process.hpp"
#include "master/master.hpp"
#include "messages/messages.hpp"
@@ -167,13 +169,14 @@ ACTION_P3(LaunchTasks, tasks, cpus, mem)
}
}
+ int nextTaskId = 0;
std::vector<TaskInfo> tasks;
- if (offeredCpus >= cpus &&
+ while (offeredCpus >= cpus &&
offeredMem >= mem &&
launched < numTasks) {
TaskInfo task;
task.set_name("TestTask");
- task.mutable_task_id()->set_value("TestTask1");
+ task.mutable_task_id()->set_value(stringify(nextTaskId++));
task.mutable_slave_id()->MergeFrom(offer.slave_id());
ExecutorInfo executor;
@@ -194,6 +197,8 @@ ACTION_P3(LaunchTasks, tasks, cpus, mem)
tasks.push_back(task);
launched++;
+ offeredCpus -= cpus;
+ offeredMem -= mem;
}
driver->launchTasks(offer.id(), tasks);
@@ -212,6 +217,7 @@ ACTION(DeclineOffers)
}
}
+
/**
* Definition of a mock Executor to be used in tests with gmock.
*/
@@ -232,8 +238,8 @@ public:
};
-template <typename T = master::Allocator>
-class MockAllocator : public master::Allocator
+template <typename T = master::AllocatorProcess>
+class MockAllocator : public master::AllocatorProcess
{
public:
MockAllocator() {
@@ -258,6 +264,9 @@ public:
ON_CALL(*this, slaveRemoved(_))
.WillByDefault(Invoke(&real, &T::slaveRemoved));
+ ON_CALL(*this, updateWhitelist(_))
+ .WillByDefault(Invoke(&real, &T::updateWhitelist));
+
ON_CALL(*this, resourcesRequested(_, _))
.WillByDefault(Invoke(&real, &T::resourcesRequested));
@@ -299,6 +308,14 @@ public:
};
+class TestAllocatorProcess
+ : public master::HierarchicalAllocatorProcess<master::DRFSorter, master::DRFSorter>
+{};
+
+
+typedef ::testing::Types<master::HierarchicalAllocatorProcess<master::DRFSorter, master::DRFSorter> > AllocatorTypes;
+
+
// The following actions make up for the fact that DoDefault
// cannot be used inside a DoAll, for example:
// EXPECT_CALL(allocator, frameworkAdded(_, _, _))
@@ -316,18 +333,104 @@ ACTION_P(InvokeFrameworkRemoved, allocat
}
+ACTION_P(InvokeFrameworkActivated, allocator)
+{
+ allocator->real.frameworkActivated(arg0, arg1);
+}
+
+
+ACTION_P(InvokeFrameworkDeactivated, allocator)
+{
+ allocator->real.frameworkDeactivated(arg0);
+}
+
+
ACTION_P(InvokeSlaveAdded, allocator)
{
allocator->real.slaveAdded(arg0, arg1, arg2);
}
+ACTION_P(InvokeSlaveRemoved, allocator)
+{
+ allocator->real.slaveRemoved(arg0);
+}
+
+
+ACTION_P(InvokeUpdateWhitelist, allocator)
+{
+ allocator->real.updateWhitelist(arg0);
+}
+
+
ACTION_P(InvokeResourcesUnused, allocator)
{
allocator->real.resourcesUnused(arg0, arg1, arg2, arg3);
}
+ACTION_P2(InvokeUnusedWithFilters, allocator, timeout)
+{
+ Filters filters;
+ filters.set_refuse_seconds(timeout);
+ allocator->real.resourcesUnused(arg0, arg1, arg2, filters);
+}
+
+
+class OfferEqMatcher
+ : public ::testing::MatcherInterface<const std::vector<Offer>& >
+{
+public:
+ OfferEqMatcher(int _cpus, int _mem)
+ : cpus(_cpus), mem(_mem) {}
+
+ virtual bool MatchAndExplain(const std::vector<Offer>& offers,
+ ::testing::MatchResultListener* listener) const
+ {
+ double totalCpus = 0;
+ double totalMem = 0;
+
+ foreach (const Offer& offer, offers) {
+ foreach (const Resource& resource, offer.resources()) {
+ if (resource.name() == "cpus") {
+ totalCpus += resource.scalar().value();
+ } else if (resource.name() == "mem") {
+ totalMem += resource.scalar().value();
+ }
+ }
+ }
+
+ bool matches = totalCpus == cpus && totalMem == mem;
+
+ if (!matches) {
+ *listener << totalCpus << " cpus and " << totalMem << "mem";
+ }
+
+ return matches;
+ }
+
+ virtual void DescribeTo(::std::ostream* os) const
+ {
+ *os << "contains " << cpus << " cpus and " << mem << " mem";
+ }
+
+ virtual void DescribeNegationTo(::std::ostream* os) const
+ {
+ *os << "does not contain " << cpus << " cpus and " << mem << " mem";
+ }
+
+private:
+ int cpus;
+ int mem;
+};
+
+
+inline const ::testing::Matcher<const std::vector<Offer>& > OfferEq(int cpus, int mem)
+{
+ return MakeMatcher(new OfferEqMatcher(cpus, mem));
+}
+
+
/**
* Definition of a mock Filter so that messages can act as triggers.
*/