Apache Mesos
store.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_STORE_HPP__
18 #define __TEST_STORE_HPP__
19 
20 #include <gmock/gmock.h>
21 
22 #include <stout/option.hpp>
23 
24 #include <process/future.hpp>
25 #include <process/shared.hpp>
26 
28 
30 
31 namespace mesos {
32 namespace internal {
33 namespace tests {
34 
35 class TestStore : public slave::Store
36 {
37 public:
38  TestStore(const hashmap<std::string, process::Shared<Rootfs>>& _rootfses)
39  : rootfses(_rootfses)
40  {
41  using testing::_;
42  using testing::DoDefault;
43  using testing::Invoke;
44 
45  ON_CALL(*this, recover())
46  .WillByDefault(Invoke(this, &TestStore::unmocked_recover));
47  EXPECT_CALL(*this, recover())
48  .WillRepeatedly(DoDefault());
49 
50  ON_CALL(*this, get(_, _))
51  .WillByDefault(Invoke(this, &TestStore::unmocked_get));
52  EXPECT_CALL(*this, get(_, _))
53  .WillRepeatedly(DoDefault());
54  }
55 
57  recover,
59 
61  get,
63  const Image& image,
64  const std::string& backend));
65 
67  {
68  return Nothing();
69  }
70 
72  const Image& image,
73  const std::string& backend)
74  {
75  if (!image.has_appc()) {
76  return process::Failure("Expecting APPC image");
77  }
78 
79  Option<process::Shared<Rootfs>> rootfs = rootfses.at(image.appc().name());
80  if (rootfs.isSome()) {
81  return slave::ImageInfo{
82  std::vector<std::string>({rootfs.get()->root}), None()};
83  }
84 
85  return process::Failure("Cannot find image '" + image.appc().name());
86  }
87 
88 private:
90 };
91 
92 } // namespace tests {
93 } // namespace internal {
94 } // namespace mesos {
95 
96 #endif // __TEST_STORE_HPP__
Definition: nothing.hpp:16
Definition: option.hpp:28
TestStore(const hashmap< std::string, process::Shared< Rootfs >> &_rootfses)
Definition: store.hpp:38
Definition: future.hpp:664
MOCK_METHOD1(get, process::Future< slave::ImageInfo >(const Image &image, const std::string &backend))
process::Future< Nothing > unmocked_recover()
Definition: store.hpp:66
Definition: store.hpp:60
bool isSome() const
Definition: option.hpp:115
Definition: store.hpp:45
Definition: hashmap.hpp:38
MOCK_METHOD0(recover, process::Future< Nothing >())
Definition: owned.hpp:25
const T & get() const &
Definition: option.hpp:118
process::Future< slave::ImageInfo > unmocked_get(const Image &image, const std::string &backend)
Definition: store.hpp:71
virtual process::Future< Nothing > recover()=0
URI image(const std::string &repository, const std::string &reference, const std::string &registry, const Option< std::string > &scheme=None(), const Option< int > &port=None())
Definition: docker.hpp:30
Definition: none.hpp:27
Definition: store.hpp:35