swagle 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_r306558000
 
 

 ##########
 File path: 
hadoop-ozone/ozone-recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestUtilizationService.java
 ##########
 @@ -0,0 +1,177 @@
+/**
+ * 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 com.google.inject.AbstractModule;
+import com.google.inject.Injector;
+import org.apache.hadoop.hdds.client.BlockID;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
+import org.apache.hadoop.ozone.om.OMMetadataManager;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup;
+import org.apache.hadoop.ozone.recon.AbstractOMMetadataManagerTest;
+import org.apache.hadoop.ozone.recon.GuiceInjectorUtilsForTestsImpl;
+import org.apache.hadoop.ozone.recon.ReconUtils;
+import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
+import org.apache.hadoop.ozone.recon.spi.impl.OzoneManagerServiceProviderImpl;
+import org.apache.hadoop.ozone.recon.tasks.FileSizeCountTask;
+import org.hadoop.ozone.recon.schema.UtilizationSchemaDefinition;
+import org.hadoop.ozone.recon.schema.tables.pojos.FileCountBySize;
+import org.jooq.Configuration;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+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 javax.ws.rs.core.Response;
+import java.util.*;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockIgnore({"javax.management.*", "javax.net.ssl.*"})
+@PrepareForTest(ReconUtils.class)
+public class TestUtilizationService extends AbstractOMMetadataManagerTest {
+
+  @Rule
+  public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+  private Injector injector;
+  private OzoneManagerServiceProviderImpl ozoneManagerServiceProvider;  
//should we use interface?
+  private OMMetadataManager omMetadataManager;
+  private GuiceInjectorUtilsForTestsImpl guiceInjectorTest =
+      new GuiceInjectorUtilsForTestsImpl();
+  private boolean isSetupDone = false;
+  private UtilizationService utilizationService;
+
+  private Injector getInjector() {
+    return injector;
+  }
+  private Configuration sqlConfiguration;
+
+  private void initializeInjector() throws Exception {
+    omMetadataManager = initializeNewOmMetadataManager();
+    OzoneConfiguration configuration =
+        guiceInjectorTest.getTestOzoneConfiguration(temporaryFolder);
+
+    ozoneManagerServiceProvider = new OzoneManagerServiceProviderImpl(
+        configuration);
+    ReconOMMetadataManager reconOMMetadataManager =
+        getTestMetadataManager(omMetadataManager);
+
+    Injector parentInjector = guiceInjectorTest.getInjector(
+        ozoneManagerServiceProvider, reconOMMetadataManager, temporaryFolder);
+
+    injector = parentInjector.createChildInjector(new AbstractModule() {
+      @Override
+      protected void configure() {
+        utilizationService = new UtilizationService();
+        bind(UtilizationService.class).toInstance(utilizationService);
+      }
+    });
+  }
+
+  @Before
+  public void setUp() throws Exception {
+
+    if (!isSetupDone) {
+      initializeInjector();
+      sqlConfiguration = getInjector().getInstance(Configuration.class);
+      isSetupDone = true;
+    }
+
+    UtilizationSchemaDefinition utilizationSchemaDefinition = 
getInjector().getInstance(
+        UtilizationSchemaDefinition.class);
+    utilizationSchemaDefinition.initializeSchema();
+
+    Pipeline pipeline = getRandomPipeline();
+    List<OmKeyLocationInfo> omKeyLocationInfoList = new ArrayList<>();
+    BlockID blockID1 = new BlockID(1, 1);
+    OmKeyLocationInfo omKeyLocationInfo1 =
+        getOmKeyLocationInfo(blockID1, pipeline);
+
+    BlockID blockID2 = new BlockID(2, 1);
+    OmKeyLocationInfo omKeyLocationInfo2 =
+        getOmKeyLocationInfo(blockID2, pipeline);
+
+    omKeyLocationInfoList.add(omKeyLocationInfo1);
+    omKeyLocationInfoList.add(omKeyLocationInfo2);
+
+    OmKeyLocationInfoGroup omKeyLocationInfoGroup =
+        new OmKeyLocationInfoGroup(0, omKeyLocationInfoList);
+
+    writeDataToOm(omMetadataManager,
+        "key_1",
+        "bucket_1",
+        "sampleVol_1",
+        1048576L,
+        Collections.singletonList(omKeyLocationInfoGroup));
+
+    writeDataToOm(omMetadataManager,
+        "key_2",
+        "bucket_2",
+        "sampleVol_2",
+        1024000L,
+        Collections.singletonList(omKeyLocationInfoGroup));
+
+    writeDataToOm(omMetadataManager,
+        "key_3",
+        "bucket_3",
+        "sampleVol_3",
+        750L,
+        Collections.singletonList(omKeyLocationInfoGroup));
+
+    writeDataToOm(omMetadataManager,
+        "key_4",
+        "bucket_4",
+        "sampleVol_4",
+        1025L,
+        Collections.singletonList(omKeyLocationInfoGroup));
+
+    FileSizeCountTask fileSizeCountTask =
+        new FileSizeCountTask(omMetadataManager, sqlConfiguration);
+
+    ozoneManagerServiceProvider.updateReconOmDBWithNewSnapshot();
+    fileSizeCountTask.reprocess(omMetadataManager);
+  }
+
+  @Test
+  public void testGetFileCounts() {
+    Response response = utilizationService.getFileCounts();
+    Map<Long, Long> resultMap = (LinkedHashMap<Long, Long>) 
response.getEntity();
+    int totalBins = 16;
+
+    assertEquals(totalBins, resultMap.size());
+
+    assertEquals(1L, (long) resultMap.get(1024L));
+
+    assertEquals(1L, (long) resultMap.get(10240L));
+
+    assertEquals(2L, (long) resultMap.get(10240000L));
+
+    assertEquals(0L, (long) resultMap.get(1024000L));
 
 Review comment:
   Should add more assertions for boundary values.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to