cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1304005 - in /cxf/trunk: rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/ systests/transports/src/test/java/org/apache/cxf/systest/http_jetty/
Date Thu, 22 Mar 2012 19:37:09 GMT
Author: dkulp
Date: Thu Mar 22 19:37:09 2012
New Revision: 1304005

URL: http://svn.apache.org/viewvc?rev=1304005&view=rev
Log:
There are a minimum number of threads that Jetty needs, but Jetty
doesn't warn about it.  We will.

Modified:
    cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
    cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/Messages.properties
    cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http_jetty/Server.java
    cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http_jetty/ThreadPoolTest.java
    cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http_jetty/cxf.xml

Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java?rev=1304005&r1=1304004&r2=1304005&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngine.java
Thu Mar 22 19:37:09 2012
@@ -458,6 +458,17 @@ public class JettyHTTPServerEngine
                 aconn.getServer().setThreadPool(pool);
                 aconn.setThreadPool(pool);
             }
+            //threads for the acceptors and selectors are taken from 
+            //the pool so we need to have room for those
+            int acc = aconn.getAcceptors() * 2;
+            if (getThreadingParameters().isSetMaxThreads()
+                && getThreadingParameters().getMaxThreads() <= acc) {
+                throw new Fault(new Message("NOT_ENOUGH_THREADS", LOG,
+                                            port,
+                                            acc + 1,
+                                            getThreadingParameters().getMaxThreads(),
+                                            acc));
+            }
             if (pool instanceof QueuedThreadPool) {
                 QueuedThreadPool pl = (QueuedThreadPool)pool;
                 if (getThreadingParameters().isSetMinThreads()) {
@@ -472,7 +483,7 @@ public class JettyHTTPServerEngine
                         pool.getClass().getMethod("setMinThreads", Integer.TYPE)
                             .invoke(pool, getThreadingParameters().getMinThreads());
                     }
-                    if (getThreadingParameters().isSetMinThreads()) {
+                    if (getThreadingParameters().isSetMaxThreads()) {
                         pool.getClass().getMethod("setMaxThreads", Integer.TYPE)
                             .invoke(pool, getThreadingParameters().getMaxThreads());
                     }

Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/Messages.properties?rev=1304005&r1=1304004&r2=1304005&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/Messages.properties
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/Messages.properties
Thu Mar 22 19:37:09 2012
@@ -26,3 +26,4 @@ FAILED_TO_SHUTDOWN_ENGINE_MSG = Failed t
 UNKNOWN_CONNECTOR_MSG = Unknown connector type {0}, can''t set the socket reuseAddress flag.
 INVALID_ENCODING_MSG = Invalid character set {0} in request.
 FALLBACK_THREADING_PARAMETERS_MSG = No explicitly configured threading parameters for port
{0}, using fallback values min:{1} max:{2}
+NOT_ENOUGH_THREADS = Not enough threads configured for port {0}.  Need at least {1} ({3}
for Jetty selectors and set managers) but only {2} configured.
\ No newline at end of file

Modified: cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http_jetty/Server.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http_jetty/Server.java?rev=1304005&r1=1304004&r2=1304005&view=diff
==============================================================================
--- cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http_jetty/Server.java
(original)
+++ cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http_jetty/Server.java
Thu Mar 22 19:37:09 2012
@@ -32,6 +32,9 @@ public class Server extends AbstractBusT
     static final String PORT = allocatePort(Server.class);
     static final String ADDRESS = "http://localhost:" + PORT + "/SoapContext/SoapPort";
 
+    Endpoint ep;
+    
+    
     protected void run()  {
 
         SpringBusFactory factory = new SpringBusFactory();
@@ -40,7 +43,14 @@ public class Server extends AbstractBusT
         setBus(bus);
 
         GreeterImpl implementor = new GreeterImpl();
-        Endpoint.publish(ADDRESS, implementor);
+        ep = Endpoint.publish(ADDRESS, implementor);
+    }
+    
+    @Override
+    public void tearDown() {
+        if (ep != null) {
+            ep.stop();
+        }
     }
         
     public static void main(String[] args) {

Modified: cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http_jetty/ThreadPoolTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http_jetty/ThreadPoolTest.java?rev=1304005&r1=1304004&r2=1304005&view=diff
==============================================================================
--- cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http_jetty/ThreadPoolTest.java
(original)
+++ cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http_jetty/ThreadPoolTest.java
Thu Mar 22 19:37:09 2012
@@ -44,8 +44,10 @@ public class ThreadPoolTest extends Abst
 
     @BeforeClass
     public static void startServers() throws Exception {
+        int threads = Math.max(1, (Runtime.getRuntime().availableProcessors() + 3) / 4) *
2 + 3;
+        System.setProperty("ThreadPoolTest.threads", Integer.toString(threads));
         assertTrue("server did not launch correctly", 
-                   launchServer(Server.class, false));
+                   launchServer(Server.class, true));
     }
 
     @Before
@@ -56,34 +58,53 @@ public class ThreadPoolTest extends Abst
         bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                    ADDRESS);
     }
+    
+    class TestRunnable implements Runnable {
+        int i;
+        long total;
+        
+        public TestRunnable(int i) {
+            this.i = i;
+        }
+        public void run() {
+            long start = System.currentTimeMillis();
+            try {
+                greeter.greetMeLater(2 * 1000);
+            } catch (Throwable t) {
+                //ignore
+                t.printStackTrace();
+            }
+            long end = System.currentTimeMillis();
+            total = end - start;
+        }
+        public long getTotal() {
+            return total;
+        }
+    }
 
     @Test
-    public void testFallbackThreadPoolConfig() throws Exception { 
-        Runnable r = new Runnable() {
-            public void run() {
-                try {
-                    greeter.greetMeLater(5 * 1000);
-                } catch (Throwable t) {
-                    //ignore
-                }
-            }
-        };
+    public void testFallbackThreadPoolConfig() throws Exception {
+        TestRunnable r[] = new TestRunnable[5];
         Thread[] invokers = new Thread[5];
-        long start = System.currentTimeMillis();
         for (int i = 0; i < invokers.length; i++) {
-            invokers[i] = new Thread(r);
+            r[i] = new TestRunnable(i);
+            invokers[i] = new Thread(r[i]);
             invokers[i].setDaemon(true);
             invokers[i].start();
         }
+        
+        int countLess = 0;
+        int countMore = 0;
         for (int i = 0; i < invokers.length; i++) {
-            invokers[i].join(15 * 1000);
-            long end = System.currentTimeMillis();
-            if ((end - start) > (10 * 1000L)) {
-                return;
+            invokers[i].join(6 * 1000);
+            if (r[i].getTotal() > 3000) {
+                countMore++;
+            } else {
+                countLess++;
             }
         }
-        long end = System.currentTimeMillis();
-        assertTrue("unexpected duration: " + (end - start),
-                   end - start > 10 * 1000L);
+        assertEquals(3, countLess);
+        assertEquals(2, countMore);
+        
     }
 }

Modified: cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http_jetty/cxf.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http_jetty/cxf.xml?rev=1304005&r1=1304004&r2=1304005&view=diff
==============================================================================
--- cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http_jetty/cxf.xml
(original)
+++ cxf/trunk/systests/transports/src/test/java/org/apache/cxf/systest/http_jetty/cxf.xml
Thu Mar 22 19:37:09 2012
@@ -25,6 +25,6 @@ http://cxf.apache.org/transports/http/co
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
   
     <http:conduit name="*.http-conduit">
-      <http:client AllowChunking="false"/>
+      <http:client AllowChunking="false" Connection="close"/>
     </http:conduit>
 </beans>
\ No newline at end of file



Mime
View raw message