Source:
<code>public void testHigherPriorityRequestPreemptedByAnother() throws Exception { ZKDistributedNonblockingLock lock = new ZKDistributedNonblockingLock(_participantScope, ZK_ADDR, 3600000L, "original " + "lock", "original_lock", 1, 1000, 25000, false, _lockListener); ZKDistributedNonblockingLock higherLock = new ZKDistributedNonblockingLock(_participantScope, ZK_ADDR, 3600000L, "higher priority lock", "high_lock", 2, 30000, 10000, false, createLockListener()); ZKDistributedNonblockingLock highestLock = new ZKDistributedNonblockingLock(_participantScope , ZK_ADDR, 3600000L, "highest priority lock", "highest_lock", 3, 30000, 20000, false, createLockListener()); Thread t = new Thread() { @Override public void run() { lock.tryLock(); } }; Thread t_highest = new Thread() { @Override public void run() { highestLock.tryLock(); } }; t.start(); t.join(); Assert.assertTrue(lock.isCurrentOwner()); LockHelper lockHelper = new LockHelper(higherLock); Thread t_higher = new Thread(lockHelper); t_higher.start(); <START> Thread.sleep(1000); <END> boolean higherResult = lockHelper.getResult(); Assert.assertFalse(higherLock.isCurrentOwner()); Assert.assertFalse(higherResult); t_highest.start(); t_highest.join(); Assert.assertTrue(highestLock.isCurrentOwner()); _isCleanupNotified.set(false); highestLock.unlock(); highestLock.close(); higherLock.close(); lock.close(); }</code><technical_language>avoid sleep here? is TestHelper methods</technical_language>

Target:
public void testHigherPriorityRequestPreemptedByAnother() throws Exception { ZKDistributedNonblockingLock lock = createLockWithConfig(); ZKDistributedNonblockingLock.Builder lockBuilder = new ZKDistributedNonblockingLock.Builder(); lockBuilder.setLockScope(_participantScope).setZkAddress(ZK_ADDR).setTimeout(3600000L) .setLockMsg("higher priority lock").setUserId("high_lock").setPriority(2) .setWaitingTimeout(30000).setCleanupTimeout(10000).setIsForceful(false) .setLockListener(createLockListener()); ZKDistributedNonblockingLock higherLock = lockBuilder.build(); ZKDistributedNonblockingLock.Builder highestLockBuilder = new ZKDistributedNonblockingLock.Builder(); highestLockBuilder.setLockScope(_participantScope).setZkAddress(ZK_ADDR).setTimeout(3600000L) .setLockMsg("highest priority lock").setUserId("highest_lock").setPriority(3) .setWaitingTimeout(30000).setCleanupTimeout(10000).setIsForceful(false) .setLockListener(createLockListener()); ZKDistributedNonblockingLock highestLock = highestLockBuilder.build(); Thread t = new Thread() { @Override public void run() { lock.tryLock(); } }; Thread t_highest = new Thread() { @Override public void run() { highestLock.tryLock(); } }; t.start(); t.join(); Assert.assertTrue(lock.isCurrentOwner()); LockHelper lockHelper = new LockHelper(higherLock); Thread t_higher = new Thread(lockHelper); t_higher.start(); boolean higherResult = TestHelper.verify(() -> { return lockHelper.getResult(); }, 1000); Assert.assertFalse(higherResult); Assert.assertFalse(higherLock.isCurrentOwner()); t_highest.start(); t_highest.join(); Assert.assertTrue(highestLock.isCurrentOwner()); _isCleanupNotified.set(false); highestLock.unlock(); highestLock.close(); higherLock.close(); lock.close(); }