@Test public void testGetFreePortsGivesFreePorts() throws IOException { int numPorts = 100; List<Integer> ports = NetworkUtil.getFreePorts(numPorts); for (Integer port : ports) { new ServerSocket(port).close(); } } }
/** * As getConfigurations(n, ports) but tries to find free ephemeral ports (but note that there is * no guarantee that ports will remain unused). */ public static Map<Integer, NetworkConfiguration> getNetworkConfigurations(int n) { List<Integer> ports = getFreePorts(n); return getNetworkConfigurations(ports); } }
@Test public void testGetFreePortsGivesUniquePorts() { int numPorts = 100; int numIterations = 5; for (int i = 0; i < numIterations; i++) { Set<Integer> uniquePorts = new HashSet<>(NetworkUtil.getFreePorts(numPorts)); assertEquals(numPorts, uniquePorts.size()); } }
protected List<NetworkConfiguration> getNetConfs(int numParties) { Map<Integer, Party> parties = new HashMap<>(numParties); List<NetworkConfiguration> confs = new ArrayList<>(numParties); List<Integer> ports = NetworkUtil.getFreePorts(numParties); int id = 1; for (Integer port : ports) { parties.put(id, new Party(id, "localhost", port)); id++; } for (int i = 1; i <= numParties; i++) { confs.add(new NetworkConfigurationImpl(i, parties)); } return confs; }
@Test public void testNaorPinkasBaseOtDes() { int noPlayers = 2; List<Integer> ports = NetworkUtil.getFreePorts(noPlayers); Map<Integer, NetworkConfiguration> netConf = NetworkUtil .getNetworkConfigurations(ports);
private void runTest(TestThreadFactory<ResourcePoolImpl, ProtocolBuilderBinary> f, EvaluationStrategy evalStrategy, boolean preprocessing, String name) { int noPlayers = 2; List<Integer> ports = NetworkUtil.getFreePorts(noPlayers); Map<Integer, NetworkConfiguration> netConf = NetworkUtil .getNetworkConfigurations(ports);