use of org.redisson.api.RLock in project redisson by redisson.
the class RedissonLockTest method testAutoExpire.
@Test
public void testAutoExpire() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
RedissonClient r = createInstance();
Thread t = new Thread() {
@Override
public void run() {
RLock lock = r.getLock("lock");
lock.lock();
latch.countDown();
try {
Thread.sleep(15000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
t.start();
Assertions.assertTrue(latch.await(1, TimeUnit.SECONDS));
RLock lock = redisson.getLock("lock");
t.join();
r.shutdown();
await().atMost(redisson.getConfig().getLockWatchdogTimeout(), TimeUnit.MILLISECONDS).until(() -> !lock.isLocked());
}
use of org.redisson.api.RLock in project redisson by redisson.
the class RedissonLockTest method testIsHeldByCurrentThreadOtherThread.
@Test
public void testIsHeldByCurrentThreadOtherThread() throws InterruptedException {
RLock lock = redisson.getLock("lock");
lock.lock();
Thread t = new Thread() {
public void run() {
RLock lock = redisson.getLock("lock");
Assertions.assertFalse(lock.isHeldByCurrentThread());
}
};
t.start();
t.join();
lock.unlock();
Thread t2 = new Thread() {
public void run() {
RLock lock = redisson.getLock("lock");
Assertions.assertFalse(lock.isHeldByCurrentThread());
}
};
t2.start();
t2.join();
}
use of org.redisson.api.RLock in project redisson by redisson.
the class RedissonLockTest method testIsLocked.
@Test
public void testIsLocked() {
RLock lock = redisson.getLock("lock");
Assertions.assertFalse(lock.isLocked());
lock.lock();
Assertions.assertTrue(lock.isLocked());
lock.unlock();
Assertions.assertFalse(lock.isLocked());
}
use of org.redisson.api.RLock in project redisson by redisson.
the class RedissonFairLockTest method testAutoExpire.
@Test
public void testAutoExpire() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
testSingleInstanceConcurrency(1, r -> {
RLock lock = r.getFairLock("lock");
lock.lock();
latch.countDown();
});
Assertions.assertTrue(latch.await(1, TimeUnit.SECONDS));
RLock lock = redisson.getFairLock("lock");
await().atMost(redisson.getConfig().getLockWatchdogTimeout() + 1000, TimeUnit.MILLISECONDS).until(() -> !lock.isLocked());
}
use of org.redisson.api.RLock in project redisson by redisson.
the class RedissonFairLockTest method testIsHeldByCurrentThreadOtherThread.
@Test
public void testIsHeldByCurrentThreadOtherThread() throws InterruptedException {
RLock lock = redisson.getFairLock("lock");
lock.lock();
Thread t = new Thread() {
public void run() {
RLock lock = redisson.getFairLock("lock");
Assertions.assertFalse(lock.isHeldByCurrentThread());
}
};
t.start();
t.join();
lock.unlock();
Thread t2 = new Thread() {
public void run() {
RLock lock = redisson.getFairLock("lock");
Assertions.assertFalse(lock.isHeldByCurrentThread());
}
};
t2.start();
t2.join();
}
Aggregations