### Question:
NodePerPortResolver implements AddressResolver { @Override public SocketAddress get() { InetSocketAddress address = releasedAddresses.poll(); if (address != null) { return address; } else { while (true) { InetSocketAddress addr = ip.get(); int port = addr.getPort() + 1; InetSocketAddress newAddress; if (port > 65535) { newAddress = new InetSocketAddress( Inet4Resolver.inetAddress( Inet4Resolver.nextAddressBytes(addr.getAddress().getAddress())), startingPortPerIp); } else { newAddress = new InetSocketAddress(addr.getAddress(), port); } if (ip.compareAndSet(addr, newAddress)) { return addr; } } } } NodePerPortResolver();  NodePerPortResolver(int startingPortPerIp);  NodePerPortResolver(byte startingAddress[], int startingPortPerIp); @Override SocketAddress get();  }### Answer:
@Test public void testNodeAssignedPerPort() { InetAddress startingAddress = Inet4Resolver.inetAddress(AddressResolver.defaultStartingIp); int expectedPort = 1000; AddressResolver resolver = new NodePerPortResolver(expectedPort); for (int i = 0; i < 1000; i++) { InetSocketAddress address = (InetSocketAddress) resolver.get(); assertThat(address.getAddress()).isEqualTo(startingAddress); assertThat(address.getPort()).isEqualTo(expectedPort++); } }
@Test public void testShouldCycleIpWhenPortsExhausted() { InetAddress expectedAddress = Inet4Resolver.inetAddress(AddressResolver.defaultStartingIp); int expectedPort = 65530; AddressResolver resolver = new NodePerPortResolver(expectedPort); for (int i = 0; i < 1000; i++) { InetSocketAddress address = (InetSocketAddress) resolver.get(); assertThat(address.getAddress()).isEqualTo(expectedAddress); assertThat(address.getPort()).isEqualTo(expectedPort++); if (expectedPort == 65536) { expectedPort = 65530; expectedAddress = Inet4Resolver.inetAddress(Inet4Resolver.nextAddressBytes(expectedAddress.getAddress())); } } }