@Test
  public void testPeriodicFlush() throws Exception {
    HiveConf conf = getHiveConfDummyRepository();
    Record record = new Record();
    // make sure we don't flush according to batch size
    conf.setIntVar(HiveConf.ConfVars.HIVE_QUERY_HISTORY_BATCH_SIZE, Integer.MAX_VALUE);
    // makre sure we don't flush according to batch size
    conf.setIntVar(HiveConf.ConfVars.HIVE_QUERY_HISTORY_MAX_MEMORY_BYTES, Integer.MAX_VALUE);
    // flush as soon as possible for testing purposes
    conf.setIntVar(HiveConf.ConfVars.HIVE_QUERY_HISTORY_FLUSH_INTERVAL_SECONDS, 1);

    QueryHistoryServiceForTest service = new QueryHistoryServiceForTest(conf, serviceContext);
    service.start();

    // add the record once: nothing is expected to happen
    service.addRecordDirectly(record);

    // The queue size is most likely 1 at this point, but let's skip this pre-assertion to avoid flakiness
    // (e.g., if the periodic check happens to run in the meantime).
    Thread.sleep(5000);

    Assert.assertEquals("Queue should have been flushed by the periodic check", 0, service.getQueue().size());
  }
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