Original title: "Workspace's FileReadDeleteTest's testFileDeletionWhileReadingNio() fails in Ubuntu 14.04"
Steps to reproduce:
1. run mvn clean install on develop branch on an Ubuntu 14.04, openjdk version "1.8.0_111", Apache Maven 3.3.9
Actual Results: Exception thrown in workspace impl's FileReadDeleteTest's testFileDeletionWhileReadingNio (the testFileDeletionWhileReadingIo test succeeds) . See exception below.
Expected Results: The Test succeeds in Ubuntu 14.04 as it does in Mac OS X: The FileChannel is thread safe enough to keep reading the file stream even though the file was deleted in the second thread.
Workaround (if any): Build matterhorn-workspace-impl with -DskiptTests=true
REF: This is the exception thrown in the first thread at "return channel.transferTo(total, 1024, sink);" immediately after the file was deleted in the second thread.
java.io.IOException: No such file or directory
at sun.nio.ch.FileDispatcherImpl.size0(Native Method)
at sun.nio.ch.FileDispatcherImpl.size(FileDispatcherImpl.java:84)
at sun.nio.ch.FileChannelImpl.size(FileChannelImpl.java:310)
at sun.nio.ch.FileChannelImpl.transferTo(FileChannelImpl.java:598)
at org.opencastproject.workspace.impl.FileReadDeleteTest$3$1.xapply(FileReadDeleteTest.java:164)
at org.opencastproject.workspace.impl.FileReadDeleteTest$3$1.xapply(FileReadDeleteTest.java:159)
at org.opencastproject.util.data.Function$X.apply(Function.java:111)
at org.opencastproject.workspace.impl.FileReadDeleteTest$2.run(FileReadDeleteTest.java:132)
at org.opencastproject.workspace.impl.FileReadDeleteTest$2.run(FileReadDeleteTest.java:124)
at org.opencastproject.util.data.Effect.apply(Effect.java:35)
at org.opencastproject.util.data.Effect.apply(Effect.java:32)
at org.opencastproject.util.IoSupport.withResource(IoSupport.java:393)
at org.opencastproject.workspace.impl.FileReadDeleteTest$1.run(FileReadDeleteTest.java:110)
at java.lang.Thread.run(Thread.java:745)
The big question is that FileUtility uses FileChannel and it doesn't seem to be as thread safe on Ubuntu (14.04) as it is on other Operating Systems.
I forgot to mention that the Ubuntu was in a Virtualbox. Apparently, memory mapping is not allowed on shared directories in Virtualbox [1] . The FileChannel tranferTo in testFileDeletionWhileReadingNio() ran successfully and all built Ok when building Opencast in a non-shared VM location within the Ubuntu Virtualbox VM. Good to know for the future. Closing ticket.
[1] https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Additions/linux/sharedfolders/regops.c#L551
Additional notes about this java nio FileChannel file access thread safety issue from a VirtualBox vm using a shared file system.
I'm currently using VirtualBox 5.0.12 r104815 and I have not tried the upgraded version of VirtualBox 5.1.8.
The thread that gives an explanation of why virtual box does not support memory mapping on shared file system: https://www.virtualbox.org/pipermail/vbox-dev/2013-April/011349.html
This looks like the VirtualBox mmap issue tracking ticket https://www.virtualbox.org/ticket/819
(Opencast FileUtils uses FileChannel which relies on mmap thread safety, per the Workspace module's junit)