-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EMAIL-204: Disable eager attachment loading on MimeMessageParser #135
base: master
Are you sure you want to change the base?
EMAIL-204: Disable eager attachment loading on MimeMessageParser #135
Conversation
Would you please write a unit test that fails without the change to main? |
Codecov Report
@@ Coverage Diff @@
## master #135 +/- ##
============================================
- Coverage 65.90% 65.84% -0.07%
- Complexity 305 308 +3
============================================
Files 18 19 +1
Lines 1053 1054 +1
Branches 138 137 -1
============================================
Hits 694 694
- Misses 280 281 +1
Partials 79 79
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@garydgregory Can you also advise on how unit can be written in this case? |
Actually, I can probably create a test to assert the object size of |
src/main/java/org/apache/commons/mail/util/MimeMessageParser.java
Outdated
Show resolved
Hide resolved
Would mocking help here? |
I reckon so, to have a test check on .getInputStream() metho invoke count and make sure it is only called when the user is accessing the attachment content. |
This is not yet ready, I'm working on the test-cases |
@garydgregory I have updated the code change once again with two new test cases to represent the scenarios of lazy loading of Email attachments with appropriate mocking. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class comment for the new lazy class should state why can't we reuse org.apache.commons.mail.ByteArrayDataSource
or javax.mail.util.ByteArrayDataSource
src/main/java/org/apache/commons/mail/LazyByteArrayDataSource.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/mail/LazyByteArrayDataSource.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/mail/LazyByteArrayDataSource.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/mail/LazyByteArrayDataSource.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/mail/LazyByteArrayDataSource.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/mail/LazyByteArrayDataSource.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/mail/LazyByteArrayDataSource.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/mail/util/MimeMessageParser.java
Outdated
Show resolved
Hide resolved
src/test/java/org/apache/commons/mail/util/MimeMessageParserTest.java
Outdated
Show resolved
Hide resolved
I believe all comments are addressed, let me know if I missed any, thanks! |
@HiuKwok |
Yes, my local build is green and I tried the exact commands used for the failed builds, which all build successfully (I couldn't reproduce this on my local). BTW my setup: |
I would try locally with Java 8. |
Since it failed on Java 8 test, I will install Java8 locally and rerun the test. |
@garydgregory I can now reproduce the issue after running the unit test locally with jdk8. |
It turns out the easymock is having issues mocking the class
I have re-run the test suite locally against JDK8, 11 and 17 and all tests are passing for all three versions :) |
@garydgregory all comments are addressed and I have fixed the test cases. Thanks, |
Hello @HiuKwok, I am sorry about not getting back to you sooner. Thank you for your patience! 😄 |
As discussed on the Jira ticket, this is the MR to update MimeMessageParser.createDataSource() to disable eager loading for email attachments, but instead keep the inputstream as a reference and only load the attachment binary into memory when
.getInputStream()
is called.