1 7 package org.jboss.test.remoting.configuration.threadpool; 8 9 import java.io.ByteArrayInputStream ; 10 import java.net.InetAddress ; 11 import javax.management.MBeanServer ; 12 import javax.management.MBeanServerFactory ; 13 import javax.management.ObjectName ; 14 import javax.xml.parsers.DocumentBuilderFactory ; 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 ; 24 25 import junit.framework.TestCase; 26 27 28 31 public class HTTPThreadPoolConfigurationTestCase extends TestCase 32 { 33 private String transport = "http"; 34 private int serverPort = 6666; 35 private String hostName = null; 36 private Connector connector = null; 37 private BasicThreadPool tp = null; 38 39 public void setUp() throws Exception 40 { 41 MBeanServer server = MBeanServerFactory.createMBeanServer(); 42 43 tp = new BasicThreadPool(); 44 ObjectName objName = new ObjectName ("test:type=threadpool"); 45 server.registerMBean(tp, objName); 46 47 48 hostName = InetAddress.getLocalHost().getHostName(); 49 50 connector = new Connector(); 51 StringBuffer buf = new StringBuffer (); 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 + "\">" + 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 xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream (buf.toString().getBytes())); 65 connector.setConfiguration(xml.getDocumentElement()); 67 server.registerMBean(connector, new ObjectName ("test:type=connector,transport=http")); 68 connector.create(); 69 connector.start(); 70 } 71 72 public void testClientConfiguration() throws Exception 73 { 74 Client client = new Client(new InvokerLocator(transport + "://" + hostName + ":" + serverPort)); 76 String param = "foobar"; 77 Object ret = null; 78 try 79 { 80 ret = client.invoke(param); 81 } 82 catch(Throwable 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 96 { 97 if(connector != null) 98 { 99 connector.stop(); 100 connector.destroy(); 101 } 102 } 103 104 public static void main(String [] args) 105 { 106 HTTPThreadPoolConfigurationTestCase testCase = new HTTPThreadPoolConfigurationTestCase(); 107 try 108 { 109 testCase.setUp(); 110 testCase.testClientConfiguration(); 111 testCase.tearDown(); 112 } 113 catch(Exception e) 114 { 115 e.printStackTrace(); 116 } 117 } 118 } | Popular Tags |