KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > remoting > configuration > threadpool > HTTPThreadPoolConfigurationTestCase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.remoting.configuration.threadpool;
8
9 import java.io.ByteArrayInputStream JavaDoc;
10 import java.net.InetAddress JavaDoc;
11 import javax.management.MBeanServer JavaDoc;
12 import javax.management.MBeanServerFactory JavaDoc;
13 import javax.management.ObjectName JavaDoc;
14 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
15 import org.jboss.remoting.Client;
16 import org.jboss.remoting.InvokerLocator;
17 import org.jboss.remoting.ServerInvoker;
18 import org.jboss.remoting.transport.Connector;
19 import org.jboss.remoting.transport.http.HTTPServerInvoker;
20 import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler;
21 import org.jboss.util.threadpool.BasicThreadPool;
22 import org.jboss.util.threadpool.ThreadPool;
23 import org.w3c.dom.Document JavaDoc;
24
25 import junit.framework.TestCase;
26
27
28 /**
29  * @author <a HREF="mailto:tom.elrod@jboss.com">Tom Elrod</a>
30  */

31 public class HTTPThreadPoolConfigurationTestCase extends TestCase
32 {
33    private String JavaDoc transport = "http";
34    private int serverPort = 6666;
35    private String JavaDoc hostName = null;
36    private Connector connector = null;
37    private BasicThreadPool tp = null;
38
39    public void setUp() throws Exception JavaDoc
40    {
41       MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
42
43       tp = new BasicThreadPool();
44       ObjectName JavaDoc objName = new ObjectName JavaDoc("test:type=threadpool");
45       server.registerMBean(tp, objName);
46
47
48       hostName = InetAddress.getLocalHost().getHostName();
49
50       connector = new Connector();
51       StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
52       buf.append("<?xml version=\"1.0\"?>\n");
53       buf.append("<config>");
54       buf.append("<invoker transport=\"" + transport + "\">");
55       buf.append("<attribute name=\"serverBindAddress\">" + hostName + "</attribute>");
56       buf.append("<attribute name=\"serverBindPort\">" + serverPort + "</attribute>");
57       //buf.append("<attribute name=\"" + HTTPServerInvoker.HTTP_THREAD_POOL_CLASS_KEY + "\">" + BasicThreadPool.class.getName() + "</attribute>");
58
buf.append("<attribute name=\"" + HTTPServerInvoker.HTTP_THREAD_POOL_CLASS_KEY + "\">" + objName + "</attribute>");
59       buf.append("</invoker>");
60       buf.append("<handlers>");
61       buf.append(" <handler subsystem=\"mock\">" + MockServerInvocationHandler.class.getName() + "</handler>\n");
62       buf.append("</handlers>");
63       buf.append("</config>");
64       Document JavaDoc xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream JavaDoc(buf.toString().getBytes()));
65       //connector.setInvokerLocator(locator.getLocatorURI());
66
connector.setConfiguration(xml.getDocumentElement());
67       server.registerMBean(connector, new ObjectName JavaDoc("test:type=connector,transport=http"));
68       connector.create();
69       connector.start();
70    }
71
72    public void testClientConfiguration() throws Exception JavaDoc
73    {
74       // make sure can call ont
75
Client client = new Client(new InvokerLocator(transport + "://" + hostName + ":" + serverPort));
76       String JavaDoc param = "foobar";
77       Object JavaDoc ret = null;
78       try
79       {
80          ret = client.invoke(param);
81       }
82       catch(Throwable JavaDoc throwable)
83       {
84          throwable.printStackTrace();
85       }
86       assertEquals(param, ret);
87
88       ServerInvoker invoker = connector.getServerInvoker();
89       HTTPServerInvoker httpInvoker = (HTTPServerInvoker)invoker;
90       ThreadPool tp2 = httpInvoker.getHTTPThreadPool();
91       assertEquals(tp, tp2);
92
93    }
94
95    public void tearDown() throws Exception JavaDoc
96    {
97       if(connector != null)
98       {
99          connector.stop();
100          connector.destroy();
101       }
102    }
103
104    public static void main(String JavaDoc[] args)
105    {
106       HTTPThreadPoolConfigurationTestCase testCase = new HTTPThreadPoolConfigurationTestCase();
107       try
108       {
109          testCase.setUp();
110          testCase.testClientConfiguration();
111          testCase.tearDown();
112       }
113       catch(Exception JavaDoc e)
114       {
115          e.printStackTrace();
116       }
117    }
118 }
Popular Tags