private void checkAppenderState(String msg, String routingAppenderName, String queryId,
      boolean expectedStopped) throws NoSuchFieldException, IllegalAccessException {
    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    Configuration configuration = context.getConfiguration();
    LoggerConfig loggerConfig = configuration.getRootLogger();
    Map<String, Appender> appendersMap = loggerConfig.getAppenders();
    RoutingAppender routingAppender = (RoutingAppender) appendersMap.get(routingAppenderName);
    Assert.assertNotNull(msg + "could not find routingAppender " + routingAppenderName, routingAppender);
    Field defaultsField = RoutingAppender.class.getDeclaredField("createdAppenders");
    defaultsField.setAccessible(true);
    ConcurrentHashMap appenders = (ConcurrentHashMap) defaultsField.get(routingAppender);
    AppenderControl appenderControl = (AppenderControl) appenders.get(queryId);
    if (!expectedStopped) {
      Assert.assertNotNull(msg + "Could not find AppenderControl for query id " + queryId, appenderControl);
      Appender appender = appenderControl.getAppender();
      Assert.assertNotNull(msg + "could not find Appender for query id " + queryId + " from AppenderControl " +
              appenderControl, appender);
      Assert.assertEquals(msg + "Appender for query is in unexpected state", expectedStopped, appender.isStopped());
    } else {
      Assert.assertNull(msg + "AppenderControl for query id is not removed" + queryId, appenderControl);
    }
  }
assert that the appender for the given queryId is in the expected state.
@param msg a diagnostic
@param routingAppenderName name of the RoutingAppender
@param queryId the query id to use as a key
@param expectedStopped the expected stop state
itests/hive-unit/src/test/java/org/apache/hive/service/cli/operation/TestOperationLoggingLayout.java