use of org.apache.oozie.service.MemoryLocksService in project oozie by apache.
the class TestMemoryLocks method testLocksAreReused.
public void testLocksAreReused() throws ServiceException, InterruptedException {
String path = "a";
MemoryLocksService lockService = new MemoryLocksService();
lockService.init(Services.get());
LockToken lock = lockService.getWriteLock(path, DEFAULT_LOCK_TIMEOUT);
int oldHash = System.identityHashCode(lockService.getMemoryLocks().getLockMap().get(path));
System.gc();
lock.release();
lock = lockService.getWriteLock(path, DEFAULT_LOCK_TIMEOUT);
assertEquals(lockService.getMemoryLocks().size(), 1);
int newHash = System.identityHashCode(lockService.getMemoryLocks().getLockMap().get(path));
assertTrue(oldHash == newHash);
}
use of org.apache.oozie.service.MemoryLocksService in project oozie by apache.
the class TestMemoryLocks method testLockReentrant.
public void testLockReentrant() throws ServiceException, InterruptedException {
final String path = UUID.randomUUID().toString();
MemoryLocksService lockService = new MemoryLocksService();
try {
lockService.init(Services.get());
LockToken lock = lockService.getWriteLock(path, DEFAULT_LOCK_TIMEOUT);
lock = (LockToken) lockService.getWriteLock(path, DEFAULT_LOCK_TIMEOUT);
lock = (LockToken) lockService.getWriteLock(path, DEFAULT_LOCK_TIMEOUT);
assertEquals(lockService.getMemoryLocks().size(), 1);
lock.release();
assertEquals(lockService.getMemoryLocks().size(), 1);
lock.release();
assertEquals(lockService.getMemoryLocks().size(), 1);
lock.release();
checkLockRelease(path, lockService);
} catch (Exception e) {
fail("Reentrant property, it should have acquired lock");
} finally {
lockService.destroy();
}
}
use of org.apache.oozie.service.MemoryLocksService in project oozie by apache.
the class TestMemoryLocks method testLocksAreGarbageCollected.
public void testLocksAreGarbageCollected() throws ServiceException, InterruptedException {
String path = new String("a");
String path1 = new String("a");
MemoryLocksService lockService = new MemoryLocksService();
lockService.init(Services.get());
LockToken lock = lockService.getWriteLock(path, DEFAULT_LOCK_TIMEOUT);
int oldHash = lockService.getMemoryLocks().getLockMap().get(path).hashCode();
lock.release();
lock = lockService.getWriteLock(path1, DEFAULT_LOCK_TIMEOUT);
int newHash = lockService.getMemoryLocks().getLockMap().get(path1).hashCode();
assertTrue(oldHash == newHash);
lock.release();
lock = null;
System.gc();
path = "a";
lock = lockService.getWriteLock(path, DEFAULT_LOCK_TIMEOUT);
newHash = lockService.getMemoryLocks().getLockMap().get(path).hashCode();
assertFalse(oldHash == newHash);
}
Aggregations