@Override public LockResponse check_lock(CheckLockRequest rqst) throws TException { return getTxnHandler().checkLock(rqst); }
@Test public void testCheckLockNoSuchLock() throws Exception { try { txnHandler.checkLock(new CheckLockRequest(23L)); fail("Allowed to check lock on non-existent lock"); } catch (NoSuchLockException e) { } }
@Test public void testLockTimeout() throws Exception { long timeout = txnHandler.setTimeout(1); try { LockComponent comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb"); comp.setTablename("mytable"); comp.setPartitionname("mypartition"); comp.setOperationType(DataOperationType.NO_TXN); List<LockComponent> components = new ArrayList<LockComponent>(1); components.add(comp); LockRequest req = new LockRequest(components, "me", "localhost"); LockResponse res = txnHandler.lock(req); assertTrue(res.getState() == LockState.ACQUIRED); Thread.sleep(10); txnHandler.performTimeOuts(); txnHandler.checkLock(new CheckLockRequest(res.getLockid())); fail("Told there was a lock, when it should have timed out."); } catch (NoSuchLockException e) { } finally { txnHandler.setTimeout(timeout); } }
@Test public void testMultipleLock() throws Exception { // Test more than one lock can be handled in a lock request LockComponent comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb"); comp.setTablename("mytable"); comp.setPartitionname("mypartition"); comp.setOperationType(DataOperationType.NO_TXN); List<LockComponent> components = new ArrayList<LockComponent>(2); components.add(comp); comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb"); comp.setTablename("mytable"); comp.setPartitionname("anotherpartition"); comp.setOperationType(DataOperationType.NO_TXN); components.add(comp); LockRequest req = new LockRequest(components, "me", "localhost"); LockResponse res = txnHandler.lock(req); long lockid = res.getLockid(); assertTrue(res.getState() == LockState.ACQUIRED); res = txnHandler.checkLock(new CheckLockRequest(lockid)); assertTrue(res.getState() == LockState.ACQUIRED); txnHandler.unlock(new UnlockRequest(lockid)); assertEquals(0, txnHandler.numLocksInLockTable()); }
@Test public void testCheckLockTxnAborted() throws Exception { // Test that when a transaction is aborted, the heartbeat fails long txnid = openTxn(); LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb"); comp.setTablename("mytable"); comp.setPartitionname("mypartition"); comp.setOperationType(DataOperationType.DELETE); List<LockComponent> components = new ArrayList<LockComponent>(1); components.add(comp); LockRequest req = new LockRequest(components, "me", "localhost"); req.setTxnid(txnid); LockResponse res = txnHandler.lock(req); long lockid = res.getLockid(); txnHandler.abortTxn(new AbortTxnRequest(txnid)); try { // This will throw NoSuchLockException (even though it's the // transaction we've closed) because that will have deleted the lock. txnHandler.checkLock(new CheckLockRequest(lockid)); fail("Allowed to check lock on aborted transaction."); } catch (NoSuchLockException e) { } }
res = txnHandler.checkLock(new CheckLockRequest(lockid2)); assertTrue(res.getState() == LockState.ACQUIRED);
@Test public void testCheckLockAcquireAfterWaiting() throws Exception { LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb"); comp.setTablename("mytable"); comp.setPartitionname("mypartition"); comp.setOperationType(DataOperationType.DELETE); List<LockComponent> components = new ArrayList<LockComponent>(1); components.add(comp); LockRequest req = new LockRequest(components, "me", "localhost"); long txnId = openTxn(); req.setTxnid(txnId); LockResponse res = txnHandler.lock(req); long lockid1 = res.getLockid(); assertTrue(res.getState() == LockState.ACQUIRED); comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb"); comp.setTablename("mytable"); comp.setPartitionname("mypartition"); comp.setOperationType(DataOperationType.UPDATE); components.clear(); components.add(comp); req = new LockRequest(components, "me", "localhost"); req.setTxnid(openTxn()); res = txnHandler.lock(req); long lockid2 = res.getLockid(); assertTrue(res.getState() == LockState.WAITING); txnHandler.abortTxn(new AbortTxnRequest(txnId)); res = txnHandler.checkLock(new CheckLockRequest(lockid2)); assertTrue(res.getState() == LockState.ACQUIRED); }
@Override public LockResponse check_lock(CheckLockRequest rqst) throws TException { return getTxnHandler().checkLock(rqst); }