swamirishi commented on code in PR #6779:
URL: https://github.com/apache/ozone/pull/6779#discussion_r1638680203


##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/container/TestContainerReplication.java:
##########
@@ -186,4 +233,205 @@ private static List<OmKeyLocationInfo> 
lookupKey(MiniOzoneCluster cluster)
     return locations.getLocationList();
   }
 
+  private static OmKeyLocationInfo lookupKeyFirstLocation(MiniOzoneCluster 
cluster)
+      throws IOException {
+    OmKeyArgs keyArgs = new OmKeyArgs.Builder()
+        .setVolumeName(VOLUME)
+        .setBucketName(BUCKET)
+        .setKeyName(KEY)
+        .build();
+    OmKeyInfo keyInfo = cluster.getOzoneManager().lookupKey(keyArgs);
+    OmKeyLocationInfoGroup locations = keyInfo.getLatestVersionLocations();
+    Assertions.assertNotNull(locations);
+    return locations.getLocationList().get(0);
+  }
+
+
+  public void assertState(MiniOzoneCluster cluster, Map<Integer, 
DatanodeDetails> expectedReplicaMap)
+      throws IOException {
+    OmKeyLocationInfo keyLocation = lookupKeyFirstLocation(cluster);
+    Map<Integer, DatanodeDetails> replicaMap =
+        keyLocation.getPipeline().getNodes().stream().collect(Collectors.toMap(
+            dn -> keyLocation.getPipeline().getReplicaIndex(dn), 
Functions.identity()));
+    Assertions.assertEquals(expectedReplicaMap, replicaMap);
+  }
+
+  private OzoneInputStream createInputStream(OzoneClient client) throws 
IOException {
+    ObjectStore objectStore = client.getObjectStore();
+    OzoneVolume volume = objectStore.getVolume(VOLUME);
+    OzoneBucket bucket = volume.getBucket(BUCKET);
+    return bucket.readKey(KEY);
+  }
+
+  private void mockContainerPlacementPolicy(final 
MockedStatic<ContainerPlacementPolicyFactory> mockedPlacementFactory,
+                                            final 
AtomicReference<DatanodeDetails> mockedDatanodeToRemove) {
+    mockedPlacementFactory.when(() -> 
ContainerPlacementPolicyFactory.getECPolicy(any(ConfigurationSource.class),
+        any(NodeManager.class), any(NetworkTopology.class), 
Mockito.anyBoolean(),
+        any(SCMContainerPlacementMetrics.class))).thenAnswer(i -> {
+          PlacementPolicy placementPolicy = (PlacementPolicy) 
Mockito.spy(i.callRealMethod());
+          Mockito.doAnswer(args -> {
+            Set<ContainerReplica> containerReplica = ((Set<ContainerReplica>) 
args.getArgument(0)).stream()
+                .filter(r -> 
r.getDatanodeDetails().equals(mockedDatanodeToRemove.get()))
+                .collect(Collectors.toSet());
+            return containerReplica;
+          
}).when(placementPolicy).replicasToRemoveToFixOverreplication(Mockito.anySet(), 
Mockito.anyInt());
+          return placementPolicy;
+        });
+  }
+
+  private void mockContainerProtocolCalls(final 
MockedStatic<ContainerProtocolCalls> mockedContainerProtocolCalls,
+                                          final Map<Integer, Integer> 
failedReadChunkCountMap) {
+    mockedContainerProtocolCalls.when(() -> 
ContainerProtocolCalls.readChunk(any(), any(), any(), anyList(), any()))
+        .thenAnswer(invocation -> {
+          int replicaIndex = ((ContainerProtos.DatanodeBlockID) 
invocation.getArgument(2)).getReplicaIndex();
+          try {
+            return invocation.callRealMethod();
+          } catch (Throwable e) {
+            failedReadChunkCountMap.compute(replicaIndex,
+                (replicaIdx, totalCount) -> totalCount == null ? 1 : 
(totalCount + 1));
+            throw e;
+          }
+        });
+  }
+
+
+  @Test
+  public void testECContainerReplication() throws Exception {

Review Comment:
   let me see if there is a simpler way to write this test. I am using the 
replication manager to swap 2 node's replica index. Let me see if I can 
directly mock the container balancer to move the container from one node to 
another.



-- 
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]

Reply via email to