Apache Mesos
zookeeper_test_server.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 __ZOOKEEPER_TEST_SERVER_HPP__
18 #define __ZOOKEEPER_TEST_SERVER_HPP__
19 
20 #include <string>
21 
22 #include <glog/logging.h>
23 
25 
27 
28 namespace mesos {
29 namespace internal {
30 namespace tests {
31 
32 // An in-process ZooKeeper server that can be manipulated to control
33 // repeatable client tests. Sessions can be programmatically expired
34 // and network partitions can be forced to simulate common failure
35 // modes.
37 {
38 public:
41 
42  // Gets a connection string that can be used to attach a ZooKeeper client to
43  // this server.
44  std::string connectString() const;
45 
46  // Shuts down the network connection to this server.
47  void shutdownNetwork();
48 
49  // Starts the network connection to this server. Binds an ephemeral port on
50  // the first call and re-uses the port on subsequent calls.
51  int startNetwork();
52 
53  // Forces the server to expire the given session.
54  // Note that there is a delay (~3s) for the corresponding client to receive
55  // a session expiration event notification from the ZooKeeper server.
56  // TODO(vinod): Fix this so that the notification is immediate.
57  // One possible solution is suggested at :
58  // http://wiki.apache.org/hadoop/ZooKeeper/FAQ#A4
59  // But according to,
60  // http://comments.gmane.org/gmane.comp.java.hadoop.zookeeper.user/4489
61  // the C binding for ZooKeeper does not yet support multiple
62  // clients with the same session id.
63  void expireSession(int64_t sessionId);
64 
65  // Sets/gets the min/max session timeouts enforced by the server.
66  void setMinSessionTimeout(const Duration& min);
67  void setMaxSessionTimeout(const Duration& max);
70 
71 private:
74 
75  int port;
76  bool started;
77 };
78 
79 } // namespace tests {
80 } // namespace internal {
81 } // namespace mesos {
82 
83 #endif // __ZOOKEEPER_TEST_SERVER_HPP__
void setMaxSessionTimeout(const Duration &max)
void setMinSessionTimeout(const Duration &min)
Definition: duration.hpp:32
Option< T > max(const Option< T > &left, const Option< T > &right)
Definition: option.hpp:199
Option< T > min(const Option< T > &left, const Option< T > &right)
Definition: option.hpp:170
Definition: zookeeper_test_server.hpp:36