This is an automated email from the ASF dual-hosted git repository. vjasani pushed a commit to branch branch-2.2 in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.2 by this push: new b1f84b1 HBASE-23569 : Validate that all default chores of HRegionServer are scheduled (ADDENDUM) b1f84b1 is described below commit b1f84b1f9ed2774d98bfd82026f1099ccd3e629a Author: Viraj Jasani <vjas...@apache.org> AuthorDate: Thu Jan 16 23:19:36 2020 -0800 HBASE-23569 : Validate that all default chores of HRegionServer are scheduled (ADDENDUM) Signed-off-by: Andrew Purtell <apurt...@apache.org> --- .../hbase/master/TestMasterChoreScheduled.java | 13 +-- .../hbase/regionserver/TestRSChoresScheduled.java | 115 +++++++++++++++++++++ 2 files changed, 116 insertions(+), 12 deletions(-) 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 index 63d0229..bbf9a0b 100644 --- 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 @@ -18,10 +18,8 @@ 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; @@ -34,7 +32,6 @@ 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; @@ -56,17 +53,9 @@ public class TestMasterChoreScheduled { 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()); + UTIL.startMiniCluster(StartMiniClusterOption.builder().numRegionServers(1).build()); hMaster = UTIL.getMiniHBaseCluster().getMaster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSChoresScheduled.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSChoresScheduled.java new file mode 100644 index 0000000..8759f08 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSChoresScheduled.java @@ -0,0 +1,115 @@ +/** + * 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.regionserver; + +import java.lang.reflect.Field; + +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.testclassification.MediumTests; +import org.apache.hadoop.hbase.testclassification.RegionServerTests; +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 HRegionServer default chores are scheduled + */ +@Category({RegionServerTests.class, MediumTests.class}) +public class TestRSChoresScheduled { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestRSChoresScheduled.class); + + private static HRegionServer hRegionServer; + + private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); + + @BeforeClass + public static void setUp() throws Exception { + UTIL.startMiniCluster(StartMiniClusterOption.builder().numRegionServers(1).build()); + hRegionServer = UTIL.getMiniHBaseCluster().getRegionServer(0); + } + + @AfterClass + public static void tearDown() throws Exception { + UTIL.shutdownMiniCluster(); + } + + private static class TestChoreField<E extends ScheduledChore> { + + private E getChoreObj(String fieldName) throws NoSuchFieldException, + IllegalAccessException { + Field hRegionServerField = HRegionServer.class.getDeclaredField(fieldName); + hRegionServerField.setAccessible(true); + E choreFieldVal = (E) hRegionServerField.get(hRegionServer); + return choreFieldVal; + } + + private void testIfChoreScheduled(E choreObj) { + Assert.assertNotNull(choreObj); + Assert.assertTrue(hRegionServer.getChoreService().isChoreScheduled(choreObj)); + } + + } + + @Test + public void testDefaultScheduledChores() throws Exception { + // test if movedRegionsCleaner chore is scheduled by default in HRegionServer init + TestChoreField<HRegionServer.MovedRegionsCleaner> movedRegionsCleanerTestChoreField = + new TestChoreField<>(); + HRegionServer.MovedRegionsCleaner movedRegionsCleaner = movedRegionsCleanerTestChoreField + .getChoreObj("movedRegionsCleaner"); + movedRegionsCleanerTestChoreField.testIfChoreScheduled(movedRegionsCleaner); + + // test if compactedHFilesDischarger chore is scheduled by default in HRegionServer init + TestChoreField<CompactedHFilesDischarger> compactedHFilesDischargerTestChoreField = + new TestChoreField<>(); + CompactedHFilesDischarger compactedHFilesDischarger = + compactedHFilesDischargerTestChoreField.getChoreObj("compactedFileDischarger"); + compactedHFilesDischargerTestChoreField.testIfChoreScheduled(compactedHFilesDischarger); + + // test if compactionChecker chore is scheduled by default in HRegionServer init + TestChoreField<ScheduledChore> compactionCheckerTestChoreField = new TestChoreField<>(); + ScheduledChore compactionChecker = + compactionCheckerTestChoreField.getChoreObj("compactionChecker"); + compactionCheckerTestChoreField.testIfChoreScheduled(compactionChecker); + + // test if periodicFlusher chore is scheduled by default in HRegionServer init + TestChoreField<ScheduledChore> periodicMemstoreFlusherTestChoreField = + new TestChoreField<>(); + ScheduledChore periodicFlusher = + periodicMemstoreFlusherTestChoreField.getChoreObj("periodicFlusher"); + periodicMemstoreFlusherTestChoreField.testIfChoreScheduled(periodicFlusher); + + // test if nonceManager chore is scheduled by default in HRegionServer init + TestChoreField<ScheduledChore> nonceManagerTestChoreField = new TestChoreField<>(); + ScheduledChore nonceManagerChore = + nonceManagerTestChoreField.getChoreObj("nonceManagerChore"); + nonceManagerTestChoreField.testIfChoreScheduled(nonceManagerChore); + + } + +}