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 2011/06/05 11:06:32 UTC

svn commit: r1132243 - in /incubator/mesos/trunk: include/ src/common/ src/examples/java/ src/master/ src/messaging/ src/slave/ src/tests/

Author: benh
Date: Sun Jun  5 09:06:31 2011
New Revision: 1132243

URL: http://svn.apache.org/viewvc?rev=1132243&view=rev
Log:
A few more updates for the multiple executors stuff, as well as a real test added!

Modified:
    incubator/mesos/trunk/include/mesos.proto
    incubator/mesos/trunk/src/common/type_utils.hpp
    incubator/mesos/trunk/src/examples/java/TestExecutor.java
    incubator/mesos/trunk/src/master/master.cpp
    incubator/mesos/trunk/src/messaging/messages.proto
    incubator/mesos/trunk/src/slave/process_based_isolation_module.cpp
    incubator/mesos/trunk/src/slave/slave.cpp
    incubator/mesos/trunk/src/slave/slave.hpp
    incubator/mesos/trunk/src/tests/master_test.cpp
    incubator/mesos/trunk/src/tests/utils.hpp

Modified: incubator/mesos/trunk/include/mesos.proto
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/include/mesos.proto?rev=1132243&r1=1132242&r2=1132243&view=diff
==============================================================================
--- incubator/mesos/trunk/include/mesos.proto (original)
+++ incubator/mesos/trunk/include/mesos.proto Sun Jun  5 09:06:31 2011
@@ -86,15 +86,15 @@ message ExecutorArgs {
   required string name = 2;
   required SlaveID slave_id = 3;
   required string hostname = 4;
-  optional bytes data = 6;
+  optional bytes data = 5;
 };
 
 
 message StatusUpdate {
   required TaskID task_id = 1;
-  required SlaveID slave_id = 3;
-  required TaskState state = 4;
-  optional bytes data = 5;
+  required SlaveID slave_id = 2;
+  required TaskState state = 3;
+  optional bytes data = 4;
 }
 
 
@@ -103,8 +103,8 @@ message TaskDescription {
   required TaskID task_id = 2;
   required SlaveID slave_id = 3;
   repeated Resource resources = 4;
-  optional bytes data = 5;
-  optional ExecutorInfo executor = 6;
+  optional ExecutorInfo executor = 5;
+  optional bytes data = 6;
 }
 
 

Modified: incubator/mesos/trunk/src/common/type_utils.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/common/type_utils.hpp?rev=1132243&r1=1132242&r2=1132243&view=diff
==============================================================================
--- incubator/mesos/trunk/src/common/type_utils.hpp (original)
+++ incubator/mesos/trunk/src/common/type_utils.hpp Sun Jun  5 09:06:31 2011
@@ -54,6 +54,7 @@ inline std::ostream& operator << (std::o
   return stream;
 }
 
+
 inline bool operator == (const FrameworkID& left, const FrameworkID& right)
 {
   return left.value() == right.value();
@@ -114,6 +115,37 @@ inline bool operator == (const ExecutorI
 }
 
 
+
+inline bool operator < (const FrameworkID& left, const FrameworkID& right)
+{
+  return left.value() < right.value();
+}
+
+
+inline bool operator < (const OfferID& left, const OfferID& right)
+{
+  return left.value() < right.value();
+}
+
+
+inline bool operator < (const SlaveID& left, const SlaveID& right)
+{
+  return left.value() < right.value();
+}
+
+
+inline bool operator < (const TaskID& left, const TaskID& right)
+{
+  return left.value() < right.value();
+}
+
+
+inline bool operator < (const ExecutorID& left, const ExecutorID& right)
+{
+  return left.value() < right.value();
+}
+
+
 inline size_t hash_value(const FrameworkID& frameworkId)
 {
   size_t seed = 0;

Modified: incubator/mesos/trunk/src/examples/java/TestExecutor.java
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/examples/java/TestExecutor.java?rev=1132243&r1=1132242&r2=1132243&view=diff
==============================================================================
--- incubator/mesos/trunk/src/examples/java/TestExecutor.java (original)
+++ incubator/mesos/trunk/src/examples/java/TestExecutor.java Sun Jun  5 09:06:31 2011
@@ -13,7 +13,12 @@ public class TestExecutor implements Exe
     new Thread() { public void run() {
       try {
         System.out.println("Running task " + task.getTaskId());
-        Thread.sleep(1000);
+
+        if (task.hasData()) {
+          Thread.sleep(Integer.parseInt(task.getData().toStringUtf8()));
+        } else {
+          Thread.sleep(1000);
+        }
 
         TaskStatus status = TaskStatus.newBuilder()
           .setTaskId(task.getTaskId())

Modified: incubator/mesos/trunk/src/master/master.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/master.cpp?rev=1132243&r1=1132242&r2=1132243&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/master.cpp (original)
+++ incubator/mesos/trunk/src/master/master.cpp Sun Jun  5 09:06:31 2011
@@ -523,8 +523,10 @@ void Master::operator () ()
         if (offer != NULL) {
           processOfferReply(offer, tasks, msg.params());
         } else {
-          // The slot offer is gone, meaning that we rescinded it or that
-          // the slave was lost; immediately report any tasks in it as lost
+          // The slot offer is gone, meaning that we rescinded it, it
+          // has already been replied to, or that the slave was lost;
+          // immediately report any tasks in it as lost (it would
+          // probably be better to have better error messages here).
           foreach (const TaskDescription &task, tasks) {
             Message<M2F_STATUS_UPDATE> out;
             out.mutable_framework_id()->MergeFrom(msg.framework_id());
@@ -758,29 +760,28 @@ void Master::operator () ()
       if (slave != NULL) {
         Framework *framework = lookupFramework(msg.framework_id());
         if (framework != NULL) {
-          LOG(INFO) << "Executor on " << slave
+          LOG(INFO) << "Executor " << msg.executor_id()
+                    << " of framework " << framework->frameworkId
+                    << " on slave " << slave->slaveId
                     << " (" << slave->info.hostname() << ") "
                     << "exited with status " << msg.status();
 
-          // Collect all the lost tasks for this framework.
-          set<Task*> tasks;
-          foreachpair (_, Task* task, framework->tasks)
-            if (task->slave_id() == slave->slaveId)
-              tasks.insert(task);
+          // Tell the framework which tasks have been lost.
+          foreachpaircopy (_, Task* task, framework->tasks) {
+            if (task->slave_id() == slave->slaveId &&
+                task->executor_id() == msg.executor_id()) {
+              Message<M2F_STATUS_UPDATE> out;
+              out.mutable_framework_id()->MergeFrom(task->framework_id());
+              TaskStatus *status = out.mutable_status();
+              status->mutable_task_id()->MergeFrom(task->task_id());
+              status->mutable_slave_id()->MergeFrom(task->slave_id());
+              status->set_state(TASK_LOST);
+              send(framework->pid, out);
 
-          // Tell the framework they have been lost and remove them.
-          foreach (Task* task, tasks) {
-            Message<M2F_STATUS_UPDATE> out;
-            out.mutable_framework_id()->MergeFrom(task->framework_id());
-            TaskStatus *status = out.mutable_status();
-            status->mutable_task_id()->MergeFrom(task->task_id());
-            status->mutable_slave_id()->MergeFrom(task->slave_id());
-            status->set_state(TASK_LOST);
-            send(framework->pid, out);
-
-            LOG(INFO) << "Removing " << task << " because of lost executor";
+              LOG(INFO) << "Removing " << task << " because of lost executor";
 
-            removeTask(task, TRR_EXECUTOR_LOST);
+              removeTask(task, TRR_EXECUTOR_LOST);
+            }
           }
 
           // TODO(benh): Send the framework it's executor's exit
@@ -1059,13 +1060,19 @@ void Master::launchTask(Framework* frame
   Slave *slave = lookupSlave(task.slave_id());
   CHECK(slave != NULL);
 
+  // Determine the executor ID for this task.
+  const ExecutorID& executorId = task.has_executor()
+    ? task.executor().executor_id()
+    : framework->info.executor().executor_id();
+
   Task *t = new Task();
+  t->mutable_framework_id()->MergeFrom(framework->frameworkId);
+  t->mutable_executor_id()->MergeFrom(executorId);
+  t->set_state(TASK_STARTING);
   t->set_name(task.name());
   t->mutable_task_id()->MergeFrom(task.task_id());
-  t->mutable_framework_id()->MergeFrom(framework->frameworkId);
   t->mutable_slave_id()->MergeFrom(task.slave_id());
   t->mutable_resources()->MergeFrom(task.resources());
-  t->set_state(TASK_STARTING);
 
   framework->addTask(t);
   slave->addTask(t);

Modified: incubator/mesos/trunk/src/messaging/messages.proto
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/messaging/messages.proto?rev=1132243&r1=1132242&r2=1132243&view=diff
==============================================================================
--- incubator/mesos/trunk/src/messaging/messages.proto (original)
+++ incubator/mesos/trunk/src/messaging/messages.proto Sun Jun  5 09:06:31 2011
@@ -3,18 +3,20 @@ import "mesos.proto";
 package mesos.internal;
 
 // TODO(benh): It would be great if this could just be a
-// TaskDescription wherever it gets used! We would need to add both
-// the framework_id field and the state field into TaskDescription
-// though. Also, one performance reason why we don't do that now is
+// TaskDescription wherever it gets used! However, doing so would
+// require adding the framework_id field, the executor_id field, and
+// the state field into TaskDescription though (or send them another
+// way). Also, one performance reason why we don't do that now is
 // because storing whatever data is coupled with a TaskDescription
 // could be large and unnecessary.
 message Task {
   required FrameworkID framework_id = 1;
-  required TaskState state = 2;
-  required string name = 3;
-  required TaskID task_id = 4;
-  required SlaveID slave_id = 5;
-  repeated Resource resources = 6;
+  required ExecutorID executor_id = 2;
+  required TaskState state = 3;
+  required string name = 4;
+  required TaskID task_id = 5;
+  required SlaveID slave_id = 6;
+  repeated Resource resources = 7;
 }
 
 

Modified: incubator/mesos/trunk/src/slave/process_based_isolation_module.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/process_based_isolation_module.cpp?rev=1132243&r1=1132242&r2=1132243&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/process_based_isolation_module.cpp (original)
+++ incubator/mesos/trunk/src/slave/process_based_isolation_module.cpp Sun Jun  5 09:06:31 2011
@@ -150,7 +150,7 @@ void ProcessBasedIsolationModule::Reaper
   while (true) {
     switch (receive(1)) {
     case PROCESS_TIMEOUT: {
-      // Check whether any child process has exited
+      // Check whether any child process has exited.
       pid_t pid;
       int status;
       if ((pid = waitpid((pid_t) -1, &status, WNOHANG)) > 0) {

Modified: incubator/mesos/trunk/src/slave/slave.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/slave.cpp?rev=1132243&r1=1132242&r2=1132243&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/slave.cpp (original)
+++ incubator/mesos/trunk/src/slave/slave.cpp Sun Jun  5 09:06:31 2011
@@ -41,14 +41,18 @@ Slave::Slave(const Resources& _resources
 Slave::Slave(const Configuration& _conf, bool _local,
              IsolationModule* _isolationModule)
   : conf(_conf), local(_local),
-    isolationModule(_isolationModule), heart(NULL) {}
+    isolationModule(_isolationModule), heart(NULL)
+{
+  resources =
+    Resources::parse(conf.get<string>("resources", "cpus:1;mem:1024"));
+}
 
 
 void Slave::registerOptions(Configurator* configurator)
 {
   // TODO(benh): Is there a way to specify units for the resources?
   configurator->addOption<string>("resources",
-                                  "Total consumable resources on machine\n");
+                                  "Total consumable resources per slave\n");
 //   configurator->addOption<string>("attributes",
 //                                   "Attributes of machine\n");
   configurator->addOption<string>("work_dir",
@@ -134,11 +138,7 @@ state::SlaveState *Slave::getState()
 void Slave::operator () ()
 {
   LOG(INFO) << "Slave started at " << self();
-
-  resources =
-    Resources::parse(conf.get<string>("resources", "cpus:1;mem:1024"));
-
-  LOG(INFO) << "Resources: " << resources;
+  LOG(INFO) << "Slave resources: " << resources;
 
   // Get our hostname
   char buf[256];

Modified: incubator/mesos/trunk/src/slave/slave.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/slave.hpp?rev=1132243&r1=1132242&r2=1132243&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/slave.hpp (original)
+++ incubator/mesos/trunk/src/slave/slave.hpp Sun Jun  5 09:06:31 2011
@@ -70,6 +70,7 @@ struct Executor
 
     Task *t = new Task();
     t->mutable_framework_id()->MergeFrom(frameworkId);
+    t->mutable_executor_id()->MergeFrom(info.executor_id());
     t->set_state(TASK_STARTING);
     t->set_name(task.name());
     t->mutable_task_id()->MergeFrom(task.task_id());

Modified: incubator/mesos/trunk/src/tests/master_test.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/master_test.cpp?rev=1132243&r1=1132242&r2=1132243&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/master_test.cpp (original)
+++ incubator/mesos/trunk/src/tests/master_test.cpp Sun Jun  5 09:06:31 2011
@@ -44,44 +44,59 @@ using testing::Sequence;
 using testing::StrEq;
 
 
-class LocalIsolationModule : public slave::IsolationModule
+class TestingIsolationModule : public slave::IsolationModule
 {
 public:
-  Executor* executor;
-  MesosExecutorDriver* driver;
-  string pid;
+  TestingIsolationModule(const map<ExecutorID, Executor*>& _executors)
+    : executors(_executors) {}
 
-  LocalIsolationModule(Executor* _executor)
-    : executor(_executor), driver(NULL) {}
+  virtual ~TestingIsolationModule() {}
 
-  virtual ~LocalIsolationModule() {}
-
-  virtual void initialize(slave::Slave* slave) {
-    pid = slave->self();
+  virtual void initialize(Slave* _slave)
+  {
+    slave = _slave;
   }
 
-  virtual void launchExecutor(slave::Framework* f, slave::Executor* e) {
-    // TODO(benh): Cleanup the way we launch local drivers!
-    setenv("MESOS_LOCAL", "1", 1);
-    setenv("MESOS_SLAVE_PID", pid.c_str(), 1);
-    setenv("MESOS_FRAMEWORK_ID", f->frameworkId.value().c_str(), 1);
-    setenv("MESOS_EXECUTOR_ID", e->info.executor_id().value().c_str(), 1);
-
-    driver = new MesosExecutorDriver(executor);
-    driver->start();
+  virtual void launchExecutor(slave::Framework* f, slave::Executor* e)
+  {
+    if (executors.count(e->info.executor_id()) > 0) {
+      Executor* executor = executors[e->info.executor_id()];
+      MesosExecutorDriver* driver = new MesosExecutorDriver(executor);
+      drivers[e->info.executor_id()] = driver;
+
+      setenv("MESOS_LOCAL", "1", 1);
+      setenv("MESOS_SLAVE_PID", string(slave->self()).c_str(), 1);
+      setenv("MESOS_FRAMEWORK_ID", f->frameworkId.value().c_str(), 1);
+      setenv("MESOS_EXECUTOR_ID", e->info.executor_id().value().c_str(), 1);
+
+      driver->start();
+
+      unsetenv("MESOS_LOCAL");
+      unsetenv("MESOS_SLAVE_PID");
+      unsetenv("MESOS_FRAMEWORK_ID");
+      unsetenv("MESOS_EXECUTOR_ID");
+    } else {
+      FAIL() << "Cannot launch executor";
+    }
   }
 
-  virtual void killExecutor(slave::Framework* f, slave::Executor* e) {
-    driver->stop();
-    driver->join();
-    delete driver;
-
-    // TODO(benh): Cleanup the way we launch local drivers!
-    unsetenv("MESOS_LOCAL");
-    unsetenv("MESOS_SLAVE_PID");
-    unsetenv("MESOS_FRAMEWORK_ID");
-    unsetenv("MESOS_EXECUTOR_ID");
+  virtual void killExecutor(slave::Framework* f, slave::Executor* e)
+  {
+    if (drivers.count(e->info.executor_id()) > 0) {
+      MesosExecutorDriver* driver = drivers[e->info.executor_id()];
+      driver->stop();
+      driver->join();
+      delete driver;
+      drivers.erase(e->info.executor_id());
+    } else {
+      FAIL() << "Cannot kill executor";
+    }
   }
+
+private:
+  map<ExecutorID, Executor*> executors;
+  map<ExecutorID, MesosExecutorDriver*> drivers;
+  Slave* slave;
 };
 
 
@@ -301,20 +316,7 @@ TEST(MasterTest, SlaveLost)
   Master m;
   PID master = Process::spawn(&m);
 
-  Resources resources;
-
-  Resource cpus;
-  cpus.set_name("cpus");
-  cpus.set_type(Resource::SCALAR);
-  cpus.mutable_scalar()->set_value(2);
-
-  Resource mem;
-  mem.set_name("mem");
-  mem.set_type(Resource::SCALAR);
-  mem.mutable_scalar()->set_value(1 * Gigabyte);
-
-  resources += cpus;
-  resources += mem;
+  Resources resources = Resources::parse("cpus:2;mem:1024");
 
   ProcessBasedIsolationModule isolationModule;
   
@@ -514,20 +516,7 @@ TEST(MasterTest, TaskRunning)
   Master m;
   PID master = Process::spawn(&m);
 
-  Resources resources;
-
-  Resource cpus;
-  cpus.set_name("cpus");
-  cpus.set_type(Resource::SCALAR);
-  cpus.mutable_scalar()->set_value(2);
-
-  Resource mem;
-  mem.set_name("mem");
-  mem.set_type(Resource::SCALAR);
-  mem.mutable_scalar()->set_value(1 * Gigabyte);
-
-  resources += cpus;
-  resources += mem;
+  Resources resources = Resources::parse("cpus:2;mem:1024");
 
   MockExecutor exec;
 
@@ -540,7 +529,13 @@ TEST(MasterTest, TaskRunning)
   EXPECT_CALL(exec, shutdown(_))
     .Times(1);
 
-  LocalIsolationModule isolationModule(&exec);
+  ExecutorID executorId;
+  executorId.set_value("default");
+
+  map<ExecutorID, Executor*> execs;
+  execs[executorId] = &exec;
+
+  TestingIsolationModule isolationModule(execs);
 
   Slave s(resources, true, &isolationModule);
   PID slave = Process::spawn(&s);
@@ -560,7 +555,7 @@ TEST(MasterTest, TaskRunning)
     .WillOnce(Return(""));
 
   EXPECT_CALL(sched, getExecutorInfo(&driver))
-    .WillOnce(Return(DEFAULT_EXECUTOR_INFO));
+    .WillOnce(Return(CREATE_EXECUTOR_INFO(executorId, "noexecutor")));
 
   EXPECT_CALL(sched, registered(&driver, _))
     .Times(1);
@@ -611,20 +606,7 @@ TEST(MasterTest, KillTask)
   Master m;
   PID master = Process::spawn(&m);
 
-  Resources resources;
-
-  Resource cpus;
-  cpus.set_name("cpus");
-  cpus.set_type(Resource::SCALAR);
-  cpus.mutable_scalar()->set_value(2);
-
-  Resource mem;
-  mem.set_name("mem");
-  mem.set_type(Resource::SCALAR);
-  mem.mutable_scalar()->set_value(1 * Gigabyte);
-
-  resources += cpus;
-  resources += mem;
+  Resources resources = Resources::parse("cpus:2;mem:1024");
 
   MockExecutor exec;
 
@@ -642,7 +624,13 @@ TEST(MasterTest, KillTask)
   EXPECT_CALL(exec, shutdown(_))
     .Times(1);
 
-  LocalIsolationModule isolationModule(&exec);
+  ExecutorID executorId;
+  executorId.set_value("default");
+
+  map<ExecutorID, Executor*> execs;
+  execs[executorId] = &exec;
+
+  TestingIsolationModule isolationModule(execs);
 
   Slave s(resources, true, &isolationModule);
   PID slave = Process::spawn(&s);
@@ -662,7 +650,7 @@ TEST(MasterTest, KillTask)
     .WillOnce(Return(""));
 
   EXPECT_CALL(sched, getExecutorInfo(&driver))
-    .WillOnce(Return(DEFAULT_EXECUTOR_INFO));
+    .WillOnce(Return(CREATE_EXECUTOR_INFO(executorId, "noexecutor")));
 
   EXPECT_CALL(sched, registered(&driver, _))
     .Times(1);
@@ -728,20 +716,7 @@ TEST(MasterTest, SchedulerFailoverStatus
   Master m;
   PID master = Process::spawn(&m);
 
-  Resources resources;
-
-  Resource cpus;
-  cpus.set_name("cpus");
-  cpus.set_type(Resource::SCALAR);
-  cpus.mutable_scalar()->set_value(2);
-
-  Resource mem;
-  mem.set_name("mem");
-  mem.set_type(Resource::SCALAR);
-  mem.mutable_scalar()->set_value(1 * Gigabyte);
-
-  resources += cpus;
-  resources += mem;
+  Resources resources = Resources::parse("cpus:2;mem:1024");
 
   MockExecutor exec;
 
@@ -754,7 +729,13 @@ TEST(MasterTest, SchedulerFailoverStatus
   EXPECT_CALL(exec, shutdown(_))
     .Times(1);
 
-  LocalIsolationModule isolationModule(&exec);
+  ExecutorID executorId;
+  executorId.set_value("default");
+
+  map<ExecutorID, Executor*> execs;
+  execs[executorId] = &exec;
+
+  TestingIsolationModule isolationModule(execs);
 
   Slave s(resources, true, &isolationModule);
   PID slave = Process::spawn(&s);
@@ -777,7 +758,7 @@ TEST(MasterTest, SchedulerFailoverStatus
     .WillOnce(Return(""));
 
   EXPECT_CALL(sched1, getExecutorInfo(&driver1))
-    .WillOnce(Return(DEFAULT_EXECUTOR_INFO));
+    .WillOnce(Return(CREATE_EXECUTOR_INFO(executorId, "noexecutor")));
 
   EXPECT_CALL(sched1, registered(&driver1, _))
     .WillOnce(SaveArg<1>(&frameworkId));
@@ -870,20 +851,7 @@ TEST(MasterTest, FrameworkMessage)
   Master m;
   PID master = Process::spawn(&m);
 
-  Resources resources;
-
-  Resource cpus;
-  cpus.set_name("cpus");
-  cpus.set_type(Resource::SCALAR);
-  cpus.mutable_scalar()->set_value(2);
-
-  Resource mem;
-  mem.set_name("mem");
-  mem.set_type(Resource::SCALAR);
-  mem.mutable_scalar()->set_value(1 * Gigabyte);
-
-  resources += cpus;
-  resources += mem;
+  Resources resources = Resources::parse("cpus:2;mem:1024");
 
   MockExecutor exec;
 
@@ -906,7 +874,13 @@ TEST(MasterTest, FrameworkMessage)
   EXPECT_CALL(exec, shutdown(_))
     .Times(1);
 
-  LocalIsolationModule isolationModule(&exec);
+  ExecutorID executorId;
+  executorId.set_value("default");
+
+  map<ExecutorID, Executor*> execs;
+  execs[executorId] = &exec;
+
+  TestingIsolationModule isolationModule(execs);
 
   Slave s(resources, true, &isolationModule);
   PID slave = Process::spawn(&s);
@@ -930,7 +904,7 @@ TEST(MasterTest, FrameworkMessage)
     .WillOnce(Return(""));
 
   EXPECT_CALL(sched, getExecutorInfo(&schedDriver))
-    .WillOnce(Return(DEFAULT_EXECUTOR_INFO));
+    .WillOnce(Return(CREATE_EXECUTOR_INFO(executorId, "noexecutor")));
 
   EXPECT_CALL(sched, registered(&schedDriver, _))
     .Times(1);
@@ -968,7 +942,7 @@ TEST(MasterTest, FrameworkMessage)
   EXPECT_EQ(TASK_RUNNING, status.state());
 
   FrameworkMessage hello;
-  *hello.mutable_slave_id() = offers[0].slave_id();
+  hello.mutable_slave_id()->MergeFrom(offers[0].slave_id());
   hello.mutable_executor_id()->set_value("default"); // TODO(benh): No constant!
   hello.set_data("hello");
 
@@ -979,7 +953,7 @@ TEST(MasterTest, FrameworkMessage)
   EXPECT_EQ("hello", execMessage.data());
 
   FrameworkMessage reply;
-  *reply.mutable_slave_id() = args.slave_id();
+  reply.mutable_slave_id()->MergeFrom(args.slave_id());
   reply.mutable_executor_id()->set_value("default"); // TODO(benh): No constant!
   reply.set_data("reply");
 
@@ -1007,20 +981,7 @@ TEST(MasterTest, SchedulerFailoverFramew
   Master m;
   PID master = Process::spawn(&m);
 
-  Resources resources;
-
-  Resource cpus;
-  cpus.set_name("cpus");
-  cpus.set_type(Resource::SCALAR);
-  cpus.mutable_scalar()->set_value(2);
-
-  Resource mem;
-  mem.set_name("mem");
-  mem.set_type(Resource::SCALAR);
-  mem.mutable_scalar()->set_value(1 * Gigabyte);
-
-  resources += cpus;
-  resources += mem;
+  Resources resources = Resources::parse("cpus:2;mem:1024");
 
   MockExecutor exec;
 
@@ -1035,7 +996,13 @@ TEST(MasterTest, SchedulerFailoverFramew
   EXPECT_CALL(exec, shutdown(_))
     .Times(1);
 
-  LocalIsolationModule isolationModule(&exec);
+  ExecutorID executorId;
+  executorId.set_value("default");
+
+  map<ExecutorID, Executor*> execs;
+  execs[executorId] = &exec;
+
+  TestingIsolationModule isolationModule(execs);
 
   Slave s(resources, true, &isolationModule);
   PID slave = Process::spawn(&s);
@@ -1056,7 +1023,7 @@ TEST(MasterTest, SchedulerFailoverFramew
     .WillOnce(Return(""));
 
   EXPECT_CALL(sched1, getExecutorInfo(&driver1))
-    .WillOnce(Return(DEFAULT_EXECUTOR_INFO));
+    .WillOnce(Return(CREATE_EXECUTOR_INFO(executorId, "noexecutor")));
 
   EXPECT_CALL(sched1, registered(&driver1, _))
     .WillOnce(SaveArg<1>(&frameworkId));
@@ -1133,3 +1100,138 @@ TEST(MasterTest, SchedulerFailoverFramew
   MesosProcess::post(master, M2M_SHUTDOWN);
   Process::wait(master);
 }
+
+
+TEST(MasterTest, MultipleExecutors)
+{
+  ASSERT_TRUE(GTEST_IS_THREADSAFE);
+
+  Master m;
+  PID master = Process::spawn(&m);
+
+  Resources resources = Resources::parse("cpus:2;mem:1024");
+
+  MockExecutor exec1;
+  TaskDescription exec1Task;
+  trigger exec1LaunchTaskCall;
+
+  EXPECT_CALL(exec1, init(_, _))
+    .Times(1);
+
+  EXPECT_CALL(exec1, launchTask(_, _))
+    .WillOnce(DoAll(SaveArg<1>(&exec1Task),
+                    Trigger(&exec1LaunchTaskCall)));
+
+  EXPECT_CALL(exec1, shutdown(_))
+    .Times(1);
+
+  MockExecutor exec2;
+  TaskDescription exec2Task;
+  trigger exec2LaunchTaskCall;
+
+  EXPECT_CALL(exec2, init(_, _))
+    .Times(1);
+
+  EXPECT_CALL(exec2, launchTask(_, _))
+    .WillOnce(DoAll(SaveArg<1>(&exec2Task),
+                    Trigger(&exec2LaunchTaskCall)));
+
+  EXPECT_CALL(exec2, shutdown(_))
+    .Times(1);
+
+  ExecutorID executorId1;
+  executorId1.set_value("executor-1");
+
+  ExecutorID executorId2;
+  executorId2.set_value("executor-2");
+
+  map<ExecutorID, Executor*> execs;
+  execs[executorId1] = &exec1;
+  execs[executorId2] = &exec2;
+
+  TestingIsolationModule isolationModule(execs);
+
+  Slave s(resources, true, &isolationModule);
+  PID slave = Process::spawn(&s);
+
+  BasicMasterDetector detector(master, slave, true);
+
+  MockScheduler sched;
+  MesosSchedulerDriver driver(&sched, master);
+
+  OfferID offerId;
+  vector<SlaveOffer> offers;
+  TaskStatus status1, status2;
+
+  trigger resourceOfferCall, statusUpdateCall1, statusUpdateCall2;
+
+  EXPECT_CALL(sched, getFrameworkName(&driver))
+    .WillOnce(Return(""));
+
+  EXPECT_CALL(sched, getExecutorInfo(&driver))
+    .WillOnce(Return(DEFAULT_EXECUTOR_INFO));
+
+  EXPECT_CALL(sched, registered(&driver, _))
+    .Times(1);
+
+  EXPECT_CALL(sched, resourceOffer(&driver, _, _))
+    .WillOnce(DoAll(SaveArg<1>(&offerId), SaveArg<2>(&offers),
+                    Trigger(&resourceOfferCall)));
+
+  EXPECT_CALL(sched, statusUpdate(&driver, _))
+    .WillOnce(DoAll(SaveArg<1>(&status1), Trigger(&statusUpdateCall1)))
+    .WillOnce(DoAll(SaveArg<1>(&status2), Trigger(&statusUpdateCall2)));
+
+  driver.start();
+
+  WAIT_UNTIL(resourceOfferCall);
+
+  ASSERT_NE(0, offers.size());
+
+  TaskDescription task1;
+  task1.set_name("");
+  task1.mutable_task_id()->set_value("1");
+  task1.mutable_slave_id()->MergeFrom(offers[0].slave_id());
+  task1.mutable_resources()->MergeFrom(Resources::parse("cpus:1;mem:512"));
+  task1.mutable_executor()->mutable_executor_id()->MergeFrom(executorId1);
+  task1.mutable_executor()->set_uri("noexecutor");
+
+  TaskDescription task2;
+  task2.set_name("");
+  task2.mutable_task_id()->set_value("2");
+  task2.mutable_slave_id()->MergeFrom(offers[0].slave_id());
+  task2.mutable_resources()->MergeFrom(Resources::parse("cpus:1;mem:512"));
+  task2.mutable_executor()->mutable_executor_id()->MergeFrom(executorId2);
+  task2.mutable_executor()->set_uri("noexecutor");
+
+  vector<TaskDescription> tasks;
+  tasks.push_back(task1);
+  tasks.push_back(task2);
+
+  driver.replyToOffer(offerId, tasks);
+
+  WAIT_UNTIL(statusUpdateCall1);
+
+  EXPECT_EQ(TASK_RUNNING, status1.state());
+
+  WAIT_UNTIL(statusUpdateCall2);
+
+  EXPECT_EQ(TASK_RUNNING, status2.state());
+
+  WAIT_UNTIL(exec1LaunchTaskCall);
+
+  EXPECT_EQ(task1.task_id(), exec1Task.task_id());
+
+  WAIT_UNTIL(exec2LaunchTaskCall);
+
+  EXPECT_EQ(task2.task_id(), exec2Task.task_id());
+
+  driver.stop();
+  driver.join();
+
+  MesosProcess::post(slave, S2S_SHUTDOWN);
+  Process::wait(slave);
+
+  MesosProcess::post(master, M2M_SHUTDOWN);
+  Process::wait(master);
+}

Modified: incubator/mesos/trunk/src/tests/utils.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/utils.hpp?rev=1132243&r1=1132242&r2=1132243&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/utils.hpp (original)
+++ incubator/mesos/trunk/src/tests/utils.hpp Sun Jun  5 09:06:31 2011
@@ -43,13 +43,20 @@ void enterTestDirectory(const char* test
 
 
 /**
- * Macro to get a "default" dummy ExecutorInfo object for testing.
+ * Macros to get a "default" dummy ExecutorInfo object for testing or
+ * create one out of an ExecutorID and string.
  */
 #define DEFAULT_EXECUTOR_INFO                                           \
-      ({ ExecutorInfo executor;                                         \
-        executor.mutable_executor_id()->set_value("default");           \
-        executor.set_uri("noexecutor");                                 \
-        executor; })
+  ({ ExecutorInfo executor;                                             \
+    executor.mutable_executor_id()->set_value("default");               \
+    executor.set_uri("noexecutor");                                     \
+    executor; })
+
+#define CREATE_EXECUTOR_INFO(executorId, uri)                           \
+  ({ ExecutorInfo executor;                                             \
+    executor.mutable_executor_id()->MergeFrom(executorId);              \
+    executor.set_uri(uri);                                              \
+    executor; })
 
 
 /**