You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2014/03/25 18:06:28 UTC
git commit: MESOS-610: Split slave specific tests out of master_tests.
Repository: mesos
Updated Branches:
refs/heads/master 7c366bad6 -> 4db81dbfc
MESOS-610: Split slave specific tests out of master_tests.
Review: https://reviews.apache.org/r/18752
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/4db81dbf
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/4db81dbf
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/4db81dbf
Branch: refs/heads/master
Commit: 4db81dbfcbb8157446fda94eac2bc971f384b635
Parents: 7c366ba
Author: Bernd Mathiske <be...@mesosphere.io>
Authored: Tue Mar 25 10:05:56 2014 -0700
Committer: Vinod Kone <vi...@twitter.com>
Committed: Tue Mar 25 10:05:56 2014 -0700
----------------------------------------------------------------------
src/Makefile.am | 1 +
src/tests/master_tests.cpp | 171 +---------------------------
src/tests/slave_tests.cpp | 247 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 251 insertions(+), 168 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/4db81dbf/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 0775a0d..47d03b3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -888,6 +888,7 @@ mesos_tests_SOURCES = \
tests/sasl_tests.cpp \
tests/script.cpp \
tests/slave_recovery_tests.cpp \
+ tests/slave_tests.cpp \
tests/sorter_tests.cpp \
tests/state_tests.cpp \
tests/status_update_manager_tests.cpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/4db81dbf/src/tests/master_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_tests.cpp b/src/tests/master_tests.cpp
index 4395883..39c8c23 100644
--- a/src/tests/master_tests.cpp
+++ b/src/tests/master_tests.cpp
@@ -20,7 +20,6 @@
#include <gmock/gmock.h>
-#include <map>
#include <string>
#include <vector>
@@ -69,7 +68,6 @@ using process::Future;
using process::Owned;
using process::PID;
-using std::map;
using std::string;
using std::vector;
@@ -79,6 +77,9 @@ using testing::DoAll;
using testing::Eq;
using testing::Return;
+// Those of the overall Mesos master/slave/scheduler/driver tests
+// that seem vaguely more master than slave-related are in this file.
+// The others are in "slave_tests.cpp".
class MasterTest : public MesosTest {};
@@ -684,172 +685,6 @@ TEST_F(MasterTest, MultipleExecutors)
}
-TEST_F(MasterTest, ShutdownUnregisteredExecutor)
-{
- Try<PID<Master> > master = StartMaster();
- ASSERT_SOME(master);
-
- // Need flags for 'executor_registration_timeout'.
- slave::Flags flags = CreateSlaveFlags();
- // Set the isolation flag so we know a MesoContainerizer will be created.
- flags.isolation = "posix/cpu,posix/mem";
-
- Try<Containerizer*> containerizer = Containerizer::create(flags, false);
- CHECK_SOME(containerizer);
-
- Try<PID<Slave> > slave = StartSlave(containerizer.get());
- ASSERT_SOME(slave);
-
- MockScheduler sched;
- MesosSchedulerDriver driver(
- &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);
-
- EXPECT_CALL(sched, registered(&driver, _, _))
- .Times(1);
-
- Future<vector<Offer> > offers;
- EXPECT_CALL(sched, resourceOffers(&driver, _))
- .WillOnce(FutureArg<1>(&offers))
- .WillRepeatedly(Return()); // Ignore subsequent offers.
-
- driver.start();
-
- AWAIT_READY(offers);
- EXPECT_NE(0u, offers.get().size());
-
- // Launch a task with the command executor.
- TaskInfo task;
- task.set_name("");
- task.mutable_task_id()->set_value("1");
- task.mutable_slave_id()->MergeFrom(offers.get()[0].slave_id());
- task.mutable_resources()->MergeFrom(offers.get()[0].resources());
-
- CommandInfo command;
- command.set_value("sleep 10");
-
- task.mutable_command()->MergeFrom(command);
-
- vector<TaskInfo> tasks;
- tasks.push_back(task);
-
- // Drop the registration message from the executor to the slave.
- Future<process::Message> registerExecutor =
- DROP_MESSAGE(Eq(RegisterExecutorMessage().GetTypeName()), _, _);
-
- driver.launchTasks(offers.get()[0].id(), tasks);
-
- AWAIT_READY(registerExecutor);
-
- Clock::pause();
-
- Future<TaskStatus> status;
- EXPECT_CALL(sched, statusUpdate(&driver, _))
- .WillOnce(FutureArg<1>(&status));
-
- // Ensure that the slave times out and kills the executor.
- Future<Nothing> destroyExecutor =
- FUTURE_DISPATCH(_, &MesosContainerizerProcess::destroy);
-
- Clock::advance(flags.executor_registration_timeout);
-
- AWAIT_READY(destroyExecutor);
-
- Clock::settle(); // Wait for Containerizer::destroy to complete.
-
- // Now advance time until the reaper reaps the executor.
- while (status.isPending()) {
- Clock::advance(Seconds(1));
- Clock::settle();
- }
-
- AWAIT_READY(status);
- ASSERT_EQ(TASK_FAILED, status.get().state());
-
- Clock::resume();
-
- driver.stop();
- driver.join();
-
- Shutdown(); // Must shutdown before 'containerizer' gets deallocated.
-}
-
-
-// This test verifies that when an executor terminates before
-// registering with slave, it is properly cleaned up.
-TEST_F(MasterTest, RemoveUnregisteredTerminatedExecutor)
-{
- Try<PID<Master> > master = StartMaster();
- ASSERT_SOME(master);
-
- MockExecutor exec(DEFAULT_EXECUTOR_ID);
-
- TestContainerizer containerizer(&exec);
-
- Try<PID<Slave> > slave = StartSlave(&containerizer);
- ASSERT_SOME(slave);
-
- MockScheduler sched;
- MesosSchedulerDriver driver(
- &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);
-
- EXPECT_CALL(sched, registered(&driver, _, _))
- .Times(1);
-
- Future<vector<Offer> > offers;
- EXPECT_CALL(sched, resourceOffers(&driver, _))
- .WillOnce(FutureArg<1>(&offers))
- .WillRepeatedly(Return()); // Ignore subsequent offers.
-
- driver.start();
-
- AWAIT_READY(offers);
- EXPECT_NE(0u, offers.get().size());
-
- TaskInfo task;
- task.set_name("");
- task.mutable_task_id()->set_value("1");
- task.mutable_slave_id()->MergeFrom(offers.get()[0].slave_id());
- task.mutable_resources()->MergeFrom(offers.get()[0].resources());
- task.mutable_executor()->MergeFrom(DEFAULT_EXECUTOR_INFO);
-
- vector<TaskInfo> tasks;
- tasks.push_back(task);
-
- // Drop the registration message from the executor to the slave.
- Future<process::Message> registerExecutorMessage =
- DROP_MESSAGE(Eq(RegisterExecutorMessage().GetTypeName()), _, _);
-
- driver.launchTasks(offers.get()[0].id(), tasks);
-
- AWAIT_READY(registerExecutorMessage);
-
- Future<TaskStatus> status;
- EXPECT_CALL(sched, statusUpdate(&driver, _))
- .WillOnce(FutureArg<1>(&status));
-
- Future<Nothing> schedule =
- FUTURE_DISPATCH(_, &GarbageCollectorProcess::schedule);
-
- // Now kill the executor.
- containerizer.destroy(offers.get()[0].framework_id(), DEFAULT_EXECUTOR_ID);
-
- AWAIT_READY(status);
- EXPECT_EQ(TASK_LOST, status.get().state());
-
- // We use 'gc.schedule' as a signal for the executor being cleaned
- // up by the slave.
- AWAIT_READY(schedule);
-
- EXPECT_CALL(exec, shutdown(_))
- .Times(AtMost(1));
-
- driver.stop();
- driver.join();
-
- Shutdown(); // Must shutdown before 'containerizer' gets deallocated.
-}
-
-
TEST_F(MasterTest, MasterInfo)
{
Try<PID<Master> > master = StartMaster();
http://git-wip-us.apache.org/repos/asf/mesos/blob/4db81dbf/src/tests/slave_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/slave_tests.cpp b/src/tests/slave_tests.cpp
new file mode 100644
index 0000000..07ce882
--- /dev/null
+++ b/src/tests/slave_tests.cpp
@@ -0,0 +1,247 @@
+/**
+ * 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 <unistd.h>
+
+#include <gmock/gmock.h>
+
+#include <string>
+#include <vector>
+
+#include <mesos/executor.hpp>
+#include <mesos/scheduler.hpp>
+
+#include <process/clock.hpp>
+#include <process/future.hpp>
+#include <process/gmock.hpp>
+#include <process/owned.hpp>
+#include <process/pid.hpp>
+
+#include <stout/option.hpp>
+#include <stout/os.hpp>
+#include <stout/try.hpp>
+
+#include "master/flags.hpp"
+#include "master/master.hpp"
+
+#include "slave/constants.hpp"
+#include "slave/containerizer/mesos_containerizer.hpp"
+#include "slave/gc.hpp"
+#include "slave/flags.hpp"
+#include "slave/slave.hpp"
+
+#include "tests/containerizer.hpp"
+#include "tests/mesos.hpp"
+
+using namespace mesos;
+using namespace mesos::internal;
+using namespace mesos::internal::tests;
+
+using mesos::internal::master::Master;
+
+using mesos::internal::slave::GarbageCollectorProcess;
+using mesos::internal::slave::Slave;
+using mesos::internal::slave::Containerizer;
+using mesos::internal::slave::MesosContainerizerProcess;
+
+using process::Clock;
+using process::Future;
+using process::Owned;
+using process::PID;
+
+using std::string;
+using std::vector;
+
+using testing::_;
+using testing::AtMost;
+using testing::DoAll;
+using testing::Eq;
+using testing::Return;
+
+// Those of the overall Mesos master/slave/scheduler/driver tests
+// that seem vaguely more slave than master-related are in this file.
+// The others are in "master_tests.cpp".
+
+class SlaveTest : public MesosTest {};
+
+
+TEST_F(SlaveTest, ShutdownUnregisteredExecutor)
+{
+ Try<PID<Master> > master = StartMaster();
+ ASSERT_SOME(master);
+
+ // Need flags for 'executor_registration_timeout'.
+ slave::Flags flags = CreateSlaveFlags();
+ // Set the isolation flag so we know a MesoContainerizer will be created.
+ flags.isolation = "posix/cpu,posix/mem";
+
+ Try<Containerizer*> containerizer = Containerizer::create(flags, false);
+ CHECK_SOME(containerizer);
+
+ Try<PID<Slave> > slave = StartSlave(containerizer.get());
+ ASSERT_SOME(slave);
+
+ MockScheduler sched;
+ MesosSchedulerDriver driver(
+ &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);
+
+ EXPECT_CALL(sched, registered(&driver, _, _))
+ .Times(1);
+
+ Future<vector<Offer> > offers;
+ EXPECT_CALL(sched, resourceOffers(&driver, _))
+ .WillOnce(FutureArg<1>(&offers))
+ .WillRepeatedly(Return()); // Ignore subsequent offers.
+
+ driver.start();
+
+ AWAIT_READY(offers);
+ EXPECT_NE(0u, offers.get().size());
+
+ // Launch a task with the command executor.
+ TaskInfo task;
+ task.set_name("");
+ task.mutable_task_id()->set_value("1");
+ task.mutable_slave_id()->MergeFrom(offers.get()[0].slave_id());
+ task.mutable_resources()->MergeFrom(offers.get()[0].resources());
+
+ CommandInfo command;
+ command.set_value("sleep 10");
+
+ task.mutable_command()->MergeFrom(command);
+
+ vector<TaskInfo> tasks;
+ tasks.push_back(task);
+
+ // Drop the registration message from the executor to the slave.
+ Future<process::Message> registerExecutor =
+ DROP_MESSAGE(Eq(RegisterExecutorMessage().GetTypeName()), _, _);
+
+ driver.launchTasks(offers.get()[0].id(), tasks);
+
+ AWAIT_READY(registerExecutor);
+
+ Clock::pause();
+
+ Future<TaskStatus> status;
+ EXPECT_CALL(sched, statusUpdate(&driver, _))
+ .WillOnce(FutureArg<1>(&status));
+
+ // Ensure that the slave times out and kills the executor.
+ Future<Nothing> destroyExecutor =
+ FUTURE_DISPATCH(_, &MesosContainerizerProcess::destroy);
+
+ Clock::advance(flags.executor_registration_timeout);
+
+ AWAIT_READY(destroyExecutor);
+
+ Clock::settle(); // Wait for Containerizer::destroy to complete.
+
+ // Now advance time until the reaper reaps the executor.
+ while (status.isPending()) {
+ Clock::advance(Seconds(1));
+ Clock::settle();
+ }
+
+ AWAIT_READY(status);
+ ASSERT_EQ(TASK_FAILED, status.get().state());
+
+ Clock::resume();
+
+ driver.stop();
+ driver.join();
+
+ Shutdown(); // Must shutdown before 'containerizer' gets deallocated.
+}
+
+
+// This test verifies that when an executor terminates before
+// registering with slave, it is properly cleaned up.
+TEST_F(SlaveTest, RemoveUnregisteredTerminatedExecutor)
+{
+ Try<PID<Master> > master = StartMaster();
+ ASSERT_SOME(master);
+
+ MockExecutor exec(DEFAULT_EXECUTOR_ID);
+
+ TestContainerizer containerizer(&exec);
+
+ Try<PID<Slave> > slave = StartSlave(&containerizer);
+ ASSERT_SOME(slave);
+
+ MockScheduler sched;
+ MesosSchedulerDriver driver(
+ &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);
+
+ EXPECT_CALL(sched, registered(&driver, _, _))
+ .Times(1);
+
+ Future<vector<Offer> > offers;
+ EXPECT_CALL(sched, resourceOffers(&driver, _))
+ .WillOnce(FutureArg<1>(&offers))
+ .WillRepeatedly(Return()); // Ignore subsequent offers.
+
+ driver.start();
+
+ AWAIT_READY(offers);
+ EXPECT_NE(0u, offers.get().size());
+
+ TaskInfo task;
+ task.set_name("");
+ task.mutable_task_id()->set_value("1");
+ task.mutable_slave_id()->MergeFrom(offers.get()[0].slave_id());
+ task.mutable_resources()->MergeFrom(offers.get()[0].resources());
+ task.mutable_executor()->MergeFrom(DEFAULT_EXECUTOR_INFO);
+
+ vector<TaskInfo> tasks;
+ tasks.push_back(task);
+
+ // Drop the registration message from the executor to the slave.
+ Future<process::Message> registerExecutorMessage =
+ DROP_MESSAGE(Eq(RegisterExecutorMessage().GetTypeName()), _, _);
+
+ driver.launchTasks(offers.get()[0].id(), tasks);
+
+ AWAIT_READY(registerExecutorMessage);
+
+ Future<TaskStatus> status;
+ EXPECT_CALL(sched, statusUpdate(&driver, _))
+ .WillOnce(FutureArg<1>(&status));
+
+ Future<Nothing> schedule =
+ FUTURE_DISPATCH(_, &GarbageCollectorProcess::schedule);
+
+ // Now kill the executor.
+ containerizer.destroy(offers.get()[0].framework_id(), DEFAULT_EXECUTOR_ID);
+
+ AWAIT_READY(status);
+ EXPECT_EQ(TASK_LOST, status.get().state());
+
+ // We use 'gc.schedule' as a signal for the executor being cleaned
+ // up by the slave.
+ AWAIT_READY(schedule);
+
+ EXPECT_CALL(exec, shutdown(_))
+ .Times(AtMost(1));
+
+ driver.stop();
+ driver.join();
+
+ Shutdown(); // Must shutdown before 'containerizer' gets deallocated.
+}
+