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  ~MockResourceEstimator() override;
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  ~MockQoSController() override;
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  slave::VolumeGidManager* volumeGidManager,
103  PendingFutureTracker* futureTracker,
104  const Option<Authorizer*>& authorizer);
105 
106  MOCK_METHOD6(___run, void(
107  const process::Future<Nothing>& future,
108  const FrameworkID& frameworkId,
109  const ExecutorID& executorId,
110  const ContainerID& containerId,
111  const std::vector<TaskInfo>& tasks,
112  const std::vector<TaskGroupInfo>& taskGroups));
113 
114  void unmocked____run(
115  const process::Future<Nothing>& future,
116  const FrameworkID& frameworkId,
117  const ExecutorID& executorId,
118  const ContainerID& containerId,
119  const std::vector<TaskInfo>& tasks,
120  const std::vector<TaskGroupInfo>& taskGroups);
121 
122  MOCK_METHOD7(runTask, void(
123  const process::UPID& from,
124  const FrameworkInfo& frameworkInfo,
125  const FrameworkID& frameworkId,
126  const process::UPID& pid,
127  const TaskInfo& task,
128  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
129  const Option<bool>& launchExecutor));
130 
131  void unmocked_runTask(
132  const process::UPID& from,
133  const FrameworkInfo& frameworkInfo,
134  const FrameworkID& frameworkId,
135  const process::UPID& pid,
136  const TaskInfo& task,
137  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
138  const Option<bool>& launchExecutor);
139 
140  MOCK_METHOD6(_run, process::Future<Nothing>(
141  const FrameworkInfo& frameworkInfo,
142  const ExecutorInfo& executorInfo,
143  const Option<TaskInfo>& task,
144  const Option<TaskGroupInfo>& taskGroup,
145  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
146  const Option<bool>& launchExecutor));
147 
148  process::Future<Nothing> unmocked__run(
149  const FrameworkInfo& frameworkInfo,
150  const ExecutorInfo& executorInfo,
151  const Option<TaskInfo>& task,
152  const Option<TaskGroupInfo>& taskGroup,
153  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
154  const Option<bool>& launchExecutor);
155 
156  MOCK_METHOD7(__run, void(
157  const FrameworkInfo& frameworkInfo,
158  const ExecutorInfo& executorInfo,
159  const Option<TaskInfo>& task,
160  const Option<TaskGroupInfo>& taskGroup,
161  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
162  const Option<bool>& launchExecutor,
163  bool executorGeneratedForCommandTask));
164 
165  void unmocked___run(
166  const FrameworkInfo& frameworkInfo,
167  const ExecutorInfo& executorInfo,
168  const Option<TaskInfo>& task,
169  const Option<TaskGroupInfo>& taskGroup,
170  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
171  const Option<bool>& launchExecutor,
172  bool executorGeneratedForCommandTask);
173 
174  MOCK_METHOD6(runTaskGroup, void(
175  const process::UPID& from,
176  const FrameworkInfo& frameworkInfo,
177  const ExecutorInfo& executorInfo,
178  const TaskGroupInfo& taskGroup,
179  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
180  const Option<bool>& launchExecutor));
181 
182  void unmocked_runTaskGroup(
183  const process::UPID& from,
184  const FrameworkInfo& frameworkInfo,
185  const ExecutorInfo& executorInfo,
186  const TaskGroupInfo& taskGroup,
187  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
188  const Option<bool>& launchExecutor);
189 
190  MOCK_METHOD2(killTask, void(
191  const process::UPID& from,
192  const KillTaskMessage& killTaskMessage));
193 
194  void unmocked_killTask(
195  const process::UPID& from,
196  const KillTaskMessage& killTaskMessage);
197 
198  MOCK_METHOD2(authenticate, void(
199  Duration minTimeout,
200  Duration maxTimeout));
201 
202  void unmocked_authenticate(
203  Duration minTimeout,
204  Duration maxTimeout);
205 
206  MOCK_METHOD1(removeFramework, void(
207  slave::Framework* framework));
208 
209  void unmocked_removeFramework(
210  slave::Framework* framework);
211 
212  MOCK_METHOD1(__recover, void(
213  const process::Future<Nothing>& future));
214 
215  void unmocked___recover(
216  const process::Future<Nothing>& future);
217 
218  MOCK_METHOD0(qosCorrections, void());
219 
220  void unmocked_qosCorrections();
221 
222  MOCK_METHOD1(_qosCorrections, void(
224  mesos::slave::QoSCorrection>>& correction));
225 
227 
228  process::Future<ResourceUsage> unmocked_usage();
229 
230  MOCK_METHOD3(executorTerminated, void(
231  const FrameworkID& frameworkId,
232  const ExecutorID& executorId,
233  const process::Future<Option<
234  mesos::slave::ContainerTermination>>& termination));
235 
236  void unmocked_executorTerminated(
237  const FrameworkID& frameworkId,
238  const ExecutorID& executorId,
239  const process::Future<Option<
240  mesos::slave::ContainerTermination>>& termination);
241 
242  MOCK_METHOD3(shutdownExecutor, void(
243  const process::UPID& from,
244  const FrameworkID& frameworkId,
245  const ExecutorID& executorId));
246 
247  void unmocked_shutdownExecutor(
248  const process::UPID& from,
249  const FrameworkID& frameworkId,
250  const ExecutorID& executorId);
251 
252  MOCK_METHOD2(_shutdownExecutor, void(
253  slave::Framework* framework,
254  slave::Executor* executor));
255 
256  void unmocked__shutdownExecutor(
257  slave::Framework* framework,
258  slave::Executor* executor);
259 
260  MOCK_METHOD1(applyOperation, void(
261  const ApplyOperationMessage& message));
262 
263  void unmocked_applyOperation(
264  const ApplyOperationMessage& message);
265 };
266 
267 } // namespace tests {
268 } // namespace internal {
269 } // namespace mesos {
270 
271 #endif // __TESTS_MOCKSLAVE_HPP__
MOCK_METHOD0(oversubscribable, process::Future< Resources >())
Definition: option.hpp:29
Definition: check.hpp:33
Definition: mock_slave.hpp:71
Definition: volume_gid_manager.hpp:42
Definition: files.hpp:73
Definition: flags.hpp:39
Definition: duration.hpp:32
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:63
Definition: slave.hpp:118
An "untyped" PID, used to encapsulate the process ID for lower-layer abstractions (eg...
Definition: pid.hpp:39
Definition: future_tracker.hpp:84
MOCK_METHOD1(initialize, Try< Nothing >(const lambda::function< process::Future< ResourceUsage >()> &))
virtual Try< Nothing > initialize(const lambda::function< process::Future< ResourceUsage >()> &usage)=0
Definition: agent.hpp:25
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:937
Definition: parse.hpp:33
Definition: slave.hpp:1124
Definition: future.hpp:58