From f34e54b3cf5450b20ef86b85bce2f59ac021989b Mon Sep 17 00:00:00 2001 From: rjung Date: Sun, 10 Jul 2011 10:10:33 +0000 Subject: [PATCH] Add option test.accesslog to activate AccessLog for unit tests. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1144802 13f79535-47bb-0310-9956-ffa450edef68 --- build.properties.default | 3 +++ build.xml | 1 + test/org/apache/catalina/mbeans/TestRegistration.java | 11 +++++++++++ test/org/apache/catalina/startup/TomcatBaseTest.java | 18 ++++++++++++++++++ webapps/docs/changelog.xml | 3 +++ 5 files changed, 36 insertions(+) diff --git a/build.properties.default b/build.properties.default index 766cc01c6..10ee5d0ff 100644 --- a/build.properties.default +++ b/build.properties.default @@ -38,7 +38,10 @@ execute.test.bio=true execute.test.nio=true # Still requires APR/native library to be present execute.test.apr=true +# Stop testing if a failure occurs test.haltonfailure=false +# Activate AccessLog during testing +test.accesslog=false # Workaround against http://bugs.sun.com/view_bug.do?bug_id=6202721 test.jvmarg.egd=-Djava.security.egd=file:/dev/./urandom diff --git a/build.xml b/build.xml index 7537c28c4..ab092b16f 100644 --- a/build.xml +++ b/build.xml @@ -1102,6 +1102,7 @@ + diff --git a/test/org/apache/catalina/mbeans/TestRegistration.java b/test/org/apache/catalina/mbeans/TestRegistration.java index de6d4c3cf..950ea1292 100644 --- a/test/org/apache/catalina/mbeans/TestRegistration.java +++ b/test/org/apache/catalina/mbeans/TestRegistration.java @@ -59,6 +59,16 @@ public class TestRegistration extends TomcatBaseTest { }; } + private String[] optionalMBeanNames(String host, String context) { + if (isAccessLogEnabled()) { + return new String[] { + "Tomcat:type=Valve,host=" + host + ",name=AccessLogValve", + }; + } else { + return new String[] { }; + } + } + private static String[] contextMBeanNames(String host, String context) { return new String[] { "Tomcat:j2eeType=WebModule,name=//" + host + context + @@ -131,6 +141,7 @@ public class TestRegistration extends TomcatBaseTest { expected.addAll(Arrays.asList(hostMBeanNames("localhost"))); expected.addAll(Arrays.asList(contextMBeanNames("localhost", contextName))); expected.addAll(Arrays.asList(connectorMBeanNames(Integer.toString(getPort()), protocol))); + expected.addAll(Arrays.asList(optionalMBeanNames("localhost", contextName))); // Did we find all expected MBeans? ArrayList missing = new ArrayList(expected); diff --git a/test/org/apache/catalina/startup/TomcatBaseTest.java b/test/org/apache/catalina/startup/TomcatBaseTest.java index 6dffa07df..52e2dfaeb 100644 --- a/test/org/apache/catalina/startup/TomcatBaseTest.java +++ b/test/org/apache/catalina/startup/TomcatBaseTest.java @@ -38,6 +38,7 @@ import org.apache.catalina.LifecycleState; import org.apache.catalina.connector.Connector; import org.apache.catalina.core.AprLifecycleListener; import org.apache.catalina.core.StandardServer; +import org.apache.catalina.valves.AccessLogValve; import org.apache.tomcat.util.buf.ByteChunk; /** @@ -47,6 +48,7 @@ import org.apache.tomcat.util.buf.ByteChunk; public abstract class TomcatBaseTest extends TestCase { private Tomcat tomcat; private File tempDir; + private boolean accessLogEnabled = false; private static int port = 8000; public static final String TEMP_DIR = System.getProperty("java.io.tmpdir"); @@ -92,6 +94,13 @@ public abstract class TomcatBaseTest extends TestCase { "output/build")); } + /** + * Sub-classes may want to check, whether an AccessLogValve is active + */ + public boolean isAccessLogEnabled() { + return accessLogEnabled; + } + @Override public void setUp() throws Exception { // Need to use JULI so log messages from the tests are visible @@ -144,6 +153,15 @@ public abstract class TomcatBaseTest extends TestCase { tomcat.setBaseDir(tempDir.getAbsolutePath()); tomcat.getHost().setAppBase(appBase.getAbsolutePath()); + + accessLogEnabled = Boolean.parseBoolean( + System.getProperty("tomcat.test.accesslog", "false")); + if (accessLogEnabled) { + AccessLogValve alv = new AccessLogValve(); + alv.setDirectory(getBuildDirectory() + "/logs"); + alv.setPattern("%h %l %u %t \"%r\" %s %b %I %D"); + tomcat.getHost().getPipeline().addValve(alv); + } } @Override diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 801405760..00a586e94 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -68,6 +68,9 @@ Fix regression producing invalid MBean names when using IPV6 addresses for connectors. (rjung) + + Add option to activate AccessLog for unit tests. (rjung) + -- 2.11.0