private static IDriver createDriver() {
    HiveConf conf = envSetup.getTestCtx().hiveConf;

    String userName = conf.get("user.name");
    SessionState ss = new SessionState(conf, userName);
    SessionState.start(ss);

    IDriver driver = DriverFactory.newDriver(conf);
    return driver;
  }
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