/** * Creates a map of party IDs to network address (uses localhost and supplied ports) information. * * @return a map of party IDs to network address information */ public static Map<Integer, NetworkConfiguration> getNetworkConfigurations(List<Integer> ports) { Map<Integer, NetworkConfiguration> confs = new HashMap<>(ports.size()); Map<Integer, Party> partyMap = new HashMap<>(); int id = 1; for (int port : ports) { partyMap.put(id, new Party(id, "localhost", port)); id++; } for (int i = 0; i < ports.size(); i++) { confs.put(i + 1, new NetworkConfigurationImpl(i + 1, partyMap)); } return confs; }
@Test(expected = IllegalArgumentException.class) public void testUniqueAddressCheckAllSameHostsAndPorts() { Map<Integer, Party> parties = new HashMap<>(3); for (int i = 1; i < numParties; i++) { Party p = new Party(i, "host", 3000); parties.put(i, p); this.me = (i == myId) ? p : me; } this.netConf = new NetworkConfigurationImpl(myId, parties); }
@Test public void testUniqueAddressCheckSameHostsDifferentPorts() { // validates that sanity check uses both hosts and ports to check for uniqueness Map<Integer, Party> parties = new HashMap<>(numParties); for (int i = 1; i < numParties; i++) { Party p = new Party(i, "host", 3000 + i); parties.put(i, p); this.me = (i == myId) ? p : me; } this.netConf = new NetworkConfigurationImpl(myId, parties); }
this.networkConfiguration = new NetworkConfigurationImpl(myId, parties); if (logPerformance) { this.network = () -> new NetworkLoggingDecorator(new SocketNetwork(networkConfiguration));
@Test public void testUniqueAddressCheckDifferentHostsSamePorts() { // validates that sanity check uses both hosts and ports to check for uniqueness Map<Integer, Party> parties = new HashMap<>(numParties); for (int i = 1; i < numParties; i++) { Party p = new Party(i, "host" + i, 3000); parties.put(i, p); this.me = (i == myId) ? p : me; } this.netConf = new NetworkConfigurationImpl(myId, parties); }
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; }
/** * Set up a configuration with 4 parties. */ @Before public void setUp() { Map<Integer, Party> parties = new HashMap<>(4); for (int i = 1; i < numParties + 1; i++) { Party p = new Party(i, "host" + i, 3000 + i); parties.put(i, p); this.me = (i == myId) ? p : me; } this.netConf = new NetworkConfigurationImpl(myId, parties); }
@Test(expected = IllegalArgumentException.class) public void testUniqueAddressCheckSameHostsAndPorts() { Map<Integer, Party> parties = new HashMap<>(3); for (int i = 1; i < numParties; i++) { Party p = new Party(i, "host", 3000 + i); parties.put(i, p); this.me = (i == myId) ? p : me; } parties.put(1, new Party(1, "host", 3002)); this.netConf = new NetworkConfigurationImpl(myId, parties); }