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
23 #include <libtest/common.h>
25 #include <libtest/blobslap_worker.h>
34 #include <sys/types.h>
38 #include <libgearman/gearman.h>
40 #ifndef __INTEL_COMPILER
41 #pragma GCC diagnostic ignored "-Wold-style-cast"
46 class BlobslapWorker
: public Server
50 BlobslapWorker(in_port_t port_arg
) :
51 Server("localhost", port_arg
)
56 pid_t
get_pid(bool error_is_ok
)
58 if (pid_file().empty())
60 Error
<< "pid_file was empty";
64 Wait
wait(pid_file(), 0);
66 if (error_is_ok
and not wait
.successful())
68 Error
<< "Pidfile was not found:" << pid_file();
72 std::stringstream error_message
;
73 pid_t ret
= get_pid_from_file(pid_file(), error_message
);
75 if (error_is_ok
and is_pid_valid(ret
) == false)
77 Error
<< error_message
.str();
85 if (pid_file().empty())
87 Error
<< "No pid file available";
91 Wait
wait(pid_file(), 0);
92 if (not wait
.successful())
94 Error
<< "Pidfile was not found:" << pid_file();
98 std::stringstream error_message
;
99 pid_t local_pid
= get_pid_from_file(pid_file(), error_message
);
100 if (is_pid_valid(local_pid
) == false)
102 Error
<< error_message
.str();
106 // Use kill to determine is the process exist
107 if (::kill(local_pid
, 0) == 0)
117 return "blobslap_worker";
120 const char *executable()
122 return "benchmark/blobslap_worker";
125 const char *pid_file_option()
127 return "--pid-file=";
130 const char *daemon_file_option()
135 const char *log_file_option()
137 return "--log-file=";
140 const char *port_option()
150 bool build(int argc
, const char *argv
[]);
156 bool BlobslapWorker::build(int argc
, const char *argv
[])
158 std::stringstream arg_buffer
;
160 for (int x
= 1 ; x
< argc
; x
++)
162 arg_buffer
<< " " << argv
[x
] << " ";
165 set_extra_args(arg_buffer
.str());
170 Server
*build_blobslap_worker(in_port_t try_port
)
172 return new BlobslapWorker(try_port
);
175 } // namespace libtest