testsuite/src/c++/TestEmbeddedServer.cpp

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------
00002 Name:      TestEmbeddedServer.cpp
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 Comment:   Testing the Timeout Features
00006 -----------------------------------------------------------------------------*/
00007 #include "TestSuite.h"
00008 #include <iostream>
00009 
00010 using namespace std;
00011 using namespace org::xmlBlaster::util;
00012 using namespace org::xmlBlaster::util::thread;
00013 using namespace org::xmlBlaster::client;
00014 using namespace org::xmlBlaster::client::qos;
00015 using namespace org::xmlBlaster::client::key;
00016 using namespace org::xmlBlaster;
00017 
00018 namespace org { namespace xmlBlaster { namespace test {
00019 
00020 class TestEmbeddedServer
00021 {
00022 private:
00023    string  ME;
00024    Global& global_;
00025    I_Log&  log_;
00026    long    sleepDelay_;
00027 
00028 
00029    inline void usage() 
00030    {
00031       log_.info(ME, "usage: all typical xmlBlaster command line arguments");
00032       log_.info(ME, "plus the following additional command line arguments:");
00033       log_.info(ME, " -h (for help: this command)");
00034       log_.info(ME, " -additional.sleep.delay (long) : the number of seconds to wait between shutting down and starting the embedded server and viceversa");
00035       log_.info(ME, " note that the embedded server will already wait until a connection is up until it continues to work, so normally you don't need additional waiting time");
00036       exit(0);
00037    }
00038 
00039 
00040 public:
00041    TestEmbeddedServer(Global& glob) 
00042       : ME("TestEmbeddedServer"), 
00043         global_(glob), 
00044         log_(glob.getLog())
00045    {
00046 
00047       int args = glob.getArgs();
00048       const char * const* argc = glob.getArgc();
00049       for (int i=0; i < args; i++) {
00050          string help = argc[i];
00051          if ( help == string("-h") || help == string("-help") || help == string("--help") || help == string("-?") ) {
00052             usage();
00053          }
00054       }
00055 
00056       sleepDelay_ = glob.getProperty().getLongProperty("additional.sleep.delay", 0L);
00057       if (sleepDelay_ < 0L) {
00058          sleepDelay_ = 0L;
00059          log_.warn(ME, "the additional.sleep.delay property was negative. Setting it to 0 s");
00060       }
00061    }
00062 
00063 
00064    virtual ~TestEmbeddedServer()
00065    {
00066    }
00067 
00068    void setUp()
00069    {
00070    }
00071 
00072    void tearDown()
00073    {
00074    }
00075 
00076    void testEmbeddedServer()
00077    {
00078       string delay = lexical_cast<string>(sleepDelay_);
00079       log_.info(ME, "testing the embedded server");
00080       log_.info(ME, "note that you should shut down running xmlBlaster servers before you run this test");
00081       log_.info(ME, string("an xmlBlaster server instance will be started now and after ") + delay + " seconds it will be");
00082       log_.info(ME, string("shut down. It then waits ") + delay + " seconds and starts again another server.");
00083       log_.info(ME, "it then will live for 15 seconds and die. The test ends there.");
00084       Thread::sleepSecs(3);
00085       EmbeddedServer server(global_, "", "");
00086       log_.info(ME, "starting the embedded server now");
00087       server.start();
00088       Thread::sleepSecs(sleepDelay_);
00089       log_.info(ME, "stopping the embedded server now");
00090       server.stop();
00091       Thread::sleepSecs(sleepDelay_);
00092       log_.info(ME, "starting the embedded server now");
00093       server.start();
00094       Thread::sleepSecs(15);
00095       log_.info(ME, "stopping the embedded server now");
00096       server.stop();
00097       log_.info(ME, "testEmbeddedServer ended successfully");
00098    }
00099 
00100 };
00101 
00102 }}} // namespace
00103 
00104 
00105 using namespace org::xmlBlaster::test;
00106 
00107 int main(int args, char *argv[])
00108 {
00109    org::xmlBlaster::util::Object_Lifetime_Manager::init();
00110    Global& glob = Global::getInstance();
00111    glob.initialize(args, argv);
00112    TestEmbeddedServer test(glob);
00113    
00114    test.setUp();
00115    test.testEmbeddedServer();
00116    test.tearDown();
00117 
00118    org::xmlBlaster::util::Object_Lifetime_Manager::fini();
00119    return 0;
00120 }