Search in sources :

Example 1 with ZKLockToken

use of org.apache.oozie.service.ZKLocksService.ZKLockToken in project oozie by apache.

the class TestZKLocksService method testLockRelease.

public void testLockRelease() throws ServiceException, InterruptedException {
    final String path = UUID.randomUUID().toString();
    ZKLocksService zkls = new ZKLocksService();
    try {
        zkls.init(Services.get());
        ZKLockToken lock = (ZKLockToken) zkls.getWriteLock(path, TestMemoryLocks.DEFAULT_LOCK_TIMEOUT);
        assertTrue(zkls.getLocks().containsKey(path));
        lock.release();
        checkLockRelease(path, zkls);
    } finally {
        zkls.destroy();
    }
}
Also used : ZKLockToken(org.apache.oozie.service.ZKLocksService.ZKLockToken)

Example 2 with ZKLockToken

use of org.apache.oozie.service.ZKLocksService.ZKLockToken in project oozie by apache.

the class TestZKLocksService method testReentrantMultipleCall.

public void testReentrantMultipleCall() throws ServiceException, InterruptedException {
    final String path = UUID.randomUUID().toString();
    ZKLocksService zkls = new ZKLocksService();
    try {
        zkls.init(Services.get());
        ZKLockToken lock = (ZKLockToken) zkls.getWriteLock(path, TestMemoryLocks.DEFAULT_LOCK_TIMEOUT);
        lock = (ZKLockToken) zkls.getWriteLock(path, TestMemoryLocks.DEFAULT_LOCK_TIMEOUT);
        lock = (ZKLockToken) zkls.getWriteLock(path, TestMemoryLocks.DEFAULT_LOCK_TIMEOUT);
        assertTrue(zkls.getLocks().containsKey(path));
        lock.release();
        assertTrue(zkls.getLocks().containsKey(path));
        lock.release();
        assertTrue(zkls.getLocks().containsKey(path));
        lock.release();
        checkLockRelease(path, zkls);
    } catch (Exception e) {
        fail("Reentrant property, it should have acquired lock");
    } finally {
        zkls.destroy();
    }
}
Also used : ZKLockToken(org.apache.oozie.service.ZKLocksService.ZKLockToken) ConnectionLossException(org.apache.zookeeper.KeeperException.ConnectionLossException)

Aggregations

ZKLockToken (org.apache.oozie.service.ZKLocksService.ZKLockToken)2 ConnectionLossException (org.apache.zookeeper.KeeperException.ConnectionLossException)1