Apache Mesos
mock_slave.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __TESTS_MOCKSLAVE_HPP__
18 #define __TESTS_MOCKSLAVE_HPP__
19 
20 #include <list>
21 #include <string>
22 #include <vector>
23 
24 #include <gmock/gmock.h>
25 
27 
29 
32 
33 #include <process/future.hpp>
34 #include <process/pid.hpp>
35 
36 #include <stout/duration.hpp>
37 #include <stout/none.hpp>
38 #include <stout/option.hpp>
39 #include <stout/try.hpp>
40 
41 #include "messages/messages.hpp"
42 
43 #include "slave/slave.hpp"
44 
45 using ::testing::_;
46 using ::testing::DoDefault;
47 using ::testing::Return;
48 
49 namespace mesos {
50 namespace internal {
51 namespace tests {
52 
54 {
55 public:
57  virtual ~MockResourceEstimator();
58 
60  initialize,
61  Try<Nothing>(const lambda::function<process::Future<ResourceUsage>()>&));
62 
66 };
67 
68 
69 // The MockQoSController is a stub which lets tests fill the
70 // correction queue for a slave.
72 {
73 public:
75  virtual ~MockQoSController();
76 
78  initialize,
79  Try<Nothing>(const lambda::function<process::Future<ResourceUsage>()>&));
80 
82  corrections, process::Future<std::list<mesos::slave::QoSCorrection>>());
83 };
84 
85 
86 // Definition of a mock Slave to be used in tests with gmock, covering
87 // potential races between runTask and killTask.
88 class MockSlave : public slave::Slave
89 {
90 public:
91  MockSlave(
92  const std::string& id,
93  const slave::Flags& flags,
95  slave::Containerizer* containerizer,
96  Files* files,
98  slave::TaskStatusUpdateManager* taskStatusUpdateManager,
99  mesos::slave::ResourceEstimator* resourceEstimator,
100  mesos::slave::QoSController* qosController,
101  SecretGenerator* secretGenerator,
102  const Option<Authorizer*>& authorizer);
103 
104  MOCK_METHOD6(runTask, void(
105  const process::UPID& from,
106  const FrameworkInfo& frameworkInfo,
107  const FrameworkID& frameworkId,
108  const process::UPID& pid,
109  const TaskInfo& task,
110  const std::vector<ResourceVersionUUID>& resourceVersionUuids));
111 
112  void unmocked_runTask(
113  const process::UPID& from,
114  const FrameworkInfo& frameworkInfo,
115  const FrameworkID& frameworkId,
116  const process::UPID& pid,
117  const TaskInfo& task,
118  const std::vector<ResourceVersionUUID>& resourceVersionUuids);
119 
120  MOCK_METHOD6(_run, void(
121  const process::Future<std::list<bool>>& unschedules,
122  const FrameworkInfo& frameworkInfo,
123  const ExecutorInfo& executorInfo,
124  const Option<TaskInfo>& task,
125  const Option<TaskGroupInfo>& taskGroup,
126  const std::vector<ResourceVersionUUID>& resourceVersionUuids));
127 
128  void unmocked__run(
129  const process::Future<std::list<bool>>& unschedules,
130  const FrameworkInfo& frameworkInfo,
131  const ExecutorInfo& executorInfo,
132  const Option<TaskInfo>& task,
133  const Option<TaskGroupInfo>& taskGroup,
134  const std::vector<ResourceVersionUUID>& resourceVersionUuids);
135 
137  const process::UPID& from,
138  const FrameworkInfo& frameworkInfo,
139  const ExecutorInfo& executorInfo,
140  const TaskGroupInfo& taskGroup,
141  const std::vector<ResourceVersionUUID>& resourceVersionUuids));
142 
144  const process::UPID& from,
145  const FrameworkInfo& frameworkInfo,
146  const ExecutorInfo& executorInfo,
147  const TaskGroupInfo& taskGroup,
148  const std::vector<ResourceVersionUUID>& resourceVersionUuids);
149 
150  MOCK_METHOD2(killTask, void(
151  const process::UPID& from,
152  const KillTaskMessage& killTaskMessage));
153 
154  void unmocked_killTask(
155  const process::UPID& from,
156  const KillTaskMessage& killTaskMessage);
157 
159  slave::Framework* framework));
160 
162  slave::Framework* framework);
163 
164  MOCK_METHOD1(__recover, void(
165  const process::Future<Nothing>& future));
166 
167  void unmocked___recover(
168  const process::Future<Nothing>& future);
169 
170  MOCK_METHOD0(qosCorrections, void());
171 
173 
176  mesos::slave::QoSCorrection>>& correction));
177 
179 
181 
183  const FrameworkID& frameworkId,
184  const ExecutorID& executorId,
185  const process::Future<Option<
186  mesos::slave::ContainerTermination>>& termination));
187 
189  const FrameworkID& frameworkId,
190  const ExecutorID& executorId,
191  const process::Future<Option<
192  mesos::slave::ContainerTermination>>& termination);
193 
195  const process::UPID& from,
196  const FrameworkID& frameworkId,
197  const ExecutorID& executorId));
198 
200  const process::UPID& from,
201  const FrameworkID& frameworkId,
202  const ExecutorID& executorId);
203 };
204 
205 } // namespace tests {
206 } // namespace internal {
207 } // namespace mesos {
208 
209 #endif // __TESTS_MOCKSLAVE_HPP__
virtual process::Future< ResourceUsage > usage()
void unmocked_runTask(const process::UPID &from, const FrameworkInfo &frameworkInfo, const FrameworkID &frameworkId, const process::UPID &pid, const TaskInfo &task, const std::vector< ResourceVersionUUID > &resourceVersionUuids)
void unmocked_removeFramework(slave::Framework *framework)
MOCK_METHOD0(oversubscribable, process::Future< Resources >())
Definition: option.hpp:28
virtual void removeFramework(Framework *framework)
Definition: try.hpp:34
virtual void shutdownExecutor(const process::UPID &from, const FrameworkID &frameworkId, const ExecutorID &executorId)
virtual Try< Nothing > initialize(const lambda::function< process::Future< ResourceUsage >()> &usage)=0
MOCK_METHOD1(removeFramework, void(slave::Framework *framework))
MOCK_METHOD2(killTask, void(const process::UPID &from, const KillTaskMessage &killTaskMessage))
Definition: mock_slave.hpp:71
void unmocked__run(const process::Future< std::list< bool >> &unschedules, const FrameworkInfo &frameworkInfo, const ExecutorInfo &executorInfo, const Option< TaskInfo > &task, const Option< TaskGroupInfo > &taskGroup, const std::vector< ResourceVersionUUID > &resourceVersionUuids)
void unmocked_killTask(const process::UPID &from, const KillTaskMessage &killTaskMessage)
virtual void runTask(const process::UPID &from, const FrameworkInfo &frameworkInfo, const FrameworkID &frameworkId, const process::UPID &pid, const TaskInfo &task, const std::vector< ResourceVersionUUID > &resourceVersionUuids)
virtual void runTaskGroup(const process::UPID &from, const FrameworkInfo &frameworkInfo, const ExecutorInfo &executorInfo, const TaskGroupInfo &taskGroupInfo, const std::vector< ResourceVersionUUID > &resourceVersionUuids)
virtual void _run(const process::Future< std::list< bool >> &unschedules, const FrameworkInfo &frameworkInfo, const ExecutorInfo &executorInfo, const Option< TaskInfo > &task, const Option< TaskGroupInfo > &taskGroup, const std::vector< ResourceVersionUUID > &resourceVersionUuids)
virtual void executorTerminated(const FrameworkID &frameworkId, const ExecutorID &executorId, const process::Future< Option< mesos::slave::ContainerTermination >> &termination)
MOCK_METHOD0(corrections, process::Future< std::list< mesos::slave::QoSCorrection >>())
Definition: files.hpp:73
Definition: flags.hpp:39
MOCK_METHOD6(runTask, void(const process::UPID &from, const FrameworkInfo &frameworkInfo, const FrameworkID &frameworkId, const process::UPID &pid, const TaskInfo &task, const std::vector< ResourceVersionUUID > &resourceVersionUuids))
Definition: task_status_update_manager.hpp:58
void unmocked_executorTerminated(const FrameworkID &frameworkId, const ExecutorID &executorId, const process::Future< Option< mesos::slave::ContainerTermination >> &termination)
virtual process::Future< std::list< QoSCorrection > > corrections()=0
virtual process::Future< Resources > oversubscribable()=0
Definition: resource_estimator.hpp:37
Definition: containerizer.hpp:57
Definition: slave.hpp:115
An &quot;untyped&quot; PID, used to encapsulate the process ID for lower-layer abstractions (eg...
Definition: pid.hpp:39
MOCK_METHOD1(initialize, Try< Nothing >(const lambda::function< process::Future< ResourceUsage >()> &))
MockSlave(const std::string &id, const slave::Flags &flags, mesos::master::detector::MasterDetector *detector, slave::Containerizer *containerizer, Files *files, slave::GarbageCollector *gc, slave::TaskStatusUpdateManager *taskStatusUpdateManager, mesos::slave::ResourceEstimator *resourceEstimator, mesos::slave::QoSController *qosController, SecretGenerator *secretGenerator, const Option< Authorizer * > &authorizer)
virtual Try< Nothing > initialize(const lambda::function< process::Future< ResourceUsage >()> &usage)=0
MOCK_METHOD5(runTaskGroup, void(const process::UPID &from, const FrameworkInfo &frameworkInfo, const ExecutorInfo &executorInfo, const TaskGroupInfo &taskGroup, const std::vector< ResourceVersionUUID > &resourceVersionUuids))
void unmocked___recover(const process::Future< Nothing > &future)
The SecretGenerator interface represents a mechanism to create a secret from a principal.
Definition: secret_generator.hpp:34
void unmocked_runTaskGroup(const process::UPID &from, const FrameworkInfo &frameworkInfo, const ExecutorInfo &executorInfo, const TaskGroupInfo &taskGroup, const std::vector< ResourceVersionUUID > &resourceVersionUuids)
Try< std::vector< Entry > > list(const std::string &hierarchy, const std::string &cgroup)
MOCK_METHOD1(initialize, Try< Nothing >(const lambda::function< process::Future< ResourceUsage >()> &))
#define flags
Definition: decoder.hpp:18
MOCK_METHOD0(qosCorrections, void())
virtual void killTask(const process::UPID &from, const KillTaskMessage &killTaskMessage)
Definition: mock_slave.hpp:88
virtual void __recover(const process::Future< Nothing > &future)
process::Future< ResourceUsage > unmocked_usage()
MOCK_METHOD3(executorTerminated, void(const FrameworkID &frameworkId, const ExecutorID &executorId, const process::Future< Option< mesos::slave::ContainerTermination >> &termination))
An abstraction of a Master detector which can be used to detect the leading master from a group...
Definition: detector.hpp:38
void unmocked_shutdownExecutor(const process::UPID &from, const FrameworkID &frameworkId, const ExecutorID &executorId)
Definition: qos_controller.hpp:44
virtual void _qosCorrections(const process::Future< std::list< mesos::slave::QoSCorrection >> &correction)
Definition: slave.hpp:986
Definition: future.hpp:57