1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 * Data Differential YATL (i.e. libtest) library
5 * Copyright (C) 2012 Data Differential, http://datadifferential.com/
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include "libtest/yatlcon.h"
39 #include "libtest/common.h"
48 #include <sys/types.h>
52 #include <libtest/server.h>
53 #include <libtest/wait.h>
55 #include <libtest/memcached.h>
57 #ifndef __INTEL_COMPILER
58 #pragma GCC diagnostic ignored "-Wold-style-cast"
63 class Memcached
: public libtest::Server
65 std::string _username
;
66 std::string _password
;
69 Memcached(const std::string
& host_arg
,
70 const in_port_t port_arg
,
71 const bool is_socket_arg
,
72 const std::string
& username_arg
,
73 const std::string
& password_arg
) :
74 libtest::Server(host_arg
, port_arg
,
75 MEMCACHED_BINARY
, false, is_socket_arg
),
76 _username(username_arg
),
77 _password(password_arg
)
80 Memcached(const std::string
& host_arg
, const in_port_t port_arg
, const bool is_socket_arg
) :
81 libtest::Server(host_arg
, port_arg
,
82 MEMCACHED_BINARY
, false, is_socket_arg
)
87 virtual const char *sasl() const
92 const std::string
& password() const
97 const std::string
& username() const
102 bool wait_for_pidfile() const
106 return wait
.successful();
111 if (out_of_ban_killed())
121 SimpleClient
client(_hostname
, _port
);
123 std::string response
;
124 return client
.send_message("version", response
);
132 const char *executable()
134 return MEMCACHED_BINARY
;
142 virtual void pid_file_option(Application
& app
, const std::string
& arg
)
144 if (arg
.empty() == false)
146 app
.add_option("-P", arg
);
150 const char *socket_file_option() const
155 virtual void port_option(Application
& app
, in_port_t arg
)
158 snprintf(buffer
, sizeof(buffer
), "%d", int(arg
));
159 app
.add_option("-p", buffer
);
162 bool has_port_option() const
167 bool has_socket_file_option() const
172 void socket_file_option(Application
& app
, const std::string
& socket_arg
)
174 if (socket_arg
.empty() == false)
176 app
.add_option("-s", socket_arg
);
180 bool broken_socket_cleanup()
185 // Memcached's pidfile is broken
186 bool broken_pid_file()
191 bool build(size_t argc
, const char *argv
[]);
197 bool Memcached::build(size_t argc
, const char *argv
[])
199 if (getuid() == 0 or geteuid() == 0)
201 add_option("-u", "root");
204 add_option("-l", "localhost");
205 #ifndef TARGET_OS_OSX
206 add_option("-m", "128");
215 for (size_t x
= 0 ; x
< argc
; x
++)
228 libtest::Server
*build_memcached(const std::string
& hostname
, const in_port_t try_port
)
230 if (HAVE_MEMCACHED_BINARY
)
232 return new Memcached(hostname
, try_port
, false);
238 libtest::Server
*build_memcached_socket(const std::string
& socket_file
, const in_port_t try_port
)
240 if (HAVE_MEMCACHED_BINARY
)
242 return new Memcached(socket_file
, try_port
, true);
248 } // namespace libtest