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/owned.hpp>
35 #include <process/pid.hpp>
36 
37 #include <stout/duration.hpp>
38 #include <stout/none.hpp>
39 #include <stout/option.hpp>
40 #include <stout/try.hpp>
41 
42 #include "messages/messages.hpp"
43 
44 #include "slave/csi_server.hpp"
45 #include "slave/slave.hpp"
46 
47 using ::testing::_;
48 using ::testing::DoDefault;
49 using ::testing::Return;
50 
51 namespace mesos {
52 namespace internal {
53 namespace tests {
54 
56 {
57 public:
59  ~MockResourceEstimator() override;
60 
62  initialize,
63  Try<Nothing>(const lambda::function<process::Future<ResourceUsage>()>&));
64 
68 };
69 
70 
71 // The MockQoSController is a stub which lets tests fill the
72 // correction queue for a slave.
74 {
75 public:
77  ~MockQoSController() override;
78 
80  initialize,
81  Try<Nothing>(const lambda::function<process::Future<ResourceUsage>()>&));
82 
84  corrections, process::Future<std::list<mesos::slave::QoSCorrection>>());
85 };
86 
87 
88 // Definition of a mock Slave to be used in tests with gmock, covering
89 // potential races between runTask and killTask.
90 class MockSlave : public slave::Slave
91 {
92 public:
93  MockSlave(
94  const std::string& id,
95  const slave::Flags& flags,
97  slave::Containerizer* containerizer,
98  Files* files,
100  slave::TaskStatusUpdateManager* taskStatusUpdateManager,
101  mesos::slave::ResourceEstimator* resourceEstimator,
102  mesos::slave::QoSController* qosController,
103  SecretGenerator* secretGenerator,
104  slave::VolumeGidManager* volumeGidManager,
105  PendingFutureTracker* futureTracker,
107  const Option<Authorizer*>& authorizer);
108 
109  MOCK_METHOD6(___run, void(
110  const process::Future<Nothing>& future,
111  const FrameworkID& frameworkId,
112  const ExecutorID& executorId,
113  const ContainerID& containerId,
114  const std::vector<TaskInfo>& tasks,
115  const std::vector<TaskGroupInfo>& taskGroups));
116 
117  void unmocked____run(
118  const process::Future<Nothing>& future,
119  const FrameworkID& frameworkId,
120  const ExecutorID& executorId,
121  const ContainerID& containerId,
122  const std::vector<TaskInfo>& tasks,
123  const std::vector<TaskGroupInfo>& taskGroups);
124 
125  MOCK_METHOD7(runTask, void(
126  const process::UPID& from,
127  const FrameworkInfo& frameworkInfo,
128  const FrameworkID& frameworkId,
129  const process::UPID& pid,
130  const TaskInfo& task,
131  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
132  const Option<bool>& launchExecutor));
133 
134  void unmocked_runTask(
135  const process::UPID& from,
136  const FrameworkInfo& frameworkInfo,
137  const FrameworkID& frameworkId,
138  const process::UPID& pid,
139  const TaskInfo& task,
140  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
141  const Option<bool>& launchExecutor);
142 
143  MOCK_METHOD6(_run, process::Future<Nothing>(
144  const FrameworkInfo& frameworkInfo,
145  const ExecutorInfo& executorInfo,
146  const Option<TaskInfo>& task,
147  const Option<TaskGroupInfo>& taskGroup,
148  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
149  const Option<bool>& launchExecutor));
150 
151  process::Future<Nothing> unmocked__run(
152  const FrameworkInfo& frameworkInfo,
153  const ExecutorInfo& executorInfo,
154  const Option<TaskInfo>& task,
155  const Option<TaskGroupInfo>& taskGroup,
156  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
157  const Option<bool>& launchExecutor);
158 
159  MOCK_METHOD7(__run, void(
160  const FrameworkInfo& frameworkInfo,
161  const ExecutorInfo& executorInfo,
162  const Option<TaskInfo>& task,
163  const Option<TaskGroupInfo>& taskGroup,
164  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
165  const Option<bool>& launchExecutor,
166  bool executorGeneratedForCommandTask));
167 
168  void unmocked___run(
169  const FrameworkInfo& frameworkInfo,
170  const ExecutorInfo& executorInfo,
171  const Option<TaskInfo>& task,
172  const Option<TaskGroupInfo>& taskGroup,
173  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
174  const Option<bool>& launchExecutor,
175  bool executorGeneratedForCommandTask);
176 
177  MOCK_METHOD6(runTaskGroup, void(
178  const process::UPID& from,
179  const FrameworkInfo& frameworkInfo,
180  const ExecutorInfo& executorInfo,
181  const TaskGroupInfo& taskGroup,
182  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
183  const Option<bool>& launchExecutor));
184 
185  void unmocked_runTaskGroup(
186  const process::UPID& from,
187  const FrameworkInfo& frameworkInfo,
188  const ExecutorInfo& executorInfo,
189  const TaskGroupInfo& taskGroup,
190  const std::vector<ResourceVersionUUID>& resourceVersionUuids,
191  const Option<bool>& launchExecutor);
192 
193  MOCK_METHOD2(killTask, void(
194  const process::UPID& from,
195  const KillTaskMessage& killTaskMessage));
196 
197  void unmocked_killTask(
198  const process::UPID& from,
199  const KillTaskMessage& killTaskMessage);
200 
201  MOCK_METHOD2(authenticate, void(
202  Duration minTimeout,
203  Duration maxTimeout));
204 
205  void unmocked_authenticate(
206  Duration minTimeout,
207  Duration maxTimeout);
208 
209  MOCK_METHOD1(removeFramework, void(
210  slave::Framework* framework));
211 
212  void unmocked_removeFramework(
213  slave::Framework* framework);
214 
215  MOCK_METHOD1(__recover, void(
216  const process::Future<Nothing>& future));
217 
218  void unmocked___recover(
219  const process::Future<Nothing>& future);
220 
221  MOCK_METHOD0(qosCorrections, void());
222 
223  void unmocked_qosCorrections();
224 
225  MOCK_METHOD1(_qosCorrections, void(
227  mesos::slave::QoSCorrection>>& correction));
228 
230 
231  process::Future<ResourceUsage> unmocked_usage();
232 
233  MOCK_METHOD3(executorTerminated, void(
234  const FrameworkID& frameworkId,
235  const ExecutorID& executorId,
236  const process::Future<Option<
237  mesos::slave::ContainerTermination>>& termination));
238 
239  void unmocked_executorTerminated(
240  const FrameworkID& frameworkId,
241  const ExecutorID& executorId,
242  const process::Future<Option<
243  mesos::slave::ContainerTermination>>& termination);
244 
245  MOCK_METHOD3(shutdownExecutor, void(
246  const process::UPID& from,
247  const FrameworkID& frameworkId,
248  const ExecutorID& executorId));
249 
250  void unmocked_shutdownExecutor(
251  const process::UPID& from,
252  const FrameworkID& frameworkId,
253  const ExecutorID& executorId);
254 
255  MOCK_METHOD2(_shutdownExecutor, void(
256  slave::Framework* framework,
257  slave::Executor* executor));
258 
259  void unmocked__shutdownExecutor(
260  slave::Framework* framework,
261  slave::Executor* executor);
262 
263  MOCK_METHOD1(applyOperation, void(
264  const ApplyOperationMessage& message));
265 
266  void unmocked_applyOperation(
267  const ApplyOperationMessage& message);
268 };
269 
270 } // namespace tests {
271 } // namespace internal {
272 } // namespace mesos {
273 
274 #endif // __TESTS_MOCKSLAVE_HPP__
MOCK_METHOD0(oversubscribable, process::Future< Resources >())
Definition: option.hpp:29
Definition: check.hpp:33
Definition: mock_slave.hpp:73
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:64
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:90
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:957
Definition: parse.hpp:33
Definition: slave.hpp:1144
Definition: future.hpp:58