Search in sources :

Example 1 with ResourceAmounts

use of com.facebook.buck.util.concurrent.ResourceAmounts in project buck by facebook.

the class BuckConfig method getResourceAmountsPerRuleType.

public ImmutableMap<String, ResourceAmounts> getResourceAmountsPerRuleType() {
    ImmutableMap.Builder<String, ResourceAmounts> result = ImmutableMap.builder();
    ImmutableMap<String, String> entries = getEntriesForSection(RESOURCES_PER_RULE_SECTION_HEADER);
    for (String ruleName : entries.keySet()) {
        ImmutableList<String> configAmounts = getListWithoutComments(RESOURCES_PER_RULE_SECTION_HEADER, ruleName);
        Preconditions.checkArgument(configAmounts.size() == ResourceAmounts.RESOURCE_TYPE_COUNT, "Buck config entry [%s].%s contains %s values, but expected to contain %s values " + "in the following order: cpu, memory, disk_io, network_io", RESOURCES_PER_RULE_SECTION_HEADER, ruleName, configAmounts.size(), ResourceAmounts.RESOURCE_TYPE_COUNT);
        ResourceAmounts amounts = ResourceAmounts.of(Integer.valueOf(configAmounts.get(0)), Integer.valueOf(configAmounts.get(1)), Integer.valueOf(configAmounts.get(2)), Integer.valueOf(configAmounts.get(3)));
        result.put(ruleName, amounts);
    }
    return result.build();
}
Also used : ResourceAmounts(com.facebook.buck.util.concurrent.ResourceAmounts) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with ResourceAmounts

use of com.facebook.buck.util.concurrent.ResourceAmounts in project buck by facebook.

the class BuckConfigTest method testGettingResourceAmountsPerRuleType.

@Test
public void testGettingResourceAmountsPerRuleType() throws IOException {
    Reader reader = new StringReader(Joiner.on('\n').join("[resources_per_rule]", "some_rule = 1, 20, 3, 4", "other_rule = 4,30,2,1"));
    BuckConfig config = BuckConfigTestUtils.createWithDefaultFilesystem(temporaryFolder, reader);
    ImmutableMap<String, ResourceAmounts> result = config.getResourceAmountsPerRuleType();
    assertEquals(ImmutableMap.of("some_rule", ResourceAmounts.of(1, 20, 3, 4), "other_rule", ResourceAmounts.of(4, 30, 2, 1)), result);
}
Also used : ResourceAmounts(com.facebook.buck.util.concurrent.ResourceAmounts) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

ResourceAmounts (com.facebook.buck.util.concurrent.ResourceAmounts)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Test (org.junit.Test)1