use of com.hazelcast.core.ILock in project hazelcast by hazelcast.
the class ClientLockTest method testMaxLockLeaseTime.
@Test
public void testMaxLockLeaseTime() {
Config config = new Config();
config.setProperty(GroupProperty.LOCK_MAX_LEASE_TIME_SECONDS.getName(), "1");
factory.newHazelcastInstance(config);
HazelcastInstance hz = factory.newHazelcastClient();
final ILock lock = hz.getLock(randomName());
lock.lock();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertFalse("Lock should be released after lease expires!", lock.isLocked());
}
}, 30);
}
use of com.hazelcast.core.ILock in project hazelcast by hazelcast.
the class ClientLockTest method testTryLockLeaseTime_lockIsReleasedEventually.
@Test
public void testTryLockLeaseTime_lockIsReleasedEventually() throws InterruptedException {
factory.newHazelcastInstance();
HazelcastInstance hz = factory.newHazelcastClient();
final ILock lock = hz.getLock(randomName());
lock.tryLock(1000, TimeUnit.MILLISECONDS, 1000, TimeUnit.MILLISECONDS);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertFalse(lock.isLocked());
}
}, 30);
}
use of com.hazelcast.core.ILock in project hazelcast by hazelcast.
the class ClientLockTest method testTryLockLeaseTime_whenLockAcquiredByOther.
@Test(timeout = 60000)
public void testTryLockLeaseTime_whenLockAcquiredByOther() throws InterruptedException {
factory.newHazelcastInstance();
HazelcastInstance hz = factory.newHazelcastClient();
final ILock lock = hz.getLock(randomName());
Thread thread = new Thread() {
public void run() {
lock.lock();
}
};
thread.start();
thread.join();
boolean isLocked = lock.tryLock(1000, TimeUnit.MILLISECONDS, 1000, TimeUnit.MILLISECONDS);
assertFalse(isLocked);
}
use of com.hazelcast.core.ILock in project hazelcast by hazelcast.
the class ClientLockTest method testStats.
@Test
public void testStats() throws InterruptedException {
factory.newHazelcastInstance();
HazelcastInstance hz = factory.newHazelcastClient();
final ILock lock = hz.getLock(randomName());
lock.lock();
assertTrue(lock.isLocked());
assertTrue(lock.isLockedByCurrentThread());
assertEquals(1, lock.getLockCount());
lock.unlock();
assertFalse(lock.isLocked());
assertEquals(0, lock.getLockCount());
assertEquals(-1L, lock.getRemainingLeaseTime());
lock.lock(1, TimeUnit.MINUTES);
assertTrue(lock.isLocked());
assertTrue(lock.isLockedByCurrentThread());
assertEquals(1, lock.getLockCount());
assertTrue(lock.getRemainingLeaseTime() > 1000 * 30);
final CountDownLatch latch = new CountDownLatch(1);
new Thread() {
public void run() {
assertTrue(lock.isLocked());
assertFalse(lock.isLockedByCurrentThread());
assertEquals(1, lock.getLockCount());
assertTrue(lock.getRemainingLeaseTime() > 1000 * 30);
latch.countDown();
}
}.start();
assertTrue(latch.await(1, TimeUnit.MINUTES));
}
use of com.hazelcast.core.ILock in project hazelcast by hazelcast.
the class ClientLockTest 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");
factory.newHazelcastInstance(config);
HazelcastInstance hz = factory.newHazelcastClient();
ILock lock = hz.getLock(randomName());
lock.lock(10, TimeUnit.SECONDS);
}
Aggregations