protected void test_try_lock() {
ExecutorService exeucotr = Executors.newCachedThreadPool();
final int count = 50;
final CountDownLatch latch = new CountDownLatch(count);
final DistributedReentrantLock lock = new DistributedReentrantLock(dir);
for (int i = 0; i < count; i++) {
exeucotr.submit(new Runnable() {
public void run() {
try {
while (lock.tryLock() == false) {
Thread.sleep(100 + RandomUtils.nextInt(100));
}
System.out.println("id: " + lock.getId() + " is leader: " + lock.isOwner());
} catch (InterruptedException e) {
want.fail();
} catch (KeeperException e) {
want.fail();
} finally {
latch.countDown();
try {
lock.unlock();
} catch (KeeperException e) {
want.fail();
}
}