flink-instrumentation/workspace/flink-1.4.1-instrumented/flink-1.4.1/flink-runtime/src/test/java/org/apache/flink/runtime/taskexecutor/TaskManagerServicesTest.java
/**
	 * Helper to test {@link TaskManagerServices#calculateNetworkBufferMemory(long, Configuration)} with the
	 * new configuration parameters.
	 *
	 * @param config configuration object
	 */
Helper to test  TaskManagerServices#calculateNetworkBufferMemory(long, Configuration) with the
new configuration parameters.

@param config configuration object
Helper to test TaskManagerServices#calculateNetworkBufferMemory ( long Configuration ) with the new configuration parameters . @param config configuration object
private static void calculateNetworkBufNew(final Configuration config) {
		config.setLong(TaskManagerOptions.NETWORK_BUFFERS_MEMORY_MIN, 1L << 20); 
		config.setLong(TaskManagerOptions.NETWORK_BUFFERS_MEMORY_MAX, 1L << 20); 
		assertEquals(1 << 20, TaskManagerServices.calculateNetworkBufferMemory(10L << 20, config));
		assertEquals(1 << 20, TaskManagerServices.calculateNetworkBufferMemory(64L << 20, config));
		assertEquals(1 << 20, TaskManagerServices.calculateNetworkBufferMemory(1L << 30, config));
		Random ran = new Random();
		for (int i = 0; i < 1_000; ++i){
			float frac = Math.max(ran.nextFloat(), Float.MIN_VALUE);
			config.setFloat(TaskManagerOptions.NETWORK_BUFFERS_MEMORY_FRACTION, frac);
			long min = Math.max(TaskManagerOptions.MEMORY_SEGMENT_SIZE.defaultValue(), ran.nextLong());
			config.setLong(TaskManagerOptions.NETWORK_BUFFERS_MEMORY_MIN, min);
			long max = Math.max(min, ran.nextLong());
			config.setLong(TaskManagerOptions.NETWORK_BUFFERS_MEMORY_MAX, max);
			long javaMem = Math.max(max + 1, ran.nextLong());
			final long networkBufMem = TaskManagerServices.calculateNetworkBufferMemory(javaMem, config);
			assertTrue("Lower bound not met with configuration: " + config.toString(),
				networkBufMem >= min);
			assertTrue("Upper bound not met with configuration: " + config.toString(),
				networkBufMem <= max);
			if (networkBufMem > min && networkBufMem < max) {
				assertEquals(
					"Wrong network buffer memory size with configuration: " + config.toString(),
					(long) (javaMem * frac), networkBufMem);
			}
		}
	}
private static void calculateNetworkBufNew ( final Configuration config ) { config . setLong ( TaskManagerOptions . NETWORK_BUFFERS_MEMORY_MIN , 1L << 20 ) ; config . setLong ( TaskManagerOptions . NETWORK_BUFFERS_MEMORY_MAX , 1L << 20 ) ; assertEquals ( 1 << 20 , TaskManagerServices . calculateNetworkBufferMemory ( 10L << 20 , config ) ) ; assertEquals ( 1 << 20 , TaskManagerServices . calculateNetworkBufferMemory ( 64L << 20 , config ) ) ; assertEquals ( 1 << 20 , TaskManagerServices . calculateNetworkBufferMemory ( 1L << 30 , config ) ) ; Random ran = new Random ( ) ; for ( int i = 0 ; i < 1_000 ; ++ i ) { float frac = Math . max ( ran . nextFloat ( ) , Float . MIN_VALUE ) ; config . setFloat ( TaskManagerOptions . NETWORK_BUFFERS_MEMORY_FRACTION , frac ) ; long min = Math . max ( TaskManagerOptions . MEMORY_SEGMENT_SIZE . defaultValue ( ) , ran . nextLong ( ) ) ; config . setLong ( TaskManagerOptions . NETWORK_BUFFERS_MEMORY_MIN , min ) ; long max = Math . max ( min , ran . nextLong ( ) ) ; config . setLong ( TaskManagerOptions . NETWORK_BUFFERS_MEMORY_MAX , max ) ; long javaMem = Math . max ( max + 1 , ran . nextLong ( ) ) ; final long networkBufMem = TaskManagerServices . calculateNetworkBufferMemory ( javaMem , config ) ; assertTrue ( "Lower bound not met with configuration: " + config . toString ( ) , networkBufMem >= min ) ; assertTrue ( "Upper bound not met with configuration: " + config . toString ( ) , networkBufMem <= max ) ; if ( networkBufMem > min && networkBufMem < max ) { assertEquals ( "Wrong network buffer memory size with configuration: " + config . toString ( ) , ( long ) ( javaMem * frac ) , networkBufMem ) ; } } }
Helper to test {@link TaskManagerServices#calculateNetworkBufferMemory(long, Configuration)} with the
 new configuration parameters.
Helper to test { @link TaskManagerServices#calculateNetworkBufferMemory ( long Configuration ) } with the new configuration parameters .
// (2) fixed size memory // 1MB // 1MB // note: actual network buffer memory size is independent of the totalJavaMemorySize // (3) random fraction, min, and max values