Skip to content
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

Made RqMultipart.Base delete its temporary files as soon as possible. #318

Closed
wants to merge 5 commits into from

Conversation

Bertram25
Copy link
Contributor

For #254

I thus added a decorator to InputStream to permit deletion of the temp file
when calling close() as advised by @dmzaytsev

Thanks to @yegor256 and @dmzaytsev for the hints.

I also added a test to the new TempInputStream class to actually test the change.

@davvd
Copy link

davvd commented May 29, 2015

@Bertram25 Thanks, let me find someone who can review this pull request

@davvd
Copy link

davvd commented May 29, 2015

@pinaf it's yours, please review

*
* @author Yegor Bugayenko (yegor@teamed.io)
* @version $Id$
* @since 0.16
Copy link

Choose a reason for hiding this comment

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

@Bertram25 0.21 here

@pinaf
Copy link

pinaf commented Jun 3, 2015

@Bertram25 3 comments above. Also, the test you added does not test RqMultiPart but TempInputStream. We should do the following:

  1. Add a test class TempInputStreamTest for the test of TempInputStream
  2. Add a unit test to RqMultiPartTest that actually uses RqMultiPart

@Bertram25
Copy link
Contributor Author

@pinaf Thanks a lot for your review. :)

0.21 here

I adapted the version in the two newly created files.

deletesTempFile()

Fixed.

  1. Add a test class TempInputStreamTest for the test of TempInputStream

Fixed. Thanks for the hint.

RqMultiPart can delete the underlying temporary file

Actually, as the test was indeed about TempInputStream, I reused your sentence as:
TempInputStream can delete the temporary cache file when it calls close().
in TempInputStreamTest.java

  1. Add a unit test to RqMultiPartTest that actually uses RqMultiPart

The problem is I cannot know which temporary file is created as its name is random.
See: https://github.com/yegor256/takes/pull/318/files#diff-27dba3b19513f2e598661b82c434a82eR235
On my system, it is something like:
/tmp/org.takes.RqMultipart_XXXXXX.tmp (The XXXXXX part is made of random digits.).
Thus, depending on the OS and the implementation of File.createTempFile() it is really not easily testable explaining why I created a test for the underlying body class instead to make sure the file gets deleted.
IMHO, the change is actually tested and is functional, but if you have a better idea, I'll listen to your advice.

Best regards,


/**
* Test case for {@link TempInputStream}.
* @author Yegor Bugayenko (yegor@teamed.io)
Copy link

Choose a reason for hiding this comment

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

@Bertram25 you should be the author here

@pinaf
Copy link

pinaf commented Jun 7, 2015

@Bertram25 thanks 2 comments

@Bertram25
Copy link
Contributor Author

@pinaf Fixes done. Thanks for the new review. :)

@pinaf
Copy link

pinaf commented Jun 7, 2015

@rultor merge

@rultor
Copy link
Collaborator

rultor commented Jun 7, 2015

@rultor merge

@pinaf Thanks for your request. @yegor256 Please confirm this.

*
* <p>All implementations of this interface must be immutable and thread-safe.
*
* @author Yegor Bugayenko (yegor@teamed.io)
Copy link
Owner

Choose a reason for hiding this comment

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

@Bertram25 I'm not the author of it :)

@yegor256
Copy link
Owner

yegor256 commented Jun 8, 2015

@Bertram25 a few comments from me

@Bertram25
Copy link
Contributor Author

@yegor256 Hey, thanks for the code review. :)

@Bertram25 I'm not the author of it :)

Fixed. (At first and some time ago already, I assumed we devs were to give the code away, hence the given authorship.)

@Bertram25 brrr... you're extending InputSteam and encapsulating it? isn't inheritance good enough?

Here, I encapsulated the origin InputStream to keep its functionalities in the functions overriden (read, skip, ...) (the origin InputStream in our specific case actually being a CapInputStream) and I extended InputStream as I simply needed it to add the desired functionalities for TempInputStream.

Also, note that you're doing the exact same thing in CapInputStream.java

If you prefer, I can have a go at extending CapInpuStream only instead, as it should suffice for our need. Is that the change you're requesting?

Best regards,

@Bertram25
Copy link
Contributor Author

@yegor256 I'll rebase as the PR has become non mergeable.

Yohann Ferreira added 4 commits June 10, 2015 01:11
@Bertram25 Bertram25 force-pushed the multipartBodyClose branch from 59ae3ae to 4c26466 Compare June 9, 2015 23:14
@Bertram25 Bertram25 force-pushed the multipartBodyClose branch from 81c8f91 to 0641abc Compare June 9, 2015 23:25
@pinaf
Copy link

pinaf commented Jun 9, 2015

@Bertram25 you could just merge with master manually instead of rebasing

@Bertram25
Copy link
Contributor Author

@pinaf Ok, most organizations usually prefer rebasing but I'll know I can just merge the next time. Thanks.

@pinaf
Copy link

pinaf commented Jun 17, 2015

@Bertram25 what's the status here?

@Bertram25
Copy link
Contributor Author

@pinaf Hi,

@yegor256 asked me why I used encapsulation and extension of the same class InputStream

I answered I was extending the InputStream class to support the file deletion handling and I encapsulated the InputStream instance as I needed the features added by the decorated object there. (The encapsulated object instance is a CapInputStream in our case.).
Plus, the exact same thing is done in CapInputStream.java (@yegor256 is the author of that file AFAIK.)

Thus, IMHO, the code is good, but if @yegor256 still would like a change, I can extend CapInputStream instead and drop the encapsulation, while I still do think the current implementation is more extensible.

So, I'm still waiting for @yegor256 's decision here.

Regards,

@pinaf
Copy link

pinaf commented Jun 17, 2015

@Bertram25 thanks! @yegor256 please advise

@pinaf
Copy link

pinaf commented Jun 26, 2015

@yegor256 ping

@pinaf
Copy link

pinaf commented Jul 3, 2015

@yegor256 is this acceptable?

@yegor256
Copy link
Owner

yegor256 commented Jul 3, 2015

@Bertram25 implementation of CapInputStream is also incorrect. You can easily reproduce a problem by this code:

InputStream stream = new CapInputStream(
  new ByteArrayInputStream(new byte[] {1, 2, 3}), 
  3
);
stream.skip(1);
assert stream.read() == 2;

Thus, I'm suggesting to submit a bug about CapInputStream and fix this branch too.

We should NOT encapsulate InputStream, but only extend it.

@pinaf
Copy link

pinaf commented Jul 19, 2015

@Bertram25 ping

@pinaf
Copy link

pinaf commented Aug 4, 2015

@Bertram25 please close the issue

@pinaf
Copy link

pinaf commented Aug 5, 2015

@yegor256 do you mind closing this issue?

@yegor256
Copy link
Owner

yegor256 commented Aug 6, 2015

@Bertram25 @pinaf I'm closing it, it's too old

@yegor256 yegor256 closed this Aug 6, 2015
@davvd davvd removed the @pinaf label Aug 6, 2015
@pinaf
Copy link

pinaf commented Aug 7, 2015

@yegor256 why did you mark it as invalid?

@yegor256
Copy link
Owner

yegor256 commented Aug 7, 2015

@pinaf my bad, I thought it's a ticket. removing the label now

@yegor256 yegor256 removed the invalid label Aug 7, 2015
@pinaf
Copy link

pinaf commented Aug 13, 2015

@yegor256 nothing yet :(

@pinaf
Copy link

pinaf commented Aug 17, 2015

@yegor256 could you please take a look at why I didn't get paid?

@pinaf
Copy link

pinaf commented Aug 20, 2015

@yegor256 I thought CRs were paid regardless of a merge. If this policy was changed please let me know so I don't have to bug you about payment.

@yegor256
Copy link
Owner

@davvd pls add extra 15 mins to @pinaf

@yegor256
Copy link
Owner

@pinaf no changes in the policy, it's just our internal problem, sorry about it

@pinaf
Copy link

pinaf commented Aug 20, 2015

@yegor256 it's cool. thank you.

@davvd
Copy link

davvd commented Aug 21, 2015

@davvd pls add extra 15 mins to @pinaf

@yegor256 15 mins extra was just paid to @pinaf, transaction AP-8J079864TA4566600

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.

5 participants