Search in sources :

Example 16 with ScheduledQueryKey

use of org.apache.hadoop.hive.metastore.api.ScheduledQueryKey in project hive by apache.

the class TestMetastoreScheduledQueries method testCreate.

@Test
public void testCreate() throws Exception {
    ScheduledQuery schq = createScheduledQuery(createKey("create", "c1"));
    ScheduledQueryMaintenanceRequest r = new ScheduledQueryMaintenanceRequest();
    r.setType(ScheduledQueryMaintenanceRequestType.CREATE);
    r.setScheduledQuery(schq);
    client.scheduledQueryMaintenance(r);
    ScheduledQuery schq2 = client.getScheduledQuery(new ScheduledQueryKey("create", "c1"));
    // next execution is set by remote
    schq.setNextExecution(schq2.getNextExecution());
    assertEquals(schq2, schq);
}
Also used : ScheduledQueryMaintenanceRequest(org.apache.hadoop.hive.metastore.api.ScheduledQueryMaintenanceRequest) ScheduledQueryKey(org.apache.hadoop.hive.metastore.api.ScheduledQueryKey) ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) MetastoreUnitTest(org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest) Test(org.junit.Test)

Example 17 with ScheduledQueryKey

use of org.apache.hadoop.hive.metastore.api.ScheduledQueryKey in project hive by apache.

the class TestMetastoreScheduledQueries method testExclusivePoll.

@Test
public void testExclusivePoll() throws Exception {
    try {
        ObjectStoreTestHook.instance = new ObjectStoreTestHook() {

            @Override
            public void scheduledQueryPoll() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        };
        ScheduledQuery schq = createScheduledQuery(new ScheduledQueryKey("q1", "exclusive"));
        ScheduledQueryMaintenanceRequest r = new ScheduledQueryMaintenanceRequest();
        r.setType(ScheduledQueryMaintenanceRequestType.CREATE);
        r.setScheduledQuery(schq);
        client.scheduledQueryMaintenance(r);
        // wait 1 sec for next execution
        Thread.sleep(1000);
        ExecutorService pool = Executors.newCachedThreadPool();
        Future<ScheduledQueryPollResponse> f1 = pool.submit(new AsyncPollCall("exclusive"));
        Future<ScheduledQueryPollResponse> f2 = pool.submit(new AsyncPollCall("exclusive"));
        ScheduledQueryPollResponse resp1 = f1.get();
        ScheduledQueryPollResponse resp2 = f2.get();
        assertTrue(resp1.isSetQuery() ^ resp2.isSetQuery());
        pool.shutdown();
    } finally {
        ObjectStoreTestHook.instance = null;
    }
}
Also used : ScheduledQueryPollResponse(org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse) ScheduledQueryMaintenanceRequest(org.apache.hadoop.hive.metastore.api.ScheduledQueryMaintenanceRequest) ExecutorService(java.util.concurrent.ExecutorService) ScheduledQueryKey(org.apache.hadoop.hive.metastore.api.ScheduledQueryKey) ObjectStoreTestHook(org.apache.hadoop.hive.metastore.ObjectStoreTestHook) ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) MetastoreUnitTest(org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest) Test(org.junit.Test)

Aggregations

ScheduledQueryKey (org.apache.hadoop.hive.metastore.api.ScheduledQueryKey)17 ScheduledQuery (org.apache.hadoop.hive.metastore.api.ScheduledQuery)11 Test (org.junit.Test)10 MetastoreUnitTest (org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest)7 ScheduledQueryMaintenanceRequest (org.apache.hadoop.hive.metastore.api.ScheduledQueryMaintenanceRequest)7 ScheduledQueryPollResponse (org.apache.hadoop.hive.metastore.api.ScheduledQueryPollResponse)5 PersistenceManager (javax.jdo.PersistenceManager)4 ScheduledQueryPollRequest (org.apache.hadoop.hive.metastore.api.ScheduledQueryPollRequest)4 MScheduledExecution (org.apache.hadoop.hive.metastore.model.MScheduledExecution)4 MScheduledQuery (org.apache.hadoop.hive.metastore.model.MScheduledQuery)4 IDriver (org.apache.hadoop.hive.ql.IDriver)4 ArrayList (java.util.ArrayList)2 ObjectStore (org.apache.hadoop.hive.metastore.ObjectStore)2 ScheduledQueryProgressInfo (org.apache.hadoop.hive.metastore.api.ScheduledQueryProgressInfo)2 CronBuilder (com.cronutils.builder.CronBuilder)1 CronDefinitionBuilder (com.cronutils.model.definition.CronDefinitionBuilder)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 JDOObjectNotFoundException (javax.jdo.JDOObjectNotFoundException)1 Query (javax.jdo.Query)1