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());
}
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);
}
}
Aggregations