private void initDriver(HiveConf conf, int threadCount) throws Exception {
    driver = Mockito.spy(new Driver(conf));
    resetParallelCompilationLimit(conf);

    AtomicInteger count = new AtomicInteger(threadCount);

    Mockito.doAnswer(invocation -> {
      Thread.sleep(500);
      verifyThatWaitingCompileOpsCountIsEqualTo(count.decrementAndGet());
      return null;
    }).when(driver).compile(eq(SHORT_QUERY), eq(true), eq(false));

    Mockito.doAnswer(invocation -> {
      Thread.sleep(5000);
      verifyThatWaitingCompileOpsCountIsEqualTo(count.decrementAndGet());
      return null;
    }).when(driver).compile(eq(LONG_QUERY), eq(true), eq(false));
  }
Class for testing HS2 compile lock behavior (serializable, parallel unbounded, parallel bounded).
ql/src/test/org/apache/hadoop/hive/ql/TestCompileLock.java