@Test
  public void testSimpleQuery() {
    new LineageInfo();
    try {

      // NOTE: It is critical to do this here so that log4j is reinitialized
      // before any of the other core hive classes are loaded
      try {
        LogUtils.initHiveLog4j();
      } catch (LogInitializationException e) {
      }
      HiveConf hconf = getHiveConf();
      hconf.setBoolVar(ConfVars.HIVE_SESSION_HISTORY_ENABLED, true);
      CliSessionState ss = new CliSessionState(hconf);
      ss.in = System.in;
      try {
        ss.out = new SessionStream(System.out, true, "UTF-8");
        ss.err = new SessionStream(System.err, true, "UTF-8");
      } catch (UnsupportedEncodingException e) {
        System.exit(3);
      }

      SessionState.start(ss);

      String cmd = "select a.key+1 from src a";
      IDriver d = DriverFactory.newDriver(conf);
      d.run(cmd);
      HiveHistoryViewer hv = new HiveHistoryViewer(SessionState.get()
          .getHiveHistory().getHistFileName());
      Map<String, QueryInfo> jobInfoMap = hv.getJobInfoMap();
      Map<String, TaskInfo> taskInfoMap = hv.getTaskInfoMap();
      if (jobInfoMap.size() != 1) {
        fail("jobInfo Map size not 1");
      }

      if (taskInfoMap.size() != 1) {
        fail("jobInfo Map size not 1");
      }

      cmd = (String) jobInfoMap.keySet().toArray()[0];
      QueryInfo ji = jobInfoMap.get(cmd);

      if (!ji.hm.get(Keys.QUERY_NUM_TASKS.name()).equals("1")) {
        fail("Wrong number of tasks");
      }

    } catch (Exception e) {
      e.printStackTrace();
      fail("Failed");
    }
  }
Check history file output for this query.
itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/history/TestHiveHistory.java