@Test
  public void testMemoryConsumptionBasedFlush() {
    HiveConf conf = getHiveConfDummyRepository();
    Record record = new Record();
    long recordSize = record.getEstimatedSizeInMemoryBytes();
    // make sure we don't flush according to batch size
    conf.setIntVar(HiveConf.ConfVars.HIVE_QUERY_HISTORY_BATCH_SIZE, 1000);
    // flush after the second record (2 * recordSize > recordSize + 1)
    conf.setIntVar(HiveConf.ConfVars.HIVE_QUERY_HISTORY_MAX_MEMORY_BYTES, (int)recordSize + 1);

    QueryHistoryServiceForTest service = new QueryHistoryServiceForTest(conf, serviceContext);

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

    // add the record once: nothing is expected to happen
    service.addRecordDirectly(record);
    Assert.assertFalse("Call to flush is not expected here (1 record, didn't reach either of the limits)",
        service.needToFlush());

    // add the record again (same size): needToFlush is supposed to return true
    service.addRecordDirectly(record);
    Assert.assertTrue("Call to flush is expected here (memory size exceeded)",
        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