@Test
  public void testBatchSizeBasedFlush() {
    HiveConf conf = getHiveConfDummyRepository();
    Record record = new Record();
    // make sure we don't flush according to estimated memory size
    conf.setIntVar(HiveConf.ConfVars.HIVE_QUERY_HISTORY_MAX_MEMORY_BYTES, 1000000);
    // flush after the third record
    conf.setIntVar(HiveConf.ConfVars.HIVE_QUERY_HISTORY_BATCH_SIZE, 3);

    QueryHistoryServiceForTest service = new QueryHistoryServiceForTest(conf, serviceContext);

    Assert.assertFalse("Call to flush is not expected here (no records)",
        service.needToFlush());

    service.addRecordDirectly(record);
    Assert.assertFalse("Call to flush is not expected here (1 record)",
        service.needToFlush());

    service.addRecordDirectly(record);
    Assert.assertFalse("Call to flush is not expected here (2 records)",
        service.needToFlush());

    service.addRecordDirectly(record);
    Assert.assertTrue("Call to flush is expected here (3 records == configured limit)",
        service.needToFlush());
  }
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