sodonnel commented on code in PR #4006:
URL: https://github.com/apache/ozone/pull/4006#discussion_r1039789071
##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/TestSCMCommonPlacementPolicy.java:
##########
@@ -51,25 +64,153 @@ public void setup() {
@Test
public void testGetResultSet() throws SCMException {
DummyPlacementPolicy dummyPlacementPolicy =
- new DummyPlacementPolicy(nodeManager, conf);
+ new DummyPlacementPolicy(nodeManager, conf, 5);
List<DatanodeDetails> list =
nodeManager.getNodes(NodeStatus.inServiceHealthy());
List<DatanodeDetails> result = dummyPlacementPolicy.getResultSet(3, list);
Set<DatanodeDetails> resultSet = new HashSet<>(result);
Assertions.assertNotEquals(1, resultSet.size());
}
+ private void testReplicasToFixMisreplication(
+ List<ContainerReplica> replicas,
+ DummyPlacementPolicy placementPolicy,
+ int expectedNumberOfReplicasToCopy,
+ Map<Node, Integer> expectedNumberOfCopyOperationFromRack) {
+ Set<ContainerReplica> replicasToCopy = placementPolicy
+ .replicasToCopyToFixMisreplication(Sets.newHashSet(replicas));
+ Assertions.assertEquals(expectedNumberOfReplicasToCopy,
+ replicasToCopy.size());
+ Map<Node, Long> rackCopyMap =
+ replicasToCopy.stream().collect(Collectors.groupingBy(
+ replica -> placementPolicy
+ .getPlacementGroup(replica.getDatanodeDetails()),
+ Collectors.counting()));
+ Set<Node> racks = replicas.stream()
+ .map(ContainerReplica::getDatanodeDetails)
+ .map(placementPolicy::getPlacementGroup)
+ .collect(Collectors.toSet());
+ for (Node rack: racks) {
+ Assertions.assertEquals(
+ expectedNumberOfCopyOperationFromRack.getOrDefault(rack, 0),
+ rackCopyMap.getOrDefault(rack, 0L).intValue());
+ }
+ }
+
+ @Test
+ public void testReplicasToFixMisreplication() {
Review Comment:
Its hard to see what is tested here. Eg can I at a glance see if we have a
test for something like 3 racks and 5, 3, 1 replicas on each rack? Or require 3
racks but have 5, 4 replicas per rack currently.
Also can we add some tests for the scenarios I added in my earlier comment
today, so we can see if those cases are really failing or not?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]