mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r1132082 - /incubator/mesos/trunk/src/tests/test_master.cpp
Date Sun, 05 Jun 2011 08:38:58 GMT
Author: benh
Date: Sun Jun  5 08:38:58 2011
New Revision: 1132082

URL: http://svn.apache.org/viewvc?rev=1132082&view=rev
Log:
Added a test to check that framework messages can be correctly sent after a scheduler failover.

Modified:
    incubator/mesos/trunk/src/tests/test_master.cpp

Modified: incubator/mesos/trunk/src/tests/test_master.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/test_master.cpp?rev=1132082&r1=1132081&r2=1132082&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/test_master.cpp (original)
+++ incubator/mesos/trunk/src/tests/test_master.cpp Sun Jun  5 08:38:58 2011
@@ -783,3 +783,94 @@ TEST(MasterTest, SchedulerFailoverStatus
 
   ProcessClock::resume();
 }
+
+class FailoverTaskRunningScheduler : public TaskRunningScheduler
+{
+public:
+  TaskRunningScheduler *failover;
+  const PID master;
+  MesosSchedulerDriver *driver;
+
+  FailoverTaskRunningScheduler(TaskRunningScheduler *_failover,
+			       const PID &_master)
+    : failover(_failover), master(_master), driver(NULL) {}
+
+  virtual ~FailoverTaskRunningScheduler() {
+    if (driver != NULL) {
+      driver->join();
+      delete driver;
+      driver = NULL;
+    }
+  }
+
+  virtual void statusUpdate(SchedulerDriver* d, const TaskStatus& status) {
+    EXPECT_EQ(TASK_RUNNING, status.state);
+    statusUpdateCalled = true;
+    driver = new MesosSchedulerDriver(failover, master, fid);
+    driver->start();
+  }
+};
+
+
+class SchedulerFailoverFrameworkMessageScheduler : public TaskRunningScheduler
+{
+public:
+  bool frameworkMessageCalled;
+
+  SchedulerFailoverFrameworkMessageScheduler()
+    : frameworkMessageCalled(false) {}
+
+  virtual void frameworkMessage(SchedulerDriver* d,
+				const FrameworkMessage& message) {
+    frameworkMessageCalled = true;
+    d->stop();
+  }
+};
+
+class SchedulerFailoverFrameworkMessageExecutor : public Executor
+{
+public:
+  ExecutorDriver *driver;
+
+  virtual void init(ExecutorDriver* d, const ExecutorArgs& args) {
+    driver = d;
+  }
+};
+
+
+TEST(MasterTest, SchedulerFailoverFrameworkMessage)
+{
+  ASSERT_TRUE(GTEST_IS_THREADSAFE);
+
+  Master m;
+  PID master = Process::spawn(&m);
+
+  SchedulerFailoverFrameworkMessageExecutor exec;
+  LocalIsolationModule isolationModule(&exec);
+
+  Slave s(Resources(2, 1 * Gigabyte), true, &isolationModule);
+  PID slave = Process::spawn(&s);
+
+  BasicMasterDetector detector(master, slave, true);
+
+  SchedulerFailoverFrameworkMessageScheduler failoverSched;
+  FailoverTaskRunningScheduler failingSched(&failoverSched, master);
+
+  MesosSchedulerDriver driver(&failingSched, master);
+
+  driver.run();
+
+  EXPECT_EQ("Framework failover", failingSched.errorMessage);
+
+  exec.driver->sendFrameworkMessage(FrameworkMessage());
+
+  failingSched.driver->join();
+
+  EXPECT_TRUE(failoverSched.frameworkMessageCalled);
+
+  MesosProcess::post(slave, pack<S2S_SHUTDOWN>());
+  Process::wait(slave);
+
+  MesosProcess::post(master, pack<M2M_SHUTDOWN>());
+  Process::wait(master);
+}



Mime
View raw message