@Test
  public void testMaterializedViewRebuildLockForSameMV() throws Exception {
    driver.run("drop materialized view if exists mv_tab_acid");
    dropTable(new String[] { "tab_acid" });

    driver.run("create table if not exists tab_acid (a int, b int) partitioned by (p string) " +
            "stored as orc TBLPROPERTIES ('transactional'='true')");
    driver.run("insert into tab_acid partition(p) (a,b,p) values(1,2,'foo'),(3,4,'bar')");

    driver.run("create materialized view mv_tab_acid partitioned on (p) " +
            "stored as orc TBLPROPERTIES ('transactional'='true') as select a, p from tab_acid where b > 1");

    driver.run("insert into tab_acid partition(p) (a,b,p) values(1,2,'foo'),(3,4,'bar')");

    // execute MV Rebuild SQL for mv_tab_acid table
    driver.compileAndRespond("alter materialized view mv_tab_acid rebuild");
    driver.lockAndRespond();
    // Corresponding MV Rebuild lock entry should be present in MATERIALIZATION_REBUILD_LOCKS table
    Assert.assertEquals("One lock should be there as MV Rebuild is in-progress", 1, TestTxnDbUtil.countQueryAgent(conf,
        "select count(*) from MATERIALIZATION_REBUILD_LOCKS where MRL_TBL_NAME='mv_tab_acid'"));

    // rollback the transaction
    txnMgr.rollbackTxn();
    // As transaction is rollback there should not be any MV Rebuild lock entry for mv_tab_acid table.
    Assert.assertEquals("There should not be any MV Rebuild lock as Txn is rollback.", 0,
        TestTxnDbUtil.countQueryAgent(conf,
            "select count(*) from MATERIALIZATION_REBUILD_LOCKS where MRL_TBL_NAME='mv_tab_acid'"));

    // re-execute MV Rebuild SQL for mv_tab_acid table
    driver.compileAndRespond("alter materialized view mv_tab_acid rebuild");
    // Should be able to execute MV Rebuild and corresponding MV Rebuild lock entry should be present for mv_tab_acid table.
    Assert.assertEquals("One lock should be there as MV Rebuild is re-triggered", 1, TestTxnDbUtil.countQueryAgent(conf,
        "select count(*) from MATERIALIZATION_REBUILD_LOCKS where MRL_TBL_NAME='mv_tab_acid'"));

    // cleanup
    driver.run("drop materialized view mv_tab_acid");
  }
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