Skip to content

Commit 2d9aad6

Browse files
Vanshita-Gosainclaude
andcommitted
Add JUnit @Category-based smoke test selection via annotation scanning
Replace the smoke profile file list in test-profiles.properties.default with @category(SmokeTest.class) annotations on each smoke test class. CategoryScanner discovers annotated tests at build time by scanning compiled classes and feeds the result into the existing batchtest fileset, preserving per-test JVM isolation. Changes: - Add SmokeTest category marker interface - Add CategoryScanner utility to scan compiled classes for a given @category annotation and output matching .java paths - Annotate all 57 smoke test classes with @category(SmokeTest.class) - Remove the smoke file list from test-profiles.properties.default; the annotation is now the single source of truth - Reorder test-nio dependencies so test-compile runs before -test-name-default, ensuring compiled classes are available when the scanner runs during profile initialisation - Update BUILDING.txt with instructions for the annotation-based approach - Update changelog.xml Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent cb623e3 commit 2d9aad6

63 files changed

Lines changed: 380 additions & 66 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎BUILDING.txt‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,48 @@ NOTE: Cobertura is licensed under GPL v2 with parts of it being under
603603

604604
test.verbose=false
605605

606-
(7.5) Running httpd integration tests
606+
(7.5) Running tests by profile
607+
608+
Tomcat provides named test profiles for running curated subsets of tests
609+
without specifying file patterns manually.
610+
611+
Available profiles:
612+
613+
smoke - Core smoke tests covering key subsystems
614+
catalina - All Catalina servlet container tests
615+
coyote - All Coyote protocol/connector tests
616+
tribes - All Tribes clustering tests
617+
performance - Performance benchmark tests (excluded by default)
618+
buildutil - Build utility tests (excluded by default)
619+
integration - httpd integration tests (excluded by default)
620+
621+
Usage:
622+
623+
ant test -Dtest.profile=smoke
624+
ant test -Dtest.profile=catalina
625+
626+
Profile patterns are defined in test-profiles.properties.default and can
627+
be overridden by creating a test-profiles.properties file at the project root.
628+
629+
(7.5.1) The smoke profile and JUnit @Category
630+
631+
The smoke profile selects tests via the @Category(SmokeTest.class)
632+
annotation rather than a file list in the properties file. At build time,
633+
CategoryScanner scans the compiled test classes, finds all classes annotated
634+
with @Category(SmokeTest.class), and feeds the result into the standard Ant
635+
batchtest mechanism so each test still runs in its own JVM.
636+
637+
ant test -Dtest.profile=smoke
638+
639+
To add a test to the smoke profile, annotate the test class:
640+
641+
import org.junit.experimental.categories.Category;
642+
import org.apache.tomcat.categories.SmokeTest;
643+
644+
@Category(SmokeTest.class)
645+
public class MyNewTest { ... }
646+
647+
(7.6) Running httpd integration tests
607648

608649
Tomcat includes integration tests that verify Tomcat's behavior when
609650
running behind an Apache HTTP Server (httpd) reverse proxy. These tests

‎build.xml‎

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,9 +2025,15 @@
20252025
<attribute name="profile"/>
20262026
<sequential>
20272027
<!-- Set test.name property based on the profile attribute -->
2028-
<condition property="test.name" value="${test.profile.smoke}">
2028+
2029+
<!-- For category-based profiles, record the category class so that the
2030+
-test-categories target (which runs after test-compile) can run
2031+
CategoryScanner and set test.name. -->
2032+
<condition property="test.category.class"
2033+
value="org.apache.tomcat.categories.SmokeTest">
20292034
<equals arg1="@{profile}" arg2="smoke"/>
20302035
</condition>
2036+
20312037
<condition property="test.name" value="${test.profile.catalina}">
20322038
<equals arg1="@{profile}" arg2="catalina"/>
20332039
</condition>
@@ -2053,10 +2059,14 @@
20532059
<target name="-test-profile-init" if="test.profile" unless="test.entry">
20542060
<set-profile-pattern profile="${test.profile}"/>
20552061

2056-
<!-- Validate that the profile exists -->
2057-
<fail message="Unknown test profile '${test.profile}'. Check test-profiles.properties[.default] for available profiles.">
2062+
<!-- Validate that the profile exists: either test.name is set (pattern-based)
2063+
or test.category.class is set (category-based, test.name set later). -->
2064+
<fail message="Unknown test profile '${test.profile}'. Available profiles: smoke, catalina, coyote, performance, tribes, buildutil, integration.">
20582065
<condition>
2059-
<not><isset property="test.name"/></not>
2066+
<and>
2067+
<not><isset property="test.name"/></not>
2068+
<not><isset property="test.category.class"/></not>
2069+
</and>
20602070
</condition>
20612071
</fail>
20622072

@@ -2083,9 +2093,25 @@
20832093
<echo message="Test profile: ${test.profile}"/>
20842094
</target>
20852095

2086-
<!-- Set default test.name if no profile specified, using ant's immutability feature -->
2096+
<!-- Set default test.name if no profile or a pattern-based profile is in use.
2097+
Skipped for category-based profiles: test.name is set by -test-categories
2098+
after test-compile completes. -->
20872099
<target name="-test-name-default" depends="-test-profile-init">
2088-
<property name="test.name" value="**/Test*.java"/>
2100+
<property name="test.name" value="**/Test*.java" unless:set="test.category.class"/>
2101+
</target>
2102+
2103+
<!-- Scan compiled test classes for the category recorded by -test-profile-init
2104+
and populate test.name. Runs after test-compile so that the .class files
2105+
produced by the annotation processor are available to the scanner. -->
2106+
<target name="-test-categories" depends="test-compile" if="test.category.class">
2107+
<java classname="org.apache.tomcat.categories.CategoryScanner"
2108+
outputproperty="test.name"
2109+
fork="true"
2110+
failonerror="true">
2111+
<classpath refid="tomcat.test.classpath"/>
2112+
<arg value="${test.category.class}"/>
2113+
<arg value="${test.classes}"/>
2114+
</java>
20892115
</target>
20902116

20912117
<!-- ==================== End of Test Profile System ==================== -->
@@ -2135,7 +2161,7 @@
21352161
</target>
21362162

21372163
<target name="test-nio" description="Runs the JUnit test cases for NIO. Does not stop on errors."
2138-
depends="-test-name-default,setup-jacoco,test-compile,deploy,test-openssl-exists,test-tcnative-exists" if="${execute.test.nio}">
2164+
depends="-test-name-default,setup-jacoco,test-compile,deploy,-test-categories,test-openssl-exists,test-tcnative-exists" if="${execute.test.nio}">
21392165
<runtests protocol="org.apache.coyote.http11.Http11NioProtocol"
21402166
extension=".NIO" />
21412167
</target>

‎test-profiles.properties.default‎

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -26,64 +26,9 @@
2626
# -----------------------------------------------------------------------------
2727

2828
# Smoke test profile
29-
test.profile.smoke=\
30-
org/apache/catalina/authenticator/TestFormAuthenticatorA.java,\
31-
org/apache/catalina/authenticator/TestSSOnonLoginAndBasicAuthenticator.java,\
32-
org/apache/catalina/core/TestAsyncContextStateChanges.java,\
33-
org/apache/catalina/core/TestStandardContextResources.java,\
34-
org/apache/catalina/core/TestStandardWrapper.java,\
35-
org/apache/catalina/loader/TestVirtualContext.java,\
36-
org/apache/catalina/mapper/TestMapperWebapps.java,\
37-
org/apache/catalina/nonblocking/TestNonBlockingAPI.java,\
38-
org/apache/catalina/servlets/TestDefaultServletEncodingPassThroughBom.java,\
39-
org/apache/catalina/servlets/TestDefaultServletEncodingWithBom.java,\
40-
org/apache/catalina/servlets/TestDefaultServletEncodingWithoutBom.java,\
41-
org/apache/catalina/servlets/TestDefaultServletIfMatchRequests.java,\
42-
org/apache/catalina/servlets/TestDefaultServlet.java,\
43-
org/apache/catalina/servlets/TestDefaultServletOptions.java,\
44-
org/apache/catalina/servlets/TestWebdavServletOptionsFile.java,\
45-
org/apache/catalina/startup/TestContextConfig.java,\
46-
org/apache/catalina/startup/TestHostConfigAutomaticDeploymentDir.java,\
47-
org/apache/catalina/startup/TestHostConfigAutomaticDeploymentWar.java,\
48-
org/apache/catalina/startup/TestHostConfigAutomaticDeploymentXml.java,\
49-
org/apache/catalina/valves/rewrite/TestRewriteValve.java,\
50-
org/apache/catalina/valves/TestStuckThreadDetectionValve.java,\
51-
org/apache/coyote/ajp/TestAbstractAjpProcessor.java,\
52-
org/apache/coyote/http11/filters/TestChunkedInputFilter.java,\
53-
org/apache/coyote/http11/TestHttp11InputBufferCRLF.java,\
54-
org/apache/coyote/http11/TestHttp11InputBuffer.java,\
55-
org/apache/coyote/http11/TestHttp11Processor.java,\
56-
org/apache/coyote/http2/TestAsync.java,\
57-
org/apache/coyote/http2/TestHttp2ConnectionTimeouts.java,\
58-
org/apache/coyote/http2/TestHttp2Limits.java,\
59-
org/apache/coyote/http2/TestHttp2Section_6_8.java,\
60-
org/apache/coyote/http2/TestStreamQueryString.java,\
61-
org/apache/el/TestELInJsp.java,\
62-
org/apache/jasper/compiler/TestCompiler.java,\
63-
org/apache/jasper/compiler/TestEncodingDetector.java,\
64-
org/apache/jasper/compiler/TestGenerator.java,\
65-
org/apache/jasper/compiler/TestJspConfig.java,\
66-
org/apache/jasper/compiler/TestJspDocumentParser.java,\
67-
org/apache/jasper/compiler/TestValidator.java,\
68-
org/apache/jasper/optimizations/TestELInterpreterTagSetters.java,\
69-
org/apache/jasper/optimizations/TestStringInterpreterTagSetters.java,\
70-
org/apache/jasper/runtime/TestCustomHttpJspPage.java,\
71-
org/apache/jasper/runtime/TestJspContextWrapper.java,\
72-
org/apache/jasper/runtime/TestJspRuntimeLibrary.java,\
73-
org/apache/jasper/runtime/TestPageContextImpl.java,\
74-
org/apache/jasper/servlet/TestTldScanner.java,\
75-
org/apache/naming/resources/TestWarDirContext.java,\
76-
org/apache/naming/TestEnvEntry.java,\
77-
org/apache/tomcat/util/net/TestClientCert.java,\
78-
org/apache/tomcat/util/net/TestCustomSslTrustManager.java,\
79-
org/apache/tomcat/util/net/TestSSLHostConfigCompat.java,\
80-
org/apache/tomcat/util/net/TestSsl.java,\
81-
org/apache/tomcat/websocket/server/TestSlowClient.java,\
82-
org/apache/tomcat/websocket/server/TestWsRemoteEndpointImplServerDeadlock.java,\
83-
org/apache/tomcat/websocket/TestWebSocketFrameClientSSL.java,\
84-
org/apache/tomcat/websocket/TestWsWebSocketContainer.java,\
85-
org/apache/tomcat/websocket/TestWsWebSocketContainerTimeoutServer.java,\
86-
org/apache/catalina/tribes/group/interceptors/TestTcpFailureDetector.java
29+
# The smoke profile is driven by @Category(SmokeTest.class) annotations on test
30+
# classes. CategoryScanner discovers matching tests at build time by scanning
31+
# compiled classes, so no file list is maintained here.
8732

8833
# Component test profiles
8934
test.profile.catalina=**/catalina/**/*Test*.java

‎test/org/apache/catalina/authenticator/TestFormAuthenticatorA.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import org.junit.Assert;
3434
import org.junit.Test;
35+
import org.junit.experimental.categories.Category;
3536

3637
import org.apache.catalina.Context;
3738
import org.apache.catalina.Valve;
@@ -40,6 +41,7 @@
4041
import org.apache.catalina.startup.TesterServlet;
4142
import org.apache.catalina.startup.Tomcat;
4243
import org.apache.catalina.startup.TomcatBaseTest;
44+
import org.apache.tomcat.categories.SmokeTest;
4345
import org.apache.tomcat.util.buf.ByteChunk;
4446
import org.apache.tomcat.util.descriptor.web.LoginConfig;
4547
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
@@ -78,6 +80,7 @@
7880
* but it makes no claims to generality).
7981
*
8082
*/
83+
@Category(SmokeTest.class)
8184
public class TestFormAuthenticatorA extends TomcatBaseTest {
8285

8386
// these should really be singletons to be type-safe,

‎test/org/apache/catalina/authenticator/TestSSOnonLoginAndBasicAuthenticator.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@
2727

2828
import org.junit.Assert;
2929
import org.junit.Test;
30+
import org.junit.experimental.categories.Category;
3031

3132
import org.apache.catalina.Context;
3233
import org.apache.catalina.Session;
3334
import org.apache.catalina.session.ManagerBase;
3435
import org.apache.catalina.startup.TesterServletEncodeUrl;
3536
import org.apache.catalina.startup.Tomcat;
3637
import org.apache.catalina.startup.TomcatBaseTest;
38+
import org.apache.tomcat.categories.SmokeTest;
3739
import org.apache.tomcat.util.buf.ByteChunk;
3840
import org.apache.tomcat.util.descriptor.web.LoginConfig;
3941
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
@@ -58,6 +60,7 @@
5860
* ignore them. The Tomcat documentation clearly states that SSO <i>requires</i> the client to support cookies, so
5961
* access to resources in other webapp containers receives no SSO assistance.
6062
*/
63+
@Category(SmokeTest.class)
6164
public class TestSSOnonLoginAndBasicAuthenticator extends TomcatBaseTest {
6265

6366
protected static final boolean USE_COOKIES = true;

‎test/org/apache/catalina/core/TestAsyncContextStateChanges.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import org.junit.Assert;
3939
import org.junit.Test;
40+
import org.junit.experimental.categories.Category;
4041
import org.junit.runner.RunWith;
4142
import org.junit.runners.Parameterized;
4243
import org.junit.runners.Parameterized.Parameter;
@@ -48,12 +49,14 @@
4849
import org.apache.catalina.startup.SimpleHttpClient;
4950
import org.apache.catalina.startup.Tomcat;
5051
import org.apache.catalina.startup.TomcatBaseTest;
52+
import org.apache.tomcat.categories.SmokeTest;
5153

5254
/*
5355
* Derived from a test for https://bz.apache.org/bugzilla/show_bug.cgi?id=63816
5456
* Expanded to cover https://bz.apache.org/bugzilla/show_bug.cgi?id=63817 and
5557
* additional scenarios.
5658
*/
59+
@Category(SmokeTest.class)
5760
@RunWith(Parameterized.class)
5861
public class TestAsyncContextStateChanges extends TomcatBaseTest {
5962

‎test/org/apache/catalina/core/TestStandardContextResources.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,19 @@
3232

3333
import org.junit.Assert;
3434
import org.junit.Test;
35+
import org.junit.experimental.categories.Category;
3536

3637
import org.apache.catalina.Context;
3738
import org.apache.catalina.startup.Constants;
3839
import org.apache.catalina.startup.ContextConfig;
3940
import org.apache.catalina.startup.Tomcat;
4041
import org.apache.catalina.startup.TomcatBaseTest;
4142
import org.apache.catalina.util.IOTools;
43+
import org.apache.tomcat.categories.SmokeTest;
4244
import org.apache.tomcat.util.buf.ByteChunk;
4345
import org.apache.tomcat.util.descriptor.web.WebXml;
4446

47+
@Category(SmokeTest.class)
4548
public class TestStandardContextResources extends TomcatBaseTest {
4649

4750
@Override

‎test/org/apache/catalina/core/TestStandardWrapper.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
import org.junit.Assert;
4242
import org.junit.Test;
43+
import org.junit.experimental.categories.Category;
4344

4445
import org.apache.catalina.Context;
4546
import org.apache.catalina.Wrapper;
@@ -48,10 +49,12 @@
4849
import org.apache.catalina.startup.TesterMapRealm;
4950
import org.apache.catalina.startup.Tomcat;
5051
import org.apache.catalina.startup.TomcatBaseTest;
52+
import org.apache.tomcat.categories.SmokeTest;
5153
import org.apache.tomcat.util.buf.ByteChunk;
5254
import org.apache.tomcat.util.descriptor.web.LoginConfig;
5355
import org.apache.tomcat.util.http.Method;
5456

57+
@Category(SmokeTest.class)
5558
public class TestStandardWrapper extends TomcatBaseTest {
5659

5760
@Test

‎test/org/apache/catalina/loader/TestVirtualContext.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import org.junit.Assert;
2727
import org.junit.Test;
28+
import org.junit.experimental.categories.Category;
2829

2930
import org.apache.catalina.WebResourceRoot;
3031
import org.apache.catalina.core.JreMemoryLeakPreventionListener;
@@ -34,9 +35,11 @@
3435
import org.apache.catalina.startup.TomcatBaseTest;
3536
import org.apache.catalina.util.IOTools;
3637
import org.apache.catalina.webresources.StandardRoot;
38+
import org.apache.tomcat.categories.SmokeTest;
3739
import org.apache.tomcat.util.buf.ByteChunk;
3840
import org.apache.tomcat.util.scan.StandardJarScanner;
3941

42+
@Category(SmokeTest.class)
4043
public class TestVirtualContext extends TomcatBaseTest {
4144

4245
@Override

‎test/org/apache/catalina/mapper/TestMapperWebapps.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828

2929
import org.junit.Assert;
3030
import org.junit.Test;
31+
import org.junit.experimental.categories.Category;
3132

3233
import org.apache.catalina.core.StandardContext;
3334
import org.apache.catalina.startup.Tomcat;
3435
import org.apache.catalina.startup.TomcatBaseTest;
3536
import org.apache.catalina.valves.RemoteHostValve;
37+
import org.apache.tomcat.categories.SmokeTest;
3638
import org.apache.tomcat.util.buf.ByteChunk;
3739
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
3840
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
@@ -41,6 +43,7 @@
4143
/**
4244
* Mapper tests that use web applications on a running Tomcat instance.
4345
*/
46+
@Category(SmokeTest.class)
4447
public class TestMapperWebapps extends TomcatBaseTest {
4548

4649
@Test

0 commit comments

Comments
 (0)