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