Author: rjung Date: Sun Jul 10 10:10:33 2011 New Revision: 1144802 URL: http://svn.apache.org/viewvc?rev=1144802&view=rev Log: Add option test.accesslog to activate AccessLog for unit tests.
Modified: tomcat/trunk/build.properties.default tomcat/trunk/build.xml tomcat/trunk/test/org/apache/catalina/mbeans/TestRegistration.java tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/build.properties.default URL: http://svn.apache.org/viewvc/tomcat/trunk/build.properties.default?rev=1144802&r1=1144801&r2=1144802&view=diff ============================================================================== --- tomcat/trunk/build.properties.default (original) +++ tomcat/trunk/build.properties.default Sun Jul 10 10:10:33 2011 @@ -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 Modified: tomcat/trunk/build.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/build.xml?rev=1144802&r1=1144801&r2=1144802&view=diff ============================================================================== --- tomcat/trunk/build.xml (original) +++ tomcat/trunk/build.xml Sun Jul 10 10:10:33 2011 @@ -1102,6 +1102,7 @@ <sysproperty key="tomcat.test.temp" value="${test.temp}" /> <sysproperty key="tomcat.test.tomcatbuild" value="${tomcat.build}" /> <sysproperty key="tomcat.test.protocol" value="@{protocol}" /> + <sysproperty key="tomcat.test.accesslog" value="${test.accesslog}" /> <formatter type="plain" usefile="true" extension="@{extension}"/> Modified: tomcat/trunk/test/org/apache/catalina/mbeans/TestRegistration.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/mbeans/TestRegistration.java?rev=1144802&r1=1144801&r2=1144802&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/mbeans/TestRegistration.java (original) +++ tomcat/trunk/test/org/apache/catalina/mbeans/TestRegistration.java Sun Jul 10 10:10:33 2011 @@ -59,6 +59,16 @@ public class TestRegistration extends To }; } + 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 To 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<String> missing = new ArrayList<String>(expected); 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=1144802&r1=1144801&r2=1144802&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java (original) +++ tomcat/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java Sun Jul 10 10:10:33 2011 @@ -38,6 +38,7 @@ import org.apache.catalina.LifecycleStat 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.ByteCh 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 ext "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 ext 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 Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1144802&r1=1144801&r2=1144802&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Sun Jul 10 10:10:33 2011 @@ -68,6 +68,9 @@ Fix regression producing invalid MBean names when using IPV6 addresses for connectors. (rjung) </fix> + <add> + Add option to activate AccessLog for unit tests. (rjung) + </add> </changelog> </subsection> <subsection name="Cluster"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org