@Test
public void calculateHeapSizeMB() throws Exception {

	Configuration config = new Configuration();
	config.setFloat(TaskManagerOptions.NETWORK_BUFFERS_MEMORY_FRACTION, 0.1f);
	config.setLong(TaskManagerOptions.NETWORK_BUFFERS_MEMORY_MIN, 64L << 20); // 64MB
	config.setLong(TaskManagerOptions.NETWORK_BUFFERS_MEMORY_MAX, 1L << 30); // 1GB
	config.setBoolean(TaskManagerOptions.MEMORY_OFF_HEAP, false);
	assertEquals(1000, TaskManagerServices.calculateHeapSizeMB(1000, config));
	config.setBoolean(TaskManagerOptions.MEMORY_OFF_HEAP, true);
	config.setLong(TaskManagerOptions.MANAGED_MEMORY_SIZE, 10); // 10MB
	assertEquals(890, TaskManagerServices.calculateHeapSizeMB(1000, config));
	config.setLong(TaskManagerOptions.MANAGED_MEMORY_SIZE, -1); // use fraction of given memory
	config.setFloat(TaskManagerOptions.MANAGED_MEMORY_FRACTION, 0.1f); // 10%
	assertEquals(810, TaskManagerServices.calculateHeapSizeMB(1000, config));
}