1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 3 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <libtest/common.h>
26 #include <libtest/gearmand.h>
28 #include "util/instance.hpp"
29 #include "util/operation.hpp"
31 using namespace datadifferential
;
32 using namespace libtest
;
42 #include <sys/types.h>
46 #include <libgearman/gearman.h>
48 #ifndef __INTEL_COMPILER
49 #pragma GCC diagnostic ignored "-Wold-style-cast"
52 class GetPid
: public util::Instance::Finish
68 bool call(const bool success
, const std::string
&response
)
71 if (success
and response
.size())
73 _pid
= atoi(response
.c_str());
76 if (is_pid_valid(_pid
) == false)
86 using namespace libtest
;
88 class Gearmand
: public libtest::Server
92 Gearmand(const std::string
& host_arg
, in_port_t port_arg
) :
93 libtest::Server(host_arg
, port_arg
, GEARMAND_BINARY
, true)
100 gearman_client_st
*client
= gearman_client_create(NULL
);
103 Error
<< "Could not allocate memory for gearman_client_create()";
106 gearman_client_set_timeout(client
, 3000);
108 if (gearman_success(gearman_client_add_server(client
, hostname().c_str(), port())))
110 gearman_return_t rc
= gearman_client_echo(client
, test_literal_param("This is my echo test"));
112 if (gearman_success(rc
))
114 gearman_client_free(client
);
118 Error
<< hostname().c_str() << ":" << port() << " was " << gearman_strerror(rc
) << " extended: " << gearman_client_error(client
);
123 Error
<< "gearman_client_add_server() " << gearman_client_error(client
);
126 gearman_client_free(client
);
136 void log_file_option(Application
& app
, const std::string
& arg
)
138 if (arg
.empty() == false)
140 std::string
buffer("--log-file=");
142 app
.add_option("--verbose=DEBUG");
143 app
.add_option(buffer
);
147 bool has_log_file_option() const
157 bool has_syslog() const
162 bool has_port_option() const
167 bool build(size_t argc
, const char *argv
[]);
170 bool Gearmand::build(size_t argc
, const char *argv
[])
172 std::stringstream arg_buffer
;
174 if (getuid() == 0 or geteuid() == 0)
176 add_option("-u", "root");
179 add_option("--listen=localhost");
181 for (size_t x
= 0 ; x
< argc
; x
++)
191 libtest::Server
*build_gearmand(const char *hostname
, in_port_t try_port
)
193 return new Gearmand(hostname
, try_port
);