Repository navigation
Fix files delete tests - #5465
sumittlearnbay wants to merge 3 commits into
Conversation
Signed-off-by: sumittlearnbay <sumit.learnbay@gmail.com>
Signed-off-by: sumittlearnbay <sumit.learnbay@gmail.com>
322ac5b to
3fe9c2b
Compare
|
I had the same problem on Windows 11. After looking into the root cause, I found that the following line was written incorrectly in the first place: According to the Mockito javadoc, it is recommended to always use doReturn() for spies: However, even if you update the code to use doReturn(), the test still fails (and now it fails on macOS as well): This is because, ItemWriter's close() method actually deletes the file using Files.delete(). Therefore, in my opinion, instead of acquiring a lock with RandomAccessFile, mocking Files.delete() would be a better approach. Here is my sample code: |
|
Thank you for the explanation and suggestion. I updated both AbstractFileItemWriterTests and StaxEventItemWriterTests to mock Files.delete() using MockedStatic instead of File.delete(), following your recommendation. I verified the updated tests locally and pushed the changes to this PR. Please let me know if you see anything else that should be adjusted. |
|
Oh, and it's no big deal, but the filename AbstractFileItemWriterTest.java is missing an 's'. |
|
Hi @sumittlearnbay , thank you for the PR! When I test the changes, I hit a build failure: Can you please check? |
|
Hi @sumittlearnbay, are you still working on this one? If you don't have time to continue, I'd be happy to build on your changes and open a follow-up PR, crediting you as a co-author. Would that work for you? |
|
Hi @noojung yes, please continue. Sorry for the delayed response. Stuck in office work |
|
@sumittlearnbay No worries at all, thanks for getting back to me. I’ll take it from here and open a new PR based on your changes, with you credited as a co-author. Good luck with everything at work! |
The tests stubbed File.delete() on a spy using when(...), which invokes the real method while stubbing. On Unix-like systems, this deleted the open output file, so the subsequent Files.delete() call in close() failed with a NoSuchFileException and the tests passed by accident. On Windows, the open file could not be deleted at that point, so Files.delete() succeeded in close() and no exception was thrown. Since the writers delete the file with Files.delete(), mock that call with Mockito.mockStatic(), scoped to the close() invocation only. See spring-projects#5465 Co-authored-by: sumittlearnbay <sumit.learnbay@gmail.com> Signed-off-by: Hyunwoo Jung <hyunwoojung@kakao.com>
|
Hi @noojung try to containeriise if possible or i will take care so consistent behaviour across the platform also it seems it needs java version upgrade . |
|
@sumittlearnbay Thanks for the suggestion. Do you have any specific concerns about mocking Also, could you clarify which part needs a Java version upgrade? |
|
Regarding the Java version, the Were you referring to the JDK used to run Maven locally? If you ran into a build issue with a specific JDK, could you share the version and the error? |
|
@noojung Thanks for the clarification regarding the Java version. My concern was primarily about achieving consistent test behavior across different operating systems and environments. The original file-deletion tests behaved differently on my Windows environment, so I explored whether containerization or a more deterministic test setup would help. I agree that explicitly mocking Regarding Java, I initially encountered build issues with my local JDK configuration. I have since switched Maven to JDK 25, and the complete multi-module build succeeds. The targeted Based on these results, I agree that containerization may not be necessary to address this specific issue. The priority should be ensuring that the tests deterministically simulate deletion failures and behave consistently across supported platforms. Thanks for the clarification. |
|
@sumittlearnbay Thanks for confirming! I've already opened a new PR to address this issue and credited you as a co-author: #5614 The PR currently uses Mockito to simulate deletion failures consistently across platforms. I'm happy to adjust the approach based on the maintainer's feedback. |
|
Thank you both! Closing this in favor of #5614 |
Thank you for taking time to contribute this pull request!
You might have already read the contributor guide, but as a reminder, please make sure to:
mainbranch and squash your commitsFor more details, please check the contributor guide.
Thank you upfront!