[ https://issues.apache.org/jira/browse/HDDS-1366?focusedWorklogId=290825&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-290825 ]
ASF GitHub Bot logged work on HDDS-1366: ---------------------------------------- Author: ASF GitHub Bot Created on: 07/Aug/19 22:41 Start Date: 07/Aug/19 22:41 Worklog Time Spent: 10m Work Description: shwetayakkali commented on 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_r311792479 ########## File path: hadoop-ozone/ozone-recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestUtilizationService.java ########## @@ -0,0 +1,108 @@ +/** + * 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.api; + +import org.apache.hadoop.ozone.recon.ReconUtils; +import org.hadoop.ozone.recon.schema.tables.daos.FileCountBySizeDao; +import org.hadoop.ozone.recon.schema.tables.pojos.FileCountBySize; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +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 java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.when; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +/** + * Test for File size count service. + */ +@RunWith(PowerMockRunner.class) +@PowerMockIgnore({"javax.management.*", "javax.net.ssl.*"}) +@PrepareForTest(ReconUtils.class) +public class TestUtilizationService { + private UtilizationService utilizationService; + @Mock private FileCountBySizeDao fileCountBySizeDao; + private List<FileCountBySize> resultList = new ArrayList<>(); + private int oneKb = 1024; + private int maxBinSize = 41; + + public void setUpResultList() { + for(int i = 0; i < 41; i++){ + resultList.add(new FileCountBySize((long) Math.pow(2, (10+i)), (long) i)); + } + } + + @Test + public void testGetFileCounts() throws IOException { + setUpResultList(); + + utilizationService = mock(UtilizationService.class); + when(utilizationService.getFileCounts()).thenCallRealMethod(); + when(utilizationService.getDao()).thenReturn(fileCountBySizeDao); + when(fileCountBySizeDao.findAll()).thenReturn(resultList); + + utilizationService.getFileCounts(); + verify(utilizationService, times(1)).getFileCounts(); + verify(fileCountBySizeDao, times(1)).findAll(); + + assertEquals(41, resultList.size()); + long fileSize = 4096L; + int index = findIndex(fileSize); + long count = resultList.get(index).getCount(); + assertEquals(index, count); + + fileSize = 1125899906842624L; + index = findIndex(fileSize); + if (index == Integer.MIN_VALUE) { + throw new IOException("File Size larger than permissible file size"); + } + + fileSize = 1025L; + index = findIndex(fileSize); + count = resultList.get(index).getCount(); + assertEquals(index, count); + + fileSize = 25L; + index = findIndex(fileSize); + count = resultList.get(index).getCount(); + assertEquals(index, count); + } + + public int findIndex(long dataSize) { + int logValue = (int) Math.ceil(Math.log(dataSize)/Math.log(2)); + if (logValue < 10) { + return 0; + } else { + int index = logValue - 10; + if (index > maxBinSize) { + return Integer.MIN_VALUE; Review comment: Sure. ---------------------------------------------------------------- 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 Issue Time Tracking ------------------- Worklog Id: (was: 290825) Time Spent: 8.5h (was: 8h 20m) > Add ability in Recon to track the number of small files in an Ozone cluster. > ---------------------------------------------------------------------------- > > Key: HDDS-1366 > URL: https://issues.apache.org/jira/browse/HDDS-1366 > Project: Hadoop Distributed Data Store > Issue Type: Sub-task > Components: Ozone Recon > Reporter: Aravindan Vijayan > Assignee: Shweta > Priority: Major > Labels: pull-request-available > Time Spent: 8.5h > Remaining Estimate: 0h > > Ozone users may want to track the number of small files they have in their > cluster and where they are present. Recon can help them with the information > by iterating the OM Key Table and dividing the keys into different buckets > based on the data size. -- This message was sent by Atlassian JIRA (v7.6.14#76016) --------------------------------------------------------------------- To unsubscribe, e-mail: hdfs-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: hdfs-issues-h...@hadoop.apache.org