use of org.apache.flink.api.common.resources.CPUResource in project flink by apache.
the class ResourceSpecTest method testSubtract.
@Test
public void testSubtract() {
final ResourceSpec rs1 = ResourceSpec.newBuilder(1.0, 100).setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1)).build();
final ResourceSpec rs2 = ResourceSpec.newBuilder(0.2, 100).setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 0.5)).build();
final ResourceSpec subtracted = rs1.subtract(rs2);
assertEquals(new CPUResource(0.8), subtracted.getCpuCores());
assertEquals(0, subtracted.getTaskHeapMemory().getMebiBytes());
assertEquals(new ExternalResource(EXTERNAL_RESOURCE_NAME, 0.6), subtracted.getExtendedResource(EXTERNAL_RESOURCE_NAME).get());
}
use of org.apache.flink.api.common.resources.CPUResource in project flink by apache.
the class ResourceSpecTest method testMerge.
@Test
public void testMerge() throws Exception {
ResourceSpec rs1 = ResourceSpec.newBuilder(1.0, 100).setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1)).build();
ResourceSpec rs2 = ResourceSpec.newBuilder(1.0, 100).build();
ResourceSpec rs3 = rs1.merge(rs2);
assertEquals(new CPUResource(2.0), rs3.getCpuCores());
assertEquals(200, rs3.getTaskHeapMemory().getMebiBytes());
assertEquals(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1), rs3.getExtendedResource(EXTERNAL_RESOURCE_NAME).get());
ResourceSpec rs4 = rs1.merge(rs3);
assertEquals(new ExternalResource(EXTERNAL_RESOURCE_NAME, 2.2), rs4.getExtendedResource(EXTERNAL_RESOURCE_NAME).get());
}
use of org.apache.flink.api.common.resources.CPUResource in project flink by apache.
the class KubernetesWorkerResourceSpecFactoryTest method testGetCpuCoresKubernetesOption.
@Test
public void testGetCpuCoresKubernetesOption() {
final Configuration configuration = new Configuration();
configuration.setDouble(KubernetesConfigOptions.TASK_MANAGER_CPU, 2.0);
configuration.setDouble(KubernetesConfigOptions.TASK_MANAGER_CPU_LIMIT_FACTOR, 1.5);
configuration.setInteger(TaskManagerOptions.NUM_TASK_SLOTS, 3);
assertThat(KubernetesWorkerResourceSpecFactory.getDefaultCpus(configuration), is(new CPUResource(2.0)));
}
use of org.apache.flink.api.common.resources.CPUResource in project flink by apache.
the class KubernetesWorkerResourceSpecFactoryTest method testGetCpuCoresCommonOption.
@Test
public void testGetCpuCoresCommonOption() {
final Configuration configuration = new Configuration();
configuration.setDouble(TaskManagerOptions.CPU_CORES, 1.0);
configuration.setDouble(KubernetesConfigOptions.TASK_MANAGER_CPU, 2.0);
configuration.setDouble(KubernetesConfigOptions.TASK_MANAGER_CPU_LIMIT_FACTOR, 1.5);
configuration.setInteger(TaskManagerOptions.NUM_TASK_SLOTS, 3);
assertThat(KubernetesWorkerResourceSpecFactory.getDefaultCpus(configuration), is(new CPUResource(1.0)));
}
use of org.apache.flink.api.common.resources.CPUResource in project flink by apache.
the class TaskExecutorProcessUtilsTest method testGenerateDynamicConfigurations.
@Test
public void testGenerateDynamicConfigurations() {
String dynamicConfigsStr = TaskExecutorProcessUtils.generateDynamicConfigsStr(TM_RESOURCE_SPEC);
Map<String, String> configs = ConfigurationUtils.parseTmResourceDynamicConfigs(dynamicConfigsStr);
assertThat(new CPUResource(Double.valueOf(configs.get(TaskManagerOptions.CPU_CORES.key()))), is(TM_RESOURCE_SPEC.getCpuCores()));
assertThat(MemorySize.parse(configs.get(TaskManagerOptions.FRAMEWORK_HEAP_MEMORY.key())), is(TM_RESOURCE_SPEC.getFrameworkHeapSize()));
assertThat(MemorySize.parse(configs.get(TaskManagerOptions.FRAMEWORK_OFF_HEAP_MEMORY.key())), is(TM_RESOURCE_SPEC.getFrameworkOffHeapMemorySize()));
assertThat(MemorySize.parse(configs.get(TaskManagerOptions.TASK_HEAP_MEMORY.key())), is(TM_RESOURCE_SPEC.getTaskHeapSize()));
assertThat(MemorySize.parse(configs.get(TaskManagerOptions.TASK_OFF_HEAP_MEMORY.key())), is(TM_RESOURCE_SPEC.getTaskOffHeapSize()));
assertThat(MemorySize.parse(configs.get(TaskManagerOptions.NETWORK_MEMORY_MAX.key())), is(TM_RESOURCE_SPEC.getNetworkMemSize()));
assertThat(MemorySize.parse(configs.get(TaskManagerOptions.NETWORK_MEMORY_MIN.key())), is(TM_RESOURCE_SPEC.getNetworkMemSize()));
assertThat(MemorySize.parse(configs.get(TaskManagerOptions.MANAGED_MEMORY_SIZE.key())), is(TM_RESOURCE_SPEC.getManagedMemorySize()));
assertThat(MemorySize.parse(configs.get(TaskManagerOptions.JVM_METASPACE.key())), is(TM_RESOURCE_SPEC.getJvmMetaspaceAndOverhead().getMetaspace()));
assertThat(MemorySize.parse(configs.get(TaskManagerOptions.JVM_OVERHEAD_MIN.key())), is(TM_RESOURCE_SPEC.getJvmMetaspaceAndOverhead().getOverhead()));
assertThat(MemorySize.parse(configs.get(TaskManagerOptions.JVM_OVERHEAD_MAX.key())), is(TM_RESOURCE_SPEC.getJvmMetaspaceAndOverhead().getOverhead()));
assertThat(Integer.valueOf(configs.get(TaskManagerOptions.NUM_TASK_SLOTS.key())), is(TM_RESOURCE_SPEC.getNumSlots()));
assertThat(configs.get(ExternalResourceOptions.EXTERNAL_RESOURCE_LIST.key()), is('"' + String.join(";", TM_RESOURCE_SPEC.getExtendedResources().keySet()) + '"'));
assertThat(configs.get(ExternalResourceOptions.getAmountConfigOptionForResource(EXTERNAL_RESOURCE_NAME_1)), is(String.valueOf(TM_RESOURCE_SPEC.getExtendedResources().get(EXTERNAL_RESOURCE_NAME_1).getValue().longValue())));
assertThat(configs.get(ExternalResourceOptions.getAmountConfigOptionForResource(EXTERNAL_RESOURCE_NAME_2)), is(String.valueOf(TM_RESOURCE_SPEC.getExtendedResources().get(EXTERNAL_RESOURCE_NAME_2).getValue().longValue())));
}
Aggregations