X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fserver_container.cc;h=05997238bb2379624f048217d9d4b488639f22f1;hb=6b83fd5838692b71a50710b9bc13680f9c586167;hp=27198ba3b53a65139cc9edc5051284af3c3698f2;hpb=5d68a7b1d0fff81d547b8a74ad72247437f412c5;p=m6w6%2Flibmemcached diff --git a/libtest/server_container.cc b/libtest/server_container.cc index 27198ba3..05997238 100644 --- a/libtest/server_container.cc +++ b/libtest/server_container.cc @@ -34,7 +34,7 @@ * */ -#include +#include "mem_config.h" #include #include @@ -55,13 +55,15 @@ static inline std::string &rtrim(std::string &s) namespace libtest { +Server* server_startup_st::last() +{ + return servers.back(); +} + 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()) { @@ -73,6 +75,9 @@ void server_startup_st::push_server(Server *arg) } 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+= ":"; @@ -111,7 +116,7 @@ bool server_startup_st::shutdown(uint32_t host_to_shutdown) void server_startup_st::clear() { - for (std::vector::iterator iter= servers.begin(); iter != servers.end(); iter++) + for (std::vector::iterator iter= servers.begin(); iter != servers.end(); ++iter) { delete *iter; } @@ -121,7 +126,7 @@ void server_startup_st::clear() bool server_startup_st::check() const { bool success= true; - for (std::vector::const_iterator iter= servers.begin(); iter != servers.end(); iter++) + for (std::vector::const_iterator iter= servers.begin(); iter != servers.end(); ++iter) { if ((*iter)->check() == false) { @@ -135,7 +140,7 @@ bool server_startup_st::check() const bool server_startup_st::shutdown() { bool success= true; - for (std::vector::iterator iter= servers.begin(); iter != servers.end(); iter++) + for (std::vector::iterator iter= servers.begin(); iter != servers.end(); ++iter) { if ((*iter)->has_pid() and (*iter)->kill() == false) { @@ -149,7 +154,7 @@ bool server_startup_st::shutdown() void server_startup_st::restart() { - for (std::vector::iterator iter= servers.begin(); iter != servers.end(); iter++) + for (std::vector::iterator iter= servers.begin(); iter != servers.end(); ++iter) { (*iter)->start(); } @@ -176,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) +{ + return 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) { @@ -196,6 +206,16 @@ bool server_startup(server_startup_st& construct, const std::string& server_type } } } + else if (server_type.compare("hostile-gearmand") == 0) + { + if (GEARMAND_BINARY) + { + if (HAVE_LIBGEARMAN) + { + server= build_gearmand("localhost", try_port, "gearmand/hostile_gearmand"); + } + } + } else if (server_type.compare("drizzled") == 0) { if (DRIZZLED_BINARY) @@ -221,17 +241,17 @@ bool server_startup(server_startup_st& construct, const std::string& server_type } else if (server_type.compare("memcached-sasl") == 0) { - if (MEMCACHED_SASL_BINARY) + if (MEMCACHED_BINARY) { if (HAVE_LIBMEMCACHED) { - server= build_memcached_sasl("localhost", try_port, construct.username(), construct.password()); + server= build_memcached_sasl("localhost", try_port, username(), password()); } } } else if (server_type.compare("memcached") == 0) { - if (MEMCACHED_BINARY) + if (HAVE_MEMCACHED_BINARY) { if (HAVE_LIBMEMCACHED) { @@ -239,22 +259,18 @@ bool server_startup(server_startup_st& construct, const std::string& server_type } } } - else if (server_type.compare("memcached-light") == 0) - { - if (MEMCACHED_LIGHT_BINARY) - { - if (HAVE_LIBMEMCACHED) - { - server= build_memcached_light("localhost", try_port); - } - } - } if (server == NULL) { - fatal_message("Launching of an unknown server was attempted"); + throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "Launching of an unknown server was attempted: %s", server_type.c_str()); } + } + catch (...) + { + throw; + } + try { /* We will now cycle the server we have created. */ @@ -267,29 +283,38 @@ bool server_startup(server_startup_st& construct, const std::string& server_type server->build(argc, argv); +#if 0 if (false) { Out << "Pausing for startup, hit return when ready."; std::string gdb_command= server->base_command(); - std::string options; -#if 0 - Out << "run " << server->args(options); -#endif getchar(); } - else if (server->start() == false) - { - delete server; - return false; - } else - { - if (opt_startup_message) +#endif + + if (server->start() == false) { - Outn(); - Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running(); - Outn(); + delete server; + return false; } + else + { + if (opt_startup_message) + { + Outn(); + Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running(); + Outn(); + } + } + } + catch (libtest::disconnected& err) + { + if (fatal::is_disabled() == false and try_port != LIBTEST_FAIL_PORT) + { + stream::cerr(err.file(), err.line(), err.func()) << err.what(); + delete server; + return false; } } catch (...) @@ -298,12 +323,14 @@ bool server_startup(server_startup_st& construct, const std::string& server_type throw; } - construct.push_server(server); + push_server(server); 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(); @@ -316,24 +343,6 @@ bool server_startup_st::start_socket_server(const std::string& server_type, cons { Error << "Socket files are not supported for gearmand yet"; } - else if (server_type.compare("memcached-sasl") == 0) - { - if (MEMCACHED_SASL_BINARY) - { - if (HAVE_LIBMEMCACHED) - { - server= build_memcached_sasl_socket("localhost", try_port, username(), password()); - } - else - { - Error << "Libmemcached was not found"; - } - } - else - { - Error << "No memcached binary is available"; - } - } else if (server_type.compare("memcached") == 0) { if (MEMCACHED_BINARY) @@ -375,17 +384,18 @@ bool server_startup_st::start_socket_server(const std::string& server_type, cons server->build(argc, argv); +#if 0 if (false) { Out << "Pausing for startup, hit return when ready."; std::string gdb_command= server->base_command(); std::string options; -#if 0 Out << "run " << server->args(options); -#endif getchar(); } - else if (server->start() == false) + else +#endif + if (server->start() == false) { Error << "Failed to start " << *server; delete server; @@ -393,7 +403,12 @@ bool server_startup_st::start_socket_server(const std::string& server_type, cons } else { - Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running(); + if (opt_startup_message) + { + Outn(); + Out << "STARTING SERVER(pid:" << server->pid() << "): " << server->running(); + Outn(); + } } } catch (...)