node2.setNetworkLocation("/rack2");
node3.setNetworkLocation("/rack3");
node4.setNetworkLocation("/rack4");
node5.setNetworkLocation("/rack5");
blocks.add(new LocatedBlock(null, new DatanodeInfo[] {node1, node2, node5}));
blocks.add(new LocatedBlock(null, new DatanodeInfo[] {node1, node2, node3}));
blocks.add(new LocatedBlock(null, new DatanodeInfo[] {node2, node3, node4}));
blocks.add(new LocatedBlock(null, new DatanodeInfo[] {node1, node4, node5}));
blocks.add(new LocatedBlock(null, new DatanodeInfo[] {node1, node3, node5}));
expectedResult.put("/rack1", 4);
expectedResult.put("/rack2", 3);
expectedResult.put("/rack3", 3);
expectedResult.put("/rack4", 2);
expectedResult.put("/rack5", 3);
result = (Map)callPrivateMethod(instance, "collateRacks", new Class[] {Collection.class}, new Object[] {blocks});
assertEquals("The collateRacks() method did not count the racks correctly", expectedResult, result);
blocks.clear();
blocks.add(new LocatedBlock(null, new DatanodeInfo[] {node1, node3, node5}));
expectedResult.clear();
expectedResult.put("/rack1", 1);
expectedResult.put("/rack3", 1);
expectedResult.put("/rack5", 1);
result = (Map)callPrivateMethod(instance, "collateRacks", new Class[] {Collection.class}, new Object[] {blocks});
assertEquals("The collateRacks() method did not count the racks correctly", expectedResult, result);
blocks.clear();
blocks.add(new LocatedBlock(null, new DatanodeInfo[] {node1}));
blocks.add(new LocatedBlock(null, new DatanodeInfo[] {node3}));
blocks.add(new LocatedBlock(null, new DatanodeInfo[] {node5}));
expectedResult.clear();
expectedResult.put("/rack1", 1);
expectedResult.put("/rack3", 1);
expectedResult.put("/rack5", 1);
result = (Map)callPrivateMethod(instance, "collateRacks", new Class[] {Collection.class}, new Object[] {blocks});
assertEquals("The collateRacks() method did not count the racks correctly", expectedResult, result);
blocks.clear();
blocks.add(new LocatedBlock(null, new DatanodeInfo[] {node1}));
expectedResult.clear();
expectedResult.put("/rack1", 1);
result = (Map)callPrivateMethod(instance, "collateRacks", new Class[] {Collection.class}, new Object[] {blocks});
assertEquals("The collateRacks() method did not count the racks correctly", expectedResult, result);
blocks.clear();
blocks.add(new LocatedBlock(null, new DatanodeInfo[] {}));
expectedResult.clear();
result = (Map)callPrivateMethod(instance, "collateRacks", new Class[] {Collection.class}, new Object[] {blocks});
assertEquals("The collateRacks() method did not count the racks correctly", expectedResult, result);
blocks.clear();
blocks.add(new LocatedBlock(null, null));
expectedResult.clear();
result = (Map)callPrivateMethod(instance, "collateRacks", new Class[] {Collection.class}, new Object[] {blocks});
assertEquals("The collateRacks() method did not count the racks correctly", expectedResult, result);