Search in sources :

Example 1 with MemoryLocksService

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);
}
Also used : MemoryLocksService(org.apache.oozie.service.MemoryLocksService)

Example 2 with MemoryLocksService

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();
    }
}
Also used : ServiceException(org.apache.oozie.service.ServiceException) MemoryLocksService(org.apache.oozie.service.MemoryLocksService)

Example 3 with MemoryLocksService

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);
}
Also used : MemoryLocksService(org.apache.oozie.service.MemoryLocksService)

Aggregations

MemoryLocksService (org.apache.oozie.service.MemoryLocksService)3 ServiceException (org.apache.oozie.service.ServiceException)1