Search in sources :

Example 21 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class TestLocalDispatchQuery method testQueryQueuedExceptionBeforeDispatch.

@Test
public void testQueryQueuedExceptionBeforeDispatch() {
    QueryStateMachine stateMachine = createStateMachine();
    CountingEventListener eventListener = new CountingEventListener();
    SettableFuture<QueryExecution> queryExecutionFuture = SettableFuture.create();
    LocalDispatchQuery query = new LocalDispatchQuery(stateMachine, createQueryMonitor(eventListener), queryExecutionFuture, createClusterSizeMonitor(0), directExecutor(), dispatchQuery -> {
        throw new QueryQueueFullException(new ResourceGroupId("global"));
    }, execution -> {
    }, false, QUERY_PREREQUISITES);
    query.startWaitingForPrerequisites();
    queryExecutionFuture.setException(new IllegalStateException("abc"));
    assertEquals(query.getBasicQueryInfo().getState(), FAILED);
    assertEquals(query.getBasicQueryInfo().getErrorCode(), QUERY_QUEUE_FULL.toErrorCode());
    assertTrue(eventListener.getQueryCompletedEvent().isPresent());
    assertTrue(eventListener.getQueryCompletedEvent().get().getFailureInfo().isPresent());
    assertEquals(eventListener.getQueryCompletedEvent().get().getFailureInfo().get().getErrorCode(), QUERY_QUEUE_FULL.toErrorCode());
}
Also used : TaskTestUtils.createQueryStateMachine(com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine) QueryStateMachine(com.facebook.presto.execution.QueryStateMachine) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) QueryQueueFullException(com.facebook.presto.execution.resourceGroups.QueryQueueFullException) QueryExecution(com.facebook.presto.execution.QueryExecution) MockQueryExecution(com.facebook.presto.execution.MockQueryExecution) Test(org.testng.annotations.Test)

Example 22 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class TestCreateMaterializedViewTask method testCreateMaterializedViewNotExistsTrue.

@Test
public void testCreateMaterializedViewNotExistsTrue() {
    SqlParser parser = new SqlParser();
    String sql = String.format("CREATE MATERIALIZED VIEW IF NOT EXISTS %s AS SELECT 2021 AS col_0 FROM %s", MATERIALIZED_VIEW_A, TABLE_A);
    CreateMaterializedView statement = (CreateMaterializedView) parser.createStatement(sql, ParsingOptions.builder().build());
    QueryStateMachine stateMachine = QueryStateMachine.begin(sql, Optional.empty(), testSession, URI.create("fake://uri"), new ResourceGroupId("test"), Optional.empty(), false, transactionManager, accessControl, executorService, metadata, WarningCollector.NOOP);
    WarningCollector warningCollector = stateMachine.getWarningCollector();
    CreateMaterializedViewTask createMaterializedViewTask = new CreateMaterializedViewTask(parser);
    getFutureValue(createMaterializedViewTask.execute(statement, transactionManager, metadata, accessControl, testSession, emptyList(), warningCollector));
    assertEquals(metadata.getCreateMaterializedViewCallCount(), 1);
}
Also used : CreateMaterializedView(com.facebook.presto.sql.tree.CreateMaterializedView) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) SqlParser(com.facebook.presto.sql.parser.SqlParser) WarningCollector(com.facebook.presto.spi.WarningCollector) Test(org.testng.annotations.Test)

Example 23 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class TestCreateMaterializedViewTask method testCreateMaterializedViewExistsFalse.

@Test
public void testCreateMaterializedViewExistsFalse() {
    SqlParser parser = new SqlParser();
    String sql = String.format("CREATE MATERIALIZED VIEW %s AS SELECT 2021 AS col_0 FROM %s", MATERIALIZED_VIEW_B, TABLE_A);
    CreateMaterializedView statement = (CreateMaterializedView) parser.createStatement(sql, ParsingOptions.builder().build());
    QueryStateMachine stateMachine = QueryStateMachine.begin(sql, Optional.empty(), testSession, URI.create("fake://uri"), new ResourceGroupId("test"), Optional.empty(), false, transactionManager, accessControl, executorService, metadata, WarningCollector.NOOP);
    WarningCollector warningCollector = stateMachine.getWarningCollector();
    try {
        getFutureValue(new CreateMaterializedViewTask(parser).execute(statement, transactionManager, metadata, accessControl, testSession, emptyList(), warningCollector));
        fail("expected exception");
    } catch (RuntimeException e) {
        // Expected
        assertTrue(e instanceof PrestoException);
        PrestoException prestoException = (PrestoException) e;
        assertEquals(prestoException.getErrorCode(), ALREADY_EXISTS.toErrorCode());
    }
    assertEquals(metadata.getCreateMaterializedViewCallCount(), 0);
}
Also used : CreateMaterializedView(com.facebook.presto.sql.tree.CreateMaterializedView) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) SqlParser(com.facebook.presto.sql.parser.SqlParser) PrestoException(com.facebook.presto.spi.PrestoException) WarningCollector(com.facebook.presto.spi.WarningCollector) Test(org.testng.annotations.Test)

Example 24 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class TestResourceGroupIntegration method testMemoryFraction.

@Test(timeOut = 60_000)
public void testMemoryFraction() throws Exception {
    try (DistributedQueryRunner queryRunner = getSimpleQueryRunner()) {
        queryRunner.execute("SELECT COUNT(*), clerk FROM orders GROUP BY clerk");
        while (true) {
            TimeUnit.SECONDS.sleep(1);
            ResourceGroupInfo global = queryRunner.getCoordinator().getResourceGroupManager().get().getResourceGroupInfo(new ResourceGroupId("global"));
            if (global.getSoftMemoryLimit().toBytes() > 0) {
                break;
            }
        }
    }
}
Also used : DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) ResourceGroupInfo(com.facebook.presto.spi.resourceGroups.ResourceGroupInfo) Test(org.testng.annotations.Test)

Example 25 with ResourceGroupId

use of com.facebook.presto.spi.resourceGroups.ResourceGroupId in project presto by prestodb.

the class TestFileResourceGroupConfigurationManager method testMissing.

@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "No matching configuration found for: missing")
public void testMissing() {
    ResourceGroupConfigurationManager manager = parse("resource_groups_config.json");
    ResourceGroup missing = new TestingResourceGroup(new ResourceGroupId("missing"));
    manager.configure(missing, new SelectionContext(true, "user", Optional.empty(), 1));
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) ResourceGroupConfigurationManager(com.facebook.presto.spi.resourceGroups.ResourceGroupConfigurationManager) SelectionContext(com.facebook.presto.spi.resourceGroups.SelectionContext) ResourceGroup(com.facebook.presto.spi.resourceGroups.ResourceGroup) Test(org.testng.annotations.Test)

Aggregations

ResourceGroupId (com.facebook.presto.spi.resourceGroups.ResourceGroupId)41 Test (org.testng.annotations.Test)31 QueryId (com.facebook.presto.spi.QueryId)12 ResourceGroupRuntimeInfo (com.facebook.presto.execution.resourceGroups.ResourceGroupRuntimeInfo)9 ResourceGroupInfo (com.facebook.presto.server.ResourceGroupInfo)5 DistributedQueryRunner (com.facebook.presto.tests.DistributedQueryRunner)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 Duration (io.airlift.units.Duration)5 String.format (java.lang.String.format)5 Optional (java.util.Optional)5 TestQueues.createResourceGroupId (com.facebook.presto.execution.TestQueues.createResourceGroupId)4 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)4 InMemoryNodeManager (com.facebook.presto.metadata.InMemoryNodeManager)3 DataSize (io.airlift.units.DataSize)3 HashMap (java.util.HashMap)3 SECONDS (java.util.concurrent.TimeUnit.SECONDS)3 Assert.assertEquals (org.testng.Assert.assertEquals)3 Assert.assertTrue (org.testng.Assert.assertTrue)3 Session (com.facebook.presto.Session)2 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)2