Skip to content

test: add boundary coverage for SimpleReadCacheSelector - #1251

Open
shps951023 wants to merge 3 commits into
apache:mainfrom
shps951023:test/1249-cache-selector-boundaries
Open

shps951023 wants to merge 3 commits into
apache:mainfrom
shps951023:test/1249-cache-selector-boundaries

Conversation

@shps951023

@shps951023 shps951023 commented Oct 21, 2026 •

Copy link
Copy Markdown

Purpose of the pull request

Related: #1249

Please feel free to give feedback, thanks 🙌

What's changed?

  • Add 14 JUnit 5 cases using controllable PackagePart and InputStream mocks.
  • Cover default 5 MB and custom 1 MB boundaries, zero size, and a known size above Integer.MAX_VALUE.
  • Cover unknown sizes via available() and MapCache fallback when opening the stream or checking available bytes throws IOException.
  • Verify known sizes never open an input stream.

Validation on Windows with Temurin JDK 17.0.20.1 and Maven 3.6.3:

  • .\mvnw.cmd package -B -pl fesod-sheet -am '-Dmaven.test.skip=false' '-DskipTests=false' '-Dtest=SimpleReadCacheSelectorTest' '-Dsurefire.failIfNoSpecifiedTests=false' - passed; 14 tests, no failures, errors, or skips. Includes Checkstyle checks.
  • .\mvnw.cmd spotless:check -B - passed across the reactor.

Checklist

  • I have read the Contributor Guide.
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

@alaahong
alaahong requested a balanced review from Copilot October 28, 2026 13:48

Copilot AI left a comment

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

9 open issues
What changed in this PR

Adds unit tests to validate SimpleReadCacheSelector behavior at size boundaries and in error/unknown-size scenarios.

Changes:

  • Introduces parameterized tests for default and custom size thresholds without opening streams when size is known.
  • Adds coverage for unknown sizes using InputStream.available().
  • Adds fallback tests for IOException when opening the stream or calling available().
File Description
fesod-sheet/​src/​test/​java/​org/​apache/​fesod/​sheet/​cache/​selector/​SimpleReadCacheSelectorTest.java New JUnit 5 tests covering threshold boundaries and fallback behavior for SimpleReadCacheSelector.

Review effort: Lite

class SimpleReadCacheSelectorTest {

@ParameterizedTest
@CsvSource({"0, false", "4999999, false", "5000000, true", "5000001, true", "2147483648, true"})

ReadCache cache = new SimpleReadCacheSelector().readCache(part);

Assertions.assertEquals(useEhcache ? Ehcache.class : MapCache.class, cache.getClass());
}

@ParameterizedTest
@CsvSource({"999999, false", "1000000, true", "1000001, true"})

ReadCache cache = selector.readCache(part);

Assertions.assertEquals(useEhcache ? Ehcache.class : MapCache.class, cache.getClass());
}

@ParameterizedTest
@CsvSource({"0, false", "4999999, false", "5000000, true", "5000001, true"})

ReadCache cache = new SimpleReadCacheSelector().readCache(part);

Assertions.assertEquals(useEhcache ? Ehcache.class : MapCache.class, cache.getClass());

@ParameterizedTest
@CsvSource({"0, false", "4999999, false", "5000000, true", "5000001, true", "2147483648, true"})
void selects_cache_using_default_threshold_without_opening_stream(long size, boolean useEhcache)

@ParameterizedTest
@CsvSource({"0, false", "4999999, false", "5000000, true", "5000001, true"})
void selects_cache_using_available_bytes_when_size_is_unknown(int available, boolean useEhcache)
Comment on lines +39 to +80
@ParameterizedTest
@CsvSource({"0, false", "4999999, false", "5000000, true", "5000001, true", "2147483648, true"})
void selects_cache_using_default_threshold_without_opening_stream(long size, boolean useEhcache)
throws IOException {
PackagePart part = Mockito.mock(PackagePart.class);
Mockito.when(part.getSize()).thenReturn(size);

ReadCache cache = new SimpleReadCacheSelector().readCache(part);

Assertions.assertEquals(useEhcache ? Ehcache.class : MapCache.class, cache.getClass());
Mockito.verify(part, Mockito.never()).getInputStream();
}

@ParameterizedTest
@CsvSource({"999999, false", "1000000, true", "1000001, true"})
void selects_cache_using_custom_threshold_without_opening_stream(long size, boolean useEhcache) throws IOException {
SimpleReadCacheSelector selector = new SimpleReadCacheSelector();
selector.setMaxUseMapCacheSize(1L);
PackagePart part = Mockito.mock(PackagePart.class);
Mockito.when(part.getSize()).thenReturn(size);

ReadCache cache = selector.readCache(part);

Assertions.assertEquals(useEhcache ? Ehcache.class : MapCache.class, cache.getClass());
Mockito.verify(part, Mockito.never()).getInputStream();
}

@ParameterizedTest
@CsvSource({"0, false", "4999999, false", "5000000, true", "5000001, true"})
void selects_cache_using_available_bytes_when_size_is_unknown(int available, boolean useEhcache)
throws IOException {
PackagePart part = Mockito.mock(PackagePart.class);
Mockito.when(part.getSize()).thenReturn(-1L);
InputStream stream = Mockito.mock(InputStream.class);
Mockito.when(part.getInputStream()).thenReturn(stream);
Mockito.when(stream.available()).thenReturn(available);

ReadCache cache = new SimpleReadCacheSelector().readCache(part);

Assertions.assertEquals(useEhcache ? Ehcache.class : MapCache.class, cache.getClass());
Mockito.verify(part).getInputStream();
Mockito.verify(stream).available();

This branch has not been deployed

No deployments
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