Skip to content

Add unit tests for FilterValve, ProxyErrorReportValve and SemaphoreValve#976

Merged
dsoumis merged 3 commits into
apache:mainfrom
onkar717:test-filter-valve
Apr 8, 2026
Merged

Add unit tests for FilterValve, ProxyErrorReportValve and SemaphoreValve#976
dsoumis merged 3 commits into
apache:mainfrom
onkar717:test-filter-valve

Conversation

@onkar717
Copy link
Copy Markdown
Contributor

@onkar717 onkar717 commented Apr 1, 2026

Summary

This PR improves test coverage by adding unit tests for several Valve
implementations that currently lack dedicated tests:

  • FilterValve
  • ProxyErrorReportValve
  • SemaphoreValve

Motivation

While reviewing Tomcat valve implementations, these components were
identified as having little or no direct test coverage. Adding tests
helps improve reliability and prevents regressions during future
changes.

Changes

Added new test classes:

  • TestFilterValve
  • TestProxyErrorReportValve
  • TestSemaphoreValve

The tests cover:

  • Basic initialization behavior
  • Request/response processing
  • Error handling paths
  • Concurrency behavior (SemaphoreValve)
  • Configuration edge cases

Testing

All tests pass locally using:

Run all 3 new test classes

JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64 ant test \
  -Dtest.name=**/TestProxyErrorReportValve.java,**/TestFilterValve.java,**/TestSemaphoreValve.java

Run with coverage to verify coverage increase

JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64 ant test -Dtest.coverage=true \
  -Dtest.haltonfailure=false \
  -Dtest.name=**/valves/Test*.java

No existing tests were modified.

Impact

No functional changes.
Test coverage improvement only.

@dsoumis dsoumis self-requested a review April 7, 2026 14:13
@dsoumis dsoumis self-assigned this Apr 7, 2026
@dsoumis dsoumis merged commit e68cc20 into apache:main Apr 8, 2026
6 checks passed
Copy link
Copy Markdown
Contributor

@ChristopherSchultz ChristopherSchultz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests appear to be unnecessary.



@Test
public void testInitParams() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this (specific) test really necessary?



@Test(expected = LifecycleException.class)
public void testInvalidFilterClassThrowsOnStart() throws Exception {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this (specific) test really necessary?



@Test
public void testGetSetFilterClassName() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this (specific) test really necessary?

}

@Test(expected = IllegalStateException.class)
public void testGetServletContextThrowsBeforeStart() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this (specific) test really necessary?



@Test
public void testGetSetProperties() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this (specific) test really necessary?



@Test
public void testGetSetProperties() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this (specific) test really necessary?

@dsoumis
Copy link
Copy Markdown
Member

dsoumis commented Apr 9, 2026

@ChristopherSchultz Those keep all coverage branches green without inflicting any issues. They can be used also as a resource for better understanding how the valves work. Since they are not resource heavy, I would keep them.

@ChristopherSchultz
Copy link
Copy Markdown
Contributor

@ChristopherSchultz Those keep all coverage branches green without inflicting any issues. They can be used also as a resource for better understanding how the valves work. Since they are not resource heavy, I would keep them.

Yeah, okay, I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants