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(___run, void(
105  const process::Future<Nothing>& future,
106  const FrameworkID& frameworkId,
107  const ExecutorID& executorId,
108  const ContainerID& containerId,
109  const std::list<TaskInfo>& tasks,
110  const std::list<TaskGroupInfo>& taskGroups));
111 
112  void unmocked____run(
113  const process::Future<Nothing>& future,
114  const FrameworkID& frameworkId,
115  const ExecutorID& executorId,
116  const ContainerID& containerId,
117  const std::list<TaskInfo>& tasks,
118  const std::list<TaskGroupInfo>& taskGroups);
119 
120  MOCK_METHOD7(runTask, void(
121  const process::UPID& from,
122  const FrameworkInfo& frameworkInfo,
123  const FrameworkID& frameworkId,
124  const process::UPID& pid,
125  const TaskInfo& task,
126  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
127  const Option<bool>& launchExecutor));
128 
129  void unmocked_runTask(
130  const process::UPID& from,
131  const FrameworkInfo& frameworkInfo,
132  const FrameworkID& frameworkId,
133  const process::UPID& pid,
134  const TaskInfo& task,
135  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
136  const Option<bool>& launchExecutor);
137 
138  MOCK_METHOD6(_run, process::Future<Nothing>(
139  const FrameworkInfo& frameworkInfo,
140  const ExecutorInfo& executorInfo,
141  const Option<TaskInfo>& task,
142  const Option<TaskGroupInfo>& taskGroup,
143  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
144  const Option<bool>& launchExecutor));
145 
146  process::Future<Nothing> unmocked__run(
147  const FrameworkInfo& frameworkInfo,
148  const ExecutorInfo& executorInfo,
149  const Option<TaskInfo>& task,
150  const Option<TaskGroupInfo>& taskGroup,
151  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
152  const Option<bool>& launchExecutor);
153 
154  MOCK_METHOD6(__run, void(
155  const FrameworkInfo& frameworkInfo,
156  const ExecutorInfo& executorInfo,
157  const Option<TaskInfo>& task,
158  const Option<TaskGroupInfo>& taskGroup,
159  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
160  const Option<bool>& launchExecutor));
161 
162  void unmocked___run(
163  const FrameworkInfo& frameworkInfo,
164  const ExecutorInfo& executorInfo,
165  const Option<TaskInfo>& task,
166  const Option<TaskGroupInfo>& taskGroup,
167  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
168  const Option<bool>& launchExecutor);
169 
170  MOCK_METHOD6(runTaskGroup, void(
171  const process::UPID& from,
172  const FrameworkInfo& frameworkInfo,
173  const ExecutorInfo& executorInfo,
174  const TaskGroupInfo& taskGroup,
175  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
176  const Option<bool>& launchExecutor));
177 
178  void unmocked_runTaskGroup(
179  const process::UPID& from,
180  const FrameworkInfo& frameworkInfo,
181  const ExecutorInfo& executorInfo,
182  const TaskGroupInfo& taskGroup,
183  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
184  const Option<bool>& launchExecutor);
185 
186  MOCK_METHOD2(killTask, void(
187  const process::UPID& from,
188  const KillTaskMessage& killTaskMessage));
189 
190  void unmocked_killTask(
191  const process::UPID& from,
192  const KillTaskMessage& killTaskMessage);
193 
194  MOCK_METHOD1(removeFramework, void(
195  slave::Framework* framework));
196 
197  void unmocked_removeFramework(
198  slave::Framework* framework);
199 
200  MOCK_METHOD1(__recover, void(
201  const process::Future<Nothing>& future));
202 
203  void unmocked___recover(
204  const process::Future<Nothing>& future);
205 
206  MOCK_METHOD0(qosCorrections, void());
207 
208  void unmocked_qosCorrections();
209 
210  MOCK_METHOD1(_qosCorrections, void(
212  mesos::slave::QoSCorrection>>& correction));
213 
215 
216  process::Future<ResourceUsage> unmocked_usage();
217 
218  MOCK_METHOD3(executorTerminated, void(
219  const FrameworkID& frameworkId,
220  const ExecutorID& executorId,
221  const process::Future<Option<
222  mesos::slave::ContainerTermination>>& termination));
223 
224  void unmocked_executorTerminated(
225  const FrameworkID& frameworkId,
226  const ExecutorID& executorId,
227  const process::Future<Option<
228  mesos::slave::ContainerTermination>>& termination);
229 
230  MOCK_METHOD3(shutdownExecutor, void(
231  const process::UPID& from,
232  const FrameworkID& frameworkId,
233  const ExecutorID& executorId));
234 
235  void unmocked_shutdownExecutor(
236  const process::UPID& from,
237  const FrameworkID& frameworkId,
238  const ExecutorID& executorId);
239 
240  MOCK_METHOD2(_shutdownExecutor, void(
241  slave::Framework* framework,
242  slave::Executor* executor));
243 
244  void unmocked__shutdownExecutor(
245  slave::Framework* framework,
246  slave::Executor* executor);
247 };
248 
249 } // namespace tests {
250 } // namespace internal {
251 } // namespace mesos {
252 
253 #endif // __TESTS_MOCKSLAVE_HPP__
MOCK_METHOD0(oversubscribable, process::Future< Resources >())
Definition: option.hpp:28
Definition: check.hpp:33
Definition: mock_slave.hpp:71
Definition: files.hpp:73
Definition: flags.hpp:39
Definition: task_status_update_manager.hpp:58
virtual process::Future< Resources > oversubscribable()=0
Definition: resource_estimator.hpp:37
Try< ResourceStatistics > usage(pid_t pid, bool mem=true, bool cpus=true)
Definition: containerizer.hpp:57
Definition: slave.hpp:116
An "untyped" 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 >()> &))
virtual Try< Nothing > initialize(const lambda::function< process::Future< ResourceUsage >()> &usage)=0
Definition: spec.hpp:30
The SecretGenerator interface represents a mechanism to create a secret from a principal.
Definition: secret_generator.hpp:34
Try< std::vector< Entry > > list(const std::string &hierarchy, const std::string &cgroup)
Definition: attributes.hpp:24
Definition: mock_slave.hpp:88
An abstraction of a Master detector which can be used to detect the leading master from a group...
Definition: detector.hpp:38
Definition: qos_controller.hpp:44
Definition: slave.hpp:881
Definition: parse.hpp:33
Definition: slave.hpp:1058
Definition: future.hpp:57