Search in sources :

Example 1 with QueryPrerequisites

use of com.facebook.presto.spi.prerequisites.QueryPrerequisites in project presto by prestodb.

the class TestLocalDispatchQuery method testPrerequisitesQueryFinishedCalled.

@Test
public void testPrerequisitesQueryFinishedCalled() {
    QueryStateMachine stateMachine = createStateMachine();
    CountingEventListener eventListener = new CountingEventListener();
    CompletableFuture<?> prequisitesFuture = new CompletableFuture<>();
    AtomicBoolean queryFinishedCalled = new AtomicBoolean();
    LocalDispatchQuery query = new LocalDispatchQuery(stateMachine, createQueryMonitor(eventListener), immediateFuture(null), createClusterSizeMonitor(0), directExecutor(), dispatchQuery -> {
    }, execution -> {
    }, false, new QueryPrerequisites() {

        @Override
        public CompletableFuture<?> waitForPrerequisites(QueryId queryId, QueryPrerequisitesContext context, WarningCollector warningCollector) {
            return prequisitesFuture;
        }

        @Override
        public void queryFinished(QueryId queryId) {
            queryFinishedCalled.set(true);
        }
    });
    assertEquals(query.getBasicQueryInfo().getState(), WAITING_FOR_PREREQUISITES);
    assertFalse(eventListener.getQueryCompletedEvent().isPresent());
    query.startWaitingForPrerequisites();
    prequisitesFuture.complete(null);
    query.fail(new PrestoException(ABANDONED_QUERY, "foo"));
    assertTrue(queryFinishedCalled.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TaskTestUtils.createQueryStateMachine(com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine) QueryStateMachine(com.facebook.presto.execution.QueryStateMachine) CompletableFuture(java.util.concurrent.CompletableFuture) QueryPrerequisitesContext(com.facebook.presto.spi.prerequisites.QueryPrerequisitesContext) QueryId(com.facebook.presto.spi.QueryId) PrestoException(com.facebook.presto.spi.PrestoException) QueryPrerequisites(com.facebook.presto.spi.prerequisites.QueryPrerequisites) WarningCollector(com.facebook.presto.spi.WarningCollector) Test(org.testng.annotations.Test)

Example 2 with QueryPrerequisites

use of com.facebook.presto.spi.prerequisites.QueryPrerequisites in project presto by prestodb.

the class QueryPrerequisitesManager method loadQueryPrerequisites.

public void loadQueryPrerequisites() throws Exception {
    if (QUERY_PREREQUISITES_CONFIG.exists()) {
        Map<String, String> properties = new HashMap<>(loadProperties(QUERY_PREREQUISITES_CONFIG));
        String factoryName = properties.remove(QUERY_PREREQUISITES_PROPERTY_NAME);
        checkArgument(!isNullOrEmpty(factoryName), "Query Prerequisites configuration %s does not contain %s", QUERY_PREREQUISITES_CONFIG.getAbsoluteFile(), QUERY_PREREQUISITES_PROPERTY_NAME);
        log.info("-- Loading query prerequisites factory --");
        QueryPrerequisitesFactory queryPrerequisitesFactory = queryPrerequisitesFactories.get(factoryName);
        checkState(queryPrerequisitesFactory != null, "Query prerequisites factory %s is not registered", factoryName);
        QueryPrerequisites queryPrerequisites = queryPrerequisitesFactory.create(properties);
        checkState(this.queryPrerequisites.compareAndSet(defaultQueryPrerequisites, queryPrerequisites), "Query prerequisites has already been set");
        log.info("-- Loaded query prerequisites %s --", factoryName);
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) QueryPrerequisitesFactory(com.facebook.presto.spi.prerequisites.QueryPrerequisitesFactory) QueryPrerequisites(com.facebook.presto.spi.prerequisites.QueryPrerequisites)

Aggregations

QueryPrerequisites (com.facebook.presto.spi.prerequisites.QueryPrerequisites)2 QueryStateMachine (com.facebook.presto.execution.QueryStateMachine)1 TaskTestUtils.createQueryStateMachine (com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine)1 PrestoException (com.facebook.presto.spi.PrestoException)1 QueryId (com.facebook.presto.spi.QueryId)1 WarningCollector (com.facebook.presto.spi.WarningCollector)1 QueryPrerequisitesContext (com.facebook.presto.spi.prerequisites.QueryPrerequisitesContext)1 QueryPrerequisitesFactory (com.facebook.presto.spi.prerequisites.QueryPrerequisitesFactory)1 HashMap (java.util.HashMap)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.testng.annotations.Test)1