diff --git ql/src/test/org/apache/hadoop/hive/ql/TestCompileLock.java ql/src/test/org/apache/hadoop/hive/ql/TestCompileLock.java index 8dc05ff480..a9917cf109 100644 --- ql/src/test/org/apache/hadoop/hive/ql/TestCompileLock.java +++ ql/src/test/org/apache/hadoop/hive/ql/TestCompileLock.java @@ -64,6 +64,8 @@ public class TestCompileLock { private static final int CONCURRENT_COMPILATION = 15151; + private static final String SHORT_QUERY = ""; + private static final String LONG_QUERY = ""; private Driver driver; private HiveConf conf; @@ -90,7 +92,13 @@ private void initDriver(HiveConf conf, int threadCount) throws Exception { Thread.sleep(500); verifyThatWaitingCompileOpsCountIsEqualTo(count.decrementAndGet()); return null; - }).when(driver).compile(eq(""), eq(true), eq(false)); + }).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)); } @Test @@ -161,6 +169,23 @@ public void testParallelCompilationTimeoutWithSingleQuota() throws Exception { verifyThatTimedOutCompileOpsCountIsNotZero(responseList); } + /** + * Test that checks that the queries above the quota are timed out, so the compilation quota maximum is honored. + * @throws Exception + */ + @Test + public void testParallelCompilationTimeoutWithMultipleQuota() throws Exception { + conf.setBoolVar(HIVE_SERVER2_PARALLEL_COMPILATION, true); + conf.setIntVar(HIVE_SERVER2_PARALLEL_COMPILATION_LIMIT, 4); + conf.setTimeVar(HIVE_SERVER2_COMPILE_LOCK_TIMEOUT, 1, TimeUnit.SECONDS); + + initDriver(conf, 10); + List responseList = compileAndRespond(LONG_QUERY, 10); + + verifyThatWaitingCompileOpsCountIsEqualTo(0); + verifyThatTimedOutCompileOpsCount(responseList, 6); + } + @Test public void testParallelCompilationWithSingleQuotaAndZeroTimeout() throws Exception { conf.setBoolVar(HIVE_SERVER2_PARALLEL_COMPILATION, true); @@ -220,10 +245,20 @@ public void testParallelCompilationWithMultipleQuotasAndClientSessionConcurrency } private List compileAndRespond(int threadCount) throws Exception { - return compileAndRespond(false, threadCount); + return compileAndRespond(SHORT_QUERY, false, threadCount); } private List compileAndRespond(boolean reuseSession, int threadCount) throws Exception { + return compileAndRespond(SHORT_QUERY, reuseSession, threadCount); + } + + + private List compileAndRespond(String query, int threadCount) throws Exception { + return compileAndRespond(query, false, threadCount); + } + + private List compileAndRespond(String query, boolean reuseSession, int threadCount) + throws Exception { List responseList = new ArrayList<>(); SessionState sessionState = new SessionState(conf); @@ -235,7 +270,7 @@ public void testParallelCompilationWithMultipleQuotasAndClientSessionConcurrency CommandProcessorResponse response; try{ - response = driver.compileAndRespond(""); + response = driver.compileAndRespond(query); } finally { SessionState.detachSession(); @@ -292,6 +327,11 @@ private void verifyThatTimedOutCompileOpsCountIsNotZero(List responseList, int count) { + verifyErrorCount(ErrorMsg.COMPILE_LOCK_TIMED_OUT.getErrorCode(), + is(equalTo(count)), responseList); + } + private void verifyThatConcurrentCompilationWasIndeed(List responseList){ verifyErrorCount(CONCURRENT_COMPILATION, is(not(equalTo(0))), responseList);