@Test
  public void testCtasLockingExclWrite() throws Exception {
    dropTable(new String[]{"target", "source"});
    conf.setBoolVar(HiveConf.ConfVars.TXN_CTAS_X_LOCK, true);
    
    driver.run("create table source (a int, b int) stored as orc TBLPROPERTIES ('transactional'='true')");
    driver.run("insert into source values (1,2), (3,4)");

    driver.compileAndRespond("create table target stored as orc TBLPROPERTIES ('transactional'='true') as select * from source");
    txnMgr.acquireLocks(driver.getPlan(), ctx, "T1");

    DbTxnManager txnMgr2 = (DbTxnManager) TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
    swapTxnManager(txnMgr2);

    driver.compileAndRespond("create table target stored as orc TBLPROPERTIES ('transactional'='true') as select * from source");
    try {
      //Query should fail with Table already exists exception
      txnMgr2.acquireLocks(driver.getPlan(), driver.getContext(), "T2", false);
    } catch (LockException e) {
      Assert.assertTrue(e.getMessage().contains("Failed to initiate a concurrent CTAS operation"));
    }
    List<ShowLocksResponseElement> locks = getLocks();
    Assert.assertEquals("Unexpected lock count", 3, locks.size());

    TestTxnDbUtil.checkLock(LockType.EXCL_WRITE, LockState.ACQUIRED, "default", "target", null, locks);
    TestTxnDbUtil.checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "source", null, locks);
    TestTxnDbUtil.checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", null, null, locks);
  }
run a merge statement using un-partitioned target table and a concurrent op on the target
Check that proper locks are acquired and Write conflict detection works and the state
of internal table.
@param causeConflict true to make 2 operations such that they update the same entity
ql/src/test/org/apache/hadoop/hive/ql/lockmgr/TestDbTxnManager2.java