garydgregory commented on a change in pull request #166:
URL: https://github.com/apache/commons-vfs/pull/166#discussion_r593547225
##########
File path:
commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/DefaultFileContentTest.java
##########
@@ -167,4 +174,32 @@ public void
testOutputStreamBufferSizeNegativeWithAppendFlag() throws Exception
}
}
+ @Test
+ public void testOutputStreamClosedInADifferentThread() throws Exception {
+ testStreamClosedInADifferentThread(content ->
content.getOutputStream());
+ }
+
+ private <T extends Closeable> void
testStreamClosedInADifferentThread(FunctionThrowingException<FileContent, T>
getStream) throws Exception {
+ final File temp = File.createTempFile("temp-file-name", ".tmp");
+ final FileSystemManager fileSystemManager = VFS.getManager();
+
+ try (FileObject file =
fileSystemManager.resolveFile(temp.getAbsolutePath())) {
+ T stream = getStream.apply(file.getContent());
+ boolean[] check = { false };
+ Thread thread = new Thread(() -> {
+ try {
+ stream.close();
+ } catch (IOException exception) {
+ }
+ check[0] = true;
+ });
+ thread.start();
+ thread.join();
+ Assert.assertTrue(check[0]);
+ }
+ }
+}
+
+interface FunctionThrowingException<T, R> {
Review comment:
FYI: I think you can reuse
`org.apache.commons.lang3.function.FailableFunction` here.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]