bharatviswa504 commented on a change in pull request #1511:
URL: https://github.com/apache/ozone/pull/1511#discussion_r532963547



##########
File path: 
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOpenKeyCleanupService.java
##########
@@ -0,0 +1,462 @@
+/*
+ * 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.om;
+
+import java.time.Instant;
+import java.util.HashSet;
+import java.util.Random;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.utils.db.Table;
+import org.apache.hadoop.ozone.MiniOzoneCluster;
+import org.apache.hadoop.ozone.OzoneConfigKeys;
+import org.apache.hadoop.ozone.common.BlockGroup;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.request.TestOMRequestUtils;
+import org.apache.hadoop.test.GenericTestUtils;
+import org.apache.ratis.util.TimeDuration;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Integration tests for the open key cleanup service on OM.
+ */
+public class TestOpenKeyCleanupService {
+  @Rule
+  public TemporaryFolder folder = new TemporaryFolder();
+
+  // Increase service interval of open key cleanup so we can trigger the
+  // service manually between setting up the DB and checking the results.
+  // Increase service interval of key deleting service to ensure it does not
+  // run during the tests, interfering with results.
+  private static final TimeDuration TESTING_SERVICE_INTERVAL =
+      TimeDuration.valueOf(24, TimeUnit.HOURS);
+  // High expiration time used so keys without modified creation time will not
+  // expire during the test.
+  private static final TimeDuration TESTING_EXPIRE_THRESHOLD =
+      TimeDuration.valueOf(24, TimeUnit.HOURS);
+  // Maximum number of keys to be cleaned up per run of the service.
+  private static final int TESTING_TASK_LIMIT = 10;
+
+  // Volume and bucket created and added to the DB that will hold open keys
+  // created by this test unless tests specify otherwise.
+  private static final String DEFAULT_VOLUME = "volume";
+  private static final String DEFAULT_BUCKET = "bucket";
+
+  private KeyManager keyManager;
+  private OpenKeyCleanupService service;
+  private  OMMetadataManager metadataManager;
+  private MiniOzoneCluster cluster;
+
+  private void setupCluster() throws Exception {
+    setupCluster(TESTING_SERVICE_INTERVAL, TESTING_EXPIRE_THRESHOLD);
+  }
+
+  private void setupCluster(TimeDuration openKeyCleanupServiceInterval,
+      TimeDuration openKeyExpireThreshold) throws Exception {
+
+    OzoneConfiguration conf = new OzoneConfiguration();
+    conf.set(OMConfigKeys.OZONE_OM_DB_DIRS, 
folder.getRoot().getAbsolutePath());
+
+    // Make sure key deletion does not run during the tests.
+    conf.setTimeDuration(OzoneConfigKeys.OZONE_BLOCK_DELETING_SERVICE_INTERVAL,
+        TESTING_SERVICE_INTERVAL.getDuration(),
+        TESTING_SERVICE_INTERVAL.getUnit());
+    // Set open key cleanup configurations.
+    conf.setTimeDuration(OMConfigKeys.OZONE_OPEN_KEY_CLEANUP_SERVICE_INTERVAL,
+        openKeyCleanupServiceInterval.getDuration(),
+        openKeyCleanupServiceInterval.getUnit());
+    conf.setTimeDuration(OMConfigKeys.OZONE_OPEN_KEY_EXPIRE_THRESHOLD,
+        openKeyExpireThreshold.getDuration(), 
openKeyExpireThreshold.getUnit());
+    conf.setInt(OMConfigKeys.OZONE_OPEN_KEY_CLEANUP_LIMIT_PER_TASK,
+        TESTING_TASK_LIMIT);
+
+    cluster = MiniOzoneCluster.newBuilder(conf).build();

Review comment:
       Can we add also a similar test for OM HA




----------------------------------------------------------------
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]



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

Reply via email to