Search in sources :

Example 6 with CheckLockRequest

use of org.apache.hadoop.hive.metastore.api.CheckLockRequest in project hive by apache.

the class TestTxnHandler method testCheckLockAcquireAfterWaiting.

@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);
}
Also used : LockComponent(org.apache.hadoop.hive.metastore.api.LockComponent) LockResponse(org.apache.hadoop.hive.metastore.api.LockResponse) ArrayList(java.util.ArrayList) CheckLockRequest(org.apache.hadoop.hive.metastore.api.CheckLockRequest) AbortTxnRequest(org.apache.hadoop.hive.metastore.api.AbortTxnRequest) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) CheckLockRequest(org.apache.hadoop.hive.metastore.api.CheckLockRequest) Test(org.junit.Test)

Aggregations

CheckLockRequest (org.apache.hadoop.hive.metastore.api.CheckLockRequest)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 LockComponent (org.apache.hadoop.hive.metastore.api.LockComponent)5 LockRequest (org.apache.hadoop.hive.metastore.api.LockRequest)5 LockResponse (org.apache.hadoop.hive.metastore.api.LockResponse)5 NoSuchLockException (org.apache.hadoop.hive.metastore.api.NoSuchLockException)3 AbortTxnRequest (org.apache.hadoop.hive.metastore.api.AbortTxnRequest)2 UnlockRequest (org.apache.hadoop.hive.metastore.api.UnlockRequest)2