private int countSites(List<Address> addresses) { Set<String> sites = new HashSet<String>(addresses.size()); for (Address a : addresses) { TopologyAwareAddress taa = (TopologyAwareAddress) a; sites.add(taa.getSiteId()); } return sites.size(); }
private int countRacks(List<Address> addresses) { Set<String> racks = new HashSet<String>(addresses.size()); for (Address a : addresses) { TopologyAwareAddress taa = (TopologyAwareAddress) a; racks.add(taa.getRackId() + taa.getSiteId()); } return racks.size(); }
private void assertSegmentLocation( int segment, int expectedOwners, int expectedMachines, int expectedRacks, int expectedSites) { List<Address> received = ch.locateOwnersForSegment(segment); // Check the number of addresses and uniqueness assertEquals(received.size(), expectedOwners); Set<Address> receivedUnique = new HashSet<Address>(received); assertEquals(receivedUnique.size(), expectedOwners); // Check the number of machines Set<String> receivedMachines = new HashSet<String>(); for (Address a : received) { TopologyAwareAddress taa = (TopologyAwareAddress) a; receivedMachines.add(taa.getMachineId() + "|" + taa.getRackId() + "|" + taa.getSiteId()); } assertEquals(receivedMachines.size(), expectedMachines); // Check the number of racks Set<String> receivedRacks = new HashSet<String>(); for (Address a : received) { TopologyAwareAddress taa = (TopologyAwareAddress) a; receivedRacks.add(taa.getRackId() + "|" + taa.getSiteId()); } assertEquals(receivedRacks.size(), expectedRacks); // Check the number of sites Set<String> receivedSites = new HashSet<String>(); for (Address a : received) { receivedSites.add(((TopologyAwareAddress) a).getSiteId()); } assertEquals(receivedSites.size(), expectedSites); }