Search in sources :

Example 1 with ScheduledQueryExecutionContext

use of org.apache.hadoop.hive.ql.scheduled.ScheduledQueryExecutionContext in project hive by apache.

the class TestScheduledQueryService method testScheduledQueryExecution.

@Test
public void testScheduledQueryExecution() throws ParseException, Exception {
    IDriver driver = createDriver();
    ExecutorService executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("SchQ %d").build());
    HiveConf conf = env_setup.getTestCtx().hiveConf;
    MockScheduledQueryService qService = new MockScheduledQueryService("insert into tu values(1),(2),(3),(4),(5)");
    ScheduledQueryExecutionContext ctx = new ScheduledQueryExecutionContext(executor, conf, qService);
    try (ScheduledQueryExecutionService sQ = ScheduledQueryExecutionService.startScheduledQueryExecutorService(ctx)) {
        // Wait for the scheduled query to finish. Hopefully 30 seconds should be more than enough.
        SessionState.getConsole().logInfo("Waiting for query execution to finish ...");
        synchronized (qService.notifier) {
            qService.notifier.wait(30000);
        }
        SessionState.getConsole().logInfo("Done waiting for query execution!");
    }
    assertThat(qService.lastProgressInfo.isSetExecutorQueryId(), is(true));
    assertThat(qService.lastProgressInfo.getExecutorQueryId(), Matchers.containsString(ctx.executorHostName + "/"));
    int nr = getNumRowsReturned(driver, "select 1 from tu");
    assertThat(nr, Matchers.equalTo(5));
}
Also used : ScheduledQueryExecutionContext(org.apache.hadoop.hive.ql.scheduled.ScheduledQueryExecutionContext) ScheduledQueryExecutionService(org.apache.hadoop.hive.ql.scheduled.ScheduledQueryExecutionService) ExecutorService(java.util.concurrent.ExecutorService) IDriver(org.apache.hadoop.hive.ql.IDriver) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) HiveConf(org.apache.hadoop.hive.conf.HiveConf) Test(org.junit.Test)

Aggregations

ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ExecutorService (java.util.concurrent.ExecutorService)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 IDriver (org.apache.hadoop.hive.ql.IDriver)1 ScheduledQueryExecutionContext (org.apache.hadoop.hive.ql.scheduled.ScheduledQueryExecutionContext)1 ScheduledQueryExecutionService (org.apache.hadoop.hive.ql.scheduled.ScheduledQueryExecutionService)1 Test (org.junit.Test)1