@Test
public void calculateNetworkBufFromHeapSize() throws Exception {

	PowerMockito.mockStatic(EnvironmentInformation.class);
	// some defaults:
	when(EnvironmentInformation.getSizeOfFreeHeapMemoryWithDefrag()).thenReturn(1000L << 20); // 1000MB
	when(EnvironmentInformation.getMaxJvmHeapMemory()).thenReturn(1000L << 20); // 1000MB
	TaskManagerServicesConfiguration tmConfig;
	tmConfig = getTmConfig(TaskManagerOptions.MANAGED_MEMORY_SIZE.defaultValue(),
		TaskManagerOptions.MANAGED_MEMORY_FRACTION.defaultValue(),
		0.1f, 60L << 20, 1L << 30, MemoryType.HEAP);
	when(EnvironmentInformation.getSizeOfFreeHeapMemoryWithDefrag()).thenReturn(1000L << 20); // 1000MB
	assertEquals(100L << 20, TaskManagerServices.calculateNetworkBufferMemory(tmConfig));
	tmConfig = getTmConfig(10, TaskManagerOptions.MANAGED_MEMORY_FRACTION.defaultValue(),
		0.1f, 60L << 20, 1L << 30, MemoryType.OFF_HEAP);
	when(EnvironmentInformation.getMaxJvmHeapMemory()).thenReturn(890L << 20); // 890MB
	assertEquals((100L << 20) + 1 /* one too many due to floating point imprecision */,
		TaskManagerServices.calculateNetworkBufferMemory(tmConfig));
	tmConfig = getTmConfig(-1, 0.1f,
		0.1f, 60L << 20, 1L << 30, MemoryType.OFF_HEAP);
	when(EnvironmentInformation.getMaxJvmHeapMemory()).thenReturn(810L << 20); // 810MB
	assertEquals((100L << 20) + 1 /* one too many due to floating point imprecision */,
		TaskManagerServices.calculateNetworkBufferMemory(tmConfig));
}