You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2010/07/22 14:18:59 UTC

svn commit: r966613 - in /tomcat/trunk: build.xml test/org/apache/catalina/startup/TestTomcatSSL.java test/org/apache/catalina/startup/TomcatBaseTest.java webapps/docs/changelog.xml

Author: markt
Date: Thu Jul 22 12:18:59 2010
New Revision: 966613

URL: http://svn.apache.org/viewvc?rev=966613&view=rev
Log:
Run all unit tests will all connectors

Modified:
    tomcat/trunk/build.xml
    tomcat/trunk/test/org/apache/catalina/startup/TestTomcatSSL.java
    tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/build.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/build.xml?rev=966613&r1=966612&r2=966613&view=diff
==============================================================================
--- tomcat/trunk/build.xml (original)
+++ tomcat/trunk/build.xml Thu Jul 22 12:18:59 2010
@@ -928,39 +928,72 @@
   </target>
 
   <target name="test" description="Runs the JUnit test cases"
-    depends="test-compile,deploy" >
+          depends="test-bio,test-nio,test-apr" >
+  </target>
+  
+  <target name="test-bio" description="Runs the JUnit test cases for BIO"
+          depends="test-compile,deploy" >
+    <runtests protocol="org.apache.coyote.http11.Http11Protocol"
+              extension=".BIO.txt" />
+  </target>
+  
+  <target name="test-nio" description="Runs the JUnit test cases for NIO"
+          depends="test-compile,deploy" >
+    <runtests protocol="org.apache.coyote.http11.Http11NioProtocol"
+              extension=".NIO.txt" />
+  </target>
+  
+  <target name="test-apr" description="Runs the JUnit test cases for APR"
+          depends="test-compile,deploy,test-apr-exists"
+  	      if="${apr.exists}">
+    <runtests protocol="org.apache.coyote.http11.Http11AprProtocol"
+              extension=".APR.txt" />
+  </target>
+  
+  <target name="test-apr-exists" description="Checks for APR lib">
+    <available file="${tomcat.build}/bin/native" property="apr.exists" />
+  </target>
+
+  <macrodef name="runtests"
+            description="Runs the unit tests using the specified connector" >
+    <attribute name="protocol"
+               description="The class name for the connector protocol"/>
+    <attribute name="extension"
+               description="The extension to use to distinguish the output"/>
 
-    <junit printsummary="yes" fork="yes" dir="." showoutput="yes">
+    <sequential>
+      <junit printsummary="yes" fork="yes" dir="." showoutput="yes">
 
-      <jvmarg value="-Dsun.security.ssl.allowUnsafeRenegotiation=true" />
-      <jvmarg value="-Djava.library.path=${tomcat.build}/bin/native"/>
+        <jvmarg value="-Djava.library.path=${tomcat.build}/bin/native"/>
 
-      <classpath refid="tomcat.test.classpath" />
+        <classpath refid="tomcat.test.classpath" />
 
-      <sysproperty key="tomcat.test.temp" value="${test.temp}" />
-      <sysproperty key="tomcat.test.tomcatbuild" value="${tomcat.build}" />
-
-      <formatter type="plain" usefile="true" />
-
-      <!-- If test.entry is defined, run a single test, otherwise run all valid tests -->
-      <test todir="${tomcat.build}/logs" name="${test.entry}" if="test.entry"/>
-      <batchtest todir="${tomcat.build}/logs" unless="test.entry"
-        errorproperty="test.result.error" failureproperty="test.result.failure" 
-        >
-        <fileset dir="test" >
-          <!-- Include all by default -->
-          <include name="**/Test*.java" />
-          <!-- Exclude helper classes -->
-          <exclude name="**/Tester*.java" />
-          <!-- Exclude the tests known to fail -->
-          <exclude name="org/apache/catalina/tribes/**" />
-        </fileset>
-      </batchtest>
-    </junit>
+        <sysproperty key="tomcat.test.temp" value="${test.temp}" />
+        <sysproperty key="tomcat.test.tomcatbuild" value="${tomcat.build}" />
+        <sysproperty key="tomcat.test.protocol" value="@{protocol}" />
+
+        <formatter type="plain" usefile="true" extension="@{extension}"/>
+
+        <!-- If test.entry is defined, run a single test, otherwise run all valid tests -->
+        <test todir="${tomcat.build}/logs" name="${test.entry}" if="test.entry"/>
+        <batchtest todir="${tomcat.build}/logs" unless="test.entry"
+          errorproperty="test.result.error" failureproperty="test.result.failure" 
+          >
+          <fileset dir="test" >
+            <!-- Include all by default -->
+            <include name="**/Test*.java" />
+            <!-- Exclude helper classes -->
+            <exclude name="**/Tester*.java" />
+            <!-- Exclude the tests known to fail -->
+            <exclude name="org/apache/catalina/tribes/**" />
+          </fileset>
+        </batchtest>
+      </junit>
 
-    <fail if="test.result.error" message="Some tests completed with an Error. See ${tomcat.build}/logs for details." />
-    <fail if="test.result.failure" message="Some tests completed with a Failure. See ${tomcat.build}/logs for details." />
-  </target>
+      <fail if="test.result.error" message="Some tests completed with an Error. See ${tomcat.build}/logs for details." />
+      <fail if="test.result.failure" message="Some tests completed with a Failure. See ${tomcat.build}/logs for details." />
+    </sequential>
+  </macrodef>
 
   <target name="extras-prepare" >
     <mkdir dir="${tomcat.extras}"/>

Modified: tomcat/trunk/test/org/apache/catalina/startup/TestTomcatSSL.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestTomcatSSL.java?rev=966613&r1=966612&r2=966613&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/TestTomcatSSL.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TestTomcatSSL.java Thu Jul 22 12:18:59 2010
@@ -30,7 +30,6 @@ import javax.net.ssl.SSLSocketFactory;
 import javax.net.ssl.TrustManager;
 import javax.net.ssl.X509TrustManager;
 
-import org.apache.catalina.connector.Connector;
 import org.apache.tomcat.util.buf.ByteChunk;
 
 /**
@@ -56,15 +55,7 @@ public class TestTomcatSSL extends Tomca
         }
     };
 
-    private void initSsl(Tomcat tomcat, boolean nio) {
-        if (nio) {
-            Connector connector = 
-                new Connector("org.apache.coyote.http11.Http11NioProtocol");
-            connector.setPort(getPort());
-            tomcat.getService().addConnector(connector);
-            tomcat.setConnector(connector);
-            tomcat.getConnector().setProperty("sslProtocol", "tls");
-        }
+    private void initSsl(Tomcat tomcat) {
         String protocol = tomcat.getConnector().getProtocolHandlerClassName();
         if (protocol.indexOf("Apr") == -1) {
             tomcat.getConnector().setProperty("sslProtocol", "tls");
@@ -88,14 +79,6 @@ public class TestTomcatSSL extends Tomca
     }
     
     public void testSimpleSsl() throws Exception {
-        simpleSsl(false);
-    }
-    
-    public void testSimpleSslNio() throws Exception {
-        simpleSsl(true);
-    }
-    
-    public void simpleSsl(boolean nio) throws Exception {
         // Install the all-trusting trust manager so https:// works 
         // with unsigned certs. 
 
@@ -113,7 +96,7 @@ public class TestTomcatSSL extends Tomca
         File appDir = new File(getBuildDirectory(), "webapps/examples");
         tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
         
-        initSsl(tomcat, nio);
+        initSsl(tomcat);
 
         tomcat.start();
         ByteChunk res = getUrl("https://localhost:" + getPort() +
@@ -124,19 +107,16 @@ public class TestTomcatSSL extends Tomca
     boolean handshakeDone = false;
     
     public void testRenegotiateFail() throws Exception {
-        renegotiateFail(false);
-    }
-    
-    public void renegotiateFail(boolean nio) throws Exception {
         Tomcat tomcat = getTomcatInstance();
 
         File appDir = new File(getBuildDirectory(), "webapps/examples");
         // app dir is relative to server home
         tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
 
-        initSsl(tomcat, nio);
-        // Default - MITM not enabled
+        initSsl(tomcat);
 
+        // Default - MITM attack prevented
+        
         tomcat.start();
         SSLContext sslCtx = SSLContext.getInstance("TLS");
         sslCtx.init(null, trustAllCerts, new java.security.SecureRandom());
@@ -191,36 +171,22 @@ public class TestTomcatSSL extends Tomca
     }
     
     public void testRenegotiateWorks() throws Exception {
-        renegotiateWorks(false);
-    }
-    
-    
-    // Re-negotiation not implemented in NIO
-    //    public void testRenegotiateWorksNio() throws Exception {
-    //        renegotiateWorks(true);    
-    //    }
-
-    public void testRenegotiateFailNio() throws Exception {
-        renegotiateFail(true);        
-    }
-    
-    
-    public void renegotiateWorks(boolean nio) throws Exception {
         Tomcat tomcat = getTomcatInstance();
 
         File appDir = new File(getBuildDirectory(), "webapps/examples");
         // app dir is relative to server home
         tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
 
-        initSsl(tomcat, nio);
+        initSsl(tomcat);
+        
         // Enable MITM attack
         tomcat.getConnector().setAttribute("allowUnsafeLegacyRenegotiation", "true");
 
         tomcat.start();
 
         String protocol = tomcat.getConnector().getProtocolHandlerClassName();
-        if (protocol.indexOf("Apr") != -1) {
-            return; // Not supported yet (10/05/25)
+        if (protocol.indexOf("Nio") != -1) {
+            return; // Not supported yet (2010-07-22)
         }
 
         SSLContext sslCtx = SSLContext.getInstance("TLS");
@@ -265,4 +231,11 @@ public class TestTomcatSSL extends Tomca
         }
         
     }
+
+    @Override
+    public void setUp() throws Exception {
+        // Make sure SSL renegotiation is not disabled in the JVM
+        System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");
+        super.setUp();
+    }
 }

Modified: tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java?rev=966613&r1=966612&r2=966613&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java (original)
+++ tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java Thu Jul 22 12:18:59 2010
@@ -32,6 +32,7 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.catalina.LifecycleState;
+import org.apache.catalina.connector.Connector;
 import org.apache.catalina.core.StandardServer;
 import org.apache.catalina.core.AprLifecycleListener;
 
@@ -109,17 +110,30 @@ public abstract class TomcatBaseTest ext
         
         tomcat = new Tomcat();
 
-        // Add AprLifecycleListener
-        StandardServer server = (StandardServer) tomcat.getServer();
-        AprLifecycleListener listener = new AprLifecycleListener();
-        server.addLifecycleListener(listener);
+        // Has a protocol been specified
+        String protocol = System.getProperty("tomcat.test.protocol");
         
-        tomcat.setBaseDir(tempDir.getAbsolutePath());
-        tomcat.getHost().setAppBase(appBase.getAbsolutePath());
-          
+        // Use BIO by default
+        if (protocol == null) {
+            protocol = "org.apache.coyote.http11.Http11Protocol";
+        }
+
+        Connector connector = new Connector(protocol);
         // If each test is running on same port - they
         // may interfere with each other (on unix at least)
-        tomcat.setPort(getNextPort());
+        connector.setPort(getNextPort());
+        tomcat.getService().addConnector(connector);
+        tomcat.setConnector(connector);
+
+        // Add AprLifecycleListener if we are using the Apr connector
+        if (protocol.contains("Apr")) {
+            StandardServer server = (StandardServer) tomcat.getServer();
+            AprLifecycleListener listener = new AprLifecycleListener();
+            server.addLifecycleListener(listener);
+        }
+        
+        tomcat.setBaseDir(tempDir.getAbsolutePath());
+        tomcat.getHost().setAppBase(appBase.getAbsolutePath());
     }
     
     @Override

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=966613&r1=966612&r2=966613&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Jul 22 12:18:59 2010
@@ -285,6 +285,10 @@
         installer, making it clear that the service will be installed. Patch
         provided by sebb. (markt)
       </fix>
+      <add>
+        Re-factor unit tests to enable them to be run once with each of the HTTP
+        connector implementations (BIO, NIO and APR/native). (markt)
+      </add>
     </changelog>
   </subsection>
 </section>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r966613 - in /tomcat/trunk: build.xml test/org/apache/catalina/startup/TestTomcatSSL.java test/org/apache/catalina/startup/TomcatBaseTest.java webapps/docs/changelog.xml

Posted by Mladen Turk <mt...@apache.org>.
On 07/28/2010 06:18 PM, Mark Thomas wrote:
> On 28/07/2010 10:52, Mladen Turk wrote:
>>
>> Using pre-cleanups wouldn't require the api change, so
>> even tcnative-1 with pre 1.3.x APR would work
>> (in some cases performing core on shutdown obviously)
>
> I don't pretend to know enough about native code to be able to help out
> with this but from my experience with the tests anything that we can do
> to make native more robust, particularly on shut down, would be great.
>

Agreed.

We would eventually need an APR versioning policy anyhow.
Having at least 1.3.x as required would solve the shutdown
problems, while having 1.4.x would allow to use the new
poll_wakeup API simplifying the poller code by an order
of magnitude, and also increasing the performance.

1.4 also uses new WSAPoll on windows
(if running under Vista and up) which allows
huge number of sockets in the poller without the
need for multiple 1k size pollsets
(I tested that with 16k sockets in one poller)

So my vote would be 1.4.x as minimum APR version
required.


Regards
-- 
^TM

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r966613 - in /tomcat/trunk: build.xml test/org/apache/catalina/startup/TestTomcatSSL.java test/org/apache/catalina/startup/TomcatBaseTest.java webapps/docs/changelog.xml

Posted by Mark Thomas <ma...@apache.org>.
On 28/07/2010 10:52, Mladen Turk wrote:
> On 07/28/2010 10:23 AM, Rainer Jung wrote:
>>>
>>> With APR 1.4.x there is a new pool pre-cleanup hook
>>> that would allow to effectively handle those situations,
>>> but it would also mean that native won't work on pre 1.4.x APR's
>>
>> If it is important, we could use that for TC 7 using a newer tcnative
>> branch?
>>
> 
> Well, actually I introduced the pre-cleanups with APR 1.3.x,
> so we would need to increase the dependency to that APR version.
> 
> Newer branch would be appropriate only with APR 2.x dependency
> in which case our native void be tcnative-2 not tcnative-1
> thought.
> 
> Using pre-cleanups wouldn't require the api change, so
> even tcnative-1 with pre 1.3.x APR would work
> (in some cases performing core on shutdown obviously)

I don't pretend to know enough about native code to be able to help out
with this but from my experience with the tests anything that we can do
to make native more robust, particularly on shut down, would be great.

There is still at least one test failing and I suspect it is due to
failing to shut down APR/native correctly. I'll try and get to that
later today.

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r966613 - in /tomcat/trunk: build.xml test/org/apache/catalina/startup/TestTomcatSSL.java test/org/apache/catalina/startup/TomcatBaseTest.java webapps/docs/changelog.xml

Posted by Mladen Turk <mt...@apache.org>.
On 07/28/2010 10:23 AM, Rainer Jung wrote:
>>
>> With APR 1.4.x there is a new pool pre-cleanup hook
>> that would allow to effectively handle those situations,
>> but it would also mean that native won't work on pre 1.4.x APR's
>
> If it is important, we could use that for TC 7 using a newer tcnative
> branch?
>

Well, actually I introduced the pre-cleanups with APR 1.3.x,
so we would need to increase the dependency to that APR version.

Newer branch would be appropriate only with APR 2.x dependency
in which case our native void be tcnative-2 not tcnative-1
thought.

Using pre-cleanups wouldn't require the api change, so
even tcnative-1 with pre 1.3.x APR would work
(in some cases performing core on shutdown obviously)




Regards
-- 
^TM

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r966613 - in /tomcat/trunk: build.xml test/org/apache/catalina/startup/TestTomcatSSL.java test/org/apache/catalina/startup/TomcatBaseTest.java webapps/docs/changelog.xml

Posted by Rainer Jung <ra...@kippdata.de>.
On 28.07.2010 07:44, Mladen Turk wrote:
> On 07/27/2010 08:00 PM, Mark Thomas wrote:
>>>
>>> What happens if you disable the terminateAPR call?
>>
>> Thanks. That was it. I changed the point where that was called and that
>> fixed it although it did then highlight a huge delay (~30s) to shutdown
>> the connector. I've got to the bottom of that too and am currently
>> testing a patch.
>>
>
> One other reason for a potential core on shutdown is
> the accept call. I did however some nasty tricks to prevent that
> directly in native, but the bottom line is that acceptor
> should be broken before its pool gets destroyed.
>
> With APR 1.4.x there is a new pool pre-cleanup hook
> that would allow to effectively handle those situations,
> but it would also mean that native won't work on pre 1.4.x APR's

If it is important, we could use that for TC 7 using a newer tcnative 
branch?

Regards,

Rainer

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r966613 - in /tomcat/trunk: build.xml test/org/apache/catalina/startup/TestTomcatSSL.java test/org/apache/catalina/startup/TomcatBaseTest.java webapps/docs/changelog.xml

Posted by Mladen Turk <mt...@apache.org>.
On 07/27/2010 08:00 PM, Mark Thomas wrote:
>>
>> What happens if you disable the terminateAPR call?
>
> Thanks. That was it. I changed the point where that was called and that
> fixed it although it did then highlight a huge delay (~30s) to shutdown
> the connector. I've got to the bottom of that too and am currently
> testing a patch.
>

One other reason for a potential core on shutdown is
the accept call. I did however some nasty tricks to prevent that
directly in native, but the bottom line is that acceptor
should be broken before its pool gets destroyed.

With APR 1.4.x there is a new pool pre-cleanup hook
that would allow to effectively handle those situations,
but it would also mean that native won't work on pre 1.4.x APR's

Regards
-- 
^TM

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r966613 - in /tomcat/trunk: build.xml test/org/apache/catalina/startup/TestTomcatSSL.java test/org/apache/catalina/startup/TomcatBaseTest.java webapps/docs/changelog.xml

Posted by Mark Thomas <ma...@apache.org>.
On 22/07/2010 14:33, Mladen Turk wrote:
> On 07/22/2010 02:22 PM, Mark Thomas wrote:
>> On 22/07/2010 13:18, markt@apache.org wrote:
>>> Author: markt
>>> Date: Thu Jul 22 12:18:59 2010
>>> New Revision: 966613
>>>
>>> URL: http://svn.apache.org/viewvc?rev=966613&view=rev
>>> Log:
>>> Run all unit tests will all connectors
>>
>> When I enable this for the APR connector it always crashes the JVM on
>> shutdown. Is this a local issue or does this happen for anyone else?
>>
> 
> It happens cause the Library.shutdown is called while
> resources are still in use.
> 
> What happens if you disable the terminateAPR call?

Thanks. That was it. I changed the point where that was called and that
fixed it although it did then highlight a huge delay (~30s) to shutdown
the connector. I've got to the bottom of that too and am currently
testing a patch.

Thanks again for the pointer.

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r966613 - in /tomcat/trunk: build.xml test/org/apache/catalina/startup/TestTomcatSSL.java test/org/apache/catalina/startup/TomcatBaseTest.java webapps/docs/changelog.xml

Posted by Mladen Turk <mt...@apache.org>.
On 07/22/2010 02:22 PM, Mark Thomas wrote:
> On 22/07/2010 13:18, markt@apache.org wrote:
>> Author: markt
>> Date: Thu Jul 22 12:18:59 2010
>> New Revision: 966613
>>
>> URL: http://svn.apache.org/viewvc?rev=966613&view=rev
>> Log:
>> Run all unit tests will all connectors
>
> When I enable this for the APR connector it always crashes the JVM on
> shutdown. Is this a local issue or does this happen for anyone else?
>

It happens cause the Library.shutdown is called while
resources are still in use.

What happens if you disable the terminateAPR call?

Regards
-- 
^TM

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r966613 - in /tomcat/trunk: build.xml test/org/apache/catalina/startup/TestTomcatSSL.java test/org/apache/catalina/startup/TomcatBaseTest.java webapps/docs/changelog.xml

Posted by Mark Thomas <ma...@apache.org>.
On 22/07/2010 13:18, markt@apache.org wrote:
> Author: markt
> Date: Thu Jul 22 12:18:59 2010
> New Revision: 966613
> 
> URL: http://svn.apache.org/viewvc?rev=966613&view=rev
> Log:
> Run all unit tests will all connectors

When I enable this for the APR connector it always crashes the JVM on
shutdown. Is this a local issue or does this happen for anyone else?

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org