1 /*------------------------------------------------------------------------------
2 Name: TestEmbeddedXmlBlaster.java
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Test start/stop xmlBlaster in a thread
6 ------------------------------------------------------------------------------*/
7 package org.xmlBlaster.test.qos;
8
9 import java.util.logging.Logger;
10 import java.util.logging.Level;
11 import org.xmlBlaster.util.Global;
12 import org.xmlBlaster.util.ThreadLister;
13 import org.xmlBlaster.util.XmlBlasterException;
14 import org.xmlBlaster.client.qos.ConnectQos;
15 import org.xmlBlaster.client.qos.DisconnectQos;
16 import org.xmlBlaster.client.I_XmlBlasterAccess;
17 import org.xmlBlaster.client.key.GetKey;
18 import org.xmlBlaster.util.MsgUnit;
19 import org.xmlBlaster.util.EmbeddedXmlBlaster;
20 import org.xmlBlaster.test.Util;
21
22 import junit.framework.*;
23
24
25 /**
26 * This client tests to start an xmlBlaster server in a thread
27 * and stop it again.
28 * <p />
29 * Invoke examples:<br />
30 * <pre>
31 * java junit.textui.TestRunner org.xmlBlaster.test.qos.TestEmbeddedXmlBlaster
32 * java junit.swingui.TestRunner org.xmlBlaster.test.qos.TestEmbeddedXmlBlaster
33 * </pre>
34 * @see <a href="http://www.xmlblaster.org/xmlBlaster/doc/requirements/engine.runlevel.html">engine.runlevel</a>
35 * @see org.xmlBlaster.util.EmbeddedXmlBlaster
36 */
37 public class TestEmbeddedXmlBlaster extends TestCase
38 {
39 private static final String ME = "TestEmbeddedXmlBlaster";
40 private final Global glob;
41 private static Logger log = Logger.getLogger(TestEmbeddedXmlBlaster.class.getName());
42
43 private I_XmlBlasterAccess con = null;
44 private String name;
45 private String passwd = "secret";
46 private EmbeddedXmlBlaster serverThread;
47 private int serverPort = 7615;
48
49 /**
50 * Constructs the TestEmbeddedXmlBlaster object.
51 * <p />
52 * @param testName The name used in the test suite
53 */
54 public TestEmbeddedXmlBlaster(String testName) {
55 this(Global.instance(), testName);
56 }
57
58 public TestEmbeddedXmlBlaster(Global glob, String testName) {
59 super(testName);
60 this.glob = glob;
61
62 this.name = testName; // name to login to xmlBlaster
63 }
64
65 /**
66 * Sets up the fixture.
67 */
68 protected void setUp()
69 {
70 }
71
72 /**
73 * Tears down the fixture.
74 */
75 protected void tearDown()
76 {
77 // reset to default server port (necessary if other tests follow in the same JVM).
78 Util.resetPorts();
79 }
80
81 /**
82 * RMI fails as we don't know how to kill the registry
83 * JacORB 1.3.30 can't reinitialize the orb if once shutdown (so we leave it alive)
84 * hopefully fixed with JacORB 1.4.2
85 * XmlRpc has one thread open???
86 *
87 * <pre>
88 * BEFORE:
89 *
90 * Thread Group: system Max Priority: 10
91 * Thread: Signal dispatcher Priority: 5 Daemon
92 * Thread: Reference Handler Priority: 10 Daemon
93 * Thread: Finalizer Priority: 8 Daemon
94 * Thread Group: main Max Priority: 10
95 * Thread: main Priority: 5
96 *
97 * AFTER:
98 *
99 * Thread Group: system Max Priority: 10
100 * Thread: Signal dispatcher Priority: 5 Daemon
101 * Thread: Reference Handler Priority: 10 Daemon
102 * Thread: Finalizer Priority: 8 Daemon
103 * Thread: RMI TCP Accept-1 Priority: 5 Daemon
104 * Thread: RMI TCP Accept-2 Priority: 5 Daemon
105 * Thread: GC Daemon Priority: 2 Daemon
106 * Thread: RMI RenewClean-[192.168.1.3:33493] Priority: 5 Daemon
107 * Thread: RMI LeaseChecker Priority: 5 Daemon
108 * Thread: RMI ConnectionExpiration-[192.168.1.3:33493] Priority: 5 Daemon
109 * Thread: RMI ConnectionExpiration-[kinder:7613] Priority: 5 Daemon
110 * Thread Group: main Max Priority: 10
111 * Thread: XmlBlaster MainThread Priority: 5
112 * Thread: Thread-11 Priority: 10 Daemon
113 * Thread: JacORB Listener Thread on port 33489 Priority: 5 Daemon
114 * Thread: Thread-14 Priority: 10 Daemon
115 * Thread: Thread-16 Priority: 5 Daemon
116 * Thread Group: XMLRPC Runner Max Priority: 10
117 * Thread Group: RMI Runtime Max Priority: 10
118 * Thread: TCP Connection(3)-192.168.1.3 Priority: 5 Daemon
119 * Thread: TCP Connection(4)-192.168.1.3 Priority: 5 Daemon
120 * </pre>
121 */
122 public void testThreadFree()
123 {
124 log.info("######## Start testThreadFree()");
125
126 int threadsBefore = ThreadLister.countThreads();
127 log.info("Testing thread consume before xmlBlaster startup=" + threadsBefore);
128 ThreadLister.listAllThreads(System.out);
129
130 // Start xmlBlaster
131 // We register here the demo plugin with xmlBlaster server, supplying an argument to the plugin
132 String[] args = {
133 "-bootstrapPort", // For all protocol we may use set an alternate server port
134 "" + serverPort,
135 "-plugin/socket/port",
136 "" + (serverPort-1),
137 "-plugin/rmi/registryPort",
138 "" + (serverPort-2),
139 "-plugin/xmlrpc/port",
140 "" + (serverPort-3),
141 "-ProtocolPlugin[IOR][1.0]",
142 "org.xmlBlaster.protocol.corba.CorbaDriver",
143 "-CbProtocolPlugin[IOR][1.0]",
144 "org.xmlBlaster.protocol.corba.CallbackCorbaDriver"
145 };
146 glob.init(args);
147
148 serverThread = EmbeddedXmlBlaster.startXmlBlaster(glob);
149 log.info("XmlBlaster is ready for testing JDBC access");
150
151 // Stop xmlBlaster
152 try { Thread.sleep(100L); } catch( InterruptedException i) {}
153 EmbeddedXmlBlaster.stopXmlBlaster(this.serverThread);
154 this.serverThread = null;
155
156
157 ThreadLister.listAllThreads(System.out);
158 int threadsAfter = ThreadLister.countThreads();
159 log.info("Currently used threads after server startup/shutdown" + threadsAfter);
160 int allow = threadsBefore + 1; // This 1 thread is temporary
161 assertTrue("We have a thread leak, threadsBefore=" + threadsBefore + " threadsAfter=" + threadsAfter, threadsAfter <= allow);
162
163 }
164
165 /**
166 * Invoke: java org.xmlBlaster.test.qos.TestEmbeddedXmlBlaster
167 * @deprecated Use the TestRunner from the testsuite to run it:<p />
168 * <pre> java -Djava.compiler= junit.textui.TestRunner org.xmlBlaster.test.qos.TestEmbeddedXmlBlaster</pre>
169 */
170 public static void main(String args[])
171 {
172 Global glob = new Global();
173 if (glob.init(args) != 0) {
174 System.out.println(ME + ": Init failed");
175 System.exit(1);
176 }
177 TestEmbeddedXmlBlaster test = new TestEmbeddedXmlBlaster(glob, "TestEmbeddedXmlBlaster");
178 test.setUp();
179 test.testThreadFree();
180 test.tearDown();
181 }
182 }
syntax highlighted by Code2HTML, v. 0.9.1