You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2016/02/20 17:37:43 UTC
[07/11] mesos git commit: Added command executor tests for
TASK_KILLING.
Added command executor tests for TASK_KILLING.
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/ee86b136
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/ee86b136
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/ee86b136
Branch: refs/heads/master
Commit: ee86b13633a9469629dbd79681d0776b6020f76a
Parents: 25d303d
Author: Benjamin Mahler <bm...@apache.org>
Authored: Sat Feb 20 16:18:22 2016 +0100
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Sat Feb 20 17:32:26 2016 +0100
----------------------------------------------------------------------
src/Makefile.am | 1 +
src/tests/command_executor_tests.cpp | 180 ++++++++++++++++++++++++++++++
2 files changed, 181 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/ee86b136/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 27aec37..73e7ff0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1803,6 +1803,7 @@ mesos_tests_SOURCES = \
tests/authentication_tests.cpp \
tests/authorization_tests.cpp \
tests/cluster.cpp \
+ tests/command_executor_tests.cpp \
tests/container_logger_tests.cpp \
tests/containerizer.cpp \
tests/cram_md5_authentication_tests.cpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/ee86b136/src/tests/command_executor_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/command_executor_tests.cpp b/src/tests/command_executor_tests.cpp
new file mode 100644
index 0000000..0d2fcf6
--- /dev/null
+++ b/src/tests/command_executor_tests.cpp
@@ -0,0 +1,180 @@
+// 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 <vector>
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include <mesos/mesos.hpp>
+
+#include <process/future.hpp>
+#include <process/gmock.hpp>
+#include <process/gtest.hpp>
+#include <process/pid.hpp>
+
+#include <stout/gtest.hpp>
+
+#include "master/master.hpp"
+
+#include "slave/slave.hpp"
+
+#include "tests/mesos.hpp"
+
+using mesos::internal::master::Master;
+
+using mesos::internal::slave::Slave;
+
+using process::Future;
+using process::PID;
+
+using std::vector;
+
+namespace mesos {
+namespace internal {
+namespace tests {
+
+// Tests that exercise the command executor implementation
+// should be located in this file.
+
+class CommandExecutorTest : public MesosTest {};
+
+
+// This test ensures that the command executor does not send
+// TASK_KILLING to frameworks that do not support the capability.
+TEST_F(CommandExecutorTest, NoTaskKillingCapability)
+{
+ Try<PID<Master>> master = StartMaster();
+ ASSERT_SOME(master);
+
+ Try<PID<Slave>> slave = StartSlave();
+ ASSERT_SOME(slave);
+
+ // Start the framework without the task killing capability.
+ MockScheduler sched;
+ MesosSchedulerDriver driver(
+ &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);
+
+ EXPECT_CALL(sched, registered(&driver, _, _));
+
+ Future<vector<Offer>> offers;
+ EXPECT_CALL(sched, resourceOffers(&driver, _))
+ .WillOnce(FutureArg<1>(&offers))
+ .WillRepeatedly(Return()); // Ignore subsequent offers.
+
+ driver.start();
+
+ AWAIT_READY(offers);
+ EXPECT_EQ(1u, offers->size());
+
+ // Launch a task with the command executor.
+ TaskInfo task = createTask(
+ offers->front().slave_id(),
+ offers->front().resources(),
+ "sleep 1000");
+
+ Future<TaskStatus> statusRunning;
+ EXPECT_CALL(sched, statusUpdate(_, _))
+ .WillOnce(FutureArg<1>(&statusRunning));
+
+ driver.launchTasks(offers->front().id(), {task});
+
+ AWAIT_READY(statusRunning);
+ EXPECT_EQ(TASK_RUNNING, statusRunning->state());
+
+ // There should only be a TASK_KILLED update.
+ Future<TaskStatus> statusKilled;
+ EXPECT_CALL(sched, statusUpdate(_, _))
+ .WillOnce(FutureArg<1>(&statusKilled));
+
+ driver.killTask(task.task_id());
+
+ AWAIT_READY(statusKilled);
+ EXPECT_EQ(TASK_KILLED, statusKilled->state());
+
+ driver.stop();
+ driver.join();
+}
+
+
+// This test ensures that the command executor sends TASK_KILLING
+// to frameworks that support the capability.
+TEST_F(CommandExecutorTest, TaskKillingCapability)
+{
+ Try<PID<Master>> master = StartMaster();
+ ASSERT_SOME(master);
+
+ Try<PID<Slave>> slave = StartSlave();
+ ASSERT_SOME(slave);
+
+ // Start the framework with the task killing capability.
+ FrameworkInfo::Capability capability;
+ capability.set_type(FrameworkInfo::Capability::TASK_KILLING_STATE);
+
+ FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
+ frameworkInfo.add_capabilities()->CopyFrom(capability);
+
+ MockScheduler sched;
+ MesosSchedulerDriver driver(
+ &sched, frameworkInfo, master.get(), DEFAULT_CREDENTIAL);
+
+ EXPECT_CALL(sched, registered(&driver, _, _));
+
+ Future<vector<Offer>> offers;
+ EXPECT_CALL(sched, resourceOffers(&driver, _))
+ .WillOnce(FutureArg<1>(&offers))
+ .WillRepeatedly(Return()); // Ignore subsequent offers.
+
+ driver.start();
+
+ AWAIT_READY(offers);
+ EXPECT_EQ(1u, offers->size());
+
+ // Launch a task with the command executor.
+ TaskInfo task = createTask(
+ offers->front().slave_id(),
+ offers->front().resources(),
+ "sleep 1000");
+
+ Future<TaskStatus> statusRunning;
+ EXPECT_CALL(sched, statusUpdate(_, _))
+ .WillOnce(FutureArg<1>(&statusRunning));
+
+ driver.launchTasks(offers->front().id(), {task});
+
+ AWAIT_READY(statusRunning);
+ EXPECT_EQ(TASK_RUNNING, statusRunning->state());
+
+ Future<TaskStatus> statusKilling, statusKilled;
+ EXPECT_CALL(sched, statusUpdate(_, _))
+ .WillOnce(FutureArg<1>(&statusKilling))
+ .WillOnce(FutureArg<1>(&statusKilled));
+
+ driver.killTask(task.task_id());
+
+ AWAIT_READY(statusKilling);
+ EXPECT_EQ(TASK_KILLING, statusKilling->state());
+
+ AWAIT_READY(statusKilled);
+ EXPECT_EQ(TASK_KILLED, statusKilled->state());
+
+ driver.stop();
+ driver.join();
+}
+
+} // namespace tests {
+} // namespace internal {
+} // namespace mesos {