vivekratnavel commented on a change in pull request #1146: HDDS-1366. Add 
ability in Recon to track the number of small files in an Ozone Cluster
URL: https://github.com/apache/hadoop/pull/1146#discussion_r311374276
 
 

 ##########
 File path: 
hadoop-ozone/ozone-recon/src/test/java/org/apache/hadoop/ozone/recon/tasks/TestFileSizeCountTask.java
 ##########
 @@ -0,0 +1,129 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.tasks;
+
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.OmMetadataManagerImpl;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.utils.db.TypedTable;
+import org.junit.Test;
+
+import org.junit.runner.RunWith;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.times;
+import static org.powermock.api.mockito.PowerMockito.mock;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+/**
+ * Unit test for Container Key mapper task.
+ */
+@RunWith(PowerMockRunner.class)
+@PowerMockIgnore({"javax.management.*", "javax.net.ssl.*"})
+@PrepareForTest(OmKeyInfo.class)
+
+public class TestFileSizeCountTask {
+  @Test
+  public void testCalculateBinIndex() {
+    FileSizeCountTask fileSizeCountTask = mock(FileSizeCountTask.class);
+
+    when(fileSizeCountTask.getMaxFileSizeUpperBound()).
+        thenReturn(1125899906842624L);    // 1 PB
+    when(fileSizeCountTask.getOneKB()).thenReturn(1024L);
+    when(fileSizeCountTask.getMaxBinSize()).thenReturn(42);
+    when(fileSizeCountTask.calculateBinIndex(anyLong())).thenCallRealMethod();
+
+    long fileSize = 1024L;            // 1 KB
+    int binIndex = fileSizeCountTask.calculateBinIndex(fileSize);
+    assertEquals(1, binIndex);
+
+    fileSize = 1023L;
+    binIndex = fileSizeCountTask.calculateBinIndex(fileSize);
+    assertEquals(0, binIndex);
+
+    fileSize = 562949953421312L;      // 512 TB
+    binIndex = fileSizeCountTask.calculateBinIndex(fileSize);
+    assertEquals(40, binIndex);
+
+    fileSize = 562949953421313L;      // (512 TB + 1B)
+    binIndex = fileSizeCountTask.calculateBinIndex(fileSize);
+    assertEquals(40, binIndex);
+
+    fileSize = 562949953421311L;      // (512 TB - 1B)
+    binIndex = fileSizeCountTask.calculateBinIndex(fileSize);
+    assertEquals(39, binIndex);
+
+    fileSize = 1125899906842624L;      // 1 PB - last (extra) bin
+    binIndex = fileSizeCountTask.calculateBinIndex(fileSize);
+    assertEquals(41, binIndex);
+
+    fileSize = 100000L;
+    binIndex = fileSizeCountTask.calculateBinIndex(fileSize);
+    assertEquals(7, binIndex);
+
+    fileSize = 1125899906842623L;
 
 Review comment:
   I suppose this is 1 PB - 1B. Can you add a comment for this one and the 
previous one as well?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to