private void testFairness2(boolean zeroWaitRead) throws Exception {
    dropTable(new String[]{"T7"});
    conf.setBoolVar(HiveConf.ConfVars.TXN_WRITE_X_LOCK, !zeroWaitRead);
    driver.run("create table if not exists T7 (a int) " +
        "partitioned by (p int) stored as orc TBLPROPERTIES ('transactional'='true')");
    driver.run("insert into T7 partition(p) values(1,1),(1,2)"); //create 2 partitions
    driver.compileAndRespond("select a from T7 ", true);
    txnMgr.acquireLocks(driver.getPlan(), ctx, "Fifer"); //gets S lock on T7
    HiveTxnManager txnMgr2 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
    swapTxnManager(txnMgr2);
    driver.compileAndRespond("alter table T7 drop partition (p=1)", true);
    //tries to get X lock on T7.p=1 and gets Waiting state
    ((DbTxnManager) txnMgr2).acquireLocks(driver.getPlan(), ctx, "Fiddler", false);
    List<ShowLocksResponseElement> locks = getLocks();
    Assert.assertEquals("Unexpected lock count", 3, locks.size());
    TestTxnDbUtil.checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "T7", "p=1", locks);
    TestTxnDbUtil.checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "T7", "p=2", locks);
    long extLockId = TestTxnDbUtil.checkLock(LockType.EXCLUSIVE, LockState.WAITING, "default", "T7", "p=1", locks).getLockid();

    HiveTxnManager txnMgr3 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
    swapTxnManager(txnMgr3);
    //this should block behind the X lock on  T7.p=1
    driver.compileAndRespond("select a from T7", true);
    //tries to get S lock on T7, S on T7.p=1 and S on T7.p=2
    try {
      ((DbTxnManager) txnMgr3).acquireLocks(driver.getPlan(), ctx, "Fifer", false);
    } catch (LockException ex) {
      Assert.assertTrue(zeroWaitRead);
      Assert.assertEquals("Exception msg didn't match",
        ErrorMsg.LOCK_CANNOT_BE_ACQUIRED.getMsg() + " LockResponse(lockid:" + (extLockId + 1) +
          ", state:NOT_ACQUIRED, errorMessage:Unable to acquire read lock due to an existing exclusive lock" +
          " {lockid:" + extLockId + " intLockId:1 txnid:" + txnMgr2.getCurrentTxnId() +
          " db:default table:t7 partition:p=1 state:WAITING type:EXCLUSIVE})",
        ex.getMessage());
    }
    locks = getLocks();
    Assert.assertEquals("Unexpected lock count", (zeroWaitRead ? 3 : 5), locks.size());
    TestTxnDbUtil.checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "T7", "p=1", locks);
    TestTxnDbUtil.checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "T7", "p=2", locks);
    if (!zeroWaitRead) {
      TestTxnDbUtil.checkLock(LockType.SHARED_READ, LockState.WAITING, "default", "T7", "p=1", locks);
      TestTxnDbUtil.checkLock(LockType.SHARED_READ, LockState.WAITING, "default", "T7", "p=2", locks);
    }
    TestTxnDbUtil.checkLock(LockType.EXCLUSIVE, LockState.WAITING, "default", "T7", "p=1", locks);

    txnMgr.commitTxn(); //release locks from "select a from T7" - to unblock the drop partition
    //re-test the "drop partiton" X lock
    ((DbLockManager)txnMgr2.getLockManager()).checkLock(locks.get(zeroWaitRead ? 2 : 4).getLockid());
    locks = getLocks();
    Assert.assertEquals("Unexpected lock count", (zeroWaitRead ? 1 : 3), locks.size());
    TestTxnDbUtil.checkLock(LockType.EXCLUSIVE, LockState.ACQUIRED, "default", "T7", "p=1", locks);
    if (!zeroWaitRead) {
      TestTxnDbUtil.checkLock(LockType.SHARED_READ, LockState.WAITING, "default", "T7", "p=1", locks);
      TestTxnDbUtil.checkLock(LockType.SHARED_READ, LockState.WAITING, "default", "T7", "p=2", locks);

      txnMgr2.rollbackTxn(); //release the X lock on T7.p=1
      //re-test the locks
      ((DbLockManager) txnMgr2.getLockManager()).checkLock(locks.get(1).getLockid()); //S lock on T7
      locks = getLocks();
      Assert.assertEquals("Unexpected lock count", 2, locks.size());
      TestTxnDbUtil.checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "T7", "p=1", locks);
      TestTxnDbUtil.checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "T7", "p=2", locks);
    } else {
      txnMgr2.rollbackTxn();
    }
    txnMgr3.rollbackTxn();
    dropTable(new String[]{"T7"});
  }
T7 is a table with 2 partitions
1. run select from T7
2. run drop partition from T7
concurrently with 1 starting first so that 2 blocks
3. start another concurrent select on T7 - it should block behind waiting X (from drop) - LM should be fair
4. finish #1 so that drop unblocks
5. rollback the drop to release its X lock
6. # should unblock
ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestDbTxnManager2.java