devmadhuu commented on code in PR #4876:
URL: https://github.com/apache/ozone/pull/4876#discussion_r1229172662
##########
hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestContainerEndpoint.java:
##########
@@ -1296,16 +1366,115 @@ public void testGetContainerInsightsNonOMContainers()
}
});
Response containerInsights =
- containerEndpoint.getContainerMisMatchInsights();
+ containerEndpoint.getContainerMisMatchInsights(10, 0, "OM");
+ Map<String, Object> response =
+ (Map<String, Object>) containerInsights.getEntity();
List<ContainerDiscrepancyInfo> containerDiscrepancyInfoList =
- (List<ContainerDiscrepancyInfo>) containerInsights.getEntity();
+ (List<ContainerDiscrepancyInfo>) response.get(
+ "containerDiscrepancyInfo");
ContainerDiscrepancyInfo containerDiscrepancyInfo =
containerDiscrepancyInfoList.get(0);
assertEquals(2, containerDiscrepancyInfo.getContainerID());
assertEquals(1, containerDiscrepancyInfoList.size());
assertEquals("SCM", containerDiscrepancyInfo.getExistsAt());
}
+ @Test
+ public void testGetContainerInsightsNonOMContainersWithPrevKey()
+ throws IOException, TimeoutException {
+ putContainerInfos(5);
+ List<ContainerKeyPrefix> deletedContainerKeyList =
+ reconContainerMetadataManager.getKeyPrefixesForContainer(2).entrySet()
+ .stream().map(entry ->
entry.getKey()).collect(Collectors.toList());
+ deletedContainerKeyList.forEach((ContainerKeyPrefix key) -> {
+ try (RDBBatchOperation rdbBatchOperation = new RDBBatchOperation()) {
+ reconContainerMetadataManager.batchDeleteContainerMapping(
+ rdbBatchOperation, key);
+ reconContainerMetadataManager.commitBatchOperation(rdbBatchOperation);
+ } catch (IOException e) {
+ LOG.error("Unable to write Container Key Prefix data in Recon DB.", e);
+ }
+ });
+
+ // Set prevKey and limit
+ long prevKey = 2;
+ int limit = 3;
+
+ Response containerInsights =
+ containerEndpoint.getContainerMisMatchInsights(limit, prevKey, "OM");
+ Map<String, Object> response =
+ (Map<String, Object>) containerInsights.getEntity();
+ List<ContainerDiscrepancyInfo> containerDiscrepancyInfoList =
+ (List<ContainerDiscrepancyInfo>) response.get(
+ "containerDiscrepancyInfo");
+
+ // Check the first two ContainerDiscrepancyInfo objects in the response
+ assertEquals(3, containerDiscrepancyInfoList.size());
+
+ ContainerDiscrepancyInfo containerDiscrepancyInfo1 =
+ containerDiscrepancyInfoList.get(0);
+ assertEquals(3, containerDiscrepancyInfo1.getContainerID());
+ assertEquals("SCM", containerDiscrepancyInfo1.getExistsAt());
+
+ ContainerDiscrepancyInfo containerDiscrepancyInfo2 =
+ containerDiscrepancyInfoList.get(1);
+ assertEquals(4, containerDiscrepancyInfo2.getContainerID());
+ assertEquals("SCM", containerDiscrepancyInfo2.getExistsAt());
+ }
Review Comment:
Assuming we have total 5 containers for both scenarios, Can we add a test
simulating pagination ,like call for prevKey = 0, limit = 3 , then using the
returned prevKey in response , call API again with same limit and verify if
total number of containers returned in 2nd API call response is just 2
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/ContainerEndpoint.java:
##########
@@ -104,6 +108,8 @@ public class ContainerEndpoint {
private static final Logger LOG =
LoggerFactory.getLogger(ContainerEndpoint.class);
private BucketLayout layout = BucketLayout.DEFAULT;
+ private static final String SCM_FILTER = "SCM";
Review Comment:
This is not enum
##########
hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestContainerEndpoint.java:
##########
@@ -1296,16 +1366,115 @@ public void testGetContainerInsightsNonOMContainers()
}
});
Response containerInsights =
- containerEndpoint.getContainerMisMatchInsights();
+ containerEndpoint.getContainerMisMatchInsights(10, 0, "OM");
+ Map<String, Object> response =
+ (Map<String, Object>) containerInsights.getEntity();
List<ContainerDiscrepancyInfo> containerDiscrepancyInfoList =
- (List<ContainerDiscrepancyInfo>) containerInsights.getEntity();
+ (List<ContainerDiscrepancyInfo>) response.get(
+ "containerDiscrepancyInfo");
ContainerDiscrepancyInfo containerDiscrepancyInfo =
containerDiscrepancyInfoList.get(0);
assertEquals(2, containerDiscrepancyInfo.getContainerID());
assertEquals(1, containerDiscrepancyInfoList.size());
assertEquals("SCM", containerDiscrepancyInfo.getExistsAt());
}
+ @Test
+ public void testGetContainerInsightsNonOMContainersWithPrevKey()
+ throws IOException, TimeoutException {
+ putContainerInfos(5);
+ List<ContainerKeyPrefix> deletedContainerKeyList =
+ reconContainerMetadataManager.getKeyPrefixesForContainer(2).entrySet()
+ .stream().map(entry ->
entry.getKey()).collect(Collectors.toList());
+ deletedContainerKeyList.forEach((ContainerKeyPrefix key) -> {
+ try (RDBBatchOperation rdbBatchOperation = new RDBBatchOperation()) {
+ reconContainerMetadataManager.batchDeleteContainerMapping(
+ rdbBatchOperation, key);
+ reconContainerMetadataManager.commitBatchOperation(rdbBatchOperation);
+ } catch (IOException e) {
+ LOG.error("Unable to write Container Key Prefix data in Recon DB.", e);
+ }
+ });
+
+ // Set prevKey and limit
+ long prevKey = 2;
+ int limit = 3;
+
+ Response containerInsights =
+ containerEndpoint.getContainerMisMatchInsights(limit, prevKey, "OM");
+ Map<String, Object> response =
+ (Map<String, Object>) containerInsights.getEntity();
+ List<ContainerDiscrepancyInfo> containerDiscrepancyInfoList =
+ (List<ContainerDiscrepancyInfo>) response.get(
+ "containerDiscrepancyInfo");
+
+ // Check the first two ContainerDiscrepancyInfo objects in the response
+ assertEquals(3, containerDiscrepancyInfoList.size());
+
+ ContainerDiscrepancyInfo containerDiscrepancyInfo1 =
+ containerDiscrepancyInfoList.get(0);
+ assertEquals(3, containerDiscrepancyInfo1.getContainerID());
+ assertEquals("SCM", containerDiscrepancyInfo1.getExistsAt());
+
+ ContainerDiscrepancyInfo containerDiscrepancyInfo2 =
+ containerDiscrepancyInfoList.get(1);
+ assertEquals(4, containerDiscrepancyInfo2.getContainerID());
+ assertEquals("SCM", containerDiscrepancyInfo2.getExistsAt());
Review Comment:
Can we also assert the last container Id here which should be equal to 5
based on your prevKey = 2 and limit = 3, and total 5 containers, so last
container Id in returned list should be 5.
--
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]