final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
final HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
final HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
final HazelcastInstance h3 = nodeFactory.newHazelcastInstance();
final String key = "testLockIsLocked";
final ILock lock = h1.getLock(key);
final ILock lock2 = h2.getLock(key);
assertFalse(lock.isLocked());
assertFalse(lock2.isLocked());
lock.lock();
assertTrue(lock.isLocked());
assertTrue(lock2.isLocked());
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
Thread thread = new Thread(new Runnable() {
public void run() {
ILock lock3 = h3.getLock(key);
assertTrue(lock3.isLocked());
try {
latch2.countDown();
while (lock3.isLocked()) {
Thread.sleep(100);
}
latch.countDown();
} catch (InterruptedException e) {
throw new RuntimeException(e);