Class ReadWriteFileLockTest
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidtest()Relies on the/proc/lockspseudo-file, which only exists on Linux.voidConcurrent readers must not race the OS-level lock acquisition.voidvoidLocks are not allowed to overlap within the same JVM.voidvoid
-
Constructor Details
-
ReadWriteFileLockTest
public ReadWriteFileLockTest()
-
-
Method Details
-
test
Relies on the/proc/lockspseudo-file, which only exists on Linux.- Throws:
IOExceptionInterruptedException
-
testOverlappingLocks
Locks are not allowed to overlap within the same JVM.- Throws:
IOException
-
testConcurrentReadWriteAccess
- Throws:
IOExceptionInterruptedException
-
testConcurrentReadersDoNotRaceTheOsLock
Concurrent readers must not race the OS-level lock acquisition.The
ReentrantReadWriteLockadmits any number of concurrent readers, so the transitions of the underlyingFileLockhave to be serialized separately. Before that serialization existed, two readers hitting an unheld lock both calledchannel.lock()and the second threwOverlappingFileLockException(seen in production onGET /datasets/26/data/raw, 2026-08-19); a reader acquiring while the last holder released could also observefileLock == nullbefore the OS lock was actually free, with the same result, or find a stale non-null lock and fail onisValid().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
- Throws:
IOException
-
testReentrantLockingWithConcurrency
- Throws:
IOExceptionInterruptedException
-