Apache Mesos
mock_master_api_subscriber.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_MASTER_MOCK_API_SUBSCRIBER__
18 #define __TESTS_MASTER_MOCK_API_SUBSCRIBER__
19 
20 #include <memory>
21 
22 #include <gmock/gmock.h>
23 
24 #include <process/future.hpp>
25 #include <process/pid.hpp>
26 
28 #include <mesos/http.hpp>
29 
30 #include "master/master.hpp"
31 
32 namespace mesos {
33 namespace internal {
34 namespace tests {
35 namespace v1 {
36 
37 class MockMasterAPISubscriberProcess;
38 
39 // This class performs subscribing to master's V1 API events
40 // and provides mock methods for setting expectations for these events
41 // similarly to MockHTTPScheduler.
43 {
44 public:
45  // Mock methods which are called by this class when an event is received.
46  MOCK_METHOD1(subscribed, void(const ::mesos::v1::master::Event::Subscribed&));
47 
48  MOCK_METHOD1(taskAdded, void(const ::mesos::v1::master::Event::TaskAdded&));
49 
50  MOCK_METHOD1(taskUpdated,
51  void(const ::mesos::v1::master::Event::TaskUpdated&));
52 
53  MOCK_METHOD1(agentAdded,
54  void(const ::mesos::v1::master::Event::AgentAdded&));
55 
56  MOCK_METHOD1(agentRemoved,
57  void(const ::mesos::v1::master::Event::AgentRemoved&));
58 
59  MOCK_METHOD1(frameworkAdded,
60  void(const ::mesos::v1::master::Event::FrameworkAdded&));
61 
62  MOCK_METHOD1(frameworkUpdated,
63  void(const ::mesos::v1::master::Event::FrameworkUpdated&));
64 
65  MOCK_METHOD1(frameworkRemoved,
66  void(const ::mesos::v1::master::Event::FrameworkRemoved&));
67 
68  MOCK_METHOD0(heartbeat, void());
69 
71  virtual ~MockMasterAPISubscriber();
72 
73  // Subscribes to the master's V1 API event stream.
74  // The returned Future becomes ready after the SUBSCRIBE call returns a
75  // 200 OK response.
76  //
77  // NOTE: This method should be called at most once per the lifetime of the
78  // mock.
79  //
80  // NOTE: All expectations on the mock methods should be set before calling
81  // this method.
84  ContentType contentType = ContentType::PROTOBUF);
85 
86 private:
88  void handleEvent(const ::mesos::v1::master::Event& event);
89 
90  bool subscribeCalled;
92 };
93 
94 
95 } // namespace v1 {
96 } // namespace tests {
97 } // namespace internal {
98 } // namespace mesos {
99 
100 #endif // __TESTS_MASTER_MOCK_API_SUBSCRIBER__
process::Future< Nothing > subscribe(const process::PID< mesos::internal::master::Master > &masterPid, ContentType contentType=ContentType::PROTOBUF)
ContentType
Definition: http.hpp:43
MOCK_METHOD1(subscribed, void(const ::mesos::v1::master::Event::Subscribed &))
mesos::v1::scheduler::Event Event
Definition: mesos.hpp:2852
Definition: mock_master_api_subscriber.hpp:42
Definition: agent.hpp:25
A "process identifier" used to uniquely identify a process when dispatching messages.
Definition: pid.hpp:289
Definition: attributes.hpp:24
friend class MockMasterAPISubscriberProcess
Definition: mock_master_api_subscriber.hpp:87