ArafatKhan2198 commented on code in PR #8995:
URL: https://github.com/apache/ozone/pull/8995#discussion_r2350144706


##########
hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestStorageDistributionEndpoint.java:
##########
@@ -0,0 +1,267 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.recon.api;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.anyMap;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.ws.rs.core.Response;
+import 
org.apache.hadoop.hdds.protocol.proto.HddsProtos.DeletedBlocksTransactionSummary;
+import org.apache.hadoop.hdds.scm.container.placement.metrics.LongMetric;
+import org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeMetric;
+import org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat;
+import org.apache.hadoop.hdds.scm.node.DatanodeInfo;
+import org.apache.hadoop.hdds.scm.protocol.StorageContainerLocationProtocol;
+import org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager;
+import org.apache.hadoop.ozone.recon.api.types.DUResponse;
+import org.apache.hadoop.ozone.recon.api.types.DeletionPendingBytesByStage;
+import org.apache.hadoop.ozone.recon.api.types.GlobalNamespaceReport;
+import org.apache.hadoop.ozone.recon.api.types.GlobalStorageReport;
+import 
org.apache.hadoop.ozone.recon.api.types.StorageCapacityDistributionResponse;
+import org.apache.hadoop.ozone.recon.api.types.UsedSpaceBreakDown;
+import org.apache.hadoop.ozone.recon.scm.ReconNodeManager;
+import org.apache.ozone.recon.schema.generated.tables.daos.GlobalStatsDao;
+import org.apache.ozone.recon.schema.generated.tables.pojos.GlobalStats;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test class for StorageDistributionEndpoint, responsible for testing
+ * the behavior and responses of the storage distribution endpoint in
+ * different scenarios, including successful responses and exception cases.
+ */
+class StorageDistributionEndpointTest {
+
+  private ReconNodeManager mockNodeManager;
+  private OMDBInsightEndpoint mockOmdbInsightEndpoint;
+  private NSSummaryEndpoint mockNsSummaryEndpoint;
+  private StorageContainerLocationProtocol mockScmClient;
+  private GlobalStatsDao globalStatsDao;
+  private OzoneStorageContainerManager mockReconScm;
+  private DatanodeInfo datanodeDetails;
+  private SCMNodeStat mockNodeStat;
+  private SCMNodeStat globalStats;
+  private DUResponse mockDuResponse;
+
+  @Test
+  void testGetStorageDistributionSuccessfulResponse() throws IOException {
+    setupMockDependencies();
+    setupSuccessfulScenario();
+    StorageDistributionEndpoint endpoint = new 
StorageDistributionEndpoint(mockReconScm, mockOmdbInsightEndpoint,
+        mockNsSummaryEndpoint, globalStatsDao, mockScmClient);
+    Response response = endpoint.getStorageDistribution();
+
+    assertNotNull(response);
+    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+    StorageCapacityDistributionResponse responsePayload = 
(StorageCapacityDistributionResponse) response.getEntity();
+    assertNotNull(responsePayload);
+
+    GlobalStorageReport globalStorage = responsePayload.getGlobalStorage();
+    assertEquals(2000L, globalStorage.getTotalUsedSpace());
+    assertEquals(3000L, globalStorage.getTotalFreeSpace());
+    assertEquals(5000L, globalStorage.getTotalCapacity());
+
+    GlobalNamespaceReport namespaceReport = 
responsePayload.getGlobalNamespace();
+    assertEquals(500L, namespaceReport.getTotalUsedSpace());
+
+    UsedSpaceBreakDown usedSpaceBreakDown = 
responsePayload.getUsedSpaceBreakDown();
+    assertEquals(150L, usedSpaceBreakDown.getOpenKeysBytes());
+    assertEquals(300L, usedSpaceBreakDown.getCommittedBytes());
+
+    DeletionPendingBytesByStage deletionBreakdown = 
usedSpaceBreakDown.getDeletionPendingBytesByStage();
+    assertEquals(50L, 
deletionBreakdown.getByStage().get("OM").get("totalBytes"));
+    assertEquals(75L, 
deletionBreakdown.getByStage().get("SCM").get("pendingBytes"));
+    assertEquals(0L, 
deletionBreakdown.getByStage().get("DN").get("pendingBytes"));
+  }
+
+  @Test
+  void testGetStorageDistributionWithSCMExceptionResponse() throws IOException 
{
+    setupMockDependencies();
+    setupScmExceptionScenario();
+    StorageDistributionEndpoint endpoint = new 
StorageDistributionEndpoint(mockReconScm, mockOmdbInsightEndpoint,
+        mockNsSummaryEndpoint, globalStatsDao, mockScmClient);
+    Response response = endpoint.getStorageDistribution();
+    assertNotNull(response);
+    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+    StorageCapacityDistributionResponse responsePayload = 
(StorageCapacityDistributionResponse) response.getEntity();
+    assertNotNull(responsePayload);
+    GlobalStorageReport globalStorage = responsePayload.getGlobalStorage();
+    assertEquals(2000L, globalStorage.getTotalUsedSpace());
+    assertEquals(3000L, globalStorage.getTotalFreeSpace());
+    assertEquals(5000L, globalStorage.getTotalCapacity());
+
+    GlobalNamespaceReport namespaceReport = 
responsePayload.getGlobalNamespace();
+    assertEquals(500L, namespaceReport.getTotalUsedSpace());
+
+    UsedSpaceBreakDown usedSpaceBreakDown = 
responsePayload.getUsedSpaceBreakDown();
+    assertEquals(150L, usedSpaceBreakDown.getOpenKeysBytes());
+    assertEquals(300L, usedSpaceBreakDown.getCommittedBytes());
+
+    DeletionPendingBytesByStage deletionBreakdown = 
usedSpaceBreakDown.getDeletionPendingBytesByStage();
+    assertEquals(50L, 
deletionBreakdown.getByStage().get("OM").get("totalBytes"));
+    assertEquals(0, 
deletionBreakdown.getByStage().get("SCM").get("pendingBytes"));
+  }
+

Review Comment:
   We can always test it out locally by shutting down a datanode to timeout the 
jmx call from recon to DN.
   
   But later on we should add a small test here trying to simulate that 
scenario - 
   
   Like an Improvement we could add later on,
   
   ```
   @Test
   void testStorageDistributionWithJMXTimeouts() {
       // Test behavior when JMX calls timeout
       // Verify partial results are returned
       // Test timeout configuration
   }
   ```



-- 
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: issues-unsubscr...@ozone.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org
For additional commands, e-mail: issues-h...@ozone.apache.org

Reply via email to