test_class.file: flink-core/src/test/java/org/apache/flink/util/NetUtilsTest.java
test_class.identifier: NetUtilsTest
test_case.body: @Test
  	public void testFreePortRangeUtility() {
  		// inspired by Hadoop's example for "yarn.app.mapreduce.am.job.client.port-range"
  		String rangeDefinition = "50000-50050, 50100-50200,51234 "; // this also contains some whitespaces
  		Iterator<Integer> portsIter = NetUtils.getPortRangeFromString(rangeDefinition);
  		Set<Integer> ports = new HashSet<>();
  		while(portsIter.hasNext()) {
  			Assert.assertTrue("Duplicate element", ports.add(portsIter.next()));
  		}
  
  		Assert.assertEquals(51+101+1, ports.size());
  		// check first range
  		Assert.assertThat(ports, hasItems(50000, 50001, 50002, 50050));
  		// check second range and last point
  		Assert.assertThat(ports, hasItems(50100, 50101, 50110, 50200, 51234));
  		// check that only ranges are included
  		Assert.assertThat(ports, not(hasItems(50051, 50052, 1337, 50201, 49999, 50099)));
  
  
  		// test single port "range":
  		portsIter = NetUtils.getPortRangeFromString(" 51234");
  		Assert.assertTrue(portsIter.hasNext());
  		Assert.assertEquals(51234, (int)portsIter.next());
  		Assert.assertFalse(portsIter.hasNext());
  
  		// test port list
  		portsIter = NetUtils.getPortRangeFromString("5,1,2,3,4");
  		Assert.assertTrue(portsIter.hasNext());
  		Assert.assertEquals(5, (int)portsIter.next());
  		Assert.assertEquals(1, (int)portsIter.next());
  		Assert.assertEquals(2, (int)portsIter.next());
  		Assert.assertEquals(3, (int)portsIter.next());
  		Assert.assertEquals(4, (int)portsIter.next());
  		Assert.assertFalse(portsIter.hasNext());
  
  
  		Throwable error = null;
  
  		// try some wrong values: String
  		try { NetUtils.getPortRangeFromString("localhost"); } catch(Throwable t) { error = t; }
  		Assert.assertTrue(error instanceof NumberFormatException);
  		error = null;
  
  		// incomplete range
  		try { NetUtils.getPortRangeFromString("5-"); } catch(Throwable t) { error = t; }
  		Assert.assertTrue(error instanceof NumberFormatException);
  		error = null;
  
  		// incomplete range
  		try { NetUtils.getPortRangeFromString("-5"); } catch(Throwable t) { error = t; }
  		Assert.assertTrue(error instanceof NumberFormatException);
  		error = null;
  
  		// empty range
  		try { NetUtils.getPortRangeFromString(",5"); } catch(Throwable t) { error = t; }
  		Assert.assertTrue(error instanceof NumberFormatException);
  		error = null;
  
  	}
test_case.class_method_signature: NetUtilsTest.testFreePortRangeUtility()
test_case.full_signature: @Test public void testFreePortRangeUtility()
test_case.identifier: testFreePortRangeUtility
test_case.invocations: getPortRangeFromString hasNext assertTrue add next assertEquals size assertThat hasItems assertThat hasItems assertThat not hasItems getPortRangeFromString assertTrue hasNext assertEquals next assertFalse hasNext getPortRangeFromString assertTrue hasNext assertEquals next assertEquals next assertEquals next assertEquals next assertEquals next assertFalse hasNext getPortRangeFromString assertTrue getPortRangeFromString assertTrue getPortRangeFromString assertTrue getPortRangeFromString assertTrue
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testFreePortRangeUtility()
focal_class.declarator: LOG = LoggerFactory.getLogger(NetUtils.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger LOG = LoggerFactory.getLogger(NetUtils.class);
focal_class.type: Logger
focal_class.var_name: LOG
focal_class.file: flink-core/src/main/java/org/apache/flink/util/NetUtils.java
focal_class.identifier: NetUtils
focal_class.class_method_signature: NetUtils.getHostnameFromFQDN(String fqdn)
focal_class.full_signature: public static String getHostnameFromFQDN(String fqdn)
focal_class.identifier: getHostnameFromFQDN
focal_class.modifiers: public static
focal_class.parameters: (String fqdn)
focal_class.return: String
focal_class.signature: String getHostnameFromFQDN(String fqdn)
focal_class.class_method_signature: NetUtils.getCorrectHostnamePort(String hostPort)
focal_class.full_signature: public static URL getCorrectHostnamePort(String hostPort)
focal_class.identifier: getCorrectHostnamePort
focal_class.modifiers: public static
focal_class.parameters: (String hostPort)
focal_class.return: URL
focal_class.signature: URL getCorrectHostnamePort(String hostPort)
focal_class.class_method_signature: NetUtils.getAvailablePort()
focal_class.full_signature: public static int getAvailablePort()
focal_class.identifier: getAvailablePort
focal_class.modifiers: public static
focal_class.parameters: ()
focal_class.return: int
focal_class.signature: int getAvailablePort()
focal_class.class_method_signature: NetUtils.ipAddressToUrlString(InetAddress address)
focal_class.full_signature: public static String ipAddressToUrlString(InetAddress address)
focal_class.identifier: ipAddressToUrlString
focal_class.modifiers: public static
focal_class.parameters: (InetAddress address)
focal_class.return: String
focal_class.signature: String ipAddressToUrlString(InetAddress address)
focal_class.class_method_signature: NetUtils.ipAddressAndPortToUrlString(InetAddress address, int port)
focal_class.full_signature: public static String ipAddressAndPortToUrlString(InetAddress address, int port)
focal_class.identifier: ipAddressAndPortToUrlString
focal_class.modifiers: public static
focal_class.parameters: (InetAddress address, int port)
focal_class.return: String
focal_class.signature: String ipAddressAndPortToUrlString(InetAddress address, int port)
focal_class.class_method_signature: NetUtils.socketAddressToUrlString(InetSocketAddress address)
focal_class.full_signature: public static String socketAddressToUrlString(InetSocketAddress address)
focal_class.identifier: socketAddressToUrlString
focal_class.modifiers: public static
focal_class.parameters: (InetSocketAddress address)
focal_class.return: String
focal_class.signature: String socketAddressToUrlString(InetSocketAddress address)
focal_class.class_method_signature: NetUtils.hostAndPortToUrlString(String host, int port)
focal_class.full_signature: public static String hostAndPortToUrlString(String host, int port)
focal_class.identifier: hostAndPortToUrlString
focal_class.modifiers: public static
focal_class.parameters: (String host, int port)
focal_class.return: String
focal_class.signature: String hostAndPortToUrlString(String host, int port)
focal_class.class_method_signature: NetUtils.getPortRangeFromString(String rangeDefinition)
focal_class.full_signature: public static Iterator<Integer> getPortRangeFromString(String rangeDefinition)
focal_class.identifier: getPortRangeFromString
focal_class.modifiers: public static
focal_class.parameters: (String rangeDefinition)
focal_class.return: Iterator<Integer>
focal_class.signature: Iterator<Integer> getPortRangeFromString(String rangeDefinition)
focal_class.class_method_signature: NetUtils.createSocketFromPorts(Iterator<Integer> portsIterator, SocketFactory factory)
focal_class.full_signature: public static ServerSocket createSocketFromPorts(Iterator<Integer> portsIterator, SocketFactory factory)
focal_class.identifier: createSocketFromPorts
focal_class.modifiers: public static
focal_class.parameters: (Iterator<Integer> portsIterator, SocketFactory factory)
focal_class.return: ServerSocket
focal_class.signature: ServerSocket createSocketFromPorts(Iterator<Integer> portsIterator, SocketFactory factory)
focal_method.body: public static Iterator<Integer> getPortRangeFromString(String rangeDefinition) throws NumberFormatException {
  		final String[] ranges = rangeDefinition.trim().split(",");
  		List<Iterator<Integer>> iterators = new ArrayList<>(ranges.length);
  		for(String rawRange: ranges) {
  			Iterator<Integer> rangeIterator = null;
  			String range = rawRange.trim();
  			int dashIdx = range.indexOf('-');
  			if (dashIdx == -1) {
  				// only one port in range:
  				rangeIterator = Iterators.singletonIterator(Integer.valueOf(range));
  			} else {
  				// evaluate range
  				final int start = Integer.valueOf(range.substring(0, dashIdx));
  				final int end = Integer.valueOf(range.substring(dashIdx+1, range.length()));
  				rangeIterator = new Iterator<Integer>() {
  					int i = start;
  					@Override
  					public boolean hasNext() {
  						return i <= end;
  					}
  
  					@Override
  					public Integer next() {
  						return i++;
  					}
  
  					@Override
  					public void remove() {
  						throw new UnsupportedOperationException("Remove not supported");
  					}
  				};
  			}
  			iterators.add(rangeIterator);
  		}
  		return Iterators.concat(iterators.iterator());
  	}
focal_method.class_method_signature: NetUtils.getPortRangeFromString(String rangeDefinition)
focal_method.full_signature: public static Iterator<Integer> getPortRangeFromString(String rangeDefinition)
focal_method.identifier: getPortRangeFromString
focal_method.invocations: split trim trim indexOf singletonIterator valueOf valueOf substring valueOf substring length add concat iterator
focal_method.modifiers: public static
focal_method.parameters: (String rangeDefinition)
focal_method.return: Iterator<Integer>
focal_method.signature: Iterator<Integer> getPortRangeFromString(String rangeDefinition)