Class ReadWriteFileLockTest

java.lang.Object
ubic.gemma.core.util.locking.ReadWriteFileLockTest

public class ReadWriteFileLockTest extends Object
  • Constructor Details

    • ReadWriteFileLockTest

      public ReadWriteFileLockTest()
  • Method Details

    • test

      @Test @EnabledOnOs(LINUX) public void test() throws IOException, InterruptedException
      Relies on the /proc/locks pseudo-file, which only exists on Linux.
      Throws:
      IOException
      InterruptedException
    • testOverlappingLocks

      @Test public void testOverlappingLocks() throws IOException
      Locks are not allowed to overlap within the same JVM.
      Throws:
      IOException
    • testConcurrentReadWriteAccess

      @Test public void testConcurrentReadWriteAccess() throws IOException, InterruptedException
      Throws:
      IOException
      InterruptedException
    • testConcurrentReadersDoNotRaceTheOsLock

      @Test public void testConcurrentReadersDoNotRaceTheOsLock() throws Exception
      Concurrent readers must not race the OS-level lock acquisition.

      The ReentrantReadWriteLock admits any number of concurrent readers, so the transitions of the underlying FileLock have to be serialized separately. Before that serialization existed, two readers hitting an unheld lock both called channel.lock() and the second threw OverlappingFileLockException (seen in production on GET /datasets/26/data/raw, 2026-08-19); a reader acquiring while the last holder released could also observe fileLock == null before the OS lock was actually free, with the same result, or find a stale non-null lock and fail on isValid().

      Every round re-crosses the zero-holder boundary, which is where all three interleavings live: the barrier lines the readers up, each round's unlocks race the next round's locks, and any of the historical failures surfaces as an exception out of Future#get.

      Throws:
      Exception
    • testReentrantLocking

      @Test public void testReentrantLocking() throws IOException
      Throws:
      IOException
    • testReentrantLockingWithConcurrency

      @Test public void testReentrantLockingWithConcurrency() throws IOException, InterruptedException
      Throws:
      IOException
      InterruptedException