Ejemplo n.º 1
0
 @Override
 public Boolean call() throws Exception {
   try {
     lock.release();
     return true;
   } catch (final Exception e) {
     logger.debug("{} failed to release lock", lock, e);
     return false;
   }
 }
Ejemplo n.º 2
0
 /**
  * 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");
   }
 }
Ejemplo n.º 3
0
 /** 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.");
   }
 }
Ejemplo n.º 4
0
 /**
  * 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");
   }
 }