@Test
  public void testHeartbeat() throws Exception {
    int transactionBatch = 20;
    conf.setTimeVar(HiveConf.ConfVars.HIVE_TXN_TIMEOUT, 200, TimeUnit.MILLISECONDS);
    StrictDelimitedInputWriter writer = StrictDelimitedInputWriter.newBuilder()
      .withFieldDelimiter(',')
      .build();
    HiveStreamingConnection connection = HiveStreamingConnection.newBuilder()
      .withDatabase(dbName2)
      .withTable(tblName2)
      .withAgentInfo("UT_" + Thread.currentThread().getName())
      .withTransactionBatchSize(transactionBatch)
      .withRecordWriter(writer)
      .withHiveConf(conf)
      .connect();
    try {
      connection.beginTransaction();
      ShowLocksRequest request = new ShowLocksRequest();
      request.setDbname(dbName2);
      request.setTablename(tblName2);
      ShowLocksResponse response = msClient.showLocks(request);
      Assert.assertEquals("Wrong number of locks: " + response, 1, response.getLocks().size());
      ShowLocksResponseElement lock = response.getLocks().get(0);
      long acquiredAt = lock.getAcquiredat();
      long heartbeatAt = lock.getLastheartbeat();
      response = msClient.showLocks(request);
      Assert.assertEquals("Wrong number of locks2: " + response, 1, response.getLocks().size());
      lock = response.getLocks().get(0);
      Assert.assertEquals("Acquired timestamp didn'table match", acquiredAt, lock.getAcquiredat());
      Assert.assertTrue("Expected new heartbeat (" + lock.getLastheartbeat() +
        ") == old heartbeat(" + heartbeatAt + ")", lock.getLastheartbeat() == heartbeatAt);
      for (int i = 0; i < transactionBatch * 3; i++) {
        connection.beginTransaction();
        if (i % 10 == 0) {
          connection.abortTransaction();
        } else {
          connection.commitTransaction();
        }
        Thread.sleep(10);
      }
    } finally {
      conf.unset(HiveConf.ConfVars.HIVE_TXN_TIMEOUT.varname);
      connection.close();
    }
  }
check that transactions that have not heartbeated and timedout get properly aborted

@throws Exception
streaming/src/test/org/apache/hive/streaming/TestStreaming.java