NlmLock implements Serializable { public boolean isOverlappingRange(NlmLock other) { if (other.length == nfs4_prot.NFS4_UINT64_MAX && length == nfs4_prot.NFS4_UINT64_MAX) { return true; } if (other.length == nfs4_prot.NFS4_UINT64_MAX) { return offset > other.offset || other.offset - length < offset; } if (length == nfs4_prot.NFS4_UINT64_MAX ){ return other.offset > offset || offset - other.length < other.offset; } if (offset > other.offset) { return offset - other.offset < other.length; } if (other.offset > offset) { return other.offset - offset < length; } return true; } NlmLock(StateOwner owner, int lockType, long offset, long length); StateOwner getOwner(); long getOffset(); long getLength(); int getLockType(); @Override int hashCode(); @Override boolean equals(Object obj); boolean isSameOwner(NlmLock other); boolean isOverlappingRange(NlmLock other); boolean isConflictingType(NlmLock other); boolean isConflicting(NlmLock other); @Override String toString();  }
@Test public void shouldDetectConflictingRangeLock() { NlmLock lock1 = new NlmLock(lo1, nfs_lock_type4.WRITE_LT, 0, nfs4_prot.NFS4_UINT64_MAX); NlmLock lock2 = new NlmLock(lo1, nfs_lock_type4.WRITE_LT, 1, 9223372036854775807L); assertTrue("overlaping lock range not detected", lock1.isOverlappingRange(lock2)); }
@Test public void shouldAllowEndingLockRange() { NlmLock lock1 = new NlmLock(lo1, nfs_lock_type4.WRITE_LT, 0, 1); NlmLock lock2 = new NlmLock(lo1, nfs_lock_type4.WRITE_LT, 2, 1); NlmLock lock = new NlmLock(lo1, nfs_lock_type4.WRITE_LT, 3, nfs4_prot.NFS4_UINT64_MAX); assertFalse("false conflicting lock range", lock.isOverlappingRange(lock1)); assertFalse("false conflicting lock range", lock.isOverlappingRange(lock2)); }