NlmLock implements Serializable { public boolean isConflicting(NlmLock other) { return isOverlappingRange(other) && !isSameOwner(other) && isConflictingType(other); } 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 shouldNotConflictFromSameOwnerSameType() { 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, 0, nfs4_prot.NFS4_UINT64_MAX); assertFalse("locks from the same owner must not conflict", lock1.isConflicting(lock2)); }
@Test public void shouldNotConflictFromSameOwnerDifferentType() { NlmLock lock1 = new NlmLock(lo1, nfs_lock_type4.WRITE_LT, 0, nfs4_prot.NFS4_UINT64_MAX); NlmLock lock2 = new NlmLock(lo1, nfs_lock_type4.READ_LT, 0, nfs4_prot.NFS4_UINT64_MAX); assertFalse("locks from the same owner must not conflict", lock1.isConflicting(lock2)); }
@Test public void shouldNotConflictReadLocksFromDifferentOwner() { NlmLock lock1 = new NlmLock(lo1, nfs_lock_type4.READ_LT, 0, nfs4_prot.NFS4_UINT64_MAX); NlmLock lock2 = new NlmLock(lo2, nfs_lock_type4.READ_LT, 0, nfs4_prot.NFS4_UINT64_MAX); assertFalse("read locks must not conflict", lock1.isConflicting(lock2)); }
@Test public void shouldConflictReadWriteFromDifferentOwner() { NlmLock lock1 = new NlmLock(lo1, nfs_lock_type4.WRITE_LT, 0, nfs4_prot.NFS4_UINT64_MAX); NlmLock lock2 = new NlmLock(lo2, nfs_lock_type4.READ_LT, 0, nfs4_prot.NFS4_UINT64_MAX); assertTrue("read locks must not conflict", lock1.isConflicting(lock2)); }