private void testCheckExpectedLocks(boolean sharedWrite) throws Exception {
    dropTable(new String[] {"acidPart", "nonAcidPart"});
    conf.setBoolVar(HiveConf.ConfVars.TXN_WRITE_X_LOCK, !sharedWrite);

    driver.run("create table acidPart(a int, b int) partitioned by (p string) " +
        "clustered by (a) into 2  buckets stored as orc TBLPROPERTIES ('transactional'='true')");
    driver.run("create table nonAcidPart(a int, b int) partitioned by (p string) " +
        "stored as orc TBLPROPERTIES ('transactional'='false')");

    driver.compileAndRespond("insert into nonAcidPart partition(p) values(1,2,3)", true);
    ((DbTxnManager) txnMgr).acquireLocks(driver.getPlan(), ctx, "Practical", false);
    List<ShowLocksResponseElement> locks = getLocks();
    Assert.assertEquals("Unexpected lock count", 1, locks.size());
    TestTxnDbUtil.checkLock(LockType.EXCLUSIVE, LockState.ACQUIRED, "default", "nonAcidPart", null, locks);
    txnMgr.releaseLocks(ctx.getHiveLocks());

    driver.compileAndRespond("insert into nonAcidPart partition(p=1) values(5,6)", true);
    ((DbTxnManager) txnMgr).acquireLocks(driver.getPlan(), ctx, "Practical", false);
    locks = getLocks();
    Assert.assertEquals("Unexpected lock count", 1, locks.size());
    TestTxnDbUtil.checkLock(LockType.EXCLUSIVE, LockState.ACQUIRED, "default", "nonAcidPart", "p=1", locks);
    txnMgr.releaseLocks(ctx.getHiveLocks());

    driver.compileAndRespond("insert into acidPart partition(p) values(1,2,3)", true);
    ((DbTxnManager) txnMgr).acquireLocks(driver.getPlan(), ctx, "Practical", false);
    locks = getLocks();
    Assert.assertEquals("Unexpected lock count", 1, locks.size());
    TestTxnDbUtil.checkLock((sharedWrite ? LockType.SHARED_WRITE : LockType.SHARED_READ),
        LockState.ACQUIRED, "default", "acidPart", null, locks);
    txnMgr.rollbackTxn();

    driver.compileAndRespond("insert into acidPart partition(p=1) values(5,6)", true);
    ((DbTxnManager) txnMgr).acquireLocks(driver.getPlan(), ctx, "Practical", false);
    locks = getLocks();
    Assert.assertEquals("Unexpected lock count", 1, locks.size());
    TestTxnDbUtil.checkLock((sharedWrite ? LockType.SHARED_WRITE : LockType.SHARED_READ),
        LockState.ACQUIRED, "default", "acidPart", "p=1", locks);
    txnMgr.rollbackTxn();

    driver.compileAndRespond("update acidPart set b = 17 where a = 1", true);
    ((DbTxnManager) txnMgr).acquireLocks(driver.getPlan(), ctx, "Practical", false);
    locks = getLocks();
    Assert.assertEquals("Unexpected lock count", 1, locks.size());
    TestTxnDbUtil.checkLock((sharedWrite ? LockType.SHARED_WRITE : LockType.EXCL_WRITE),
        LockState.ACQUIRED, "default", "acidPart", null, locks);
    txnMgr.rollbackTxn();

    driver.compileAndRespond("update acidPart set b = 17 where p = 1", true);
    ((DbTxnManager) txnMgr).acquireLocks(driver.getPlan(), ctx, "Practical", false);
    locks = getLocks();
    Assert.assertEquals("Unexpected lock count", 1, locks.size());
    //https://issues.apache.org/jira/browse/HIVE-13212
    TestTxnDbUtil.checkLock((sharedWrite ? LockType.SHARED_WRITE : LockType.EXCL_WRITE),
        LockState.ACQUIRED, "default", "acidPart", null, locks);
    txnMgr.rollbackTxn();
  }
Collection of queries where we ensure that we get the locks that are expected.
ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestDbTxnManager2.java