Search in sources :

Example 1 with TaskManagerServicesBuilder

use of org.apache.flink.runtime.taskexecutor.TaskManagerServicesBuilder in project flink by apache.

the class MetricUtilsTest method testManagedMemoryMetricsInitialization.

@Test
public void testManagedMemoryMetricsInitialization() throws MemoryAllocationException {
    final int maxMemorySize = 16284;
    final int numberOfAllocatedPages = 2;
    final int pageSize = 4096;
    final Object owner = new Object();
    final MemoryManager memoryManager = MemoryManager.create(maxMemorySize, pageSize);
    memoryManager.allocatePages(owner, numberOfAllocatedPages);
    final TaskManagerServices taskManagerServices = new TaskManagerServicesBuilder().setTaskSlotTable(new TestingTaskSlotTable.TestingTaskSlotTableBuilder<Task>().memoryManagerGetterReturns(memoryManager).allActiveSlotAllocationIds(() -> Sets.newHashSet(new AllocationID())).build()).setManagedMemorySize(maxMemorySize).build();
    List<String> actualSubGroupPath = new ArrayList<>();
    final InterceptingOperatorMetricGroup metricGroup = new InterceptingOperatorMetricGroup() {

        @Override
        public MetricGroup addGroup(String name) {
            actualSubGroupPath.add(name);
            return this;
        }
    };
    MetricUtils.instantiateFlinkMemoryMetricGroup(metricGroup, taskManagerServices.getTaskSlotTable(), taskManagerServices::getManagedMemorySize);
    Gauge<Number> usedMetric = (Gauge<Number>) metricGroup.get("Used");
    Gauge<Number> maxMetric = (Gauge<Number>) metricGroup.get("Total");
    assertThat(usedMetric.getValue().intValue(), is(numberOfAllocatedPages * pageSize));
    assertThat(maxMetric.getValue().intValue(), is(maxMemorySize));
    assertThat(actualSubGroupPath, is(Arrays.asList(METRIC_GROUP_FLINK, METRIC_GROUP_MEMORY, METRIC_GROUP_MANAGED_MEMORY)));
}
Also used : TaskManagerServicesBuilder(org.apache.flink.runtime.taskexecutor.TaskManagerServicesBuilder) TaskManagerServices(org.apache.flink.runtime.taskexecutor.TaskManagerServices) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) ArrayList(java.util.ArrayList) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) Gauge(org.apache.flink.metrics.Gauge) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Gauge (org.apache.flink.metrics.Gauge)1 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)1 MemoryManager (org.apache.flink.runtime.memory.MemoryManager)1 TaskManagerServices (org.apache.flink.runtime.taskexecutor.TaskManagerServices)1 TaskManagerServicesBuilder (org.apache.flink.runtime.taskexecutor.TaskManagerServicesBuilder)1 Test (org.junit.Test)1