diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestDLS.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestDLS.java index 419db220e17f..e79ba578140b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestDLS.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestDLS.java @@ -19,9 +19,9 @@ import static org.apache.hadoop.hbase.HConstants.HBASE_SPLIT_WAL_MAX_SPLITTER; import static org.apache.hadoop.hbase.SplitLogCounters.tot_mgr_wait_for_zk_delete; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.ArrayList; @@ -69,13 +69,12 @@ import org.apache.hadoop.hbase.wal.WALEditInternalHelper; import org.apache.hadoop.hbase.wal.WALKeyImpl; import org.apache.hadoop.hbase.zookeeper.ZKUtil; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -94,18 +93,12 @@ public abstract class AbstractTestDLS { private static final int NUM_RS = 5; private static byte[] COLUMN_FAMILY = Bytes.toBytes("family"); - @Rule - public TestName testName = new TestName(); - private TableName tableName; private SingleProcessHBaseCluster cluster; private HMaster master; private Configuration conf; - @Rule - public TestName name = new TestName(); - - @BeforeClass + @BeforeAll public static void setup() throws Exception { // Uncomment the following line if more verbosity is needed for // debugging (see HBASE-12285 for details). @@ -114,7 +107,7 @@ public static void setup() throws Exception { TEST_UTIL.startMiniDFSCluster(3); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -147,13 +140,13 @@ public boolean evaluate() throws Exception { }); } - @Before - public void before() throws Exception { + @BeforeEach + public void before(TestInfo testInfo) throws Exception { conf = TEST_UTIL.getConfiguration(); - tableName = TableName.valueOf(testName.getMethodName()); + tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); } - @After + @AfterEach public void after() throws Exception { TEST_UTIL.shutdownMiniHBaseCluster(); TEST_UTIL.getTestFileSystem().delete(CommonFSUtils.getRootDir(TEST_UTIL.getConfiguration()), diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestMasterRegionMutation.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestMasterRegionMutation.java new file mode 100644 index 000000000000..d5977fe59701 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestMasterRegionMutation.java @@ -0,0 +1,137 @@ +/* + * 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 static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.hadoop.hbase.HBaseTestingUtil; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.SingleProcessHBaseCluster; +import org.apache.hadoop.hbase.StartTestingClusterOption; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; +import org.apache.hadoop.hbase.client.TableDescriptor; +import org.apache.hadoop.hbase.client.TableDescriptorBuilder; +import org.apache.hadoop.hbase.master.hbck.HbckChore; +import org.apache.hadoop.hbase.master.hbck.HbckReport; +import org.apache.hadoop.hbase.regionserver.HRegion; +import org.apache.hadoop.hbase.util.Bytes; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos; + +public abstract class AbstractTestMasterRegionMutation { + + private static final Logger LOG = LoggerFactory.getLogger(AbstractTestMasterRegionMutation.class); + + protected static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); + protected static ServerName rs0; + + protected static final AtomicBoolean ERROR_OUT = new AtomicBoolean(false); + protected static final AtomicInteger ERROR_COUNTER = new AtomicInteger(0); + protected static final AtomicBoolean FIRST_TIME_ERROR = new AtomicBoolean(true); + + protected static void setUpBeforeClass(int numMasters, Class regionImplClass) + throws Exception { + TEST_UTIL.getConfiguration().setClass(HConstants.REGION_IMPL, regionImplClass, HRegion.class); + StartTestingClusterOption.Builder builder = StartTestingClusterOption.builder(); + builder.numMasters(numMasters).numRegionServers(3); + TEST_UTIL.startMiniCluster(builder.build()); + SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); + rs0 = cluster.getRegionServer(0).getServerName(); + TEST_UTIL.getAdmin().balancerSwitch(false, true); + } + + protected static void tearDownAfterClass() throws Exception { + TEST_UTIL.shutdownMiniCluster(); + } + + @BeforeEach + protected void setUp(TestInfo testInfo) throws Exception { + TableName tableName = TableName.valueOf(testInfo.getTestMethod().orElseThrow().getName()); + TableDescriptor tableDesc = TableDescriptorBuilder.newBuilder(tableName) + .setColumnFamily(ColumnFamilyDescriptorBuilder.of("fam1")).build(); + int startKey = 0; + int endKey = 80000; + TEST_UTIL.getAdmin().createTable(tableDesc, Bytes.toBytes(startKey), Bytes.toBytes(endKey), 9); + } + + @Test + protected void testMasterRegionMutations() throws Exception { + HbckChore hbckChore = new HbckChore(TEST_UTIL.getHBaseCluster().getMaster()); + SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); + + int numRegions0 = cluster.getRegionServer(0).getNumberOfOnlineRegions(); + int numRegions1 = cluster.getRegionServer(1).getNumberOfOnlineRegions(); + int numRegions2 = cluster.getRegionServer(2).getNumberOfOnlineRegions(); + + hbckChore.choreForTesting(); + HbckReport hbckReport = hbckChore.getLastReport(); + assertEquals(0, hbckReport.getInconsistentRegions().size()); + assertEquals(0, hbckReport.getOrphanRegionsOnFS().size()); + assertEquals(0, hbckReport.getOrphanRegionsOnRS().size()); + + ERROR_OUT.set(true); + TEST_UTIL.getAdmin().move( + cluster.getRegionServer(1).getRegions().get(0).getRegionInfo().getEncodedNameAsBytes(), rs0); + + ERROR_OUT.set(true); + TEST_UTIL.getAdmin().move( + cluster.getRegionServer(2).getRegions().get(0).getRegionInfo().getEncodedNameAsBytes(), rs0); + + HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); + + TEST_UTIL.waitFor(5000, 1000, () -> { + LOG.info("numRegions0: {} , numRegions1: {} , numRegions2: {}", numRegions0, numRegions1, + numRegions2); + LOG.info("Online regions - server0 : {} , server1: {} , server2: {}", + cluster.getRegionServer(0).getNumberOfOnlineRegions(), + cluster.getRegionServer(1).getNumberOfOnlineRegions(), + cluster.getRegionServer(2).getNumberOfOnlineRegions()); + LOG.info("Num of successfully completed procedures: {} , num of all procedures: {}", + master.getMasterProcedureExecutor().getProcedures().stream() + .filter(masterProcedureEnvProcedure -> masterProcedureEnvProcedure.getState() + == ProcedureProtos.ProcedureState.SUCCESS) + .count(), + master.getMasterProcedureExecutor().getProcedures().size()); + return (numRegions0 + numRegions1 + numRegions2) + == (cluster.getRegionServer(0).getNumberOfOnlineRegions() + + cluster.getRegionServer(1).getNumberOfOnlineRegions() + + cluster.getRegionServer(2).getNumberOfOnlineRegions()) + && master.getMasterProcedureExecutor().getProcedures().stream() + .filter(masterProcedureEnvProcedure -> masterProcedureEnvProcedure.getState() + == ProcedureProtos.ProcedureState.SUCCESS) + .count() == master.getMasterProcedureExecutor().getProcedures().size(); + }); + + TEST_UTIL.waitFor(5000, 1000, () -> { + HbckChore hbck = new HbckChore(TEST_UTIL.getHBaseCluster().getMaster()); + hbck.choreForTesting(); + HbckReport report = hbck.getLastReport(); + return report.getInconsistentRegions().isEmpty() && report.getOrphanRegionsOnFS().isEmpty() + && report.getOrphanRegionsOnRS().isEmpty(); + }); + } +} diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestRestartCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestRestartCluster.java index 5ba25efaed75..342e807352da 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestRestartCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestRestartCluster.java @@ -21,8 +21,8 @@ import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +39,7 @@ public abstract class AbstractTestRestartCluster { protected abstract boolean splitWALCoordinatedByZk(); - @Before + @BeforeEach public void setUp() { boolean splitWALCoordinatedByZk = splitWALCoordinatedByZk(); LOG.info("WAL splitting coordinated by zk {}", splitWALCoordinatedByZk); @@ -47,7 +47,7 @@ public void setUp() { splitWALCoordinatedByZk); } - @After + @AfterEach public void tearDown() throws Exception { UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestActiveMasterManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestActiveMasterManager.java index fcb67ed31b47..1229eefa5bc6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestActiveMasterManager.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestActiveMasterManager.java @@ -17,10 +17,10 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -30,7 +30,6 @@ import java.util.List; import java.util.concurrent.Semaphore; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.monitoring.MonitoredTask; @@ -46,11 +45,10 @@ import org.apache.hadoop.hbase.zookeeper.ZKWatcher; import org.apache.hadoop.hbase.zookeeper.ZNodePaths; import org.apache.zookeeper.KeeperException; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,22 +56,19 @@ /** * Test the {@link ActiveMasterManager}. */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestActiveMasterManager { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestActiveMasterManager.class); - private final static Logger LOG = LoggerFactory.getLogger(TestActiveMasterManager.class); private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { TEST_UTIL.startMiniZKCluster(); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL.shutdownMiniZKCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAlwaysStandByHMaster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAlwaysStandByHMaster.java index dd0d5304606f..e50b394aa416 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAlwaysStandByHMaster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAlwaysStandByHMaster.java @@ -17,34 +17,30 @@ */ package org.apache.hadoop.hbase.master; -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; -import org.apache.hadoop.hbase.MiniClusterRule; +import org.apache.hadoop.hbase.MiniClusterExtension; import org.apache.hadoop.hbase.StartTestingClusterOption; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; -@Category({ MediumTests.class, MasterTests.class }) +@Tag(MediumTests.TAG) +@Tag(MasterTests.TAG) public class TestAlwaysStandByHMaster { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestAlwaysStandByHMaster.class); - private static final StartTestingClusterOption OPTION = StartTestingClusterOption.builder() .numAlwaysStandByMasters(1).numMasters(1).numRegionServers(1).build(); - @ClassRule - public static final MiniClusterRule miniClusterRule = - MiniClusterRule.newBuilder().setMiniClusterOption(OPTION).build(); + @RegisterExtension + public static final MiniClusterExtension miniClusterExtension = + MiniClusterExtension.newBuilder().setMiniClusterOption(OPTION).build(); /** * Tests that the AlwaysStandByHMaster does not transition to active state even if no active @@ -52,7 +48,7 @@ public class TestAlwaysStandByHMaster { */ @Test public void testAlwaysStandBy() throws Exception { - HBaseTestingUtil testUtil = miniClusterRule.getTestingUtility(); + HBaseTestingUtil testUtil = miniClusterExtension.getTestingUtility(); // Make sure there is an active master. assertNotNull(testUtil.getMiniHBaseCluster().getMaster()); assertEquals(2, testUtil.getMiniHBaseCluster().getMasterThreads().size()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerMetrics.java index b503595a4472..08ea1c88791a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerMetrics.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManagerMetrics.java @@ -17,12 +17,11 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.CompatibilityFactory; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.SingleProcessHBaseCluster; @@ -40,23 +39,19 @@ import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.TableDescriptorChecker; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestAssignmentManagerMetrics { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestAssignmentManagerMetrics.class); - private static final Logger LOG = LoggerFactory.getLogger(TestAssignmentManagerMetrics.class); private static final MetricsAssertHelper METRICS_HELPER = CompatibilityFactory.getInstance(MetricsAssertHelper.class); @@ -65,11 +60,14 @@ public class TestAssignmentManagerMetrics { private static HMaster MASTER; private static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static final int MSG_INTERVAL = 1000; + private String testMethodName; - @Rule - public TestName name = new TestName(); + @BeforeEach + public void setTestMethod(TestInfo testInfo) { + testMethodName = testInfo.getTestMethod().get().getName(); + } - @BeforeClass + @BeforeAll public static void startCluster() throws Exception { LOG.info("Starting cluster"); Configuration conf = TEST_UTIL.getConfiguration(); @@ -104,7 +102,7 @@ public static void startCluster() throws Exception { MASTER.getConfiguration().setBoolean(TableDescriptorChecker.TABLE_SANITY_CHECKS, false); } - @AfterClass + @AfterAll public static void after() throws Exception { LOG.info("AFTER {} <= IS THIS NULL?", TEST_UTIL); TEST_UTIL.shutdownMiniCluster(); @@ -112,7 +110,7 @@ public static void after() throws Exception { @Test public void testRITAssignmentManagerMetrics() throws Exception { - final TableName TABLENAME = TableName.valueOf(name.getMethodName()); + final TableName TABLENAME = TableName.valueOf(testMethodName); final byte[] FAMILY = Bytes.toBytes("family"); try (Table table = TEST_UTIL.createTable(TABLENAME, FAMILY)) { final byte[] row = Bytes.toBytes("row"); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestBalancer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestBalancer.java index d5ff71000a8c..28ab0fa7c551 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestBalancer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestBalancer.java @@ -17,12 +17,11 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; import java.util.Map; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -32,42 +31,40 @@ import org.apache.hadoop.hbase.master.assignment.RegionStates; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; /** * Test balancer with disabled table */ -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestBalancer { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestBalancer.class); - private final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); + private String testMethodName; - @Rule - public TestName name = new TestName(); + @BeforeEach + public void setTestMethod(TestInfo testInfo) { + testMethodName = testInfo.getTestMethod().get().getName(); + } - @Before + @BeforeEach public void before() throws Exception { TEST_UTIL.startMiniCluster(); } - @After + @AfterEach public void after() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @Test public void testAssignmentsForBalancer() throws Exception { - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(testMethodName); TEST_UTIL.createMultiRegionTable(tableName, HConstants.CATALOG_FAMILY, 10); // disable table final TableName disableTableName = TableName.valueOf("testDisableTable"); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClientMetaServiceRPCs.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClientMetaServiceRPCs.java index ac56f2d9c597..d56ccf78e815 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClientMetaServiceRPCs.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClientMetaServiceRPCs.java @@ -19,7 +19,7 @@ import static org.apache.hadoop.hbase.HConstants.DEFAULT_HBASE_RPC_TIMEOUT; import static org.apache.hadoop.hbase.HConstants.HBASE_RPC_TIMEOUT_KEY; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.ArrayList; @@ -27,7 +27,6 @@ import java.util.List; import java.util.concurrent.TimeUnit; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.ServerName; @@ -40,11 +39,10 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.JVMClusterUtil; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.generated.RegistryProtos.ClientMetaService; @@ -55,13 +53,10 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.RegistryProtos.GetMetaRegionLocationsRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.RegistryProtos.GetMetaRegionLocationsResponse; -@Category({ MediumTests.class, MasterTests.class }) +@Tag(MediumTests.TAG) +@Tag(MasterTests.TAG) public class TestClientMetaServiceRPCs { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestClientMetaServiceRPCs.class); - // Total number of masters (active + stand by) for the purpose of this test. private static final int MASTER_COUNT = 3; private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); @@ -69,7 +64,7 @@ public class TestClientMetaServiceRPCs { private static int rpcTimeout; private static RpcClient rpcClient; - @BeforeClass + @BeforeAll public static void setUp() throws Exception { // Start the mini cluster with stand-by masters. StartTestingClusterOption.Builder builder = StartTestingClusterOption.builder(); @@ -82,7 +77,7 @@ public static void setUp() throws Exception { TEST_UTIL.getMiniHBaseCluster().getMaster().getClusterId()); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { if (rpcClient != null) { rpcClient.close(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClockSkewDetection.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClockSkewDetection.java index 2d5d9a4bc18f..e0c7589dfa09 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClockSkewDetection.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClockSkewDetection.java @@ -17,35 +17,30 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.net.InetAddress; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.ClockOutOfSyncException; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.master.assignment.AssignmentManager; import org.apache.hadoop.hbase.master.assignment.RegionStates; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupRequest; -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestClockSkewDetection { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestClockSkewDetection.class); - private static final Logger LOG = LoggerFactory.getLogger(TestClockSkewDetection.class); private static final class DummyMasterServices extends MockNoopMasterServices { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCloseAnOpeningRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCloseAnOpeningRegion.java index 77087026136c..8c34cb909cd6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCloseAnOpeningRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestCloseAnOpeningRegion.java @@ -21,7 +21,6 @@ import java.io.UncheckedIOException; import java.util.concurrent.CountDownLatch; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.PleaseHoldException; @@ -36,23 +35,19 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode; import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionResponse; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestCloseAnOpeningRegion { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestCloseAnOpeningRegion.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static TableName TABLE_NAME = TableName.valueOf("race"); @@ -93,7 +88,7 @@ public ReportRegionStateTransitionResponse reportRegionStateTransition( } } - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.getConfiguration().setInt(HConstants.HBASE_RPC_SHORTOPERATION_TIMEOUT_KEY, 60000); UTIL.startMiniCluster(StartTestingClusterOption.builder().numRegionServers(2) @@ -102,7 +97,7 @@ public static void setUp() throws Exception { UTIL.getAdmin().balancerSwitch(false, true); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestart.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestart.java index 945ea7619315..95de7de5bc15 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestart.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestart.java @@ -17,30 +17,25 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.TableExistsException; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestClusterRestart extends AbstractTestRestartCluster { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestClusterRestart.class); - private static final Logger LOG = LoggerFactory.getLogger(TestClusterRestart.class); private static final int NUM_REGIONS = 3; @@ -83,7 +78,7 @@ public void test() throws Exception { for (TableName TABLE : TABLES) { try { UTIL.createTable(TABLE, FAMILY); - assertTrue("Able to create table that should already exist", false); + assertTrue(false, "Able to create table that should already exist"); } catch (TableExistsException tee) { LOG.info("Table already exists as expected"); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestartFailover.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestartFailover.java index 64ca75217928..d187f2308f60 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestartFailover.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestartFailover.java @@ -17,10 +17,10 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.List; @@ -29,7 +29,6 @@ import java.util.stream.Collectors; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.CompatibilityFactory; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.StartTestingClusterOption; import org.apache.hadoop.hbase.TableName; @@ -45,19 +44,15 @@ import org.apache.hadoop.hbase.test.MetricsAssertHelper; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestClusterRestartFailover extends AbstractTestRestartCluster { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestClusterRestartFailover.class); - private static final Logger LOG = LoggerFactory.getLogger(TestClusterRestartFailover.class); private static final MetricsAssertHelper metricsHelper = CompatibilityFactory.getInstance(MetricsAssertHelper.class); @@ -87,8 +82,8 @@ public void test() throws Exception { UTIL.waitFor(60000, () -> getServerStateNode(SERVER_FOR_TEST) != null); ServerStateNode serverNode = getServerStateNode(SERVER_FOR_TEST); assertNotNull(serverNode); - assertTrue("serverNode should be ONLINE when cluster runs normally", - serverNode.isInState(ServerState.ONLINE)); + assertTrue(serverNode.isInState(ServerState.ONLINE), + "serverNode should be ONLINE when cluster runs normally"); SCP_LATCH = new CountDownLatch(1); @@ -122,23 +117,22 @@ public String explainFailure() throws Exception { .filter(p -> (p instanceof ServerCrashProcedure) && ((ServerCrashProcedure) p).getServerName().equals(SERVER_FOR_TEST)) .findAny(); - assertTrue("Should have one SCP for " + SERVER_FOR_TEST, procedure.isPresent()); - assertEquals("Submit the SCP for the same serverName " + SERVER_FOR_TEST + " which should fail", - Procedure.NO_PROC_ID, - UTIL.getHBaseCluster().getMaster().getServerManager().expireServer(SERVER_FOR_TEST)); + assertTrue(procedure.isPresent(), "Should have one SCP for " + SERVER_FOR_TEST); + assertEquals(Procedure.NO_PROC_ID, + UTIL.getHBaseCluster().getMaster().getServerManager().expireServer(SERVER_FOR_TEST), + "Submit the SCP for the same serverName " + SERVER_FOR_TEST + " which should fail"); // Wait the SCP to finish LOG.info("Waiting on latch"); SCP_LATCH.countDown(); UTIL.waitFor(60000, () -> procedure.get().isFinished()); - assertNull("serverNode should be deleted after SCP finished", - getServerStateNode(SERVER_FOR_TEST)); + assertNull(getServerStateNode(SERVER_FOR_TEST), + "serverNode should be deleted after SCP finished"); - assertEquals( + assertEquals(Procedure.NO_PROC_ID, + UTIL.getHBaseCluster().getMaster().getServerManager().expireServer(SERVER_FOR_TEST), "Even when the SCP is finished, the duplicate SCP should not be scheduled for " - + SERVER_FOR_TEST, - Procedure.NO_PROC_ID, - UTIL.getHBaseCluster().getMaster().getServerManager().expireServer(SERVER_FOR_TEST)); + + SERVER_FOR_TEST); MetricsMasterSource masterSource = UTIL.getHBaseCluster().getMaster().getMasterMetrics().getMetricsSource(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestartFailoverSplitWithoutZk.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestartFailoverSplitWithoutZk.java index 8889abfdca87..c5cc4fa11b88 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestartFailoverSplitWithoutZk.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestartFailoverSplitWithoutZk.java @@ -17,19 +17,14 @@ */ package org.apache.hadoop.hbase.master; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestClusterRestartFailoverSplitWithoutZk extends TestClusterRestartFailover { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestClusterRestartFailoverSplitWithoutZk.class); - @Override protected boolean splitWALCoordinatedByZk() { return false; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestartSplitWithoutZk.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestartSplitWithoutZk.java index 9c7806ed4187..b2ea531e9555 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestartSplitWithoutZk.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterRestartSplitWithoutZk.java @@ -17,19 +17,14 @@ */ package org.apache.hadoop.hbase.master; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestClusterRestartSplitWithoutZk extends TestClusterRestart { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestClusterRestartSplitWithoutZk.class); - @Override protected boolean splitWALCoordinatedByZk() { return false; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterStatusPublisher.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterStatusPublisher.java index ef22776aba07..8e21501d7d77 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterStatusPublisher.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestClusterStatusPublisher.java @@ -17,31 +17,28 @@ */ package org.apache.hadoop.hbase.master; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.ArrayList; import java.util.List; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.ManualEnvironmentEdge; import org.apache.hadoop.hbase.util.Pair; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; -@Category({ MasterTests.class, SmallTests.class }) // Plays with the ManualEnvironmentEdge +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) // Plays with the ManualEnvironmentEdge public class TestClusterStatusPublisher { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestClusterStatusPublisher.class); - private ManualEnvironmentEdge mee = new ManualEnvironmentEdge(); - @Before + @BeforeEach public void before() { mee.setValue(0); EnvironmentEdgeManager.injectEdge(mee); @@ -56,7 +53,7 @@ protected List> getDeadServers(long since) { } }; - Assert.assertTrue(csp.generateDeadServersListToSend().isEmpty()); + assertTrue(csp.generateDeadServersListToSend().isEmpty()); } @Test @@ -80,10 +77,10 @@ protected List> getDeadServers(long since) { mee.setValue(2); for (int i = 0; i < ClusterStatusPublisher.NB_SEND; i++) { - Assert.assertEquals("i=" + i, 1, csp.generateDeadServersListToSend().size()); + assertEquals(1, csp.generateDeadServersListToSend().size(), "i=" + i); } mee.setValue(1000); - Assert.assertTrue(csp.generateDeadServersListToSend().isEmpty()); + assertTrue(csp.generateDeadServersListToSend().isEmpty()); } @Test @@ -103,34 +100,34 @@ protected List> getDeadServers(long since) { mee.setValue(3); List allSNS = csp.generateDeadServersListToSend(); - Assert.assertEquals(10, ClusterStatusPublisher.MAX_SERVER_PER_MESSAGE); - Assert.assertEquals(10, allSNS.size()); + assertEquals(10, ClusterStatusPublisher.MAX_SERVER_PER_MESSAGE); + assertEquals(10, allSNS.size()); List nextMes = csp.generateDeadServersListToSend(); - Assert.assertEquals(10, nextMes.size()); + assertEquals(10, nextMes.size()); for (ServerName sn : nextMes) { if (!allSNS.contains(sn)) { allSNS.add(sn); } } - Assert.assertEquals(20, allSNS.size()); + assertEquals(20, allSNS.size()); nextMes = csp.generateDeadServersListToSend(); - Assert.assertEquals(10, nextMes.size()); + assertEquals(10, nextMes.size()); for (ServerName sn : nextMes) { if (!allSNS.contains(sn)) { allSNS.add(sn); } } - Assert.assertEquals(25, allSNS.size()); + assertEquals(25, allSNS.size()); nextMes = csp.generateDeadServersListToSend(); - Assert.assertEquals(10, nextMes.size()); + assertEquals(10, nextMes.size()); for (ServerName sn : nextMes) { if (!allSNS.contains(sn)) { allSNS.add(sn); } } - Assert.assertEquals(25, allSNS.size()); + assertEquals(25, allSNS.size()); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestDLSAsyncFSWAL.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestDLSAsyncFSWAL.java index e9864263f8bf..5fa4ba958957 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestDLSAsyncFSWAL.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestDLSAsyncFSWAL.java @@ -17,19 +17,14 @@ */ package org.apache.hadoop.hbase.master; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestDLSAsyncFSWAL extends AbstractTestDLS { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestDLSAsyncFSWAL.class); - @Override protected String getWalProvider() { return "asyncfs"; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestDLSFSHLog.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestDLSFSHLog.java index 0b63455e0ae5..d1dfa5f90a8a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestDLSFSHLog.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestDLSFSHLog.java @@ -17,19 +17,14 @@ */ package org.apache.hadoop.hbase.master; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestDLSFSHLog extends AbstractTestDLS { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestDLSFSHLog.class); - @Override protected String getWalProvider() { return "filesystem"; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestDeadServer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestDeadServer.java index 97ee4ccee6e0..33743e83ec86 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestDeadServer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestDeadServer.java @@ -17,13 +17,13 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; import java.util.Set; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; @@ -35,19 +35,14 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.ManualEnvironmentEdge; import org.apache.hadoop.hbase.util.Pair; -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; - -@Category({ MasterTests.class, MediumTests.class }) -public class TestDeadServer { +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestDeadServer.class); +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) +public class TestDeadServer { private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); @@ -56,12 +51,12 @@ public class TestDeadServer { final ServerName hostname1234 = ServerName.valueOf("127.0.0.2", 1234, 4L); final ServerName hostname12345 = ServerName.valueOf("127.0.0.2", 12345, 4L); - @BeforeClass + @BeforeAll public static void setupBeforeClass() throws Exception { TEST_UTIL.startMiniCluster(); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -123,13 +118,13 @@ public void testSortExtract() { d.putIfAbsent(hostname12345); List> copy = d.copyDeadServersSince(2L); - Assert.assertEquals(2, copy.size()); + assertEquals(2, copy.size()); - Assert.assertEquals(hostname1234, copy.get(0).getFirst()); - Assert.assertEquals(Long.valueOf(2L), copy.get(0).getSecond()); + assertEquals(hostname1234, copy.get(0).getFirst()); + assertEquals(Long.valueOf(2L), copy.get(0).getSecond()); - Assert.assertEquals(hostname12345, copy.get(1).getFirst()); - Assert.assertEquals(Long.valueOf(3L), copy.get(1).getSecond()); + assertEquals(hostname12345, copy.get(1).getFirst()); + assertEquals(Long.valueOf(3L), copy.get(1).getSecond()); EnvironmentEdgeManager.reset(); } @@ -140,13 +135,13 @@ public void testClean() { d.putIfAbsent(hostname123); d.cleanPreviousInstance(hostname12345); - Assert.assertFalse(d.isEmpty()); + assertFalse(d.isEmpty()); d.cleanPreviousInstance(hostname1234); - Assert.assertFalse(d.isEmpty()); + assertFalse(d.isEmpty()); d.cleanPreviousInstance(hostname123_2); - Assert.assertTrue(d.isEmpty()); + assertTrue(d.isEmpty()); } @Test @@ -154,17 +149,17 @@ public void testClearDeadServer() { DeadServer d = new DeadServer(); d.putIfAbsent(hostname123); d.putIfAbsent(hostname1234); - Assert.assertEquals(2, d.size()); + assertEquals(2, d.size()); d.removeDeadServer(hostname123); - Assert.assertEquals(1, d.size()); + assertEquals(1, d.size()); d.removeDeadServer(hostname1234); - Assert.assertTrue(d.isEmpty()); + assertTrue(d.isEmpty()); d.putIfAbsent(hostname1234); - Assert.assertFalse(d.removeDeadServer(hostname123_2)); - Assert.assertEquals(1, d.size()); - Assert.assertTrue(d.removeDeadServer(hostname1234)); - Assert.assertTrue(d.isEmpty()); + assertFalse(d.removeDeadServer(hostname123_2)); + assertEquals(1, d.size()); + assertTrue(d.removeDeadServer(hostname1234)); + assertTrue(d.isEmpty()); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetInfoPort.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetInfoPort.java index 0eec58f91572..52da25c4edfc 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetInfoPort.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetInfoPort.java @@ -17,38 +17,33 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Trivial test to confirm that we do not get 0 infoPort. See HBASE-12863. */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestGetInfoPort { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestGetInfoPort.class); - private final HBaseTestingUtil testUtil = new HBaseTestingUtil(); - @Before + @BeforeEach public void setUp() throws Exception { testUtil.getConfiguration().setInt(HConstants.MASTER_INFO_PORT, 0); testUtil.startMiniCluster(); } - @After + @AfterEach public void tearDown() throws Exception { testUtil.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetLastFlushedSequenceId.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetLastFlushedSequenceId.java index 0fb910147180..b7c533a859ca 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetLastFlushedSequenceId.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetLastFlushedSequenceId.java @@ -17,13 +17,12 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.List; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.NamespaceDescriptor; @@ -36,11 +35,10 @@ import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.JVMClusterUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos.RegionStoreSequenceIds; @@ -48,13 +46,9 @@ * Trivial test to confirm that we can get last flushed sequence id by encodedRegionName. See * HBASE-12715. */ -@Category(MediumTests.class) +@Tag(MediumTests.TAG) public class TestGetLastFlushedSequenceId { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestGetLastFlushedSequenceId.class); - private final HBaseTestingUtil testUtil = new HBaseTestingUtil(); private final TableName tableName = TableName.valueOf(getClass().getSimpleName(), "test"); @@ -63,13 +57,13 @@ public class TestGetLastFlushedSequenceId { private final byte[][] families = new byte[][] { family }; - @Before + @BeforeEach public void setUp() throws Exception { testUtil.getConfiguration().setInt("hbase.regionserver.msginterval", 1000); testUtil.startMiniCluster(); } - @After + @AfterEach public void tearDown() throws Exception { testUtil.shutdownMiniCluster(); } @@ -103,8 +97,8 @@ public void test() throws IOException, InterruptedException { Thread.sleep(2000); ids = testUtil.getHBaseCluster().getMaster().getServerManager() .getLastFlushedSequenceId(region.getRegionInfo().getEncodedNameAsBytes()); - assertTrue(ids.getLastFlushedSequenceId() + " > " + storeSequenceId, - ids.getLastFlushedSequenceId() > storeSequenceId); + assertTrue(ids.getLastFlushedSequenceId() > storeSequenceId, + ids.getLastFlushedSequenceId() + " > " + storeSequenceId); assertEquals(ids.getLastFlushedSequenceId(), ids.getStoreSequenceId(0).getSequenceId()); table.close(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetReplicationLoad.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetReplicationLoad.java index ae9554ae0fc4..020df268fecf 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetReplicationLoad.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetReplicationLoad.java @@ -17,13 +17,12 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.HashMap; import java.util.List; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.SingleProcessHBaseCluster; @@ -34,11 +33,10 @@ import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Pair; import org.apache.zookeeper.KeeperException; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,11 +44,9 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos; import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestGetReplicationLoad { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestGetReplicationLoad.class); private static final Logger LOG = LoggerFactory.getLogger(TestGetReplicationLoad.class); @@ -64,7 +60,7 @@ public MyMaster(Configuration conf) throws IOException, KeeperException, Interru } } - @BeforeClass + @BeforeAll public static void startCluster() throws Exception { LOG.info("Starting cluster"); TEST_UTIL = new HBaseTestingUtil(); @@ -78,7 +74,7 @@ public static void startCluster() throws Exception { master = cluster.getMaster(); } - @AfterClass + @AfterAll public static void after() throws Exception { if (TEST_UTIL != null) { TEST_UTIL.shutdownMiniCluster(); @@ -121,12 +117,13 @@ public void testGetReplicationMetrics() throws Exception { master.getMasterRpcServices().regionServerReport(null, request.build()); HashMap>> replicationLoad = master.getReplicationLoad(new ServerName[] { serverName }); - assertEquals("peer size ", 2, replicationLoad.size()); - assertEquals("load size ", 1, replicationLoad.get(peer1).size()); - assertEquals("log queue size of peer1", sizeOfLogQueue, - replicationLoad.get(peer1).get(0).getSecond().getSizeOfLogQueue()); - assertEquals("replication lag of peer2", replicationLag + 1, - replicationLoad.get(peer2).get(0).getSecond().getReplicationLag()); + assertEquals(2, replicationLoad.size(), "peer size "); + assertEquals(1, replicationLoad.get(peer1).size(), "load size "); + assertEquals(sizeOfLogQueue, replicationLoad.get(peer1).get(0).getSecond().getSizeOfLogQueue(), + "log queue size of peer1"); + assertEquals(replicationLag + 1, + replicationLoad.get(peer2).get(0).getSecond().getReplicationLag(), + "replication lag of peer2"); master.stopMaster(); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterCommandLine.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterCommandLine.java index 89e751f3df7f..d12253d7a816 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterCommandLine.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterCommandLine.java @@ -17,23 +17,18 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestHMasterCommandLine { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestHMasterCommandLine.class); - private static final HBaseTestingUtil TESTING_UTIL = new HBaseTestingUtil(); @Test diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterRPCException.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterRPCException.java index c22fbb7a01b7..d2d619676de7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterRPCException.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestHMasterRPCException.java @@ -17,11 +17,10 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -34,11 +33,10 @@ import org.apache.hadoop.hbase.zookeeper.ZKUtil; import org.apache.hadoop.hbase.zookeeper.ZKWatcher; import org.apache.zookeeper.KeeperException; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,13 +47,10 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.IsMasterRunningRequest; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestHMasterRPCException { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestHMasterRPCException.class); - private static final Logger LOG = LoggerFactory.getLogger(TestHMasterRPCException.class); private final HBaseTestingUtil testUtil = new HBaseTestingUtil(); @@ -64,7 +59,7 @@ public class TestHMasterRPCException { private RpcClient rpcClient; - @Before + @BeforeEach public void setUp() throws Exception { Configuration conf = testUtil.getConfiguration(); conf.set(HConstants.MASTER_PORT, "0"); @@ -78,7 +73,7 @@ public void setUp() throws Exception { rpcClient = RpcClientFactory.createClient(conf, HConstants.CLUSTER_ID_DEFAULT); } - @After + @AfterEach public void tearDown() throws IOException { if (rpcClient != null) { rpcClient.close(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestListTablesByState.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestListTablesByState.java index 224939f78392..fae7f764c6c2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestListTablesByState.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestListTablesByState.java @@ -17,7 +17,8 @@ */ package org.apache.hadoop.hbase.master; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import static org.junit.jupiter.api.Assertions.assertEquals; + import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; @@ -27,19 +28,15 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestListTablesByState { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestListTablesByState.class); private static HBaseTestingUtil UTIL; private static Admin ADMIN; @@ -50,14 +47,14 @@ public class TestListTablesByState { .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(COLUMN).setMaxVersions(3).build()) .build(); - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { UTIL = new HBaseTestingUtil(); UTIL.startMiniCluster(SLAVES); ADMIN = UTIL.getAdmin(); } - @Before + @BeforeEach public void before() throws Exception { if (ADMIN.tableExists(TABLE)) { if (ADMIN.isTableEnabled(TABLE)) { @@ -72,21 +69,21 @@ public void before() throws Exception { public void testListTableNamesByState() throws Exception { ADMIN.createTable(TABLE_DESC); ADMIN.disableTable(TABLE); - Assert.assertEquals(ADMIN.listTableNamesByState(false).get(0), TABLE); + assertEquals(ADMIN.listTableNamesByState(false).get(0), TABLE); ADMIN.enableTable(TABLE); - Assert.assertEquals(ADMIN.listTableNamesByState(true).get(0), TABLE); + assertEquals(ADMIN.listTableNamesByState(true).get(0), TABLE); } @Test public void testListTableDescriptorByState() throws Exception { ADMIN.createTable(TABLE_DESC); ADMIN.disableTable(TABLE); - Assert.assertEquals(ADMIN.listTableDescriptorsByState(false).get(0).getTableName(), TABLE); + assertEquals(ADMIN.listTableDescriptorsByState(false).get(0).getTableName(), TABLE); ADMIN.enableTable(TABLE); - Assert.assertEquals(ADMIN.listTableDescriptorsByState(true).get(0).getTableName(), TABLE); + assertEquals(ADMIN.listTableDescriptorsByState(true).get(0).getTableName(), TABLE); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { if (ADMIN != null) { ADMIN.close(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestLoadProcedureError.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestLoadProcedureError.java index 13d819088d20..4399e2270e66 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestLoadProcedureError.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestLoadProcedureError.java @@ -17,10 +17,9 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.util.concurrent.CountDownLatch; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; @@ -32,24 +31,20 @@ import org.apache.hadoop.hbase.procedure2.ProcedureYieldException; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.ProcedureState; /** * Testcase for HBASE-21490. */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestLoadProcedureError { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestLoadProcedureError.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static TableName NAME = TableName.valueOf("Load"); @@ -103,12 +98,12 @@ public TableOperationType getTableOperationType() { } } - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.startMiniCluster(1); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java index 41848a58b784..16e1bf3a2e9e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMaster.java @@ -17,11 +17,11 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.List; @@ -32,7 +32,6 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.CatalogFamilyFormat; import org.apache.hadoop.hbase.ClientMetaTableAccessor; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MetaTableAccessor; @@ -58,34 +57,34 @@ import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.hbase.util.Threads; import org.apache.hadoop.util.StringUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hbase.thirdparty.com.google.common.base.Joiner; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMaster { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule.forClass(TestMaster.class); - private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static final Logger LOG = LoggerFactory.getLogger(TestMaster.class); private static final TableName TABLENAME = TableName.valueOf("TestMaster"); private static final byte[] FAMILYNAME = Bytes.toBytes("fam"); private static Admin admin; + private String testMethodName; - @Rule - public TestName name = new TestName(); + @BeforeEach + public void setTestMethod(TestInfo testInfo) { + testMethodName = testInfo.getTestMethod().get().getName(); + } - @BeforeClass + @BeforeAll public static void beforeAllTests() throws Exception { // we will retry operations when PleaseHoldException is thrown TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 3); @@ -99,7 +98,7 @@ public static void beforeAllTests() throws Exception { admin = TEST_UTIL.getAdmin(); } - @AfterClass + @AfterAll public static void afterAllTests() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -190,7 +189,7 @@ public void testMoveRegionWhenNotInitialized() { @Test public void testMoveThrowsUnknownRegionException() throws IOException { - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(testMethodName); TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tableName); ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("value")).build(); @@ -211,7 +210,7 @@ public void testMoveThrowsUnknownRegionException() throws IOException { @Test public void testMoveThrowsPleaseHoldException() throws IOException { - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(testMethodName); HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tableName); ColumnFamilyDescriptor columnFamilyDescriptor = diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterAbortAndRSGotKilled.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterAbortAndRSGotKilled.java index 216e47b59c64..983d15fabbad 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterAbortAndRSGotKilled.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterAbortAndRSGotKilled.java @@ -17,10 +17,11 @@ */ package org.apache.hadoop.hbase.master; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.IOException; import java.util.Optional; import java.util.concurrent.CountDownLatch; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.RegionInfo; @@ -37,24 +38,19 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.JVMClusterUtil; import org.apache.hadoop.hbase.util.Threads; -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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterAbortAndRSGotKilled { private static Logger LOG = LoggerFactory.getLogger(TestMasterAbortAndRSGotKilled.class.getName()); - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterAbortAndRSGotKilled.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static TableName TABLE_NAME = TableName.valueOf("test"); @@ -63,7 +59,7 @@ public class TestMasterAbortAndRSGotKilled { private static byte[] CF = Bytes.toBytes("cf"); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.getConfiguration().setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, DelayCloseCP.class.getName()); @@ -73,7 +69,7 @@ public static void setUp() throws Exception { UTIL.waitTableAvailable(TABLE_NAME); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { UTIL.shutdownMiniCluster(); } @@ -104,8 +100,8 @@ public void test() throws Exception { // wait until master initialized UTIL.waitFor(30000, () -> UTIL.getMiniHBaseCluster().getMaster() != null && UTIL.getMiniHBaseCluster().getMaster().isInitialized()); - Assert.assertTrue("Should be 3 RS after master restart", - UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().size() == 3); + assertTrue(UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().size() == 3, + "Should be 3 RS after master restart"); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterBalanceThrottling.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterBalanceThrottling.java index 09d9867f5d9d..fbad18de3b40 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterBalanceThrottling.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterBalanceThrottling.java @@ -17,12 +17,11 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -31,31 +30,27 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -@Ignore // SimpleLoadBalancer seems borked whether AMv2 or not. Disabling till gets attention. -@Category({ MasterTests.class, MediumTests.class }) +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +@Disabled // SimpleLoadBalancer seems borked whether AMv2 or not. Disabling till gets attention. +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterBalanceThrottling { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterBalanceThrottling.class); - private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static final byte[] FAMILYNAME = Bytes.toBytes("fam"); - @Before + @BeforeEach public void setupConfiguration() { TEST_UTIL.getConfiguration().set(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, "org.apache.hadoop.hbase.master.balancer.SimpleLoadBalancer"); } - @After + @AfterEach public void shutdown() throws Exception { TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_BALANCER_MAX_BALANCING, HConstants.DEFAULT_HBASE_BALANCER_PERIOD); @@ -83,7 +78,7 @@ public void testThrottlingByBalanceInterval() throws Exception { stop.set(true); checker.interrupt(); checker.join(); - assertTrue("max regions in transition: " + maxCount.get(), maxCount.get() == 1); + assertTrue(maxCount.get() == 1, "max regions in transition: " + maxCount.get()); TEST_UTIL.deleteTable(tableName); } @@ -107,7 +102,7 @@ public void testThrottlingByMaxRitPercent() throws Exception { checker.interrupt(); checker.join(); // The max number of regions in transition is 100 * 0.05 = 5 - assertTrue("max regions in transition: " + maxCount.get(), maxCount.get() == 5); + assertTrue(maxCount.get() == 5, "max regions in transition: " + maxCount.get()); TEST_UTIL.deleteTable(tableName); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterBalancerNPE.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterBalancerNPE.java index 7dd4f753665a..ab21025d7a9b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterBalancerNPE.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterBalancerNPE.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; @@ -26,7 +26,6 @@ import java.util.Map; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.atomic.AtomicReference; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; @@ -36,29 +35,28 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterBalancerNPE { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterBalancerNPE.class); - private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static final byte[] FAMILYNAME = Bytes.toBytes("fam"); - @Rule - public TestName name = new TestName(); + private String testMethodName; + + @BeforeEach + public void setTestMethod(TestInfo testInfo) { + testMethodName = testInfo.getTestMethod().get().getName(); + } - @Before + @BeforeEach public void setupConfiguration() { /** * Make {@link BalancerChore} not run,so does not disrupt the test. @@ -66,7 +64,7 @@ public void setupConfiguration() { HMaster.setDisableBalancerChoreForTest(true); } - @After + @AfterEach public void shutdown() throws Exception { HMaster.setDisableBalancerChoreForTest(false); TEST_UTIL.shutdownMiniCluster(); @@ -80,7 +78,7 @@ public void shutdown() throws Exception { public void testBalancerNPE() throws Exception { TEST_UTIL.startMiniCluster(2); TEST_UTIL.getAdmin().balancerSwitch(false, true); - TableName tableName = createTable(name.getMethodName()); + TableName tableName = createTable(testMethodName); final HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); List regionInfos = TEST_UTIL.getAdmin().getRegions(tableName); assertTrue(regionInfos.size() == 1); 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 0692e4a33d69..31da027db024 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 @@ -17,9 +17,11 @@ */ package org.apache.hadoop.hbase.master; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.lang.reflect.Field; import java.util.ArrayList; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.ScheduledChore; import org.apache.hadoop.hbase.StartTestingClusterOption; @@ -32,34 +34,29 @@ import org.apache.hadoop.hbase.master.janitor.CatalogJanitor; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Tests to validate if HMaster default chores are scheduled */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterChoreScheduled { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterChoreScheduled.class); - private static HMaster hMaster; private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.startMiniCluster(StartTestingClusterOption.builder().numRegionServers(1).build()); hMaster = UTIL.getMiniHBaseCluster().getMaster(); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { UTIL.shutdownMiniCluster(); } @@ -132,8 +129,8 @@ private E getChoreObj(String fieldName) { } private void testIfChoreScheduled(E choreObj) { - Assert.assertNotNull(choreObj); - Assert.assertTrue(hMaster.getChoreService().isChoreScheduled(choreObj)); + assertNotNull(choreObj); + assertTrue(hMaster.getChoreService().isChoreScheduled(choreObj)); } } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterCoprocessorServices.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterCoprocessorServices.java index e0c13b42f9d9..b8988944fdf5 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterCoprocessorServices.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterCoprocessorServices.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -26,7 +26,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.JMXListener; import org.apache.hadoop.hbase.coprocessor.MasterCoprocessor; import org.apache.hadoop.hbase.coprocessor.MasterObserver; @@ -35,10 +34,9 @@ import org.apache.hadoop.hbase.security.access.AccessController; import org.apache.hadoop.hbase.security.visibility.VisibilityController; import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback; import org.apache.hbase.thirdparty.com.google.protobuf.RpcController; @@ -67,13 +65,9 @@ * Tests that the MasterRpcServices is correctly searching for implementations of the Coprocessor * Service and not just the "default" implementations of those services. */ -@Category({ SmallTests.class }) +@Tag(SmallTests.TAG) public class TestMasterCoprocessorServices { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterCoprocessorServices.class); - private static class MockAccessController implements AccessControlService.Interface, MasterCoprocessor, RegionCoprocessor, MasterObserver, RegionObserver { @@ -135,7 +129,7 @@ public void listLabels(RpcController controller, ListLabelsRequest request, private MasterRpcServices masterServices; @SuppressWarnings("unchecked") - @Before + @BeforeEach public void setup() { masterServices = mock(MasterRpcServices.class); when(masterServices.hasAccessControlServiceCoprocessor(any(MasterCoprocessorHost.class))) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterDryRunBalancer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterDryRunBalancer.java index c8da2759e65d..3d048c7a38fe 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterDryRunBalancer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterDryRunBalancer.java @@ -17,12 +17,11 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; @@ -34,22 +33,19 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.After; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterDryRunBalancer { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterDryRunBalancer.class); private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static final byte[] FAMILYNAME = Bytes.toBytes("fam"); - @After + @AfterEach public void shutdown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailover.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailover.java index 5e6b8db58243..06b539bb7ee5 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailover.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailover.java @@ -17,14 +17,13 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; import java.util.concurrent.TimeUnit; import org.apache.hadoop.hbase.ClusterMetrics; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.SingleProcessHBaseCluster; @@ -35,24 +34,24 @@ import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread; import org.apache.hadoop.hbase.zookeeper.MetaTableLocator; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ FlakeyTests.class, LargeTests.class }) +@Tag(FlakeyTests.TAG) +@Tag(LargeTests.TAG) public class TestMasterFailover { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterFailover.class); - private static final Logger LOG = LoggerFactory.getLogger(TestMasterFailover.class); - @Rule - public TestName name = new TestName(); + private String testMethodName; + + @BeforeEach + public void setTestMethod(TestInfo testInfo) { + testMethodName = testInfo.getTestMethod().get().getName(); + } /** * Simple test of master failover. @@ -194,8 +193,8 @@ public void testMetaInTransitionWhenMasterFailover() throws Exception { // meta should remain where it was RegionState metaState = MetaTableLocator.getMetaRegionState(hrs.getZooKeeper()); - assertEquals("hbase:meta should be online on RS", metaState.getServerName(), metaServerName); - assertEquals("hbase:meta should be online on RS", State.OPEN, metaState.getState()); + assertEquals(metaServerName, metaState.getServerName(), "hbase:meta should be online on RS"); + assertEquals(metaState.getState(), State.OPEN, "hbase:meta should be online on RS"); // Start up a new master LOG.info("Starting up a new master"); @@ -206,8 +205,8 @@ public void testMetaInTransitionWhenMasterFailover() throws Exception { // ensure meta is still deployed on RS metaState = MetaTableLocator.getMetaRegionState(activeMaster.getZooKeeper()); - assertEquals("hbase:meta should be online on RS", metaState.getServerName(), metaServerName); - assertEquals("hbase:meta should be online on RS", State.OPEN, metaState.getState()); + assertEquals(metaServerName, metaState.getServerName(), "hbase:meta should be online on RS"); + assertEquals(metaState.getState(), State.OPEN, "hbase:meta should be online on RS"); // Done, shutdown the cluster } finally { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailoverBalancerPersistence.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailoverBalancerPersistence.java index e80c2c73b556..7d8690384efa 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailoverBalancerPersistence.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFailoverBalancerPersistence.java @@ -17,13 +17,12 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.List; import org.apache.hadoop.hbase.ClusterMetrics; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.MasterNotRunningException; import org.apache.hadoop.hbase.SingleProcessHBaseCluster; @@ -31,17 +30,13 @@ import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.util.JVMClusterUtil; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestMasterFailoverBalancerPersistence { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterFailoverBalancerPersistence.class); - /** * Test that if the master fails, the load balancer maintains its state (running or not) when the * next master takes over diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFileSystem.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFileSystem.java index 0f43e97abcf6..dc62e49ba3b3 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFileSystem.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFileSystem.java @@ -17,13 +17,12 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.util.List; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Table; @@ -32,39 +31,38 @@ import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.CommonFSUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Test the master filesystem in a local cluster */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterFileSystem { + private String testMethodName; - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterFileSystem.class); - - @Rule - public TestName name = new TestName(); + @BeforeEach + public void setTestMethod(TestInfo testInfo) { + testMethodName = testInfo.getTestMethod().get().getName(); + } private static final Logger LOG = LoggerFactory.getLogger(TestMasterFileSystem.class); private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); - @BeforeClass + @BeforeAll public static void setupTest() throws Exception { UTIL.startMiniCluster(); } - @AfterClass + @AfterAll public static void teardownTest() throws Exception { UTIL.shutdownMiniCluster(); } @@ -87,7 +85,7 @@ public void testCheckNoTempDir() throws Exception { final MasterFileSystem masterFileSystem = UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem(); - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(testMethodName); final byte[] FAM = Bytes.toBytes("fam"); final byte[][] splitKeys = new byte[][] { Bytes.toBytes("b"), Bytes.toBytes("c"), Bytes.toBytes("d") }; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFileSystemWithStoreFileTracking.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFileSystemWithStoreFileTracking.java index b3fadc7ed27a..6a6899968990 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFileSystemWithStoreFileTracking.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFileSystemWithStoreFileTracking.java @@ -19,45 +19,35 @@ import static org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory.TRACKER_IMPL; import static org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory.Trackers.FILE; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Test the master filesystem in a local cluster with Store File Tracking explicitly set in global * config */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterFileSystemWithStoreFileTracking { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterFileSystemWithStoreFileTracking.class); - - @Rule - public TestName name = new TestName(); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); - @BeforeClass + @BeforeAll public static void setupTest() throws Exception { UTIL.getConfiguration().set(TRACKER_IMPL, FILE.name()); UTIL.startMiniCluster(); } - @AfterClass + @AfterAll public static void teardownTest() throws Exception { UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFileSystemWithWALDir.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFileSystemWithWALDir.java index 49428f356d86..3c8687bf7efa 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFileSystemWithWALDir.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterFileSystemWithWALDir.java @@ -17,40 +17,35 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.StartTestingClusterOption; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.CommonFSUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Test the master filesystem in a local cluster */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterFileSystemWithWALDir { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterFileSystemWithWALDir.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); - @BeforeClass + @BeforeAll public static void setupTest() throws Exception { // Set createWALDir to true and use default values for other options. UTIL.startMiniCluster(StartTestingClusterOption.builder().createWALDir(true).build()); } - @AfterClass + @AfterAll public static void teardownTest() throws Exception { UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterHandlerFullWhenTransitRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterHandlerFullWhenTransitRegion.java index f522e2449003..d921f2e14473 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterHandlerFullWhenTransitRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterHandlerFullWhenTransitRegion.java @@ -19,7 +19,6 @@ import java.io.IOException; import java.util.Optional; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -31,28 +30,24 @@ import org.apache.hadoop.hbase.coprocessor.RegionObserver; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestMasterHandlerFullWhenTransitRegion { private static Logger LOG = LoggerFactory.getLogger(TestMasterHandlerFullWhenTransitRegion.class.getName()); - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterHandlerFullWhenTransitRegion.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static final String TABLENAME = "table"; - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.getConfiguration().setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, DelayOpenCP.class.getName()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java index 09618b3d899e..a64193ad1f15 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetrics.java @@ -22,7 +22,6 @@ import java.util.HashMap; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.CompatibilityFactory; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.ServerMetricsBuilder; import org.apache.hadoop.hbase.ServerName; @@ -34,11 +33,10 @@ import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.zookeeper.KeeperException; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,13 +49,10 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupResponse; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterMetrics { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterMetrics.class); - private static final Logger LOG = LoggerFactory.getLogger(TestMasterMetrics.class); private static final MetricsAssertHelper metricsHelper = CompatibilityFactory.getInstance(MetricsAssertHelper.class); @@ -113,7 +108,7 @@ protected void tryRegionServerReport(long reportStartTime, long reportEndTime) { } } - @BeforeClass + @BeforeAll public static void startCluster() throws Exception { LOG.info("Starting cluster"); // Set master class and use default values for other options. @@ -126,7 +121,7 @@ public static void startCluster() throws Exception { master = cluster.getMaster(); } - @AfterClass + @AfterAll public static void after() throws Exception { master.stopMaster(); TEST_UTIL.shutdownMiniCluster(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetricsWrapper.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetricsWrapper.java index d1389ee68e9f..dc4f1f3b267e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetricsWrapper.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterMetricsWrapper.java @@ -17,13 +17,12 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.List; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; @@ -40,32 +39,28 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.PairOfSameType; import org.apache.hadoop.hbase.util.Threads; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterMetricsWrapper { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterMetricsWrapper.class); - private static final Logger LOG = LoggerFactory.getLogger(TestMasterMetricsWrapper.class); private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static final int NUM_RS = 4; - @BeforeClass + @BeforeAll public static void setup() throws Exception { TEST_UTIL.startMiniCluster(NUM_RS); } - @AfterClass + @AfterAll public static void teardown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterNoCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterNoCluster.java index bd4c39a36015..eaf441f86433 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterNoCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterNoCluster.java @@ -18,11 +18,12 @@ package org.apache.hadoop.hbase.master; import static org.apache.hadoop.hbase.HConstants.ZOOKEEPER_QUORUM; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Abortable; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.Waiter; @@ -35,15 +36,11 @@ import org.apache.hadoop.hbase.zookeeper.ZKWatcher; import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; import org.apache.zookeeper.KeeperException; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,21 +51,15 @@ * cluster context. TODO: Speed up the zk connection by Master. It pauses 5 seconds establishing * session. */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterNoCluster { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterNoCluster.class); - private static final Logger LOG = LoggerFactory.getLogger(TestMasterNoCluster.class); private static final HBaseTestingUtil TESTUTIL = new HBaseTestingUtil(); - @Rule - public TestName name = new TestName(); - - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { Configuration c = TESTUTIL.getConfiguration(); // We use local filesystem. Set it so it writes into the testdir. @@ -78,15 +69,15 @@ public static void setUpBeforeClass() throws Exception { TESTUTIL.startMiniZKCluster(); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TESTUTIL.shutdownMiniZKCluster(); } - @After + @AfterEach public void tearDown() throws KeeperException, ZooKeeperConnectionException, IOException { // Make sure zk is clean before we run the next test. - ZKWatcher zkw = new ZKWatcher(TESTUTIL.getConfiguration(), "@Before", new Abortable() { + ZKWatcher zkw = new ZKWatcher(TESTUTIL.getConfiguration(), "@BeforeEach", new Abortable() { @Override public void abort(String why, Throwable e) { throw new RuntimeException(why, e); @@ -140,7 +131,7 @@ public void testMasterInitWithSameClientServerZKQuorum() throws Exception { @Test public void testMasterInitWithObserverModeClientZKQuorum() throws Exception { Configuration conf = new Configuration(TESTUTIL.getConfiguration()); - Assert.assertFalse(Boolean.getBoolean(HConstants.CLIENT_ZOOKEEPER_OBSERVER_MODE)); + assertFalse(Boolean.getBoolean(HConstants.CLIENT_ZOOKEEPER_OBSERVER_MODE)); // set client ZK to some non-existing address and make sure server won't access client ZK // (server start should not be affected) conf.set(HConstants.CLIENT_ZOOKEEPER_QUORUM, HConstants.LOCALHOST); @@ -157,8 +148,8 @@ public void testMasterInitWithObserverModeClientZKQuorum() throws Exception { while (!master.isInitialized()) { Threads.sleep(200); } - Assert.assertNull(master.getMetaLocationSyncer()); - Assert.assertNull(master.masterAddressSyncer); + assertNull(master.getMetaLocationSyncer()); + assertNull(master.masterAddressSyncer); master.stopMaster(); master.join(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterOperationsForRegionReplicas.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterOperationsForRegionReplicas.java index f640c3084cb8..2a134cc7f5ac 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterOperationsForRegionReplicas.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterOperationsForRegionReplicas.java @@ -17,10 +17,10 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -37,7 +37,6 @@ import org.apache.hadoop.hbase.CatalogFamilyFormat; import org.apache.hadoop.hbase.ClientMetaTableAccessor; import org.apache.hadoop.hbase.ClusterMetrics.Option; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionLocation; @@ -61,25 +60,21 @@ import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.JVMClusterUtil; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hbase.thirdparty.com.google.common.io.Closeables; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterOperationsForRegionReplicas { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterOperationsForRegionReplicas.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionPlacement.class); private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static Connection CONNECTION = null; @@ -88,11 +83,14 @@ public class TestMasterOperationsForRegionReplicas { private final static StartTestingClusterOption option = StartTestingClusterOption.builder() .numRegionServers(numSlaves).numMasters(1).numAlwaysStandByMasters(1).build(); private static Configuration conf; + private String testMethodName; - @Rule - public TestName name = new TestName(); + @BeforeEach + public void setTestMethod(TestInfo testInfo) { + testMethodName = testInfo.getTestMethod().get().getName(); + } - @BeforeClass + @BeforeAll public static void setupBeforeClass() throws Exception { conf = TEST_UTIL.getConfiguration(); conf.setBoolean("hbase.tests.use.shortcircuit.reads", false); @@ -114,7 +112,7 @@ private static void resetConnections() throws IOException { ADMIN = CONNECTION.getAdmin(); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { Closeables.close(ADMIN, true); Closeables.close(CONNECTION, true); @@ -125,7 +123,7 @@ public static void tearDownAfterClass() throws Exception { public void testCreateTableWithSingleReplica() throws Exception { final int numRegions = 3; final int numReplica = 1; - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(testMethodName); try { TableDescriptor desc = TableDescriptorBuilder.newBuilder(tableName).setRegionReplication(numReplica) @@ -145,7 +143,7 @@ public void testCreateTableWithSingleReplica() throws Exception { @Test public void testCreateTableWithMultipleReplicas() throws Exception { - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(testMethodName); final int numRegions = 3; final int numReplica = 2; try { @@ -237,8 +235,8 @@ public void testCreateTableWithMultipleReplicas() throws Exception { TEST_UTIL.waitUntilNoRegionsInTransition(); List regions = TEST_UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager() .getRegionStates().getRegionsOfTable(tableName); - assertTrue("regions.size=" + regions.size() + ", numRegions=" + numRegions + ", numReplica=" - + numReplica, regions.size() == numRegions * (numReplica + 1)); + assertTrue(regions.size() == numRegions * (numReplica + 1), "regions.size=" + regions.size() + + ", numRegions=" + numRegions + ", numReplica=" + numReplica); // decrease the replica(earlier, table was modified to have a replica count of numReplica + 1) ADMIN.disableTable(tableName); @@ -287,7 +285,7 @@ private void assertRegionStateNotNull(List hris, int numRegions, int @Test public void testIncompleteMetaTableReplicaInformation() throws Exception { - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(testMethodName); final int numRegions = 3; final int numReplica = 2; try { @@ -386,7 +384,7 @@ private void validateSingleRegionServerAssignment(Connection connection, int num Map regionToServerMap = snapshot.getRegionToRegionServerMap(); assertEquals(regionToServerMap.size(), numRegions * numReplica); Map> serverToRegionMap = snapshot.getRegionServerToRegionMap(); - assertEquals("One Region Only", 1, serverToRegionMap.keySet().size()); + assertEquals(1, serverToRegionMap.keySet().size(), "One Region Only"); for (Map.Entry> entry : serverToRegionMap.entrySet()) { if (entry.getKey().equals(TEST_UTIL.getHBaseCluster().getMaster().getServerName())) { continue; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterQosFunction.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterQosFunction.java index 79fa8e713652..9a8cd69916d8 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterQosFunction.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterQosFunction.java @@ -21,7 +21,6 @@ import java.io.IOException; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -31,10 +30,9 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.apache.hbase.thirdparty.com.google.protobuf.ByteString; @@ -43,18 +41,15 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos; import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos; -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestMasterQosFunction extends QosTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterQosFunction.class); - private Configuration conf; private MasterRpcServices rpcServices; private MasterAnnotationReadingPriorityFunction qosFunction; - @Before + @BeforeEach public void setUp() { conf = HBaseConfiguration.create(); rpcServices = Mockito.mock(MasterRpcServices.class); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRegionMutation1.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRegionMutation1.java index 337cd3deeee0..99b1920ca17e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRegionMutation1.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRegionMutation1.java @@ -18,170 +18,41 @@ package org.apache.hadoop.hbase.master; import java.io.IOException; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; -import org.apache.hadoop.hbase.HBaseTestingUtil; -import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.RegionTooBusyException; -import org.apache.hadoop.hbase.ServerName; -import org.apache.hadoop.hbase.SingleProcessHBaseCluster; -import org.apache.hadoop.hbase.StartTestingClusterOption; -import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; import org.apache.hadoop.hbase.client.Mutation; import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.TableDescriptor; -import org.apache.hadoop.hbase.client.TableDescriptorBuilder; -import org.apache.hadoop.hbase.master.hbck.HbckChore; -import org.apache.hadoop.hbase.master.hbck.HbckReport; import org.apache.hadoop.hbase.master.region.MasterRegionFactory; import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.HRegionFileSystem; -import org.apache.hadoop.hbase.regionserver.HRegionServer; import org.apache.hadoop.hbase.regionserver.OperationStatus; import org.apache.hadoop.hbase.regionserver.RegionServerServices; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; -import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.wal.WAL; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; /** * MasterRegion related test that ensures the operations continue even when Procedure state update * encounters retriable IO errors. */ -@Category({ MasterTests.class, LargeTests.class }) -public class TestMasterRegionMutation1 { - - private static final Logger LOG = LoggerFactory.getLogger(TestMasterRegionMutation1.class); - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterRegionMutation1.class); - - @Rule - public TestName name = new TestName(); - - protected static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); - protected static ServerName rs0; +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) +public class TestMasterRegionMutation1 extends AbstractTestMasterRegionMutation { - protected static final AtomicBoolean ERROR_OUT = new AtomicBoolean(false); - private static final AtomicInteger ERROR_COUNTER = new AtomicInteger(0); - private static final AtomicBoolean FIRST_TIME_ERROR = new AtomicBoolean(true); - - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { - TEST_UTIL.getConfiguration().setClass(HConstants.REGION_IMPL, TestRegion.class, HRegion.class); - StartTestingClusterOption.Builder builder = StartTestingClusterOption.builder(); - // 1 master is expected to be aborted with this test - builder.numMasters(2).numRegionServers(3); - TEST_UTIL.startMiniCluster(builder.build()); - SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); - rs0 = cluster.getRegionServer(0).getServerName(); - TEST_UTIL.getAdmin().balancerSwitch(false, true); + AbstractTestMasterRegionMutation.setUpBeforeClass(2, TestRegion.class); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { - TEST_UTIL.shutdownMiniCluster(); - } - - @Before - public void setUp() throws Exception { - final TableName tableName = TableName.valueOf(name.getMethodName()); - TableDescriptor tableDesc = TableDescriptorBuilder.newBuilder(tableName) - .setColumnFamily(ColumnFamilyDescriptorBuilder.of("fam1")).build(); - int startKey = 0; - int endKey = 80000; - TEST_UTIL.getAdmin().createTable(tableDesc, Bytes.toBytes(startKey), Bytes.toBytes(endKey), 9); - } - - @Test - public void testMasterRegionMutations() throws Exception { - HbckChore hbckChore = new HbckChore(TEST_UTIL.getHBaseCluster().getMaster()); - SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); - - HRegionServer hRegionServer0 = cluster.getRegionServer(0); - HRegionServer hRegionServer1 = cluster.getRegionServer(1); - HRegionServer hRegionServer2 = cluster.getRegionServer(2); - int numRegions0 = hRegionServer0.getNumberOfOnlineRegions(); - int numRegions1 = hRegionServer1.getNumberOfOnlineRegions(); - int numRegions2 = hRegionServer2.getNumberOfOnlineRegions(); - - hbckChore.choreForTesting(); - HbckReport hbckReport = hbckChore.getLastReport(); - Assert.assertEquals(0, hbckReport.getInconsistentRegions().size()); - Assert.assertEquals(0, hbckReport.getOrphanRegionsOnFS().size()); - Assert.assertEquals(0, hbckReport.getOrphanRegionsOnRS().size()); - - // procedure state store update encounters retriable error, master abort is not required - ERROR_OUT.set(true); - - // move one region from server 1 to server 0 - TEST_UTIL.getAdmin() - .move(hRegionServer1.getRegions().get(0).getRegionInfo().getEncodedNameAsBytes(), rs0); - - // procedure state store update encounters retriable error, however all retries are exhausted. - // This leads to the trigger of active master abort and hence master failover. - ERROR_OUT.set(true); - - // move one region from server 2 to server 0 - TEST_UTIL.getAdmin() - .move(hRegionServer2.getRegions().get(0).getRegionInfo().getEncodedNameAsBytes(), rs0); - - HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); - - // Ensure: - // 1. num of regions before and after master abort remain same - // 2. all procedures are successfully completed - TEST_UTIL.waitFor(5000, 1000, () -> { - LOG.info("numRegions0: {} , numRegions1: {} , numRegions2: {}", numRegions0, numRegions1, - numRegions2); - LOG.info("Online regions - server0 : {} , server1: {} , server2: {}", - cluster.getRegionServer(0).getNumberOfOnlineRegions(), - cluster.getRegionServer(1).getNumberOfOnlineRegions(), - cluster.getRegionServer(2).getNumberOfOnlineRegions()); - LOG.info("Num of successfully completed procedures: {} , num of all procedures: {}", - master.getMasterProcedureExecutor().getProcedures().stream() - .filter(masterProcedureEnvProcedure -> masterProcedureEnvProcedure.getState() - == ProcedureProtos.ProcedureState.SUCCESS) - .count(), - master.getMasterProcedureExecutor().getProcedures().size()); - return (numRegions0 + numRegions1 + numRegions2) - == (cluster.getRegionServer(0).getNumberOfOnlineRegions() - + cluster.getRegionServer(1).getNumberOfOnlineRegions() - + cluster.getRegionServer(2).getNumberOfOnlineRegions()) - && master.getMasterProcedureExecutor().getProcedures().stream() - .filter(masterProcedureEnvProcedure -> masterProcedureEnvProcedure.getState() - == ProcedureProtos.ProcedureState.SUCCESS) - .count() == master.getMasterProcedureExecutor().getProcedures().size(); - }); - - // Ensure we have no inconsistent regions - TEST_UTIL.waitFor(5000, 1000, () -> { - HbckChore hbck = new HbckChore(TEST_UTIL.getHBaseCluster().getMaster()); - hbck.choreForTesting(); - HbckReport report = hbck.getLastReport(); - return report.getInconsistentRegions().isEmpty() && report.getOrphanRegionsOnFS().isEmpty() - && report.getOrphanRegionsOnRS().isEmpty(); - }); - + AbstractTestMasterRegionMutation.tearDownAfterClass(); } public static class TestRegion extends HRegion { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRegionMutation2.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRegionMutation2.java index dc918889503c..07fc156b1e6b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRegionMutation2.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRegionMutation2.java @@ -21,10 +21,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.SingleProcessHBaseCluster; -import org.apache.hadoop.hbase.StartTestingClusterOption; import org.apache.hadoop.hbase.client.Mutation; import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.TableDescriptor; @@ -36,49 +32,26 @@ import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.wal.WAL; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; /** * MasterRegion related test that ensures the operations continue even when Procedure state update * encounters non-retriable IO errors. */ -@Category({ MasterTests.class, LargeTests.class }) -public class TestMasterRegionMutation2 extends TestMasterRegionMutation1 { +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) +public class TestMasterRegionMutation2 extends AbstractTestMasterRegionMutation { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterRegionMutation2.class); - - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { - TEST_UTIL.getConfiguration().setClass(HConstants.REGION_IMPL, TestRegion.class, HRegion.class); - StartTestingClusterOption.Builder builder = StartTestingClusterOption.builder(); - // 2 masters are expected to be aborted with this test - builder.numMasters(3).numRegionServers(3); - TEST_UTIL.startMiniCluster(builder.build()); - SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); - rs0 = cluster.getRegionServer(0).getServerName(); - TEST_UTIL.getAdmin().balancerSwitch(false, true); + AbstractTestMasterRegionMutation.setUpBeforeClass(3, TestRegion.class); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { - TEST_UTIL.shutdownMiniCluster(); - } - - @Before - public void setUp() throws Exception { - super.setUp(); - } - - @Test - public void testMasterRegionMutations() throws Exception { - super.testMasterRegionMutations(); + AbstractTestMasterRegionMutation.tearDownAfterClass(); } public static class TestRegion extends HRegion { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRepairMode.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRepairMode.java index 910692d93c30..e37621c5b28f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRepairMode.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRepairMode.java @@ -17,16 +17,15 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.concurrent.TimeUnit; import java.util.stream.Stream; import java.util.stream.StreamSupport; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.StartTestingClusterOption; @@ -41,25 +40,23 @@ import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestMasterRepairMode { + private String testMethodName; - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterRepairMode.class); - - @Rule - public TestName name = new TestName(); + @BeforeEach + public void setTestMethod(TestInfo testInfo) { + testMethodName = testInfo.getTestMethod().get().getName(); + } private static final Logger LOG = LoggerFactory.getLogger(TestMasterRepairMode.class); @@ -67,12 +64,12 @@ public class TestMasterRepairMode { private static HBaseTestingUtil TEST_UTIL; - @Before + @BeforeEach public void setUp() throws Exception { TEST_UTIL = new HBaseTestingUtil(); } - @After + @AfterEach public void tearDown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -95,13 +92,13 @@ public void testNewCluster() throws Exception { try (Table table = conn.getTable(TableName.META_TABLE_NAME); ResultScanner scanner = table.getScanner(new Scan())) { - assertNotNull("Could not read meta.", scanner.next()); + assertNotNull(scanner.next(), "Could not read meta."); } } @Test public void testExistingCluster() throws Exception { - TableName testRepairMode = TableName.valueOf(name.getMethodName()); + TableName testRepairMode = TableName.valueOf(testMethodName); TEST_UTIL.startMiniCluster(); Table t = TEST_UTIL.createTable(testRepairMode, FAMILYNAME); @@ -123,17 +120,16 @@ public void testExistingCluster() throws Exception { try (Table table = conn.getTable(TableName.META_TABLE_NAME); ResultScanner scanner = table.getScanner(HConstants.TABLE_FAMILY); Stream results = StreamSupport.stream(scanner.spliterator(), false)) { - assertTrue("Did not find user table records while reading hbase:meta", - results.anyMatch(r -> Arrays.equals(r.getRow(), testRepairMode.getName()))); + assertTrue(results.anyMatch(r -> Arrays.equals(r.getRow(), testRepairMode.getName())), + "Did not find user table records while reading hbase:meta"); } // use async table so we can set the timeout and retry value to let the operation fail fast AsyncTable table = conn.toAsyncConnection().getTableBuilder(testRepairMode) .setScanTimeout(5, TimeUnit.SECONDS).setMaxRetries(2).build(); - assertThrows("Should not be able to access user-space tables in repair mode.", Exception.class, - () -> { - try (ResultScanner scanner = table.getScanner(new Scan())) { - scanner.next(); - } - }); + assertThrows(Exception.class, () -> { + try (ResultScanner scanner = table.getScanner(new Scan())) { + scanner.next(); + } + }, "Should not be able to access user-space tables in repair mode."); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRestartAfterDisablingTable.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRestartAfterDisablingTable.java index d096da3ab70a..13c2b94eb2d1 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRestartAfterDisablingTable.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterRestartAfterDisablingTable.java @@ -17,13 +17,12 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; import java.util.NavigableSet; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.SingleProcessHBaseCluster; @@ -37,26 +36,25 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestMasterRestartAfterDisablingTable { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterRestartAfterDisablingTable.class); - private static final Logger LOG = LoggerFactory.getLogger(TestMasterRestartAfterDisablingTable.class); + private String testMethodName; - @Rule - public TestName name = new TestName(); + @BeforeEach + public void setTestMethod(TestInfo testInfo) { + testMethodName = testInfo.getTestMethod().get().getName(); + } @Test public void testForCheckingIfEnableAndDisableWorksFineAfterSwitch() throws Exception { @@ -75,7 +73,7 @@ public void testForCheckingIfEnableAndDisableWorksFineAfterSwitch() throws Excep cluster.waitForActiveAndReadyMaster(); // Create a table with regions - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(testMethodName); byte[] family = Bytes.toBytes("family"); log("Creating table with " + NUM_REGIONS_TO_CREATE + " regions"); Table ht = TEST_UTIL.createMultiRegionTable(tableName, family, NUM_REGIONS_TO_CREATE); @@ -90,8 +88,8 @@ public void testForCheckingIfEnableAndDisableWorksFineAfterSwitch() throws Excep TEST_UTIL.getAdmin().disableTable(tableName); NavigableSet regions = HBaseTestingUtil.getAllOnlineRegions(cluster); - assertEquals("The number of regions for the table tableRestart should be 0 and only" - + "the catalog table should be present.", 1, regions.size()); + assertEquals(1, regions.size(), "The number of regions for the table tableRestart should be 0 " + + "and onlythe catalog table should be present."); List masterThreads = cluster.getMasterThreads(); MasterThread activeMaster = null; @@ -105,10 +103,10 @@ public void testForCheckingIfEnableAndDisableWorksFineAfterSwitch() throws Excep cluster.hbaseCluster.waitOnMaster(activeMaster); cluster.waitForActiveAndReadyMaster(); - assertTrue("The table should not be in enabled state", - cluster.getMaster().getTableStateManager().isTableState( - TableName.valueOf(name.getMethodName()), TableState.State.DISABLED, - TableState.State.DISABLING)); + assertTrue( + cluster.getMaster().getTableStateManager().isTableState(TableName.valueOf(testMethodName), + TableState.State.DISABLED, TableState.State.DISABLING), + "The table should not be in enabled state"); log("Enabling table\n"); // Need a new Admin, the previous one is on the old master Admin admin = TEST_UTIL.getAdmin(); @@ -118,10 +116,11 @@ public void testForCheckingIfEnableAndDisableWorksFineAfterSwitch() throws Excep TEST_UTIL.waitUntilNoRegionsInTransition(60000); log("Verifying there are " + numRegions + " assigned on cluster\n"); regions = HBaseTestingUtil.getAllOnlineRegions(cluster); - assertEquals("The assigned regions were not onlined after master" - + " switch except for the catalog table.", 5, regions.size()); - assertTrue("The table should be in enabled state", cluster.getMaster().getTableStateManager() - .isTableState(TableName.valueOf(name.getMethodName()), TableState.State.ENABLED)); + assertEquals(5, regions.size(), + "The assigned regions were not onlined after master switch except for the catalog table."); + assertTrue(cluster.getMaster().getTableStateManager() + .isTableState(TableName.valueOf(testMethodName), TableState.State.ENABLED), + "The table should be in enabled state"); ht.close(); TEST_UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterShutdown.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterShutdown.java index e6cf205fcc37..42cb33643bab 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterShutdown.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterShutdown.java @@ -17,16 +17,15 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.IOException; import java.util.List; import java.util.concurrent.TimeUnit; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.ClusterMetrics; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.LocalHBaseCluster; @@ -38,26 +37,22 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread; import org.apache.hadoop.hbase.zookeeper.ReadOnlyZKClient; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hbase.thirdparty.org.apache.commons.collections4.CollectionUtils; -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestMasterShutdown { private static final Logger LOG = LoggerFactory.getLogger(TestMasterShutdown.class); - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterShutdown.class); - private HBaseTestingUtil htu; - @Before + @BeforeEach public void shutdownCluster() throws IOException { if (htu != null) { // an extra check in case the test cluster was not terminated after HBaseClassTestRule's @@ -155,8 +150,9 @@ public void testMasterShutdownBeforeStartingAnyRegionServer() throws Exception { // manager is usually init'ed in time for the RPC to be made. For now, adding an explicit // wait() in the test, waiting for the server manager to become available. final long timeout = TimeUnit.MINUTES.toMillis(10); - assertNotEquals("timeout waiting for server manager to become available.", -1, - htu.waitFor(timeout, () -> masterThread.getMaster().getServerManager() != null)); + assertNotEquals(-1, + htu.waitFor(timeout, () -> masterThread.getMaster().getServerManager() != null), + "timeout waiting for server manager to become available."); // Master has come up far enough that we can terminate it without creating a zombie. try { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterTransitions.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterTransitions.java index e59ef4919126..e94083786ed2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterTransitions.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterTransitions.java @@ -17,9 +17,10 @@ */ package org.apache.hadoop.hbase.master; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.io.IOException; import org.apache.hadoop.hbase.CatalogFamilyFormat; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -34,14 +35,12 @@ import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,13 +48,10 @@ * Test transitions of state across the master. Sets up the cluster once and then runs a couple of * tests. */ -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestMasterTransitions { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterTransitions.class); - private static final Logger LOG = LoggerFactory.getLogger(TestMasterTransitions.class); private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static final TableName TABLENAME = TableName.valueOf("master_transitions"); @@ -65,7 +61,7 @@ public class TestMasterTransitions { /** * Start up a mini cluster and put a small table of many empty regions into it. */ - @BeforeClass + @BeforeAll public static void beforeAllTests() throws Exception { TEST_UTIL.startMiniCluster(2); // Create a table of three families. This will assign a region. @@ -80,12 +76,12 @@ public static void beforeAllTests() throws Exception { t.close(); } - @AfterClass + @AfterAll public static void afterAllTests() throws Exception { TEST_UTIL.shutdownMiniCluster(); } - @Before + @BeforeEach public void setup() throws IOException { TEST_UTIL.ensureSomeRegionServersAvailable(2); } @@ -139,7 +135,7 @@ public void setup() throws IOException { * In 2428, the meta region has just been set offline and then a close comes in. * @see HBASE-2428 */ - @Ignore + @Disabled @Test public void testRegionCloseWhenNoMetaHBase2428() throws Exception { /* @@ -172,7 +168,7 @@ public void testRegionCloseWhenNoMetaHBase2428() throws Exception { * onerous by having the server under test carry the meta. If confusion between old and new, * purportedly meta never comes back. Test that meta gets redeployed. */ - @Ignore + @Disabled @Test public void testAddingServerBeforeOldIsDead2413() throws IOException { /* @@ -241,7 +237,7 @@ public void testAddingServerBeforeOldIsDead2413() throws IOException { * happen soon as the processing of the killed server is done. * @see HBASE-2482 */ - @Ignore + @Disabled @Test public void testKillRSWithOpeningRegion2482() throws Exception { /* @@ -325,7 +321,7 @@ private static int addToEachStartKey(final int expected) throws IOException { rows++; } s.close(); - Assert.assertEquals(expected, rows); + assertEquals(expected, rows); t.close(); meta.close(); return rows; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterUseIp.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterUseIp.java index 4cb85150851f..03a8c5743c57 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterUseIp.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterUseIp.java @@ -17,11 +17,10 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.net.InetAddress; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; @@ -29,19 +28,16 @@ import org.apache.hadoop.hbase.StartTestingClusterOption; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterUseIp { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterUseIp.class); private static final Logger LOG = LoggerFactory.getLogger(TestMasterUseIp.class); @@ -51,7 +47,7 @@ public class TestMasterUseIp { private static final int NUM_MASTERS = 1; private static final int NUM_RS = 1; - @Before + @BeforeEach public void setup() throws Exception { Configuration conf = HBaseConfiguration.create(); conf.setBoolean(HConstants.HBASE_SERVER_USEIP_ENABLED_KEY, true); @@ -61,7 +57,7 @@ public void setup() throws Exception { CLUSTER = TEST_UTIL.startMiniCluster(option); } - @After + @AfterEach public void teardown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMergeTableRegionsWhileRSCrash.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMergeTableRegionsWhileRSCrash.java index f9a6fc0ab312..fb6fdc4cb0aa 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMergeTableRegionsWhileRSCrash.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMergeTableRegionsWhileRSCrash.java @@ -17,9 +17,10 @@ */ package org.apache.hadoop.hbase.master; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.List; import java.util.concurrent.CountDownLatch; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; @@ -36,22 +37,17 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; -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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMergeTableRegionsWhileRSCrash { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMergeTableRegionsWhileRSCrash.class); - private static final Logger LOG = LoggerFactory.getLogger(TestMergeTableRegionsWhileRSCrash.class); @@ -63,7 +59,7 @@ public class TestMergeTableRegionsWhileRSCrash { private static CountDownLatch mergeCommitArrive = new CountDownLatch(1); private static Table TABLE; - @BeforeClass + @BeforeAll public static void setupCluster() throws Exception { UTIL.startMiniCluster(1); admin = UTIL.getAdmin(); @@ -73,7 +69,7 @@ public static void setupCluster() throws Exception { UTIL.waitTableAvailable(TABLE_NAME); } - @AfterClass + @AfterAll public static void cleanupTest() throws Exception { try { UTIL.shutdownMiniCluster(); @@ -114,6 +110,6 @@ public void test() throws Exception { while ((result = results.next()) != null) { count++; } - Assert.assertEquals("There should be 10 rows!", 10, count); + assertEquals(10, count, "There should be 10 rows!"); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaAssignmentWithStopMaster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaAssignmentWithStopMaster.java index b6bce31eed9c..60d2afcbbb7c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaAssignmentWithStopMaster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaAssignmentWithStopMaster.java @@ -17,10 +17,9 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.StartTestingClusterOption; @@ -30,35 +29,30 @@ import org.apache.hadoop.hbase.client.RegionLocator; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ LargeTests.class }) +@Tag(LargeTests.TAG) public class TestMetaAssignmentWithStopMaster { private static final Logger LOG = LoggerFactory.getLogger(TestMetaAssignmentWithStopMaster.class); - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMetaAssignmentWithStopMaster.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static final long WAIT_TIMEOUT = 120000; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { StartTestingClusterOption option = StartTestingClusterOption.builder().numMasters(2).numRegionServers(3).numDataNodes(3).build(); UTIL.startMiniCluster(option); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { UTIL.shutdownMiniCluster(); } @@ -92,8 +86,8 @@ public void testStopActiveMaster() throws Exception { } ServerName newMetaServer = locator.getAllRegionLocations().get(0).getServerName(); - assertTrue("The new meta server " + newMetaServer + " should be same with" - + " the old meta server " + oldMetaServer, newMetaServer.equals(oldMetaServer)); + assertTrue(newMetaServer.equals(oldMetaServer), "The new meta server " + newMetaServer + + " should be same with" + " the old meta server " + oldMetaServer); } } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaShutdownHandler.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaShutdownHandler.java index 48693ea2e870..de27d6fe3c96 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaShutdownHandler.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMetaShutdownHandler.java @@ -17,13 +17,12 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.SingleProcessHBaseCluster; @@ -39,35 +38,31 @@ import org.apache.hadoop.hbase.zookeeper.ZKUtil; import org.apache.hadoop.hbase.zookeeper.ZNodePaths; import org.apache.zookeeper.KeeperException; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Tests handling of meta-carrying region server failover. */ -@Category(MediumTests.class) +@Tag(MediumTests.TAG) public class TestMetaShutdownHandler { private static final Logger LOG = LoggerFactory.getLogger(TestMetaShutdownHandler.class); - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMetaShutdownHandler.class); private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); final static Configuration conf = TEST_UTIL.getConfiguration(); - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { StartTestingClusterOption option = StartTestingClusterOption.builder().numRegionServers(3) .rsClass(MyRegionServer.class).numDataNodes(3).build(); TEST_UTIL.startMiniCluster(option); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -100,8 +95,8 @@ public void testExpireMetaRegionServer() throws Exception { regionStates.getRegionServerOfRegion(RegionInfoBuilder.FIRST_META_REGIONINFO); } RegionState metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper()); - assertEquals("Wrong state for meta!", RegionState.State.OPEN, metaState.getState()); - assertNotEquals("Meta is on master!", metaServerName, master.getServerName()); + assertEquals(metaState.getState(), RegionState.State.OPEN, "Wrong state for meta!"); + assertNotEquals(master.getServerName(), metaServerName, "Meta is on master!"); HRegionServer metaRegionServer = cluster.getRegionServer(metaServerName); // Delete the ephemeral node of the meta-carrying region server. @@ -124,15 +119,16 @@ public boolean evaluate() throws Exception { LOG.info("Past wait on RIT"); TEST_UTIL.waitUntilNoRegionsInTransition(60000); // Now, make sure meta is assigned - assertTrue("Meta should be assigned", - regionStates.isRegionOnline(RegionInfoBuilder.FIRST_META_REGIONINFO)); + assertTrue(regionStates.isRegionOnline(RegionInfoBuilder.FIRST_META_REGIONINFO), + "Meta should be assigned"); // Now, make sure meta is registered in zk metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper()); - assertEquals("Meta should not be in transition", RegionState.State.OPEN, metaState.getState()); - assertEquals("Meta should be assigned", metaState.getServerName(), - regionStates.getRegionServerOfRegion(RegionInfoBuilder.FIRST_META_REGIONINFO)); - assertNotEquals("Meta should be assigned on a different server", metaState.getServerName(), - metaServerName); + assertEquals(RegionState.State.OPEN, metaState.getState(), "Meta should not be in transition"); + assertEquals(metaState.getServerName(), + regionStates.getRegionServerOfRegion(RegionInfoBuilder.FIRST_META_REGIONINFO), + "Meta should be assigned"); + assertNotEquals(metaServerName, metaState.getServerName(), + "Meta should be assigned on a different server"); } public static class MyRegionServer extends MiniHBaseClusterRegionServer { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMigrateAndMirrorMetaLocations.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMigrateAndMirrorMetaLocations.java index cdb243b06cdb..b61c970379c1 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMigrateAndMirrorMetaLocations.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMigrateAndMirrorMetaLocations.java @@ -19,15 +19,14 @@ import static org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil.lengthOfPBMagic; import static org.apache.hadoop.hbase.zookeeper.ZKMetadata.removeMetaData; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.hadoop.hbase.CatalogFamilyFormat; import org.apache.hadoop.hbase.Cell; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.RegionLocations; @@ -44,11 +43,10 @@ import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.zookeeper.ZKUtil; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos; @@ -56,22 +54,19 @@ /** * Testcase for HBASE-26193. */ -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestMigrateAndMirrorMetaLocations { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMigrateAndMirrorMetaLocations.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.startMiniCluster(3); HBaseTestingUtil.setReplicas(UTIL.getAdmin(), TableName.META_TABLE_NAME, 2); } - @AfterClass + @AfterAll public static void tearDown() throws IOException { UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMigrateNamespaceTable.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMigrateNamespaceTable.java index 30dd308c28f3..fb47a045a75f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMigrateNamespaceTable.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMigrateNamespaceTable.java @@ -17,15 +17,14 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.NamespaceDescriptor; @@ -48,11 +47,10 @@ import org.apache.hadoop.hbase.util.CommonFSUtils; import org.apache.hadoop.hbase.util.FSTableDescriptors; import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos; @@ -60,13 +58,10 @@ /** * Testcase for HBASE-21154. */ -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestMigrateNamespaceTable { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMigrateNamespaceTable.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static volatile boolean CONTINUE = false; @@ -138,14 +133,14 @@ protected void deserializeStateData(ProcedureStateSerializer serializer) throws } } - @BeforeClass + @BeforeAll public static void setUp() throws Exception { StartTestingClusterOption option = StartTestingClusterOption.builder().numMasters(1) .numAlwaysStandByMasters(1).numRegionServers(1).build(); UTIL.startMiniCluster(option); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestNewStartedRegionServerVersion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestNewStartedRegionServerVersion.java index 50028bf001e5..f481738fce2a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestNewStartedRegionServerVersion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestNewStartedRegionServerVersion.java @@ -17,42 +17,37 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import java.io.IOException; import java.util.List; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.JVMClusterUtil; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestNewStartedRegionServerVersion { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestNewStartedRegionServerVersion.class); - private static final Logger LOG = LoggerFactory.getLogger(TestNewStartedRegionServerVersion.class); private static HBaseTestingUtil UTIL = new HBaseTestingUtil(); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.startMiniCluster(1); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestOldWALsDirSizeChore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestOldWALsDirSizeChore.java index 7bd4ec5a1c24..e0784de6f68b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestOldWALsDirSizeChore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestOldWALsDirSizeChore.java @@ -17,21 +17,19 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.master.assignment.MockMasterServices; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,11 +37,9 @@ * Tests for OldWALsDirSizeChore Here we are using the {@link MockMasterServices} to mock the Hbase * Master. Chore's won't be running automatically; we need to run every time. */ -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestOldWALsDirSizeChore { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestOldWALsDirSizeChore.class); private static final Logger LOG = LoggerFactory.getLogger(TestOldWALsDirSizeChore.class); @@ -51,13 +47,13 @@ public class TestOldWALsDirSizeChore { private static final HBaseTestingUtil HBASE_TESTING_UTILITY = new HBaseTestingUtil(); - @Before + @BeforeEach public void setUp() throws Exception { master = new MockMasterServices(HBASE_TESTING_UTILITY.getConfiguration()); master.start(10, null); } - @After + @AfterEach public void tearDown() throws Exception { master.stop("tearDown"); } @@ -66,8 +62,8 @@ public void tearDown() throws Exception { public void testOldWALsDirSizeChore() throws IOException { // Assume the OldWALs directory size is initially zero as the chore hasn't run yet long currentOldWALsDirSize = master.getMasterWalManager().getOldWALsDirSize(); - assertEquals("Initial OldWALs directory size should be zero before running the chore", 0, - currentOldWALsDirSize); + assertEquals(0, currentOldWALsDirSize, + "Initial OldWALs directory size should be zero before running the chore"); int dummyFileSize = 50 * 1024 * 1024; // 50MB byte[] dummyData = new byte[dummyFileSize]; @@ -84,7 +80,7 @@ public void testOldWALsDirSizeChore() throws IOException { oldWALsDirSizeChore.chore(); // Verify that the OldWALs directory size has increased by the file size - assertEquals("OldWALs directory size after chore should be as expected", dummyFileSize, - master.getMasterWalManager().getOldWALsDirSize()); + assertEquals(dummyFileSize, master.getMasterWalManager().getOldWALsDirSize(), + "OldWALs directory size after chore should be as expected"); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRecreateCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRecreateCluster.java index 42f54e5c8758..0a5f0339e8f5 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRecreateCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRecreateCluster.java @@ -17,16 +17,15 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.time.Duration; import java.util.List; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Cell; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.SingleProcessHBaseCluster; @@ -43,34 +42,25 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.CommonFSUtils; import org.apache.hadoop.hbase.zookeeper.ZKUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Test reuse storefiles within data directory when cluster failover with a set of new region * servers with different hostnames with or without WALs and Zookeeper ZNodes, the master and * cluster should fail respectively if there is any situation considered as not supported. */ -@Category({ LargeTests.class }) +@Tag(LargeTests.TAG) public class TestRecreateCluster { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRecreateCluster.class); - - @Rule - public TestName name = new TestName(); private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static final int NUM_RS = 3; private static final long TIMEOUT_MS = Duration.ofMinutes(1).toMillis(); private static final long MASTER_INIT_TIMEOUT_MS = Duration.ofSeconds(45).toMillis(); - @Before + @BeforeEach public void setup() throws Exception { TEST_UTIL.getConfiguration().setLong("hbase.master.init.timeout.localHBaseCluster", MASTER_INIT_TIMEOUT_MS); @@ -78,7 +68,7 @@ public void setup() throws Exception { .numDataNodes(NUM_RS).createWALDir(true).build()); } - @After + @AfterEach public void tearDown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -183,8 +173,8 @@ private void prepareDataBeforeRecreate(HBaseTestingUtil testUtil, TableName tabl private void ensureTableNotColocatedWithSystemTable(TableName userTable, TableName systemTable) throws IOException, InterruptedException { SingleProcessHBaseCluster hbaseCluster = TEST_UTIL.getHBaseCluster(); - assertTrue("Please start more than 1 regionserver", - hbaseCluster.getRegionServerThreads().size() > 1); + assertTrue(hbaseCluster.getRegionServerThreads().size() > 1, + "Please start more than 1 regionserver"); int userTableServerNum = getServerNumForTableWithOnlyOneRegion(userTable); int systemTableServerNum = getServerNumForTableWithOnlyOneRegion(systemTable); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java index cccc05072cc7..055d2203d71a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java @@ -17,11 +17,11 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.net.InetSocketAddress; @@ -37,7 +37,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.CatalogFamilyFormat; import org.apache.hadoop.hbase.ClientMetaTableAccessor; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionLocation; @@ -66,22 +65,18 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Pair; import org.apache.zookeeper.KeeperException; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestRegionPlacement { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionPlacement.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionPlacement.class); private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private final static int SLAVES = 10; @@ -93,7 +88,7 @@ public class TestRegionPlacement { private int REGION_NUM = 10; private Map favoredNodesAssignmentPlan = new HashMap<>(); - @BeforeClass + @BeforeAll public static void setupBeforeClass() throws Exception { Configuration conf = TEST_UTIL.getConfiguration(); // Enable the favored nodes based load balancer @@ -106,12 +101,12 @@ public static void setupBeforeClass() throws Exception { rp = new RegionPlacementMaintainer(conf); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL.shutdownMiniCluster(); } - @Ignore("Test for unfinished feature") + @Disabled("Test for unfinished feature") @Test public void testRegionPlacement() throws Exception { String tableStr = "testRegionAssignment"; @@ -182,12 +177,12 @@ public void testRegionPlacement() throws Exception { assertTrue(report.getTotalFavoredAssignments() >= REGION_NUM); assertTrue(report.getNumRegionsOnFavoredNodeByPosition(FavoredNodesPlan.Position.PRIMARY) > 0); assertTrue( + (report.getNumRegionsOnFavoredNodeByPosition(FavoredNodesPlan.Position.SECONDARY) > 0 + || report.getNumRegionsOnFavoredNodeByPosition(FavoredNodesPlan.Position.TERTIARY) > 0), "secondary " + report.getNumRegionsOnFavoredNodeByPosition(FavoredNodesPlan.Position.SECONDARY) + " tertiary " - + report.getNumRegionsOnFavoredNodeByPosition(FavoredNodesPlan.Position.TERTIARY), - (report.getNumRegionsOnFavoredNodeByPosition(FavoredNodesPlan.Position.SECONDARY) > 0 - || report.getNumRegionsOnFavoredNodeByPosition(FavoredNodesPlan.Position.TERTIARY) > 0)); + + report.getNumRegionsOnFavoredNodeByPosition(FavoredNodesPlan.Position.TERTIARY)); assertTrue((report.getNumRegionsOnFavoredNodeByPosition(FavoredNodesPlan.Position.PRIMARY) + report.getNumRegionsOnFavoredNodeByPosition(FavoredNodesPlan.Position.SECONDARY) + report.getNumRegionsOnFavoredNodeByPosition(FavoredNodesPlan.Position.TERTIARY)) @@ -266,7 +261,7 @@ private void killRandomServerAndVerifyAssignment() /** * Used to test the correctness of this class. */ - @Ignore("Test for unfinished feature") + @Disabled("Test for unfinished feature") @Test public void testRandomizedMatrix() { int rows = 100; @@ -369,8 +364,8 @@ private void verifyRegionAssignment(FavoredNodesPlan plan, int regionMovementNum */ private void verifyMETAUpdated(FavoredNodesPlan expectedPlan) throws IOException { FavoredNodesPlan planFromMETA = rp.getRegionAssignmentSnapshot().getExistingAssignmentPlan(); - assertTrue("The assignment plan is NOT consistent with the expected plan ", - planFromMETA.equals(expectedPlan)); + assertTrue(planFromMETA.equals(expectedPlan), + "The assignment plan is NOT consistent with the expected plan "); } /** @@ -398,8 +393,8 @@ private void verifyRegionMovementNum(int expected) throws InterruptedException, // update the lastRegionOpenedCount lastRegionOpenedCount = currentRegionOpened; - assertEquals("There are only " + regionMovement + " instead of " + expected - + " region movement for " + attempt + " attempts", expected, regionMovement); + assertEquals(expected, regionMovement, "There are only " + regionMovement + " instead of " + + expected + " region movement for " + attempt + " attempts"); } /** @@ -409,9 +404,8 @@ private void verifyRegionMovementNum(int expected) throws InterruptedException, */ private void verifyRegionOnPrimaryRS(int expectedNum) throws IOException { lastRegionOnPrimaryRSCount = getNumRegionisOnPrimaryRS(); - assertEquals( - "Only " + expectedNum + " of user regions running " + "on the primary region server", - expectedNum, lastRegionOnPrimaryRSCount); + assertEquals(expectedNum, lastRegionOnPrimaryRSCount, + "Only " + expectedNum + " of user regions running " + "on the primary region server"); } /** @@ -434,8 +428,8 @@ private void verifyRegionServerUpdated(FavoredNodesPlan plan) throws IOException TableDescriptor desc = region.getTableDescriptor(); // Verify they are ROOT and hbase:meta regions since no favored nodes assertNull(favoredSocketAddress); - assertTrue("User region " + region.getTableDescriptor().getTableName() - + " should have favored nodes", desc.isMetaRegion()); + assertTrue(desc.isMetaRegion(), "User region " + + region.getTableDescriptor().getTableName() + " should have favored nodes"); } else { // For user region, the favored nodes in the region server should be // identical to favored nodes in the assignmentPlan @@ -448,11 +442,10 @@ private void verifyRegionServerUpdated(FavoredNodesPlan plan) throws IOException assertNotNull(addrFromRS); assertNotNull(addrFromPlan); - assertTrue( + assertTrue(addrFromRS.equals(addrFromPlan), "Region server " + rs.getServerName().getAddress() + " has the " + positions[j] + " for region " + region.getRegionInfo().getRegionNameAsString() + " is " - + addrFromRS + " which is inconsistent with the plan " + addrFromPlan, - addrFromRS.equals(addrFromPlan)); + + addrFromRS + " which is inconsistent with the plan " + addrFromPlan); } } } @@ -546,9 +539,8 @@ private static void createTable(TableName tableName, int regionNum) throws IOExc try (RegionLocator r = CONNECTION.getRegionLocator(tableName)) { List regions = r.getAllRegionLocations(); - assertEquals( - "Tried to create " + expectedRegions + " regions " + "but only found " + regions.size(), - expectedRegions, regions.size()); + assertEquals(expectedRegions, regions.size(), + "Tried to create " + expectedRegions + " regions " + "but only found " + regions.size()); } } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement2.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement2.java index 60414b37d0e9..5b5b591b343d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement2.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement2.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; @@ -26,7 +26,6 @@ import java.util.Map; import java.util.Set; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -40,31 +39,30 @@ import org.apache.hadoop.hbase.master.balancer.MasterClusterInfoProvider; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestRegionPlacement2 { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionPlacement2.class); - private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private final static int SLAVES = 7; private final static int PRIMARY = Position.PRIMARY.ordinal(); private final static int SECONDARY = Position.SECONDARY.ordinal(); private final static int TERTIARY = Position.TERTIARY.ordinal(); + private String testMethodName; - @Rule - public TestName name = new TestName(); + @BeforeEach + public void setTestMethod(TestInfo testInfo) { + testMethodName = testInfo.getTestMethod().get().getName(); + } - @BeforeClass + @BeforeAll public static void setupBeforeClass() throws Exception { Configuration conf = TEST_UTIL.getConfiguration(); // Enable the favored nodes based load balancer @@ -74,7 +72,7 @@ public static void setupBeforeClass() throws Exception { TEST_UTIL.startMiniCluster(SLAVES); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -94,8 +92,7 @@ public void testFavoredNodesPresentForRoundRobinAssignment() throws IOException servers.add(server); } List regions = new ArrayList<>(1); - RegionInfo region = - RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())).build(); + RegionInfo region = RegionInfoBuilder.newBuilder(TableName.valueOf(testMethodName)).build(); regions.add(region); Map> assignmentMap = balancer.roundRobinAssignment(regions, servers); @@ -158,8 +155,7 @@ public void testFavoredNodesPresentForRandomAssignment() throws IOException { servers.add(server); } List regions = new ArrayList<>(1); - RegionInfo region = - RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())).build(); + RegionInfo region = RegionInfoBuilder.newBuilder(TableName.valueOf(testMethodName)).build(); regions.add(region); ServerName serverBefore = balancer.randomAssignment(region, servers); List favoredNodesBefore = diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlansWithThrottle.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlansWithThrottle.java index b5c234a960b2..3aa9cce7aed7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlansWithThrottle.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlansWithThrottle.java @@ -17,9 +17,10 @@ */ package org.apache.hadoop.hbase.master; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.ArrayList; import java.util.List; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.StartTestingClusterOption; import org.apache.hadoop.hbase.TableName; @@ -32,31 +33,26 @@ import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.util.Bytes; -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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; -@Category({ MiscTests.class, MediumTests.class }) +@Tag(MiscTests.TAG) +@Tag(MediumTests.TAG) public class TestRegionPlansWithThrottle { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionPlansWithThrottle.class); - private static HMaster hMaster; private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.startMiniCluster(StartTestingClusterOption.builder().numRegionServers(2).build()); hMaster = UTIL.getMiniHBaseCluster().getMaster(); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { UTIL.shutdownMiniCluster(); } @@ -91,7 +87,7 @@ public void testExecuteRegionPlansWithThrottling() throws Exception { UTIL.getHBaseCluster().getRegionServer(1).getServerName())); } List successPlans = hMaster.executeRegionPlansWithThrottling(plans); - Assert.assertEquals(regionInfos.size(), successPlans.size()); + assertEquals(regionInfos.size(), successPlans.size()); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionState.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionState.java index 5819483e4a98..e8d6a692b34d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionState.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionState.java @@ -17,31 +17,21 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.RegionInfoBuilder; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.apache.hadoop.hbase.shaded.protobuf.generated.ClusterStatusProtos; -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestRegionState { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionState.class); - - @Rule - public TestName name = new TestName(); - @Test public void testSerializeDeserialize() { final TableName tableName = TableName.valueOf("testtb"); @@ -56,7 +46,7 @@ private void testSerializeDeserialize(final TableName tableName, final RegionSta ClusterStatusProtos.RegionState protobuf1 = state1.convert(); RegionState state2 = RegionState.convert(protobuf1); ClusterStatusProtos.RegionState protobuf2 = state1.convert(); - assertEquals("RegionState does not match " + state, state1, state2); - assertEquals("Protobuf does not match " + state, protobuf1, protobuf2); + assertEquals(state1, state2, "RegionState does not match " + state); + assertEquals(protobuf1, protobuf2, "Protobuf does not match " + state); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionsRecoveryChore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionsRecoveryChore.java index 31fcf9fd47f5..06b66d118bf3 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionsRecoveryChore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionsRecoveryChore.java @@ -26,7 +26,6 @@ import java.util.Set; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.ClusterMetrics; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.RegionMetrics; import org.apache.hadoop.hbase.ServerMetrics; @@ -45,11 +44,10 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,13 +55,10 @@ /** * Test for RegionsRecoveryChore */ -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestRegionsRecoveryChore { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionsRecoveryChore.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionsRecoveryChore.class); private static final HBaseTestingUtil HBASE_TESTING_UTILITY = new HBaseTestingUtil(); @@ -96,13 +91,13 @@ private Configuration getCustomConf() { return conf; } - @Before + @BeforeEach public void setUp() throws Exception { this.hMaster = Mockito.mock(HMaster.class); this.assignmentManager = Mockito.mock(AssignmentManager.class); } - @After + @AfterEach public void tearDown() throws Exception { Mockito.verifyNoMoreInteractions(this.hMaster); Mockito.verifyNoMoreInteractions(this.assignmentManager); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionsRecoveryConfigManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionsRecoveryConfigManager.java index 7c512a4d396c..c35a4fe119ef 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionsRecoveryConfigManager.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRegionsRecoveryConfigManager.java @@ -17,33 +17,28 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.SingleProcessHBaseCluster; import org.apache.hadoop.hbase.StartTestingClusterOption; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Test for Regions Recovery Config Manager */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestRegionsRecoveryConfigManager { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionsRecoveryConfigManager.class); - private static final HBaseTestingUtil HBASE_TESTING_UTILITY = new HBaseTestingUtil(); private SingleProcessHBaseCluster cluster; @@ -54,7 +49,7 @@ public class TestRegionsRecoveryConfigManager { private Configuration conf; - @Before + @BeforeEach public void setup() throws Exception { conf = HBASE_TESTING_UTILITY.getConfiguration(); conf.unset("hbase.regions.recovery.store.file.ref.count"); @@ -65,7 +60,7 @@ public void setup() throws Exception { cluster = HBASE_TESTING_UTILITY.getMiniHBaseCluster(); } - @After + @AfterEach public void tearDown() throws Exception { HBASE_TESTING_UTILITY.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRestartWithEmptyWALDirectory.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRestartWithEmptyWALDirectory.java index 866f74b73191..7e71e94f0728 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRestartWithEmptyWALDirectory.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRestartWithEmptyWALDirectory.java @@ -17,11 +17,10 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import java.io.IOException; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -32,23 +31,19 @@ import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.CommonFSUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Simulate the scenario described in HBASE-26245, where we clean the WAL directory and try to start * the cluster. */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestRestartWithEmptyWALDirectory { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRestartWithEmptyWALDirectory.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static TableName NAME = TableName.valueOf("test"); @@ -57,7 +52,7 @@ public class TestRestartWithEmptyWALDirectory { private static byte[] QUALIFIER = Bytes.toBytes("qualifier"); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { // in the test we shutdown the only master and after restarting its port will be changed, so the // default rpc region server can not work @@ -68,7 +63,7 @@ public static void setUp() throws Exception { UTIL.waitTableAvailable(NAME); } - @AfterClass + @AfterAll public static void tearDown() throws IOException { UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRetainAssignmentOnRestart.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRetainAssignmentOnRestart.java index 2767bb106f43..d86c03a8b668 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRetainAssignmentOnRestart.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRetainAssignmentOnRestart.java @@ -20,16 +20,15 @@ import static org.apache.hadoop.hbase.master.assignment.AssignmentManager.FORCE_REGION_RETAINMENT; import static org.apache.hadoop.hbase.master.assignment.AssignmentManager.FORCE_REGION_RETAINMENT_WAIT_INTERVAL; import static org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure.MASTER_SCP_RETAIN_ASSIGNMENT; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.io.UncheckedIOException; import java.util.List; import java.util.Map; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.SingleProcessHBaseCluster; @@ -39,19 +38,15 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.JVMClusterUtil; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestRetainAssignmentOnRestart extends AbstractTestRestartCluster { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRetainAssignmentOnRestart.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRetainAssignmentOnRestart.class); private static int NUM_OF_RS = 3; @@ -151,7 +146,7 @@ public void testRetainAssignmentOnClusterRestart() throws Exception { ServerName currentServer = entry.getValue(); LOG.info( "Key=" + entry.getKey() + " oldServer=" + oldServer + ", currentServer=" + currentServer); - assertEquals(entry.getKey().toString(), oldServer.getAddress(), currentServer.getAddress()); + assertEquals(oldServer.getAddress(), currentServer.getAddress(), entry.getKey().toString()); assertNotEquals(oldServer.getStartcode(), currentServer.getStartcode()); } } @@ -220,7 +215,7 @@ public void testRetainAssignmentOnSingleRSRestart() throws Exception { ServerName currentServer = entry.getValue(); LOG.info( "Key=" + entry.getKey() + " oldServer=" + oldServer + ", currentServer=" + currentServer); - assertEquals(entry.getKey().toString(), oldServer.getAddress(), currentServer.getAddress()); + assertEquals(oldServer.getAddress(), currentServer.getAddress(), entry.getKey().toString()); if (deadRS.getPort() == oldServer.getPort()) { // Restarted RS start code wont be same @@ -292,7 +287,7 @@ public void testForceRetainAssignment() throws Exception { ServerName currentServer = entry.getValue(); LOG.info( "Key=" + entry.getKey() + " oldServer=" + oldServer + ", currentServer=" + currentServer); - assertEquals(entry.getKey().toString(), oldServer.getAddress(), currentServer.getAddress()); + assertEquals(oldServer.getAddress(), currentServer.getAddress(), entry.getKey().toString()); if (deadRS.getPort() == oldServer.getPort()) { // Restarted RS start code wont be same diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRetainAssignmentOnRestartSplitWithoutZk.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRetainAssignmentOnRestartSplitWithoutZk.java index 9a9d6d282d71..3afa8b524cbf 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRetainAssignmentOnRestartSplitWithoutZk.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRetainAssignmentOnRestartSplitWithoutZk.java @@ -17,19 +17,14 @@ */ package org.apache.hadoop.hbase.master; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestRetainAssignmentOnRestartSplitWithoutZk extends TestRetainAssignmentOnRestart { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRetainAssignmentOnRestartSplitWithoutZk.class); - @Override protected boolean splitWALCoordinatedByZk() { return false; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRollingRestart.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRollingRestart.java index 6a37d68db0ef..33aae02217c6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRollingRestart.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRollingRestart.java @@ -17,18 +17,18 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.Arrays; -import java.util.Collection; import java.util.List; import java.util.NavigableSet; import java.util.Set; import java.util.TreeSet; +import java.util.stream.Stream; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -44,13 +44,11 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread; import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.TestTemplate; +import org.junit.jupiter.params.provider.Arguments; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,24 +57,28 @@ /** * Tests the restarting of everything as done during rolling restarts. */ -@RunWith(Parameterized.class) -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) +@HBaseParameterizedTestTemplate(name = "{index}: splitWALCoordinatedByZK={0}") public class TestRollingRestart { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRollingRestart.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRollingRestart.class); private static HBaseTestingUtil TEST_UTIL; - @Rule - public TestName name = new TestName(); + private String testMethodName; + + @BeforeEach + public void setTestMethod(TestInfo testInfo) { + testMethodName = testInfo.getTestMethod().get().getName(); + } - @Parameterized.Parameter - public boolean splitWALCoordinatedByZK; + private final boolean splitWALCoordinatedByZK; + + public TestRollingRestart(boolean splitWALCoordinatedByZK) { + this.splitWALCoordinatedByZK = splitWALCoordinatedByZK; + } - @Test + @TestTemplate public void testBasicRollingRestart() throws Exception { // Start a cluster with 2 masters and 4 regionservers @@ -99,8 +101,7 @@ public void testBasicRollingRestart() throws Exception { cluster.waitForActiveAndReadyMaster(); // Create a table with regions - final TableName tableName = - TableName.valueOf(name.getMethodName().replaceAll("[\\[|\\]]", "-")); + final TableName tableName = TableName.valueOf(testMethodName.replaceAll("[\\[|\\]]", "-")); byte[] family = Bytes.toBytes("family"); log("Creating table with " + NUM_REGIONS_TO_CREATE + " regions"); Table ht = TEST_UTIL.createMultiRegionTable(tableName, family, NUM_REGIONS_TO_CREATE); @@ -302,8 +303,7 @@ private NavigableSet getDoubleAssignedRegions(SingleProcessHBaseCluster return doubled; } - @Parameterized.Parameters - public static Collection coordinatedByZK() { - return Arrays.asList(false, true); + public static Stream parameters() { + return Arrays.asList(false, true).stream().map(Arguments::of); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRoundRobinAssignmentOnRestart.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRoundRobinAssignmentOnRestart.java index da5d1aabb2e1..63a9d1ec9f6e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRoundRobinAssignmentOnRestart.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRoundRobinAssignmentOnRestart.java @@ -17,12 +17,11 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.SingleProcessHBaseCluster; @@ -31,19 +30,15 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.JVMClusterUtil; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestRoundRobinAssignmentOnRestart extends AbstractTestRestartCluster { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRoundRobinAssignmentOnRestart.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRoundRobinAssignmentOnRestart.class); @@ -110,7 +105,7 @@ public void test() throws Exception { List newRegionInfos = cluster.getMaster().getAssignmentManager().getRegionsOnServer(newTestServer); LOG.debug("RegionServer {} has {} regions", newTestServer, newRegionInfos.size()); - assertTrue("Should not retain all regions when restart", - newRegionInfos.size() < regionInfos.size()); + assertTrue(newRegionInfos.size() < regionInfos.size(), + "Should not retain all regions when restart"); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRoundRobinAssignmentOnRestartSplitWithoutZk.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRoundRobinAssignmentOnRestartSplitWithoutZk.java index 8ea7aa3bcb49..67d8d9438a0f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRoundRobinAssignmentOnRestartSplitWithoutZk.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestRoundRobinAssignmentOnRestartSplitWithoutZk.java @@ -17,20 +17,15 @@ */ package org.apache.hadoop.hbase.master; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestRoundRobinAssignmentOnRestartSplitWithoutZk extends TestRoundRobinAssignmentOnRestart { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRoundRobinAssignmentOnRestartSplitWithoutZk.class); - @Override protected boolean splitWALCoordinatedByZk() { return false; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestServerCrashProcedureCarryingMetaStuck.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestServerCrashProcedureCarryingMetaStuck.java index 8263298a8e4f..64eebdc443ab 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestServerCrashProcedureCarryingMetaStuck.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestServerCrashProcedureCarryingMetaStuck.java @@ -19,7 +19,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.AsyncAdmin; @@ -34,28 +33,24 @@ import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestServerCrashProcedureCarryingMetaStuck { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestServerCrashProcedureCarryingMetaStuck.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.startMiniCluster(3); UTIL.getAdmin().balancerSwitch(false, true); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestServerCrashProcedureStuck.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestServerCrashProcedureStuck.java index 48d18297853b..5056585a6293 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestServerCrashProcedureStuck.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestServerCrashProcedureStuck.java @@ -19,7 +19,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.AsyncAdmin; @@ -34,29 +33,25 @@ import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Testcase for HBASE-20634 */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestServerCrashProcedureStuck { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestServerCrashProcedureStuck.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static TableName TABLE_NAME = TableName.valueOf("test"); private static byte[] CF = Bytes.toBytes("cf"); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.startMiniCluster(3); UTIL.getAdmin().balancerSwitch(false, true); @@ -64,7 +59,7 @@ public static void setUp() throws Exception { UTIL.waitTableAvailable(TABLE_NAME); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestShutdownBackupMaster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestShutdownBackupMaster.java index aadbdda8cfe8..424e1193386d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestShutdownBackupMaster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestShutdownBackupMaster.java @@ -17,12 +17,11 @@ */ package org.apache.hadoop.hbase.master; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.IOException; import java.util.concurrent.CountDownLatch; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.SingleProcessHBaseCluster; @@ -30,23 +29,19 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Test to confirm that we will not hang when stop a backup master which is trying to become the * active master. See HBASE-19838 */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestShutdownBackupMaster { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestShutdownBackupMaster.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static volatile CountDownLatch ARRIVE; @@ -69,7 +64,7 @@ protected void initClusterSchemaService() throws IOException, InterruptedExcepti } } - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { UTIL.getConfiguration().setClass(HConstants.MASTER_IMPL, MockHMaster.class, HMaster.class); StartTestingClusterOption option = @@ -78,7 +73,7 @@ public static void setUpBeforeClass() throws Exception { UTIL.waitUntilAllSystemRegionsAssigned(); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { // make sure that we can stop the cluster cleanly UTIL.shutdownMiniCluster(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestShutdownWithNoRegionServer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestShutdownWithNoRegionServer.java index 473e253ce1b5..7cb8dbee3943 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestShutdownWithNoRegionServer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestShutdownWithNoRegionServer.java @@ -17,35 +17,30 @@ */ package org.apache.hadoop.hbase.master; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Testcase to confirm that we will not hang when shutdown a cluster with no live region servers. */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestShutdownWithNoRegionServer { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestShutdownWithNoRegionServer.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.startMiniCluster(1); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitLogManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitLogManager.java index 91ce6227c7cb..31a84ff48d66 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitLogManager.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitLogManager.java @@ -30,9 +30,9 @@ import static org.apache.hadoop.hbase.SplitLogCounters.tot_mgr_resubmit_threshold_reached; import static org.apache.hadoop.hbase.SplitLogCounters.tot_mgr_resubmit_unassigned; import static org.apache.hadoop.hbase.SplitLogCounters.tot_mgr_task_deleted; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.Map; @@ -41,7 +41,6 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.CoordinatedStateManager; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -62,23 +61,18 @@ import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.ZooDefs.Ids; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestSplitLogManager { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestSplitLogManager.class); - private static final Logger LOG = LoggerFactory.getLogger(TestSplitLogManager.class); private final ServerManager sm = Mockito.mock(ServerManager.class); @@ -117,7 +111,7 @@ public ServerManager getServerManager() { } } - @Before + @BeforeEach public void setup() throws Exception { TEST_UTIL = new HBaseTestingUtil(); TEST_UTIL.startMiniZKCluster(); @@ -149,7 +143,7 @@ public void setup() throws Exception { to = to + 16 * 100; } - @After + @AfterEach public void teardown() throws IOException, KeeperException { master.stop(""); if (slm != null) { @@ -342,8 +336,7 @@ public long eval() { return (tot_mgr_resubmit.sum() + tot_mgr_resubmit_failed.sum()); } }, 0, 1, 5 * 60000); // wait long enough - Assert.assertEquals("Could not run test. Lost ZK connection?", 0, - tot_mgr_resubmit_failed.sum()); + assertEquals(tot_mgr_resubmit_failed.sum(), 0, "Could not run test. Lost ZK connection?"); int version1 = ZKUtil.checkExists(zkw, tasknode); assertTrue(version1 > version); byte[] taskstate = ZKUtil.getData(zkw, tasknode); @@ -503,7 +496,7 @@ public void testWorkerCrash() throws Exception { } // Not yet resubmitted. - Assert.assertEquals(0, tot_mgr_resubmit.sum()); + assertEquals(0, tot_mgr_resubmit.sum()); // This server becomes dead Mockito.when(sm.isServerOnline(worker1)).thenReturn(false); @@ -511,7 +504,7 @@ public void testWorkerCrash() throws Exception { Thread.sleep(1300); // The timeout checker is done every 1000 ms (hardcoded). // It has been resubmitted - Assert.assertEquals(1, tot_mgr_resubmit.sum()); + assertEquals(1, tot_mgr_resubmit.sum()); } @Test diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitRegionWhileRSCrash.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitRegionWhileRSCrash.java index d0a1fcb8cec1..1dcf847664c7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitRegionWhileRSCrash.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitRegionWhileRSCrash.java @@ -17,8 +17,9 @@ */ package org.apache.hadoop.hbase.master; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.List; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; @@ -34,24 +35,19 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; -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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hbase.thirdparty.com.google.common.io.Closeables; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestSplitRegionWhileRSCrash { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestSplitRegionWhileRSCrash.class); - private static final Logger LOG = LoggerFactory.getLogger(TestSplitRegionWhileRSCrash.class); protected static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); @@ -60,7 +56,7 @@ public class TestSplitRegionWhileRSCrash { private static byte[] CF = Bytes.toBytes("cf"); private static Table TABLE; - @BeforeClass + @BeforeAll public static void setupCluster() throws Exception { UTIL.startMiniCluster(1); ADMIN = UTIL.getAdmin(); @@ -68,7 +64,7 @@ public static void setupCluster() throws Exception { UTIL.waitTableAvailable(TABLE_NAME); } - @AfterClass + @AfterAll public static void cleanupTest() throws Exception { Closeables.close(TABLE, true); UTIL.shutdownMiniCluster(); @@ -109,6 +105,6 @@ public void test() throws Exception { while (results.next() != null) { count++; } - Assert.assertEquals("There should be 10 rows!", 10, count); + assertEquals(10, count, "There should be 10 rows!"); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitWALManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitWALManager.java index 7e6922b0fc48..76ae6345c046 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitWALManager.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitWALManager.java @@ -18,11 +18,11 @@ package org.apache.hadoop.hbase.master; import static org.apache.hadoop.hbase.master.procedure.ServerProcedureInterface.ServerOperationType.SPLIT_WAL; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; @@ -31,7 +31,6 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -53,11 +52,10 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.JVMClusterUtil; import org.apache.hadoop.hbase.wal.AbstractFSWALProvider; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,13 +64,10 @@ import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos; -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestSplitWALManager { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestSplitWALManager.class); - private static final Logger LOG = LoggerFactory.getLogger(TestSplitWALManager.class); private static HBaseTestingUtil TEST_UTIL; private HMaster master; @@ -80,7 +75,7 @@ public class TestSplitWALManager { private TableName TABLE_NAME; private byte[] FAMILY; - @Before + @BeforeEach public void setUp() throws Exception { TEST_UTIL = new HBaseTestingUtil(); TEST_UTIL.getConfiguration().setBoolean(HConstants.HBASE_SPLIT_WAL_COORDINATED_BY_ZK, false); @@ -93,7 +88,7 @@ public void setUp() throws Exception { FAMILY = Bytes.toBytes("test"); } - @After + @AfterEach public void tearDown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -257,8 +252,8 @@ private void splitLogsTestHelper(HBaseTestingUtil testUtil) throws Exception { assertEquals(0, splitWALManager.getWALsToSplit(metaServer, true).size()); assertEquals(1, splitWALManager.getWALsToSplit(metaServer, false).size()); // There should be archiveFileCount + 1 WALs after SplitWALProcedure finish - assertEquals("Splitted WAL files should be archived", archiveFileCount + 1, - walFS.listStatus(walArchivePath).length); + assertEquals(archiveFileCount + 1, walFS.listStatus(walArchivePath).length, + "Splitted WAL files should be archived"); } @Test diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestUnknownServers.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestUnknownServers.java index fb2f645872c6..627a4335b9df 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestUnknownServers.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestUnknownServers.java @@ -17,33 +17,29 @@ */ package org.apache.hadoop.hbase.master; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.io.IOException; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.testclassification.MediumTests; -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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; -@Category(MediumTests.class) +@Tag(MediumTests.TAG) public class TestUnknownServers { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestUnknownServers.class); private static HBaseTestingUtil UTIL; private static Admin ADMIN; private final static int SLAVES = 1; private static boolean IS_UNKNOWN_SERVER = true; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { UTIL = new HBaseTestingUtil(); UTIL.getConfiguration().setClass(HConstants.MASTER_IMPL, @@ -54,12 +50,12 @@ public static void setUpBeforeClass() throws Exception { @Test public void testListUnknownServers() throws Exception { - Assert.assertEquals(ADMIN.listUnknownServers().size(), SLAVES); + assertEquals(ADMIN.listUnknownServers().size(), SLAVES); IS_UNKNOWN_SERVER = false; - Assert.assertEquals(ADMIN.listUnknownServers().size(), 0); + assertEquals(ADMIN.listUnknownServers().size(), 0); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { if (ADMIN != null) { ADMIN.close(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestWarmupRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestWarmupRegion.java index 95b3c6dd3ae6..80dd53f7d07d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestWarmupRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestWarmupRegion.java @@ -18,10 +18,9 @@ package org.apache.hadoop.hbase.master; import static org.apache.hadoop.hbase.regionserver.HRegion.warmupHRegion; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Waiter; @@ -36,13 +35,12 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,13 +49,10 @@ * up the HBase mini cluster once at start and runs through all client tests. Each creates a table * named for the method and does its stuff against that. */ -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestWarmupRegion { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestWarmupRegion.class); - private static final Logger LOG = LoggerFactory.getLogger(TestWarmupRegion.class); protected TableName TABLENAME = TableName.valueOf("testPurgeFutureDeletes"); protected final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); @@ -72,7 +67,7 @@ public class TestWarmupRegion { /** * @throws java.lang.Exception */ - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { TEST_UTIL.startMiniCluster(SLAVES); } @@ -80,7 +75,7 @@ public static void setUpBeforeClass() throws Exception { /** * @throws java.lang.Exception */ - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -88,7 +83,7 @@ public static void tearDownAfterClass() throws Exception { /** * @throws java.lang.Exception */ - @Before + @BeforeEach public void setUp() throws Exception { table = TEST_UTIL.createTable(TABLENAME, FAMILY); @@ -118,7 +113,7 @@ public boolean evaluate() throws IOException { /** * @throws java.lang.Exception */ - @After + @AfterEach public void tearDown() throws Exception { TEST_UTIL.deleteTable(TABLENAME); }