private CommandProcessorResponse runAsUser(String userName, String sql, boolean asAdmin)
      throws CommandProcessorException {
    HiveConf conf = envSetup.getTestCtx().hiveConf;
    conf.set("user.name", userName);
    SessionState.get().setAuthenticator(null);
    SessionState.get().setAuthorizer(null);
    try (IDriver driver = createDriver()) {
      if (asAdmin) {
        driver.run("set role admin");
      }
      return driver.run(sql);
    }
  }
ScheduledQuery integration test.

Checks for more complex scenarios; like impersonation works when scheduled queries are executed.
itests/hive-unit/src/test/java/org/apache/hadoop/hive/schq/TestScheduledQueryIntegration.java