/** Verify non-reentrant behavior. */ @Test public void verifyNonReentrantBehavior() { final String appId = "reentrant"; final String uniqueId = appId + "-1"; final LockingStrategy lock = newLockTxProxy(appId, uniqueId, JpaTicketRegistryProperties.DEFAULT_LOCK_TIMEOUT); try { assertTrue(lock.acquire()); assertEquals(uniqueId, getOwner(appId)); assertFalse(lock.acquire()); lock.release(); assertNull(getOwner(appId)); } catch (final Exception e) { logger.debug("testNonReentrantBehavior produced an error", e); fail("testNonReentrantBehavior failed."); } }
@Override public Boolean call() throws Exception { try { return lock.acquire(); } catch (final Exception e) { logger.debug("{} failed to acquire lock", lock, e); return false; } }
/** * Test lock expiration. * * @throws Exception On errors. */ @Test public void verifyLockExpiration() throws Exception { final String appId = "expquick"; final String uniqueId = appId + "-1"; final LockingStrategy lock = newLockTxProxy(appId, uniqueId, "1"); try { assertTrue(lock.acquire()); assertEquals(uniqueId, getOwner(appId)); assertFalse(lock.acquire()); Thread.sleep(1500); assertTrue(lock.acquire()); assertEquals(uniqueId, getOwner(appId)); lock.release(); assertNull(getOwner(appId)); } catch (final Exception e) { logger.debug("testLockExpiration produced an error", e); fail("testLockExpiration failed"); } }
/** * Test basic acquire/release semantics. * * @throws Exception On errors. */ @Test public void verifyAcquireAndRelease() throws Exception { final String appId = "basic"; final String uniqueId = appId + "-1"; final LockingStrategy lock = newLockTxProxy(appId, uniqueId, JpaTicketRegistryProperties.DEFAULT_LOCK_TIMEOUT); try { assertTrue(lock.acquire()); assertEquals(uniqueId, getOwner(appId)); lock.release(); assertNull(getOwner(appId)); } catch (final Exception e) { logger.debug("testAcquireAndRelease produced an error", e); fail("testAcquireAndRelease failed"); } }