private void testConcurrentMergeInsert(String query, boolean sharedWrite, boolean slowCompile, boolean extectedDuplicates) throws Exception {
    dropTable(new String[]{"target", "source"});
    conf.setBoolVar(HiveConf.ConfVars.TXN_WRITE_X_LOCK, !sharedWrite);
    driver2.getConf().setBoolVar(HiveConf.ConfVars.TXN_WRITE_X_LOCK, !sharedWrite);

    driver.run("create table target (a int, b int) stored as orc TBLPROPERTIES ('transactional'='true')");
    driver.run("insert into target values (1,2), (3,4)");
    driver.run("create table source (a int, b int)");
    driver.run("insert into source values (5,6), (7,8)");

    if (!slowCompile) {
      driver.compileAndRespond(query);
    }

    DbTxnManager txnMgr2 = (DbTxnManager) TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
    swapTxnManager(txnMgr2);
    driver2.compileAndRespond("merge into target t using source s on t.a = s.a " +
      "when not matched then insert values (s.a, s.b)");

    swapTxnManager(txnMgr);
    if (!slowCompile) {
      driver.run();
    } else {
      driver.run(query);
    }

    swapTxnManager(txnMgr2);
    try {
      driver2.run();
    } catch (CommandProcessorException ex ){
      Assert.assertTrue(ex.getMessage().contains("write conflict on default/target"));
    }

    swapTxnManager(txnMgr);
    driver.run("select * from target");
    List<String> res = new ArrayList<>();
    driver.getFetchTask().fetch(res);
    Assert.assertEquals("Duplicate records " + (extectedDuplicates ? "" : "not") + "found",
      extectedDuplicates ? 5 : 4, res.size());
    dropTable(new String[]{"target", "source"});
  }
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