@Test
  public void testSimpleFlush() throws Exception {
    HiveConf conf = getHiveConfDummyRepository();
    QueryHistoryService service = new QueryHistoryService(conf, serviceContext);
    service.start();

    // prepare the source object from which the QueryHistoryService will obtain query information
    QueryInfo queryInfo = spy(new QueryInfo(DummyRecord.QUERY_STATE, DummyRecord.END_USER,
        DummyRecord.EXECUTION_ENGINE, DummyRecord.SESSION_ID,
        DummyRecord.OPERATION_ID));
    // elapsed time is calculated from System.currentTimeMillis(), let's mock it here for unit test convenience's sake
    when(queryInfo.getElapsedTime()).thenReturn(DummyRecord.TOTAL_TIME);
    queryInfo.setEndTime();

    HiveConf.setQueryString(conf, DummyRecord.SQL);

    QueryState queryState = DriverFactory.getNewQueryState(conf);
    queryState.setCommandType(HiveOperation.valueOf(DummyRecord.OPERATION));

    // prepare SessionState
    SessionState ss = SessionState.start(conf);
    prepareSessionState(ss);

    // DriverContext
    DriverContext driverContext = spy(new DriverContext(queryState, queryInfo, null, null));
    prepareDriverContext(driverContext);

    // prepare perfLogger
    PerfLogger perfLogger = SessionState.getPerfLogger();
    preparePerfLogger(queryInfo, perfLogger);

    // QueryPlan
    QueryPlan plan = new QueryPlan();
    plan.setRootTasks(Arrays.asList(generateTezTask()));
    driverContext.setPlan(plan);

    // let the QueryHistoryService consume the data
    service.logQuery(driverContext);

    // get the prepared record from the service/repository
    DummyQueryHistoryRepository repository = (DummyQueryHistoryRepository)service.getRepository();
    Record record = repository.record;

    // check all the values are as expected in the record
    checkValues(ss, queryState, driverContext, record);

    service.stop();
  }
This unit test asserts that the record is created as expected from the various hive source objects like:
DriverContext, SessionState, QueryInfo, etc.
itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/queryhistory/TestQueryHistoryService.java