Browse Source

Update to keep app as a part of server bits.

Brian Aker 13 years ago
parent
commit
7c10594221
5 changed files with 23 additions and 30 deletions
  1. 1 6
      libtest/blobslap_worker.cc
  2. 1 6
      libtest/gearmand.cc
  3. 6 6
      libtest/memcached.cc
  4. 11 10
      libtest/server.cc
  5. 4 2
      libtest/server.h

+ 1 - 6
libtest/blobslap_worker.cc

@@ -49,7 +49,7 @@ class BlobslapWorker : public Server
 private:
 public:
   BlobslapWorker(in_port_t port_arg) :
-    Server("localhost", port_arg)
+    Server("localhost", port_arg, "benchmark/blobslap_worker", true)
   { 
     set_pid_file();
   }
@@ -118,11 +118,6 @@ public:
     return "blobslap_worker";
   };
 
-  const char *executable()
-  {
-    return "benchmark/blobslap_worker";
-  }
-
   const char *daemon_file_option()
   {
     return "--daemon";

+ 1 - 6
libtest/gearmand.cc

@@ -90,7 +90,7 @@ class Gearmand : public libtest::Server
 private:
 public:
   Gearmand(const std::string& host_arg, in_port_t port_arg) :
-    libtest::Server(host_arg, port_arg)
+    libtest::Server(host_arg, port_arg, GEARMAND_BINARY, true)
   {
     set_pid_file();
   }
@@ -160,11 +160,6 @@ public:
     return "gearmand";
   };
 
-  const char *executable()
-  {
-    return GEARMAND_BINARY;
-  }
-
   const char *daemon_file_option()
   {
     return "--daemon";

+ 6 - 6
libtest/memcached.cc

@@ -57,7 +57,7 @@ class Memcached : public libtest::Server
 
 public:
   Memcached(const std::string& host_arg, const in_port_t port_arg, const bool is_socket_arg, const std::string& username_arg, const std::string& password_arg) :
-    libtest::Server(host_arg, port_arg, is_socket_arg),
+    libtest::Server(host_arg, port_arg, is_socket_arg, MEMCACHED_BINARY, false),
     _username(username_arg),
     _password(password_arg)
   { }
@@ -228,8 +228,8 @@ class MemcachedLight : public libtest::Server
 {
 
 public:
-  MemcachedLight(const std::string& host_arg, const in_port_t port_arg):
-    libtest::Server(host_arg, port_arg)
+  MemcachedLight(const std::string& host_arg, const in_port_t port_arg) :
+    libtest::Server(host_arg, port_arg, MEMCACHED_LIGHT_BINARY, true)
   {
     set_pid_file();
   }
@@ -402,9 +402,9 @@ public:
   bool ping()
   {
     // Memcached is slow to start, so we need to do this
-    if (not pid_file().empty())
+    if (pid_file().empty() == false)
     {
-      if (not wait_for_pidfile())
+      if (wait_for_pidfile() == false)
       {
         Error << "Pidfile was not found:" << pid_file();
         return -1;
@@ -423,7 +423,7 @@ public:
       ret= libmemcached_util_ping2(hostname().c_str(), port(), username().c_str(), password().c_str(), &rc);
     }
 
-    if (memcached_failed(rc) or not ret)
+    if (memcached_failed(rc) or ret == false)
     {
       Error << "libmemcached_util_ping2(" << hostname() << ", " << port() << ", " << username() << ", " << password() << ") error: " << memcached_strerror(NULL, rc);
     }

+ 11 - 10
libtest/server.cc

@@ -76,12 +76,15 @@ std::ostream& operator<<(std::ostream& output, const Server &arg)
 
 #define MAGIC_MEMORY 123570
 
-Server::Server(const std::string& host_arg, const in_port_t port_arg, bool is_socket_arg) :
+Server::Server(const std::string& host_arg, const in_port_t port_arg,
+               const std::string& executable, const bool _is_libtool,
+               bool is_socket_arg) :
   _magic(MAGIC_MEMORY),
   _is_socket(is_socket_arg),
   _pid(-1),
   _port(port_arg),
-  _hostname(host_arg)
+  _hostname(host_arg),
+  _app(executable, _is_libtool)
 {
 }
 
@@ -147,35 +150,33 @@ bool Server::start()
     fatal_message("has_pid() failed, programer error");
   }
 
-  Application app(executable(), is_libtool());
-
   if (is_debug())
   {
-    app.use_gdb();
+    _app.use_gdb();
   }
   else if (getenv("TESTS_ENVIRONMENT"))
   {
     if (strstr(getenv("TESTS_ENVIRONMENT"), "gdb"))
     {
-      app.use_gdb();
+      _app.use_gdb();
     }
   }
 
-  if (args(app) == false)
+  if (args(_app) == false)
   {
     Error << "Could not build command()";
     return false;
   }
 
   Application::error_t ret;
-  if (Application::SUCCESS !=  (ret= app.run()))
+  if (Application::SUCCESS !=  (ret= _app.run()))
   {
     Error << "Application::run() " << ret;
     return false;
   }
-  _running= app.print();
+  _running= _app.print();
 
-  if (Application::SUCCESS !=  (ret= app.wait()))
+  if (Application::SUCCESS !=  (ret= _app.wait()))
   {
     Error << "Application::wait() " << _running << " " << ret;
     return false;

+ 4 - 2
libtest/server.h

@@ -55,12 +55,13 @@ protected:
   std::string _extra_args;
 
 public:
-  Server(const std::string& hostname, const in_port_t port_arg, const bool is_socket_arg= false);
+  Server(const std::string& hostname, const in_port_t port_arg,
+         const std::string& executable, const bool _is_libtool,
+         const bool is_socket_arg= false);
 
   virtual ~Server();
 
   virtual const char *name()= 0;
-  virtual const char *executable()= 0;
   virtual const char *daemon_file_option()= 0;
   virtual bool is_libtool()= 0;
 
@@ -235,6 +236,7 @@ public:
 protected:
   bool set_pid_file();
   Options _options;
+  Application _app;
 
 private:
   bool is_helgrind() const;