Repository navigation
test: add boundary coverage for SimpleReadCacheSelector - #1251
Open
shps951023 wants to merge 3 commits into
Open
shps951023 wants to merge 3 commits into
shps951023 wants to merge 3 commits into
Conversation
Co-authored-by: Copilot <[email protected]>
4 tasks
Contributor
There was a problem hiding this comment.
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
The boundary values are hard-coded as decimal MB (e.g., 5,000,000 and 1,000,000). If… · New These assertions require the cache implementation to be the exact concrete class… · New The boundary values are hard-coded as decimal MB (e.g., 5,000,000 and 1,000,000). If… · New These assertions require the cache implementation to be the exact concrete class… · New The boundary values are hard-coded as decimal MB (e.g., 5,000,000 and 1,000,000). If… · New These assertions require the cache implementation to be the exact concrete class… · New The three selection tests duplicate the same arrange/act/assert pattern (mock part, call selector,… · New The three selection tests duplicate the same arrange/act/assert pattern (mock part, call selector,… · New The three selection tests duplicate the same arrange/act/assert pattern (mock part, call selector,… · New
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
IOExceptionwhen opening the stream or callingavailable().
| 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(); |
Copilot stopped reviewing on behalf of
alaahong due to an error
October 28, 2026 14:43
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Purpose of the pull request
Related: #1249
Please feel free to give feedback, thanks 🙌
What's changed?
PackagePartandInputStreammocks.Integer.MAX_VALUE.available()andMapCachefallback when opening the stream or checking available bytes throwsIOException.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