Apache Mesos
isolator.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 __TEST_ISOLATOR_HPP__
18 #define __TEST_ISOLATOR_HPP__
19 
20 #include <gmock/gmock.h>
21 
23 
24 namespace mesos {
25 namespace internal {
26 namespace tests {
27 
28 // Provides a mock Isolator that by default expects calls to
29 // Isolator::prepare, Isolator::isolate, Isolator::watch, and
30 // Isolator::cleanup and simply returns "nothing" as appropriate for
31 // each call. This behavior can be overridden by adding EXPECT_CALL as
32 // necessary. For example, if you don't expect any calls to
33 // Isolator::cleanup you can do:
34 //
35 // MockIsolator isolator;
36 // EXPECT_CALL(isolator, prepare(_, _))
37 // .Times(0);
38 //
39 // Or if you want to override that only a single invocation should
40 // occur you can do:
41 //
42 // MockIsolator isolator;
43 // EXPECT_CALL(isolator, prepare(_, _))
44 // .WillOnce(Return(ContainerLaunchInfo(...)));
45 //
46 // But note that YOU MUST use exactly `prepare(_, _)` otherwise gmock
47 // will not properly match this new expectation with the default
48 // expectation created by MockIsolator.
49 //
50 // In the event you want to override a single invocation but let all
51 // subsequent invocations return the "default" you can do:
52 //
53 // MockIsolator isolator;
54 // EXPECT_CALL(isolator, prepare(_, _))
55 // .WillOnce(Return(ContainerLaunchInfo(...)))
56 // .RetiresOnSaturation();
57 //
58 // Another example, if you want to override what gets returned for a
59 // every invocation you can do:
60 //
61 // MockIsolator isolator;
62 // EXPECT_CALL(isolator, prepare(_, _))
63 // .WillRepeatedly(Return(Failure(...)));
64 //
65 // Again, YOU MUST use exactly `prepare(_, _)` to override the default
66 // expectation.
68 {
69 public:
71  {
72  EXPECT_CALL(*this, prepare(_, _))
73  .WillRepeatedly(Return(None()));
74 
75  EXPECT_CALL(*this, isolate(_, _))
76  .WillRepeatedly(Return(Nothing()));
77 
78  EXPECT_CALL(*this, watch(_))
79  .WillRepeatedly(
81 
82  EXPECT_CALL(*this, cleanup(_))
83  .WillRepeatedly(Return(Nothing()));
84  }
85 
87  recover,
89  const std::vector<mesos::slave::ContainerState>&,
90  const hashset<ContainerID>&));
91 
93  prepare,
95  const ContainerID&,
96  const mesos::slave::ContainerConfig&));
97 
99  isolate,
100  process::Future<Nothing>(const ContainerID&, pid_t));
101 
102  MOCK_METHOD1(
103  watch,
105 
106  MOCK_METHOD3(
107  update,
109  const ContainerID&,
110  const Resources&,
111  const google::protobuf::Map<std::string, Value::Scalar>&));
112 
113  MOCK_METHOD1(
114  usage,
115  process::Future<ResourceStatistics>(const ContainerID&));
116 
117  MOCK_METHOD1(
118  cleanup,
119  process::Future<Nothing>(const ContainerID&));
120 };
121 
122 } // namespace tests {
123 } // namespace internal {
124 } // namespace mesos {
125 
126 #endif // __TEST_ISOLATOR_HPP__
Definition: nothing.hpp:16
MOCK_METHOD3(update, process::Future< Nothing >(const ContainerID &, const Resources &, const google::protobuf::Map< std::string, Value::Scalar > &))
Definition: resources.hpp:83
virtual process::Future< Nothing > cleanup(const ContainerID &containerId)
Definition: isolator.hpp:130
MOCK_METHOD1(watch, process::Future< mesos::slave::ContainerLimitation >(const ContainerID &))
MOCK_METHOD2(recover, process::Future< Nothing >(const std::vector< mesos::slave::ContainerState > &, const hashset< ContainerID > &))
DWORD pid_t
Definition: windows.hpp:181
virtual process::Future< Nothing > recover(const std::vector< ContainerState > &states, const hashset< ContainerID > &orphans)
Definition: isolator.hpp:60
Definition: agent.hpp:25
MockIsolator()
Definition: isolator.hpp:70
virtual process::Future< Nothing > update(const ContainerID &containerId, const Resources &resourceRequests, const google::protobuf::Map< std::string, Value::Scalar > &resourceLimits={})
Definition: isolator.hpp:98
Definition: none.hpp:27
Definition: attributes.hpp:24
virtual process::Future< ContainerLimitation > watch(const ContainerID &containerId)
Definition: isolator.hpp:91
virtual process::Future< Nothing > isolate(const ContainerID &containerId, pid_t pid)
Definition: isolator.hpp:81
virtual process::Future< Option< ContainerLaunchInfo > > prepare(const ContainerID &containerId, const ContainerConfig &containerConfig)
Definition: isolator.hpp:73
Definition: isolator.hpp:39
virtual process::Future< ResourceStatistics > usage(const ContainerID &containerId)
Definition: isolator.hpp:108
Definition: isolator.hpp:67