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