private void executeWithOperationLog(String query, boolean queryLogEnabled) throws Exception {
    // verify whether the sql operation log is generated and fetch correctly.
    OperationHandle operationHandle = client.executeStatement(sessionHandle, query, null);
    RowSet rowSetLog = client.fetchResults(operationHandle, FetchOrientation.FETCH_FIRST, 1000,
            FetchType.LOG);
    String queryId = "";
    boolean expectedStopped = true;
    if (queryLogEnabled) {
      queryId = getQueryId(rowSetLog);
      expectedStopped = false;
      Assert.assertNotNull("Could not find query id, perhaps a logging message changed", queryId);
    } else {
      Assert.assertEquals("Operation log is generated even if query logging is disabled", rowSetLog.numRows(), 0);
      Assert.assertNull("Query id present even if logging is disabled.", getQueryId(rowSetLog));
    }

    checkAppenderState("before operation close ", LogDivertAppender.QUERY_ROUTING_APPENDER, queryId, expectedStopped);
    checkAppenderState("before operation close ", LogDivertAppenderForTest.TEST_QUERY_ROUTING_APPENDER, queryId, expectedStopped);
    client.closeOperation(operationHandle);
    checkAppenderState("after operation close ", LogDivertAppender.QUERY_ROUTING_APPENDER, queryId, expectedStopped);
    checkAppenderState("after operation close ", LogDivertAppenderForTest.TEST_QUERY_ROUTING_APPENDER, queryId, expectedStopped);
    Thread.sleep(8000);
    checkAppenderState("after operation close ", LogDivertAppender.QUERY_ROUTING_APPENDER, queryId, true);
    checkAppenderState("after operation close ", LogDivertAppenderForTest.TEST_QUERY_ROUTING_APPENDER, queryId, true);
  }
Open a session, and create a table for cases usage

@throws Exception
itests/hive-unit/src/test/java/org/apache/hive/service/cli/operation/TestOperationLoggingLayout.java