### Question:
TaskManagerServices { public static long calculateHeapSizeMB(long totalJavaMemorySizeMB, Configuration config) { Preconditions.checkArgument(totalJavaMemorySizeMB > 0); final long networkBufMB = calculateNetworkBufferMemory( totalJavaMemorySizeMB << 20, config) >> 20; final long remainingJavaMemorySizeMB = totalJavaMemorySizeMB - networkBufMB; final boolean useOffHeap = config.getBoolean(TaskManagerOptions.MEMORY_OFF_HEAP); final long heapSizeMB; if (useOffHeap) { long offHeapSize = config.getLong(TaskManagerOptions.MANAGED_MEMORY_SIZE); if (offHeapSize <= 0) { double fraction = config.getFloat(TaskManagerOptions.MANAGED_MEMORY_FRACTION); offHeapSize = (long) (fraction * remainingJavaMemorySizeMB); } TaskManagerServicesConfiguration .checkConfigParameter(offHeapSize < remainingJavaMemorySizeMB, offHeapSize, TaskManagerOptions.MANAGED_MEMORY_SIZE.key(), "Managed memory size too large for " + networkBufMB + " MB network buffer memory and a total of " + totalJavaMemorySizeMB + " MB JVM memory"); heapSizeMB = remainingJavaMemorySizeMB - offHeapSize; } else { heapSizeMB = remainingJavaMemorySizeMB; } return heapSizeMB; } TaskManagerServices(
		TaskManagerLocation taskManagerLocation,
		MemoryManager memoryManager,
		IOManager ioManager,
		NetworkEnvironment networkEnvironment,
		BroadcastVariableManager broadcastVariableManager,
		FileCache fileCache,
		TaskSlotTable taskSlotTable,
		JobManagerTable jobManagerTable,
		JobLeaderService jobLeaderService,
		TaskExecutorLocalStateStoresManager taskManagerStateStore); MemoryManager getMemoryManager(); IOManager getIOManager(); NetworkEnvironment getNetworkEnvironment(); TaskManagerLocation getTaskManagerLocation(); BroadcastVariableManager getBroadcastVariableManager(); FileCache getFileCache(); TaskSlotTable getTaskSlotTable(); JobManagerTable getJobManagerTable(); JobLeaderService getJobLeaderService(); TaskExecutorLocalStateStoresManager getTaskManagerStateStore(); void shutDown(); static TaskManagerServices fromConfiguration(
			TaskManagerServicesConfiguration taskManagerServicesConfiguration,
			ResourceID resourceID,
			Executor taskIOExecutor,
			long freeHeapMemoryWithDefrag,
			long maxJvmHeapMemory); @SuppressWarnings("deprecation") static long calculateNetworkBufferMemory(long totalJavaMemorySize, Configuration config); static long calculateNetworkBufferMemory(TaskManagerServicesConfiguration tmConfig, long maxJvmHeapMemory); static long calculateHeapSizeMB(long totalJavaMemorySizeMB, Configuration config); @VisibleForTesting
	static final String LOCAL_STATE_SUB_DIRECTORY_ROOT; }### Answer:
@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); config.setLong(TaskManagerOptions.NETWORK_BUFFERS_MEMORY_MAX, 1L << 30); config.setBoolean(TaskManagerOptions.MEMORY_OFF_HEAP, false); assertEquals(900, TaskManagerServices.calculateHeapSizeMB(1000, config)); config.setBoolean(TaskManagerOptions.MEMORY_OFF_HEAP, false); config.setFloat(TaskManagerOptions.NETWORK_BUFFERS_MEMORY_FRACTION, 0.2f); assertEquals(800, TaskManagerServices.calculateHeapSizeMB(1000, config)); config.setBoolean(TaskManagerOptions.MEMORY_OFF_HEAP, true); config.setFloat(TaskManagerOptions.NETWORK_BUFFERS_MEMORY_FRACTION, 0.1f); config.setLong(TaskManagerOptions.MANAGED_MEMORY_SIZE, 10); assertEquals(890, TaskManagerServices.calculateHeapSizeMB(1000, config)); config.setLong(TaskManagerOptions.MANAGED_MEMORY_SIZE, -1); config.setFloat(TaskManagerOptions.MANAGED_MEMORY_FRACTION, 0.1f); assertEquals(810, TaskManagerServices.calculateHeapSizeMB(1000, config)); }