[
https://issues.apache.org/jira/browse/SOLR-13545?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16864902#comment-16864902
]
Colvin Cowie commented on SOLR-13545:
-------------------------------------
Hi Mikhail, I had a look at doing it with a mock/spy. It worked, but it feels
fairly fragile, since I didn't have direct access to the InputStream that is
created, and had to spy on the invocations all the way down to it.
I also saw StreamingUpdateRequest (which is using an autoclose) and it is
newing up the stream right where it is used.
{code:java}
@Override
public void write(OutputStream os) throws IOException {
try (InputStream is = new FileInputStream(f)) {
IOUtils.copy(is, os);
}
}
{code}
So if I was to try and write a mocking test for it, I wouldn't have anywhere to
hook in.
I could change the actual ContentStreamUpdateRequest and StreamingUpdateRequest
classes to expose the InputStream(s) they open, so that it's easier to mock
out, but I don't know what the testing strategy is when it comes to something
like this.
For now, I've updated the tests for both so that they create a copy of the file
they were uploading, upload it, then delete it. That will fail on Windows if
the stream isn't closed, but will (probably) always pass on linux, even if the
stream isn't closed. So it's not a foolproof test either.
I've submitted the PR (https://github.com/apache/lucene-solr/pull/723), but I'm
happy to do something different with the tests though, if it's worth pursuing.
Thanks
> ContentStreamUpdateRequest no longer closes stream
> --------------------------------------------------
>
> Key: SOLR-13545
> URL: https://issues.apache.org/jira/browse/SOLR-13545
> Project: Solr
> Issue Type: Bug
> Security Level: Public(Default Security Level. Issues are Public)
> Components: SolrJ
> Affects Versions: 7.4, 7.5, 7.6, 7.7, 7.7.1, 7.7.2, 8.0, 8.1, 8.1.1
> Environment: Windows - file locking may not cause a visible failure
> on Linux?
> Reporter: Colvin Cowie
> Priority: Major
> Attachments: ContentStreamUpdateRequestBug.java
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> Since the change made in SOLR-12142 _ContentStreamUpdateRequest_ no longer
> closes the stream that it opens. Therefore if streaming a file, it cannot be
> deleted until the process exits.
>
> {code:java}
> @Override
> public RequestWriter.ContentWriter getContentWriter(String expectedType) {
> if (contentStreams == null || contentStreams.isEmpty() ||
> contentStreams.size() > 1) return null;
> ContentStream stream = contentStreams.get(0);
> return new RequestWriter.ContentWriter() {
> @Override
> public void write(OutputStream os) throws IOException {
> IOUtils.copy(stream.getStream(), os);
> }
> @Override
> public String getContentType() {
> return stream.getContentType();
> }
> };
> }
> {code}
> IOUtils.copy will not close the stream. Adding a close to the write(), is
> enough to "fix" it for the test case I've attached, e.g.
>
> {code:java}
> @Override
> public void write(OutputStream os) throws IOException {
> final InputStream innerStream = stream.getStream();
> try {
> IOUtils.copy(innerStream, os);
> } finally {
> IOUtils.closeQuietly(innerStream);
> }
> }
> {code}
>
> I don't know whether any other streaming classes have similar issues
>
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]