@Test public void testAddHostsAndBlockWeight() throws Exception { HDFSBlocksDistribution distribution = new HDFSBlocksDistribution(); distribution.addHostsAndBlockWeight(null, 100); assertEquals("Expecting no hosts weights", 0, distribution.getHostAndWeights().size()); distribution.addHostsAndBlockWeight(new String[0], 100); assertEquals("Expecting no hosts weights", 0, distribution.getHostAndWeights().size()); distribution.addHostsAndBlockWeight(new String[] {"test"}, 101); assertEquals("Should be one host", 1, distribution.getHostAndWeights().size()); distribution.addHostsAndBlockWeight(new String[] {"test"}, 202); assertEquals("Should be one host", 1, distribution.getHostAndWeights().size()); assertEquals("test host should have weight 303", 303, distribution.getHostAndWeights().get("test").getWeight()); distribution.addHostsAndBlockWeight(new String[] {"testTwo"}, 222); assertEquals("Should be two hosts", 2, distribution.getHostAndWeights().size()); assertEquals("Total weight should be 525", 525, distribution.getUniqueBlocksTotalWeight()); }
public void addHostsAndBlockWeight(String[] hosts, long weight) { if (hosts == null || hosts.length == 0) { return; } addUniqueWeight(weight); for (String hostname : hosts) { addHostAndBlockWeight(hostname, weight); } }
HDFSBlocksDistribution { public void addHostsAndBlockWeight(String[] hosts, long weight) { if (hosts == null || hosts.length == 0) { return; } addUniqueWeight(weight); for (String hostname : hosts) { addHostAndBlockWeight(hostname, weight); } } }
HDFSBlocksDistribution { public void addHostsAndBlockWeight(String[] hosts, long weight) { if (hosts == null || hosts.length == 0) { return; } addUniqueWeight(weight); for (String hostname : hosts) { addHostAndBlockWeight(hostname, weight); } } HDFSBlocksDistribution(); }
HDFSBlocksDistribution { public void addHostsAndBlockWeight(String[] hosts, long weight) { if (hosts == null || hosts.length == 0) { return; } addUniqueWeight(weight); for (String hostname : hosts) { addHostAndBlockWeight(hostname, weight); } } HDFSBlocksDistribution(); @Override synchronized String toString(); void addHostsAndBlockWeight(String[] hosts, long weight); Map<String,HostAndWeight> getHostAndWeights(); long getWeight(String host); long getUniqueBlocksTotalWeight(); float getBlockLocalityIndex(String host); void add(HDFSBlocksDistribution otherBlocksDistribution); List<String> getTopHosts(); HostAndWeight[] getTopHostsWithWeights(); }
HDFSBlocksDistribution { public void addHostsAndBlockWeight(String[] hosts, long weight) { if (hosts == null || hosts.length == 0) { return; } addUniqueWeight(weight); for (String hostname : hosts) { addHostAndBlockWeight(hostname, weight); } } HDFSBlocksDistribution(); @Override synchronized String toString(); void addHostsAndBlockWeight(String[] hosts, long weight); Map<String,HostAndWeight> getHostAndWeights(); long getWeight(String host); long getUniqueBlocksTotalWeight(); float getBlockLocalityIndex(String host); void add(HDFSBlocksDistribution otherBlocksDistribution); List<String> getTopHosts(); HostAndWeight[] getTopHostsWithWeights();  }