Search in sources :

Example 31 with ResourceGroupId

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

the class TestResourceGroupIdTemplate method testExpansion.

@Test
public void testExpansion() {
    ResourceGroupIdTemplate template = new ResourceGroupIdTemplate("test.${USER}.${SOURCE}");
    ResourceGroupId expected = new ResourceGroupId(new ResourceGroupId(new ResourceGroupId("test"), "u"), "s");
    assertEquals(template.expandTemplate(new VariableMap(ImmutableMap.of("USER", "u", "SOURCE", "s"))), expected);
    template = new ResourceGroupIdTemplate("test.${USER}");
    assertEquals(template.expandTemplate(new VariableMap(ImmutableMap.of("USER", "alice.smith", "SOURCE", "s"))), new ResourceGroupId(new ResourceGroupId("test"), "alice.smith"));
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Test(org.testng.annotations.Test)

Example 32 with ResourceGroupId

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

the class TestResourceGroupsDao method testExactMatchSelector.

@Test
public void testExactMatchSelector() {
    H2ResourceGroupsDao dao = setup("exact_match_selector");
    dao.createExactMatchSelectorsTable();
    ResourceGroupId resourceGroupId1 = new ResourceGroupId(ImmutableList.of("global", "test", "user", "insert"));
    ResourceGroupId resourceGroupId2 = new ResourceGroupId(ImmutableList.of("global", "test", "user", "select"));
    JsonCodec<ResourceGroupId> codec = JsonCodec.jsonCodec(ResourceGroupId.class);
    dao.insertExactMatchSelector("test", "@test@test_pipeline", INSERT.name(), codec.toJson(resourceGroupId1));
    dao.insertExactMatchSelector("test", "@test@test_pipeline", SELECT.name(), codec.toJson(resourceGroupId2));
    assertNull(dao.getExactMatchResourceGroup("test", "@test@test_pipeline", null));
    assertEquals(dao.getExactMatchResourceGroup("test", "@test@test_pipeline", INSERT.name()), codec.toJson(resourceGroupId1));
    assertEquals(dao.getExactMatchResourceGroup("test", "@test@test_pipeline", SELECT.name()), codec.toJson(resourceGroupId2));
    assertNull(dao.getExactMatchResourceGroup("test", "@test@test_pipeline", DELETE.name()));
    assertNull(dao.getExactMatchResourceGroup("test", "abc", INSERT.name()));
    assertNull(dao.getExactMatchResourceGroup("prod", "@test@test_pipeline", INSERT.name()));
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Test(org.testng.annotations.Test)

Example 33 with ResourceGroupId

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

the class TestFileResourceGroupConfigurationManager method testConfiguration.

@SuppressWarnings("SimplifiedTestNGAssertion")
@Test
public void testConfiguration() {
    ResourceGroupConfigurationManager<VariableMap> manager = parse("resource_groups_config.json");
    ResourceGroupId globalId = new ResourceGroupId("global");
    ResourceGroup global = new TestingResourceGroup(globalId);
    manager.configure(global, new SelectionContext<>(globalId, new VariableMap(ImmutableMap.of("USER", "user"))));
    assertEquals(global.getPerQueryLimits().getExecutionTimeLimit(), Optional.of(new Duration(1, HOURS)));
    assertEquals(global.getPerQueryLimits().getTotalMemoryLimit(), Optional.of(new DataSize(1, MEGABYTE)));
    assertEquals(global.getPerQueryLimits().getCpuTimeLimit(), Optional.of(new Duration(1, HOURS)));
    assertEquals(global.getCpuQuotaGenerationMillisPerSecond(), 1000 * 24);
    assertEquals(global.getMaxQueuedQueries(), 1000);
    assertEquals(global.getHardConcurrencyLimit(), 100);
    assertEquals(global.getSchedulingPolicy(), WEIGHTED);
    assertEquals(global.getSchedulingWeight(), 0);
    assertEquals(global.getJmxExport(), true);
    ResourceGroupId subId = new ResourceGroupId(globalId, "sub");
    ResourceGroup sub = new TestingResourceGroup(subId);
    manager.configure(sub, new SelectionContext<>(subId, new VariableMap(ImmutableMap.of("USER", "user"))));
    assertEquals(sub.getSoftMemoryLimit(), new DataSize(2, MEGABYTE));
    assertEquals(sub.getHardConcurrencyLimit(), 3);
    assertEquals(sub.getMaxQueuedQueries(), 4);
    assertEquals(sub.getSchedulingPolicy(), null);
    assertEquals(sub.getSchedulingWeight(), 5);
    assertEquals(sub.getJmxExport(), false);
    assertEquals(sub.getPerQueryLimits().getExecutionTimeLimit(), Optional.empty());
    assertEquals(sub.getPerQueryLimits().getTotalMemoryLimit(), Optional.empty());
    assertEquals(sub.getPerQueryLimits().getCpuTimeLimit(), Optional.empty());
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) DataSize(io.airlift.units.DataSize) Duration(io.airlift.units.Duration) ResourceGroup(com.facebook.presto.spi.resourceGroups.ResourceGroup) Test(org.testng.annotations.Test)

Example 34 with ResourceGroupId

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

the class TestFileResourceGroupConfigurationManager method testExtractVariableConfiguration.

@Test
public void testExtractVariableConfiguration() {
    ResourceGroupConfigurationManager<VariableMap> manager = parse("resource_groups_config_extract_variable.json");
    VariableMap variableMap = new VariableMap(ImmutableMap.of("USER", "user", "domain", "prestodb", "region", "us_east", "cluster", "12"));
    ResourceGroupId globalId = new ResourceGroupId("global");
    manager.configure(new TestingResourceGroup(globalId), new SelectionContext<>(globalId, variableMap));
    ResourceGroupId childId = new ResourceGroupId(new ResourceGroupId("global"), "prestodb:us_east:12");
    TestingResourceGroup child = new TestingResourceGroup(childId);
    manager.configure(child, new SelectionContext<>(childId, variableMap));
    assertEquals(child.getHardConcurrencyLimit(), 3);
}
Also used : ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) Test(org.testng.annotations.Test)

Example 35 with ResourceGroupId

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

the class TestResourceGroupIdTemplate method testExtraction.

@Test
public void testExtraction() {
    ResourceGroupIdTemplate template = new ResourceGroupIdTemplate("test.pipeline.job_${pipeline}_user:${USER}.${USER}");
    ResourceGroupId expected = new ResourceGroupId(new ResourceGroupId(new ResourceGroupId(new ResourceGroupId("test"), "pipeline"), "job_testpipeline_user:user"), "user");
    Pattern sourcePattern = Pattern.compile("scheduler.important.(?<pipeline>[^\\[]*).*");
    StaticSelector selector = new StaticSelector(Optional.empty(), Optional.of(sourcePattern), Optional.empty(), Optional.empty(), Optional.empty(), template);
    SelectionCriteria context = new SelectionCriteria(true, "user", Optional.of("scheduler.important.testpipeline[5]"), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.empty());
    assertEquals(selector.match(context).map(SelectionContext::getResourceGroupId), Optional.of(expected));
}
Also used : Pattern(java.util.regex.Pattern) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) SelectionCriteria(com.facebook.presto.spi.resourceGroups.SelectionCriteria) 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