@Override
  public void beforeTest(QTestUtil qt) throws Exception {
    HiveConf hiveConf = qt.getConf();
    if (enabled) {
      HiveConf.setBoolVar(hiveConf, HiveConf.ConfVars.HIVE_QUERY_HISTORY_ENABLED, true);
      // no matter what is default size, in qtest let's persist as soon as possible
      HiveConf.setIntVar(hiveConf, HiveConf.ConfVars.HIVE_QUERY_HISTORY_BATCH_SIZE, 0);

      QueryHistoryService queryHistoryService = QueryHistoryService.newInstance(hiveConf, new ServiceContext(() ->
          "localhost", () -> 0));
      queryHistoryService.start();
    }
  }
QTest Query History Service option
<p>
Enables the query history service for a qtest.
<p>
Example:
--! qt:queryhistory
itests/util/src/main/java/org/apache/hadoop/hive/ql/qoption/QTestQueryHistoryHandler.java