1 /*-----------------------------------------------------------------------------
2 Name: TestEmbeddedServer.cpp
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Testing the Timeout Features
6 -----------------------------------------------------------------------------*/
7 #include "TestSuite.h"
8 #include <iostream>
9
10 using namespace std;
11 using namespace org::xmlBlaster::util;
12 using namespace org::xmlBlaster::util::thread;
13 using namespace org::xmlBlaster::client;
14 using namespace org::xmlBlaster::client::qos;
15 using namespace org::xmlBlaster::client::key;
16 using namespace org::xmlBlaster;
17
18 namespace org { namespace xmlBlaster { namespace test {
19
20 class TestEmbeddedServer
21 {
22 private:
23 string ME;
24 Global& global_;
25 I_Log& log_;
26 long sleepDelay_;
27
28
29 inline void usage()
30 {
31 log_.info(ME, "usage: all typical xmlBlaster command line arguments");
32 log_.info(ME, "plus the following additional command line arguments:");
33 log_.info(ME, " -h (for help: this command)");
34 log_.info(ME, " -additional.sleep.delay (long) : the number of seconds to wait between shutting down and starting the embedded server and viceversa");
35 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");
36 exit(0);
37 }
38
39
40 public:
41 TestEmbeddedServer(Global& glob)
42 : ME("TestEmbeddedServer"),
43 global_(glob),
44 log_(glob.getLog())
45 {
46
47 int args = glob.getArgs();
48 const char * const* argc = glob.getArgc();
49 for (int i=0; i < args; i++) {
50 string help = argc[i];
51 if ( help == string("-h") || help == string("-help") || help == string("--help") || help == string("-?") ) {
52 usage();
53 }
54 }
55
56 sleepDelay_ = glob.getProperty().getLongProperty("additional.sleep.delay", 0L);
57 if (sleepDelay_ < 0L) {
58 sleepDelay_ = 0L;
59 log_.warn(ME, "the additional.sleep.delay property was negative. Setting it to 0 s");
60 }
61 }
62
63
64 virtual ~TestEmbeddedServer()
65 {
66 }
67
68 void setUp()
69 {
70 }
71
72 void tearDown()
73 {
74 }
75
76 void testEmbeddedServer()
77 {
78 string delay = lexical_cast<string>(sleepDelay_);
79 log_.info(ME, "testing the embedded server");
80 log_.info(ME, "note that you should shut down running xmlBlaster servers before you run this test");
81 log_.info(ME, string("an xmlBlaster server instance will be started now and after ") + delay + " seconds it will be");
82 log_.info(ME, string("shut down. It then waits ") + delay + " seconds and starts again another server.");
83 log_.info(ME, "it then will live for 15 seconds and die. The test ends there.");
84 Thread::sleepSecs(3);
85 EmbeddedServer server(global_, "", "");
86 log_.info(ME, "starting the embedded server now");
87 server.start();
88 Thread::sleepSecs(sleepDelay_);
89 log_.info(ME, "stopping the embedded server now");
90 server.stop();
91 Thread::sleepSecs(sleepDelay_);
92 log_.info(ME, "starting the embedded server now");
93 server.start();
94 Thread::sleepSecs(15);
95 log_.info(ME, "stopping the embedded server now");
96 server.stop();
97 log_.info(ME, "testEmbeddedServer ended successfully");
98 }
99
100 };
101
102 }}} // namespace
103
104
105 using namespace org::xmlBlaster::test;
106
107 int main(int args, char *argv[])
108 {
109 org::xmlBlaster::util::Object_Lifetime_Manager::init();
110 Global& glob = Global::getInstance();
111 glob.initialize(args, argv);
112 TestEmbeddedServer test(glob);
113
114 test.setUp();
115 test.testEmbeddedServer();
116 test.tearDown();
117
118 org::xmlBlaster::util::Object_Lifetime_Manager::fini();
119 return 0;
120 }
syntax highlighted by Code2HTML, v. 0.9.1