private List<Long> replOpenTxnForTest(long startId, int numTxn, String replPolicy)
          throws Exception {
    conf.setIntVar(HiveConf.ConfVars.HIVE_TXN_MAX_OPEN_BATCH, numTxn);
    long lastId = startId + numTxn - 1;
    OpenTxnRequest rqst = new OpenTxnRequest(numTxn, "me", "localhost");
    rqst.setReplPolicy(replPolicy);
    rqst.setReplSrcTxnIds(LongStream.rangeClosed(startId, lastId)
            .boxed().collect(Collectors.toList()));
    rqst.setTxn_type(TxnType.REPL_CREATED);
    OpenTxnsResponse openedTxns = txnHandler.openTxns(rqst);
    List<Long> txnList = openedTxns.getTxn_ids();
    assertEquals(txnList.size(), numTxn);
    int numTxnPresentNow = TestTxnDbUtil.countQueryAgent(conf, "SELECT COUNT(*) FROM \"TXNS\" WHERE \"TXN_ID\" >= " +
            txnList.get(0) + " and \"TXN_ID\" <= " + txnList.get(numTxn - 1));
    assertEquals(numTxn, numTxnPresentNow);

    checkReplTxnForTest(startId, lastId, replPolicy, txnList);
    return txnList;
  }
counter = 0;
Thread1 counter=1, lock, wait 3s, check counter(should be 2), counter=3, unlock
Thread2 counter=2, lock (and block), inc counter, should be 4
ql/src/test/org/apache/hadoop/hive/metastore/txn/TestTxnHandler.java