use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class ConditionAdvancedTest method testDestroyLock_whenOtherWaitingOnConditionAwait.
@Test(timeout = 60000, expected = DistributedObjectDestroyedException.class)
public void testDestroyLock_whenOtherWaitingOnConditionAwait() throws InterruptedException {
final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
final HazelcastInstance instance = nodeFactory.newHazelcastInstance();
final ILock lock = instance.getLock(randomString());
final ICondition condition = lock.newCondition("condition");
final CountDownLatch latch = new CountDownLatch(1);
new Thread(new Runnable() {
public void run() {
try {
latch.await(30, TimeUnit.SECONDS);
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
lock.destroy();
}
}).start();
lock.lock();
latch.countDown();
condition.await();
lock.unlock();
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class LockAdvancedTest method testIsLocked2.
//todo: what does isLocked2 test?
@Test(timeout = 60000)
public void testIsLocked2() throws Exception {
final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
final HazelcastInstance instance1 = nodeFactory.newHazelcastInstance();
final HazelcastInstance instance2 = nodeFactory.newHazelcastInstance();
final String key = randomString();
final ILock lock = instance1.getLock(key);
lock.lock();
assertTrue(lock.isLocked());
assertTrue(lock.isLockedByCurrentThread());
assertTrue(lock.tryLock());
assertTrue(lock.isLocked());
assertTrue(lock.isLockedByCurrentThread());
final AtomicBoolean result = new AtomicBoolean();
final Thread thread = new Thread() {
public void run() {
result.set(lock.isLockedByCurrentThread());
}
};
thread.start();
thread.join();
assertFalse(result.get());
lock.unlock();
assertTrue(lock.isLocked());
assertTrue(lock.isLockedByCurrentThread());
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class LockAdvancedTest method testShutDownNodeWhenOtherWaitingOnLock.
private void testShutDownNodeWhenOtherWaitingOnLock(boolean localKey) throws InterruptedException {
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
final HazelcastInstance instance = nodeFactory.newHazelcastInstance();
final HazelcastInstance instance2 = nodeFactory.newHazelcastInstance();
warmUpPartitions(instance2, instance);
final String key;
if (localKey) {
key = generateKeyOwnedBy(instance);
} else {
key = generateKeyNotOwnedBy(instance);
}
final ILock lock = instance.getLock(key);
Thread thread = new Thread(new Runnable() {
public void run() {
lock.lock();
}
});
thread.start();
thread.join();
new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
instance.shutdown();
}
}).start();
lock.lock();
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class LockAdvancedTest method testScheduledLockActionForDeadMember.
@Test(timeout = 100000)
public void testScheduledLockActionForDeadMember() throws Exception {
final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
final HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
final ILock lock1 = h1.getLock("default");
final HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
final ILock lock2 = h2.getLock("default");
assertTrue(lock1.tryLock());
final AtomicBoolean error = new AtomicBoolean(false);
Thread thread = new Thread(new Runnable() {
public void run() {
try {
lock2.lock();
error.set(true);
} catch (Throwable ignored) {
}
}
});
thread.start();
Thread.sleep(5000);
assertTrue(lock1.isLocked());
h2.shutdown();
thread.join(10000);
assertFalse(thread.isAlive());
assertFalse(error.get());
assertTrue(lock1.isLocked());
lock1.unlock();
assertFalse(lock1.isLocked());
assertTrue(lock1.tryLock());
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class LockAdvancedTest method testLockFail_whenGreaterThanMaxLeaseTimeUsed.
@Test(expected = IllegalArgumentException.class)
public void testLockFail_whenGreaterThanMaxLeaseTimeUsed() {
Config config = new Config();
config.setProperty(GroupProperty.LOCK_MAX_LEASE_TIME_SECONDS.getName(), "1");
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
HazelcastInstance hz = factory.newHazelcastInstance(config);
ILock lock = hz.getLock(randomName());
lock.lock(10, TimeUnit.SECONDS);
}
Aggregations