You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by vj...@apache.org on 2020/01/15 07:16:35 UTC

[hbase] branch branch-2 updated: HBASE-23569 : Validate that all default chores of HMaster are scheduled

This is an automated email from the ASF dual-hosted git repository.

vjasani pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2 by this push:
     new 3800f6f  HBASE-23569 : Validate that all default chores of HMaster are scheduled
3800f6f is described below

commit 3800f6f131b3a2da8e98da277dc86b43646e7be3
Author: Viraj Jasani <vj...@apache.org>
AuthorDate: Tue Jan 14 23:01:49 2020 -0800

    HBASE-23569 : Validate that all default chores of HMaster are scheduled
    
    Signed-off-by: Andrew Purtell <ap...@apache.org>
---
 .../hbase/master/TestMasterChoreScheduled.java     | 145 +++++++++++++++++++++
 1 file changed, 145 insertions(+)

diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterChoreScheduled.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterChoreScheduled.java
new file mode 100644
index 0000000..63d0229
--- /dev/null
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterChoreScheduled.java
@@ -0,0 +1,145 @@
+/**
+ * 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.hbase.master;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.ScheduledChore;
+import org.apache.hadoop.hbase.StartMiniClusterOption;
+import org.apache.hadoop.hbase.master.balancer.BalancerChore;
+import org.apache.hadoop.hbase.master.balancer.ClusterStatusChore;
+import org.apache.hadoop.hbase.master.cleaner.HFileCleaner;
+import org.apache.hadoop.hbase.master.cleaner.LogCleaner;
+import org.apache.hadoop.hbase.master.cleaner.ReplicationBarrierCleaner;
+import org.apache.hadoop.hbase.master.normalizer.RegionNormalizerChore;
+import org.apache.hadoop.hbase.testclassification.MasterTests;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.zookeeper.KeeperException;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Tests to validate if HMaster default chores are scheduled
+ */
+@Category({MasterTests.class, MediumTests.class})
+public class TestMasterChoreScheduled {
+
+  @ClassRule
+  public static final HBaseClassTestRule CLASS_RULE =
+    HBaseClassTestRule.forClass(TestMasterChoreScheduled.class);
+
+  private static HMaster hMaster;
+
+  private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
+
+  public static final class MockHMaster extends HMaster {
+
+    public MockHMaster(Configuration conf) throws IOException, KeeperException {
+      super(conf);
+    }
+  }
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    UTIL.startMiniCluster(StartMiniClusterOption.builder().numRegionServers(1)
+      .masterClass(TestCloseAnOpeningRegion.MockHMaster.class).build());
+    hMaster = UTIL.getMiniHBaseCluster().getMaster();
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    UTIL.shutdownMiniCluster();
+  }
+
+  @Test
+  public void testDefaultScheduledChores() throws Exception {
+    // test if logCleaner chore is scheduled by default in HMaster init
+    TestChoreField<LogCleaner> logCleanerTestChoreField = new TestChoreField<>();
+    LogCleaner logCleaner = logCleanerTestChoreField.getChoreObj("logCleaner");
+    logCleanerTestChoreField.testIfChoreScheduled(logCleaner);
+
+    // test if hfileCleaner chore is scheduled by default in HMaster init
+    TestChoreField<HFileCleaner> hFileCleanerTestChoreField = new TestChoreField<>();
+    HFileCleaner hFileCleaner = hFileCleanerTestChoreField.getChoreObj("hfileCleaner");
+    hFileCleanerTestChoreField.testIfChoreScheduled(hFileCleaner);
+
+    // test if replicationBarrierCleaner chore is scheduled by default in HMaster init
+    TestChoreField<ReplicationBarrierCleaner> replicationBarrierCleanerTestChoreField =
+      new TestChoreField<>();
+    ReplicationBarrierCleaner replicationBarrierCleaner =
+      replicationBarrierCleanerTestChoreField.getChoreObj("replicationBarrierCleaner");
+    replicationBarrierCleanerTestChoreField.testIfChoreScheduled(replicationBarrierCleaner);
+
+    // test if clusterStatusChore chore is scheduled by default in HMaster init
+    TestChoreField<ClusterStatusChore> clusterStatusChoreTestChoreField = new TestChoreField<>();
+    ClusterStatusChore clusterStatusChore = clusterStatusChoreTestChoreField
+      .getChoreObj("clusterStatusChore");
+    clusterStatusChoreTestChoreField.testIfChoreScheduled(clusterStatusChore);
+
+    // test if balancerChore chore is scheduled by default in HMaster init
+    TestChoreField<BalancerChore> balancerChoreTestChoreField = new TestChoreField<>();
+    BalancerChore balancerChore = balancerChoreTestChoreField.getChoreObj("balancerChore");
+    balancerChoreTestChoreField.testIfChoreScheduled(balancerChore);
+
+    // test if normalizerChore chore is scheduled by default in HMaster init
+    TestChoreField<RegionNormalizerChore> regionNormalizerChoreTestChoreField =
+      new TestChoreField<>();
+    RegionNormalizerChore regionNormalizerChore = regionNormalizerChoreTestChoreField
+      .getChoreObj("normalizerChore");
+    regionNormalizerChoreTestChoreField.testIfChoreScheduled(regionNormalizerChore);
+
+    // test if catalogJanitorChore chore is scheduled by default in HMaster init
+    TestChoreField<CatalogJanitor> catalogJanitorTestChoreField = new TestChoreField<>();
+    CatalogJanitor catalogJanitor = catalogJanitorTestChoreField
+      .getChoreObj("catalogJanitorChore");
+    catalogJanitorTestChoreField.testIfChoreScheduled(catalogJanitor);
+
+    // test if hbckChore chore is scheduled by default in HMaster init
+    TestChoreField<HbckChore> hbckChoreTestChoreField = new TestChoreField<>();
+    HbckChore hbckChore = hbckChoreTestChoreField.getChoreObj("hbckChore");
+    hbckChoreTestChoreField.testIfChoreScheduled(hbckChore);
+  }
+
+
+  private static class TestChoreField<E extends ScheduledChore> {
+
+    private E getChoreObj(String fieldName) throws NoSuchFieldException,
+        IllegalAccessException {
+      Field masterField = HMaster.class.getDeclaredField(fieldName);
+      masterField.setAccessible(true);
+      E choreFieldVal = (E) masterField.get(hMaster);
+      return choreFieldVal;
+    }
+
+    private void testIfChoreScheduled(E choreObj) {
+      Assert.assertNotNull(choreObj);
+      Assert.assertTrue(hMaster.getChoreService().isChoreScheduled(choreObj));
+    }
+
+  }
+
+}