projects
/
m6w6
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
Merge of cppcheck, assert fix.
[m6w6/libmemcached]
/
libtest
/
server_container.cc
diff --git
a/libtest/server_container.cc
b/libtest/server_container.cc
index 3315b3bb5a6243a7cdc36929450b1f8d965c62de..0448e20900e2b847831a6f5c802a073e68eb9135 100644
(file)
--- a/
libtest/server_container.cc
+++ b/
libtest/server_container.cc
@@
-55,13
+55,15
@@
static inline std::string &rtrim(std::string &s)
namespace libtest {
namespace libtest {
+Server* server_startup_st::last()
+{
+ return servers.back();
+}
+
void server_startup_st::push_server(Server *arg)
{
servers.push_back(arg);
void server_startup_st::push_server(Server *arg)
{
servers.push_back(arg);
- char port_str[NI_MAXSERV];
- snprintf(port_str, sizeof(port_str), "%u", int(arg->port()));
-
std::string server_config_string;
if (arg->has_socket())
{
std::string server_config_string;
if (arg->has_socket())
{
@@
-73,6
+75,9
@@
void server_startup_st::push_server(Server *arg)
}
else
{
}
else
{
+ char port_str[NI_MAXSERV]= { 0 };
+ snprintf(port_str, sizeof(port_str), "%u", int(arg->port()));
+
server_config_string+= "--server=";
server_config_string+= arg->hostname();
server_config_string+= ":";
server_config_string+= "--server=";
server_config_string+= arg->hostname();
server_config_string+= ":";
@@
-91,13
+96,14
@@
Server* server_startup_st::pop_server()
return tmp;
}
return tmp;
}
-bool server_startup_st::shutdown(uint32_t number_of_host)
+// host_to_shutdown => host number to shutdown in array
+bool server_startup_st::shutdown(uint32_t host_to_shutdown)
{
{
- if (servers.size() >
number_of_host
)
+ if (servers.size() >
host_to_shutdown
)
{
{
- Server* tmp= servers[
number_of_host
];
+ Server* tmp= servers[
host_to_shutdown
];
- if (tmp and tmp->
has_pid() and tmp->
kill() == false)
+ if (tmp and tmp->kill() == false)
{ }
else
{
{ }
else
{
@@
-108,9
+114,9
@@
bool server_startup_st::shutdown(uint32_t number_of_host)
return false;
}
return false;
}
-void server_startup_st::
shutdown_and_remove
()
+void server_startup_st::
clear
()
{
{
- for (std::vector<Server *>::iterator iter= servers.begin(); iter != servers.end();
iter++
)
+ for (std::vector<Server *>::iterator iter= servers.begin(); iter != servers.end();
++iter
)
{
delete *iter;
}
{
delete *iter;
}
@@
-120,7
+126,7
@@
void server_startup_st::shutdown_and_remove()
bool server_startup_st::check() const
{
bool success= true;
bool server_startup_st::check() const
{
bool success= true;
- for (std::vector<Server *>::const_iterator iter= servers.begin(); iter != servers.end();
iter++
)
+ for (std::vector<Server *>::const_iterator iter= servers.begin(); iter != servers.end();
++iter
)
{
if ((*iter)->check() == false)
{
{
if ((*iter)->check() == false)
{
@@
-134,7
+140,7
@@
bool server_startup_st::check() const
bool server_startup_st::shutdown()
{
bool success= true;
bool server_startup_st::shutdown()
{
bool success= true;
- for (std::vector<Server *>::iterator iter= servers.begin(); iter != servers.end();
iter++
)
+ for (std::vector<Server *>::iterator iter= servers.begin(); iter != servers.end();
++iter
)
{
if ((*iter)->has_pid() and (*iter)->kill() == false)
{
{
if ((*iter)->has_pid() and (*iter)->kill() == false)
{
@@
-148,7
+154,7
@@
bool server_startup_st::shutdown()
void server_startup_st::restart()
{
void server_startup_st::restart()
{
- for (std::vector<Server *>::iterator iter= servers.begin(); iter != servers.end();
iter++
)
+ for (std::vector<Server *>::iterator iter= servers.begin(); iter != servers.end();
++iter
)
{
(*iter)->start();
}
{
(*iter)->start();
}
@@
-166,7
+172,7
@@
server_startup_st::server_startup_st() :
server_startup_st::~server_startup_st()
{
server_startup_st::~server_startup_st()
{
-
shutdown_and_remove
();
+
clear
();
}
bool server_startup_st::validate()
}
bool server_startup_st::validate()
@@
-175,6
+181,11
@@
bool server_startup_st::validate()
}
bool server_startup(server_startup_st& construct, const std::string& server_type, in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message)
}
bool server_startup(server_startup_st& construct, const std::string& server_type, in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message)
+{
+ construct.start_server(server_type, try_port, argc, argv, opt_startup_message);
+}
+
+bool server_startup_st::start_server(const std::string& server_type, in_port_t try_port, int argc, const char *argv[], const bool opt_startup_message)
{
if (try_port <= 0)
{
{
if (try_port <= 0)
{
@@
-182,209
+193,240
@@
bool server_startup(server_startup_st& construct, const std::string& server_type
}
libtest::Server *server= NULL;
}
libtest::Server *server= NULL;
- if (0)
- { }
- else if (server_type.compare("gearmand") == 0)
- {
- if (GEARMAND_BINARY)
+ try {
+ if (0)
+ { }
+ else if (server_type.compare("gearmand") == 0)
{
{
- if (
HAVE_LIBGEARMAN
)
+ if (
GEARMAND_BINARY
)
{
{
- server= build_gearmand("localhost", try_port);
+ if (HAVE_LIBGEARMAN)
+ {
+ server= build_gearmand("localhost", try_port);
+ }
}
}
}
}
- }
- else if (server_type.compare("drizzled") == 0)
- {
- if (DRIZZLED_BINARY)
+ else if (server_type.compare("hostile-gearmand") == 0)
{
{
- if (
HAVE_LIBDRIZZLE
)
+ if (
GEARMAND_BINARY
)
{
{
- server= build_drizzled("localhost", try_port);
+ if (HAVE_LIBGEARMAN)
+ {
+ server= build_gearmand("localhost", try_port, "gearmand/hostile_gearmand");
+ }
}
}
}
}
- }
- else if (server_type.compare("blobslap_worker") == 0)
- {
- if (GEARMAND_BINARY)
+ else if (server_type.compare("drizzled") == 0)
{
{
- if (
GEARMAND_BLOBSLAP_WORKER
)
+ if (
DRIZZLED_BINARY
)
{
{
- if (HAVE_LIB
GEARMAN
)
+ if (HAVE_LIB
DRIZZLE
)
{
{
- server= build_
blobslap_worker(
try_port);
+ server= build_
drizzled("localhost",
try_port);
}
}
}
}
}
}
- }
- else if (server_type.compare("memcached-sasl") == 0)
- {
- if (MEMCACHED_SASL_BINARY)
+ else if (server_type.compare("blobslap_worker") == 0)
{
{
- if (
HAVE_LIBMEMCACHED
)
+ if (
GEARMAND_BINARY
)
{
{
- server= build_memcached_sasl("localhost", try_port, construct.username(), construct.password());
+ if (GEARMAND_BLOBSLAP_WORKER)
+ {
+ if (HAVE_LIBGEARMAN)
+ {
+ server= build_blobslap_worker(try_port);
+ }
+ }
}
}
}
}
- }
- else if (server_type.compare("memcached") == 0)
- {
- if (MEMCACHED_BINARY)
+ else if (server_type.compare("memcached-sasl") == 0)
+ {
+ if (MEMCACHED_SASL_BINARY)
+ {
+ if (HAVE_LIBMEMCACHED)
+ {
+ server= build_memcached_sasl("localhost", try_port, username(), password());
+ }
+ }
+ }
+ else if (server_type.compare("memcached") == 0)
{
{
- if (HAVE_
LIBMEMCACHED
)
+ if (HAVE_
MEMCACHED_BINARY
)
{
{
- server= build_memcached("localhost", try_port);
+ if (HAVE_LIBMEMCACHED)
+ {
+ server= build_memcached("localhost", try_port);
+ }
}
}
}
}
- }
- else if (server_type.compare("memcached-light") == 0)
- {
- if (MEMCACHED_LIGHT_BINARY)
+ else if (server_type.compare("memcached-light") == 0)
{
{
- if (
HAVE_LIBMEMCACHED
)
+ if (
MEMCACHED_LIGHT_BINARY
)
{
{
- server= build_memcached_light("localhost", try_port);
+ if (HAVE_LIBMEMCACHED)
+ {
+ server= build_memcached_light("localhost", try_port);
+ }
}
}
}
}
- }
- if (server == NULL)
- {
-
fatal_message("Launching of an unknown server was attempted"
);
- }
+
if (server == NULL)
+
{
+
throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Launching of an unknown server was attempted: %s", server_type.c_str()
);
+
}
- /*
- We will now cycle the server we have created.
- */
- if (server->cycle() == false)
- {
- Error << "Could not start up server " << *server;
- delete server;
- return false;
- }
+
/*
+
We will now cycle the server we have created.
+
*/
+
if (server->cycle() == false)
+
{
+
Error << "Could not start up server " << *server;
+
delete server;
+
return false;
+
}
- server->build(argc, argv);
+
server->build(argc, argv);
- if (false)
- {
- Out << "Pausing for startup, hit return when ready.";
- std::string gdb_command= server->base_command();
- std::string options;
#if 0
#if 0
- Out << "run " << server->args(options);
+ if (false)
+ {
+ Out << "Pausing for startup, hit return when ready.";
+ std::string gdb_command= server->base_command();
+ getchar();
+ }
+ else
#endif
#endif
- getchar();
+ if (server->start() == false)
+ {
+ delete server;
+ return false;
+ }
+ else
+ {
+ if (opt_startup_message)
+ {
+ Outn();
+ Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running();
+ Outn();
+ }
+ }
}
}
-
else if (server->start() == false
)
+
catch (...
)
{
delete server;
{
delete server;
- return false;
- }
- else
- {
- if (opt_startup_message)
- {
- Outn();
- Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running();
- Outn();
- }
+ throw;
}
}
-
construct.
push_server(server);
+ push_server(server);
return true;
}
return true;
}
-bool server_startup_st::start_socket_server(const std::string& server_type, const in_port_t try_port, int argc, const char *argv[])
+bool server_startup_st::start_socket_server(const std::string& server_type, const in_port_t try_port, int argc,
+ const char *argv[],
+ const bool opt_startup_message)
{
(void)try_port;
Outn();
Server *server= NULL;
{
(void)try_port;
Outn();
Server *server= NULL;
- if (0)
- { }
- else if (server_type.compare("gearmand") == 0)
- {
- Error << "Socket files are not supported for gearmand yet";
- }
- else if (server_type.compare("memcached-sasl") == 0)
- {
- if (MEMCACHED_SASL_BINARY)
+ try {
+ if (0)
+ { }
+ else if (server_type.compare("gearmand") == 0)
{
{
- if (HAVE_LIBMEMCACHED)
+ Error << "Socket files are not supported for gearmand yet";
+ }
+ else if (server_type.compare("memcached-sasl") == 0)
+ {
+ if (MEMCACHED_SASL_BINARY)
{
{
- server= build_memcached_sasl_socket("localhost", try_port, username(), password());
+ if (HAVE_LIBMEMCACHED)
+ {
+ server= build_memcached_sasl_socket("localhost", try_port, username(), password());
+ }
+ else
+ {
+ Error << "Libmemcached was not found";
+ }
}
else
{
}
else
{
- Error << "
Libmemcached was not found
";
+ Error << "
No memcached binary is available
";
}
}
}
}
- else
- {
- Error << "No memcached binary is available";
- }
- }
- else if (server_type.compare("memcached") == 0)
- {
- if (MEMCACHED_BINARY)
+ else if (server_type.compare("memcached") == 0)
{
{
- if (
HAVE_LIBMEMCACHED
)
+ if (
MEMCACHED_BINARY
)
{
{
- server= build_memcached_socket("localhost", try_port);
+ if (HAVE_LIBMEMCACHED)
+ {
+ server= build_memcached_socket("localhost", try_port);
+ }
+ else
+ {
+ Error << "Libmemcached was not found";
+ }
}
else
{
}
else
{
- Error << "
Libmemcached was not found
";
+ Error << "
No memcached binary is available
";
}
}
else
{
}
}
else
{
- Error << "
No memcached binary is available
";
+ Error << "
Failed to start " << server_type << ", no support was found to be compiled in for it.
";
}
}
- }
- else
- {
- Error << "Failed to start " << server_type << ", no support was found to be compiled in for it.";
- }
- if (server == NULL)
- {
- Error << "Failure occured while creating server: " << server_type;
- return false;
- }
+
if (server == NULL)
+
{
+
Error << "Failure occured while creating server: " << server_type;
+
return false;
+
}
- /*
- We will now cycle the server we have created.
- */
- if (server->cycle() == false)
- {
- Error << "Could not start up server " << *server;
- delete server;
- return false;
- }
+
/*
+
We will now cycle the server we have created.
+
*/
+
if (server->cycle() == false)
+
{
+
Error << "Could not start up server " << *server;
+
delete server;
+
return false;
+
}
- server->build(argc, argv);
+
server->build(argc, argv);
- if (false)
- {
- Out << "Pausing for startup, hit return when ready.";
- std::string gdb_command= server->base_command();
- std::string options;
#if 0
#if 0
- Out << "run " << server->args(options);
+ if (false)
+ {
+ Out << "Pausing for startup, hit return when ready.";
+ std::string gdb_command= server->base_command();
+ std::string options;
+ Out << "run " << server->args(options);
+ getchar();
+ }
+ else
#endif
#endif
- getchar();
+ if (server->start() == false)
+ {
+ Error << "Failed to start " << *server;
+ delete server;
+ return false;
+ }
+ else
+ {
+ if (opt_startup_message)
+ {
+ Outn();
+ Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running();
+ Outn();
+ }
+ }
}
}
-
else if (server->start() == false
)
+
catch (...
)
{
{
- Error << "Failed to start " << *server;
delete server;
delete server;
- return false;
- }
- else
- {
- Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running();
+ throw;
}
push_server(server);
}
push_server(server);