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 d228c5f60723..dbcf36b998b6 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 @@ -18,9 +18,9 @@ package org.apache.hadoop.hbase.master; import static org.apache.hadoop.hbase.HConstants.HBASE_SPLIT_WAL_MAX_SPLITTER; -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; @@ -59,13 +59,12 @@ import org.apache.hadoop.hbase.wal.WALEdit; 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; @@ -84,18 +83,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 MiniHBaseCluster 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). @@ -104,7 +97,7 @@ public static void setup() throws Exception { TEST_UTIL.startMiniDFSCluster(3); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -137,13 +130,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..dc60e130745a --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestMasterRegionMutation.java @@ -0,0 +1,202 @@ +/* + * 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.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.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.MiniHBaseCluster; +import org.apache.hadoop.hbase.RegionTooBusyException; +import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.StartMiniClusterOption; +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.util.Bytes; +import org.apache.hadoop.hbase.wal.WAL; +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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); + 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); + StartMiniClusterOption.Builder builder = StartMiniClusterOption.builder(); + builder.numMasters(numMasters).numRegionServers(3); + TEST_UTIL.startMiniCluster(builder.build()); + MiniHBaseCluster 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 + public void setUp(TestInfo testInfo) throws Exception { + final TableName tableName = TableName.valueOf(testInfo.getTestMethod().get().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 + public void testMasterRegionMutations() throws Exception { + HbckChore hbckChore = new HbckChore(TEST_UTIL.getHBaseCluster().getMaster()); + MiniHBaseCluster 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(); + assertEquals(0, hbckReport.getInconsistentRegions().size()); + assertEquals(0, hbckReport.getOrphanRegionsOnFS().size()); + 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(); + }); + + } + + public static class TestRegion extends HRegion { + + public TestRegion(Path tableDir, WAL wal, FileSystem fs, Configuration confParam, + RegionInfo regionInfo, TableDescriptor htd, RegionServerServices rsServices) { + super(tableDir, wal, fs, confParam, regionInfo, htd, rsServices); + } + + public TestRegion(HRegionFileSystem fs, WAL wal, Configuration confParam, TableDescriptor htd, + RegionServerServices rsServices) { + super(fs, wal, confParam, htd, rsServices); + } + + @Override + public OperationStatus[] batchMutate(Mutation[] mutations, boolean atomic, long nonceGroup, + long nonce) throws IOException { + if ( + MasterRegionFactory.TABLE_NAME.equals(getTableDescriptor().getTableName()) + && ERROR_OUT.get() + ) { + // First time errors are recovered with enough retries + if (FIRST_TIME_ERROR.get() && ERROR_COUNTER.getAndIncrement() == 5) { + ERROR_OUT.set(false); + ERROR_COUNTER.set(0); + FIRST_TIME_ERROR.set(false); + return super.batchMutate(mutations, atomic, nonceGroup, nonce); + } + // Second time errors are not recovered with enough retries, leading to master abort + if (!FIRST_TIME_ERROR.get() && ERROR_COUNTER.getAndIncrement() == 8) { + ERROR_OUT.set(false); + ERROR_COUNTER.set(0); + } + throw new RegionTooBusyException("test error..."); + } + return super.batchMutate(mutations, atomic, nonceGroup, nonce); + } + } +} 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 a0e21fc7feb0..20f0d22aada0 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 0206e23cee4f..79843b0693a2 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; @@ -33,7 +33,6 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hbase.ChoreService; import org.apache.hadoop.hbase.CoordinatedStateManager; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.Server; import org.apache.hadoop.hbase.ServerName; @@ -51,11 +50,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; @@ -63,22 +61,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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); - @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 48a747a735f3..252a0c7bc612 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.HBaseTestingUtility; -import org.apache.hadoop.hbase.MiniClusterRule; +import org.apache.hadoop.hbase.MiniClusterExtension; import org.apache.hadoop.hbase.StartMiniClusterOption; 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 StartMiniClusterOption OPTION = StartMiniClusterOption.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 { - HBaseTestingUtility testUtil = miniClusterRule.getTestingUtility(); + HBaseTestingUtility 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 d1c8e5ddf6bb..ddbe372b37c7 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MiniHBaseCluster; @@ -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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); 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 3efd3911c684..25560e60bfff 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 @@ -23,12 +23,11 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.notNullValue; -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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -38,45 +37,43 @@ 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; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Test balancer with disabled table */ -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestBalancer { private static final Logger LOG = LoggerFactory.getLogger(TestBalancer.class); - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestBalancer.class); - private final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); + 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 f9c815a18a1c..c3561ffb6961 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.HBaseTestingUtility; 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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); @@ -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. StartMiniClusterOption.Builder builder = StartMiniClusterOption.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 503a618791ec..606559c9b610 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.HBaseTestingUtility; 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); 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( @@ -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 88bd149cb797..35bea26c7472 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); @Override @@ -81,7 +76,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 00a1ca8d4f35..f9eb5d057b0c 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.StartMiniClusterOption; import org.apache.hadoop.hbase.TableName; @@ -47,19 +46,15 @@ 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; 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); @@ -98,8 +93,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); @@ -133,23 +128,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 c94c3e70cfb9..ecd98961f140 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.HBaseTestingUtility; 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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); @@ -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 5c6aecb4293f..3de9ab40f7f7 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.HBaseTestingUtility; 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 HBaseTestingUtility testUtil = new HBaseTestingUtility(); - @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 e38e79176bc6..b72876f44f43 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MiniHBaseCluster; @@ -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 HBaseTestingUtility testUtil = new HBaseTestingUtility(); 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() .getLastSequenceId(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 f0a87f6396e1..7e87bdd9eefb 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.HBaseTestingUtility; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.ServerName; @@ -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); @@ -69,7 +65,7 @@ protected void tryRegionServerReport(long reportStartTime, long reportEndTime) { } } - @BeforeClass + @BeforeAll public static void startCluster() throws Exception { LOG.info("Starting cluster"); TEST_UTIL = new HBaseTestingUtility(); @@ -83,7 +79,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(); @@ -126,12 +122,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 6fe170f1dae5..4a7266f49b79 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.HBaseTestingUtility; 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 HBaseTestingUtility TESTING_UTIL = new HBaseTestingUtility(); @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 9cc24e7c3865..b212db0b5a27 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.HBaseTestingUtility; 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 HBaseTestingUtility testUtil = HBaseTestingUtility.createLocalHTU(); @@ -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 26d26d2fdfd3..dddab9a8adea 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.HBaseTestingUtility; 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 HBaseTestingUtility 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 HBaseTestingUtility(); 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 63375921d6ae..2c6e47706911 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.HBaseTestingUtility; 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); 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 e78fa081a6bb..1c30b00a42b2 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,18 +17,17 @@ */ 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; import java.util.concurrent.atomic.AtomicReference; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; @@ -51,34 +50,34 @@ import org.apache.hadoop.hbase.util.HBaseFsck; import org.apache.hadoop.hbase.util.Pair; 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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); 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); @@ -92,7 +91,7 @@ public static void beforeAllTests() throws Exception { admin = TEST_UTIL.getAdmin(); } - @AfterClass + @AfterAll public static void afterAllTests() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -183,7 +182,7 @@ public void testMoveRegionWhenNotInitialized() { @Test public void testMoveThrowsUnknownRegionException() throws IOException { - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(testMethodName); HTableDescriptor htd = new HTableDescriptor(tableName); HColumnDescriptor hcd = new HColumnDescriptor("value"); htd.addFamily(hcd); @@ -203,7 +202,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(); HTableDescriptor htd = new HTableDescriptor(tableName); HColumnDescriptor hcd = new HColumnDescriptor("value"); 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 4cf4e7eb3b64..baa198210cfa 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.HBaseTestingUtility; 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); 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 f82385e8b374..b0c7b0c7fcc3 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; @@ -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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); 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 1fb43429aabb..d5184e651706 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -38,29 +37,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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); 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. @@ -70,7 +68,7 @@ public void setupConfiguration() { MyLoadBalancer.class.getName()); } - @After + @AfterEach public void shutdown() throws Exception { HMaster.setDisableBalancerChoreForTest(false); TEST_UTIL.getConfiguration().set(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, @@ -86,7 +84,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 14e01a2b9553..f10ccd5801ce 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.HBaseTestingUtility; import org.apache.hadoop.hbase.ScheduledChore; import org.apache.hadoop.hbase.StartMiniClusterOption; @@ -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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.startMiniCluster(StartMiniClusterOption.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 e933ea65c319..f11eea575fbd 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.Mockito.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -28,7 +28,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; @@ -56,22 +55,17 @@ 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; /** * 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 { @@ -133,7 +127,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 c5a2880b96d3..72d0b2aa5bb8 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.HBaseTestingUtility; 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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); 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 7ee375f4a122..7154124879ae 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.HBaseTestingUtility; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.ServerName; @@ -35,24 +34,16 @@ 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.Tag; +import org.junit.jupiter.api.Test; 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(); /** * Simple test of master failover. @@ -194,8 +185,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 +197,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 471cb45ed916..3c3d8690d31a 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.HBaseTestingUtility; import org.apache.hadoop.hbase.MasterNotRunningException; import org.apache.hadoop.hbase.MiniHBaseCluster; @@ -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 714894fc0b36..c6aa1bc85449 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.HBaseTestingUtility; 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); - @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 cba272039ee0..9dc492fac7a9 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.HBaseTestingUtility; 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); - @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 f30678c83c8b..4e080fc7692a 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.HBaseTestingUtility; import org.apache.hadoop.hbase.StartMiniClusterOption; 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); - @BeforeClass + @BeforeAll public static void setupTest() throws Exception { // Set createWALDir to true and use default values for other options. UTIL.startMiniCluster(StartMiniClusterOption.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 e11695b91d2d..56fb250a41df 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.HBaseTestingUtility; 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); 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 078dd5d4a55f..6bdf31ac22ea 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.HBaseTestingUtility; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.ServerMetricsBuilder; @@ -35,11 +34,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; @@ -52,13 +50,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); @@ -105,7 +100,7 @@ public RegionServerStartupResponse regionServerStartup(RpcController controller, } } - @BeforeClass + @BeforeAll public static void startCluster() throws Exception { LOG.info("Starting cluster"); TEST_UTIL = new HBaseTestingUtility(); @@ -119,7 +114,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(); @@ -128,9 +123,7 @@ public static void after() throws Exception { @Test public void testClusterRequests() throws Exception { - // sending fake request to master to see how metric value has changed - RegionServerStatusProtos.RegionServerReportRequest.Builder request = RegionServerStatusProtos.RegionServerReportRequest.newBuilder(); ServerName serverName = cluster.getMaster(0).getServerName(); 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 104eee4f1f66..c7dd897537ba 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,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.io.IOException; import java.util.AbstractMap.SimpleImmutableEntry; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot; import org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus; @@ -29,32 +28,28 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; 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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); 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 1f804f1c171f..ab514b3a9784 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,14 +18,15 @@ package org.apache.hadoop.hbase.master; import static org.apache.hadoop.hbase.HConstants.ZOOKEEPER_QUORUM; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Abortable; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; @@ -48,16 +49,13 @@ 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.Ignore; -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.Disabled; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -72,20 +70,14 @@ * 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 HBaseTestingUtility TESTUTIL = new HBaseTestingUtility(); - @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. @@ -95,15 +87,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); @@ -150,9 +142,9 @@ public void testStopDuringStart() throws IOException, KeeperException, Interrupt * Test master failover. Start up three fake regionservers and a master. * @throws org.apache.hbase.thirdparty.com.google.protobuf.ServiceException */ - @Ignore + @Disabled @Test // Disabled since HBASE-18511. Reenable when master can carry regions. - public void testFailover() throws Exception { + public void testFailover(TestInfo testInfo) throws Exception { final long now = EnvironmentEdgeManager.currentTime(); // Names for our three servers. Make the port numbers match hostname. // Will come in use down in the server when we need to figure how to respond. @@ -169,7 +161,7 @@ public void testFailover() throws Exception { // Put data into sn2 so it looks like it has a few regions for a table named 't'. MetaTableLocator.setMetaLocation(rs0.getZooKeeper(), rs0.getServerName(), RegionState.State.OPEN); - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); Result[] results = new Result[] { MetaMockingUtil.getMetaTableRowResult( new HRegionInfo(tableName, HConstants.EMPTY_START_ROW, HBaseTestingUtility.KEYS[1]), @@ -271,7 +263,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); @@ -287,8 +279,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 09bebd89f22f..31afc6b1c1d9 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; @@ -35,7 +35,6 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.ClusterMetrics.Option; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionLocation; @@ -60,25 +59,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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private static Connection CONNECTION = null; @@ -87,11 +82,14 @@ public class TestMasterOperationsForRegionReplicas { private final static StartMiniClusterOption option = StartMiniClusterOption.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); @@ -113,7 +111,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); @@ -124,7 +122,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) @@ -144,7 +142,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 { @@ -236,8 +234,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); @@ -286,7 +284,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 { @@ -383,7 +381,7 @@ private void validateSingleRegionServerAssignment(Connection connection, int num Map regionToServerMap = snapshot.getRegionToRegionServerMap(); assertEquals(regionToServerMap.size(), numRegions * numReplica + 1); 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 18ad3a47953b..b591d395f3c3 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.HRegionInfo; @@ -34,10 +33,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; @@ -46,18 +44,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 QosTestHelper { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterQosFunction.class); - private Configuration conf; private RSRpcServices rpcServices; private AnnotationReadingPriorityFunction 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 7073f08de72d..64b911ab6713 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.HBaseTestingUtility; -import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.RegionTooBusyException; -import org.apache.hadoop.hbase.ServerName; -import org.apache.hadoop.hbase.StartMiniClusterOption; -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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); - protected static ServerName rs0; - - 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); +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) +public class TestMasterRegionMutation1 extends AbstractTestMasterRegionMutation { - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { - TEST_UTIL.getConfiguration().setClass(HConstants.REGION_IMPL, TestRegion.class, HRegion.class); - StartMiniClusterOption.Builder builder = StartMiniClusterOption.builder(); - // 1 master is expected to be aborted with this test - builder.numMasters(2).numRegionServers(3); - TEST_UTIL.startMiniCluster(builder.build()); - MiniHBaseCluster 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()); - MiniHBaseCluster 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 { @@ -220,5 +91,4 @@ public OperationStatus[] batchMutate(Mutation[] mutations, boolean atomic, long return super.batchMutate(mutations, atomic, nonceGroup, nonce); } } - } 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 4fae5596e285..e8f761b269cc 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.MiniHBaseCluster; -import org.apache.hadoop.hbase.StartMiniClusterOption; 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); - StartMiniClusterOption.Builder builder = StartMiniClusterOption.builder(); - // 2 masters are expected to be aborted with this test - builder.numMasters(3).numRegionServers(3); - TEST_UTIL.startMiniCluster(builder.build()); - MiniHBaseCluster 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 { @@ -106,5 +79,4 @@ public OperationStatus[] batchMutate(Mutation[] mutations, boolean atomic, long return super.batchMutate(mutations, atomic, nonceGroup, nonce); } } - } 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 f5068160f3dd..1a60c3337dc6 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.StartMiniClusterOption; @@ -43,25 +42,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); @@ -69,12 +66,12 @@ public class TestMasterRepairMode { private static HBaseTestingUtility TEST_UTIL; - @Before + @BeforeEach public void setUp() throws Exception { TEST_UTIL = new HBaseTestingUtility(); } - @After + @AfterEach public void tearDown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -97,13 +94,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); @@ -125,20 +122,19 @@ 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"); } try (AsyncConnection asyncConn = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get()) { // use async table so we can set the timeout and retry value to let the operation fail fast AsyncTable table = asyncConn.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 b53b0fbc949d..6ceded656714 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.HBaseTestingUtility; import org.apache.hadoop.hbase.MiniHBaseCluster; @@ -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,9 @@ public void testForCheckingIfEnableAndDisableWorksFineAfterSwitch() throws Excep TEST_UTIL.getAdmin().disableTable(tableName); NavigableSet regions = HBaseTestingUtility.getAllOnlineRegions(cluster); - assertEquals("The number of regions for the table tableRestart should be 0 and only" - + "the catalog and namespace tables should be present.", 2, regions.size()); + assertEquals(2, regions.size(), + "The number of regions for the table tableRestart should be 0 and only" + + "the catalog and namespace tables should be present."); List masterThreads = cluster.getMasterThreads(); MasterThread activeMaster = null; @@ -105,10 +104,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 +117,11 @@ public void testForCheckingIfEnableAndDisableWorksFineAfterSwitch() throws Excep TEST_UTIL.waitUntilNoRegionsInTransition(60000); log("Verifying there are " + numRegions + " assigned on cluster\n"); regions = HBaseTestingUtility.getAllOnlineRegions(cluster); - assertEquals("The assigned regions were not onlined after master" - + " switch except for the catalog and namespace tables.", 6, regions.size()); - assertTrue("The table should be in enabled state", cluster.getMaster().getTableStateManager() - .isTableState(TableName.valueOf(name.getMethodName()), TableState.State.ENABLED)); + assertEquals(6, regions.size(), "The assigned regions were not onlined after master" + + " switch except for the catalog and namespace tables."); + 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 1fd644adb14d..ebc7f23cc69e 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.HBaseTestingUtility; import org.apache.hadoop.hbase.LocalHBaseCluster; @@ -37,26 +36,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 HBaseTestingUtility 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 @@ -153,9 +148,10 @@ 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, + assertNotEquals(-1, Waiter.waitFor(htu.getConfiguration(), timeout, - () -> masterThread.getMaster().getServerManager() != null)); + () -> masterThread.getMaster().getServerManager() != null), + "Timeout waiting for server manager to become available."); htu.getConnection().getAdmin().shutdown(); masterThread.join(); } finally { 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 a99c7aa97d19..4d4842ff13dc 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,8 +17,9 @@ */ package org.apache.hadoop.hbase.master; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.io.IOException; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MetaTableAccessor; @@ -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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); 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 a3f9f9b505e5..62754e2d84e8 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; @@ -29,19 +28,16 @@ import org.apache.hadoop.hbase.StartMiniClusterOption; 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 cf47a07e2db6..bfe857e68f7f 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.HBaseTestingUtility; 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.getHBaseAdmin(); @@ -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 8ec078fe524a..febbde037ed7 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.HBaseTestingUtility; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.StartMiniClusterOption; @@ -29,35 +28,30 @@ import org.apache.hadoop.hbase.client.ConnectionFactory; 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); private static final long WAIT_TIMEOUT = 120000; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { StartMiniClusterOption option = StartMiniClusterOption.builder().numMasters(2).numRegionServers(3).numDataNodes(3).build(); UTIL.startMiniCluster(option); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { UTIL.shutdownMiniCluster(); } @@ -91,7 +85,7 @@ public void testStopActiveMaster() throws Exception { } ServerName newMetaServer = conn.locateRegions(TableName.META_TABLE_NAME).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 ce1ac00cc0d8..55f9739cd3d3 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.MiniHBaseCluster; @@ -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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); final static Configuration conf = TEST_UTIL.getConfiguration(); - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { StartMiniClusterOption option = StartMiniClusterOption.builder().numRegionServers(3) .rsClass(MyRegionServer.class).numDataNodes(3).build(); TEST_UTIL.startMiniCluster(option); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -99,8 +94,8 @@ public void testExpireMetaRegionServer() throws Exception { metaServerName = regionStates.getRegionServerOfRegion(HRegionInfo.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. @@ -123,15 +118,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(HRegionInfo.FIRST_META_REGIONINFO)); + assertTrue(regionStates.isRegionOnline(HRegionInfo.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(HRegionInfo.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(HRegionInfo.FIRST_META_REGIONINFO), + "Meta should be assigned"); + assertNotEquals(metaState.getServerName(), metaServerName, + "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 86f0e3a4c47b..2ca45b451a8f 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,14 +19,13 @@ 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.Cell; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MetaTableAccessor; @@ -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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.startMiniCluster(3); HBaseTestingUtility.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/TestNewStartedRegionServerVersion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestNewStartedRegionServerVersion.java index a01403ab4dab..7901e1026edd 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.HBaseTestingUtility; 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); - @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 469527a75a37..1e4912726d5d 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.HBaseTestingUtility; 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 HBaseTestingUtility HTU = new HBaseTestingUtility(); - @Before + @BeforeEach public void setUp() throws Exception { master = new MockMasterServices(HTU.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 c3c04112c39b..afa05b93aaa9 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.HBaseTestingUtility; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.ServerName; @@ -42,34 +41,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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); 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); @@ -77,7 +67,7 @@ public void setup() throws Exception { .numDataNodes(NUM_RS).createWALDir(true).build()); } - @After + @AfterEach public void tearDown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -178,8 +168,8 @@ private void prepareDataBeforeRecreate(HBaseTestingUtility testUtil, TableName t private void ensureTableNotColocatedWithSystemTable(TableName userTable, TableName systemTable) throws IOException, InterruptedException { MiniHBaseCluster 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 63769b23d43b..c3e40ae3e962 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; @@ -35,7 +35,6 @@ import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicInteger; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; @@ -64,22 +63,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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private final static int SLAVES = 10; @@ -91,7 +86,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 @@ -104,12 +99,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"; @@ -180,12 +175,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)) @@ -264,7 +259,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; @@ -367,8 +362,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 "); } /** @@ -396,8 +391,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"); } /** @@ -407,9 +402,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"); } /** @@ -432,8 +426,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 @@ -446,11 +440,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); } } } @@ -544,9 +537,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 aba4ce73673d..c107c9d27d96 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.util.ArrayList; import java.util.Collection; @@ -25,7 +25,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.HBaseIOException; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; @@ -39,34 +38,33 @@ import org.apache.hadoop.hbase.master.balancer.LoadBalancerFactory; 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; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@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 static final Logger LOG = LoggerFactory.getLogger(TestRegionPlacement2.class); private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); 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 @@ -76,7 +74,7 @@ public static void setupBeforeClass() throws Exception { TEST_UTIL.startMiniCluster(SLAVES); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -92,8 +90,7 @@ public void testFavoredNodesPresentForRoundRobinAssignment() throws HBaseIOExcep 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); @@ -152,8 +149,7 @@ public void testFavoredNodesPresentForRandomAssignment() throws HBaseIOException 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 0482ef7d3396..a8e7d26de6de 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.HBaseTestingUtility; import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.TableName; @@ -31,31 +32,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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.startMiniCluster(StartMiniClusterOption.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 7a90f2aeee94..1dbfb8b9dfd1 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.HRegionInfo; import org.apache.hadoop.hbase.TableName; 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"); @@ -55,7 +45,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 7679f03f54db..34e6eb63c21f 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.HBaseTestingUtility; 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 HBaseTestingUtility HBASE_TESTING_UTILITY = new HBaseTestingUtility(); @@ -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 51258ba5b988..2e5faaecfce6 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.HBaseTestingUtility; import org.apache.hadoop.hbase.MiniHBaseCluster; import org.apache.hadoop.hbase.StartMiniClusterOption; 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 HBaseTestingUtility HBASE_TESTING_UTILITY = new HBaseTestingUtility(); private MiniHBaseCluster 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 4371b610cf0a..af1db62f55c7 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.HBaseTestingUtility; 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); 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 9b42a68e3328..0c042716ed66 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.MiniHBaseCluster; import org.apache.hadoop.hbase.ServerName; @@ -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 19f9ae14a600..ef0c062308e3 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MiniHBaseCluster; @@ -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,30 @@ /** * 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 HBaseTestingUtility TEST_UTIL; - @Rule - public TestName name = new TestName(); - @Parameterized.Parameter - public boolean splitWALCoordinatedByZK; + private String testMethodName; + + @BeforeEach + public void setTestMethod(TestInfo testInfo) { + testMethodName = (testInfo.getTestMethod().get().getName() + "_" + testInfo.getDisplayName()) + .replaceAll("[^0-9A-Za-z_]", "_"); + } + + 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 +103,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); 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); @@ -304,8 +307,7 @@ private NavigableSet getDoubleAssignedRegions(MiniHBaseCluster cluster) 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 b8622022596d..65e1833e7b2d 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.MiniHBaseCluster; import org.apache.hadoop.hbase.ServerName; @@ -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 1cc1e346a1a0..2a92ced93f05 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.HBaseTestingUtility; 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); - @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 7ebbff0b76a3..25d504ac161e 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.HBaseTestingUtility; 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); 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 eaca894c61a4..07f460e28750 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MiniHBaseCluster; @@ -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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); 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); StartMiniClusterOption 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 c1c23a9e654a..a78b8fa6db28 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.HBaseTestingUtility; 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); - @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 c8c2444ceff7..6bbbeb047fce 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.HBaseTestingUtility; 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 HBaseTestingUtility(); 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 @@ -562,7 +555,7 @@ public void run() { } } } - }; + } }.start(); slm.splitLogDistributed(logDirPath); 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 4aad5bec6ae6..b1eb33c22f5a 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.HBaseTestingUtility; 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); @@ -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 40af3f2f9015..feed9a65da37 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.HBaseTestingUtility; 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 HBaseTestingUtility 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 HBaseTestingUtility(); 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(HBaseTestingUtility 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 9e36f36a7a21..df6de628c81d 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,34 +17,31 @@ */ 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.HBaseTestingUtility; 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.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; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MediumTests.TAG) +@Tag(MasterTests.TAG) public class TestUnknownServers { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestUnknownServers.class); private static HBaseTestingUtility 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 HBaseTestingUtility(); UTIL.getConfiguration().setClass(HConstants.MASTER_IMPL, @@ -55,12 +52,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 21b192caee85..cc1974c4aa44 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.MiniHBaseCluster; @@ -38,13 +37,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; @@ -53,13 +51,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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); @@ -75,7 +70,7 @@ public class TestWarmupRegion { /** * @throws java.lang.Exception */ - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { TEST_UTIL.startMiniCluster(SLAVES); } @@ -83,7 +78,7 @@ public static void setUpBeforeClass() throws Exception { /** * @throws java.lang.Exception */ - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -91,7 +86,7 @@ public static void tearDownAfterClass() throws Exception { /** * @throws java.lang.Exception */ - @Before + @BeforeEach public void setUp() throws Exception { table = TEST_UTIL.createTable(TABLENAME, FAMILY); @@ -121,7 +116,7 @@ public boolean evaluate() throws IOException { /** * @throws java.lang.Exception */ - @After + @AfterEach public void tearDown() throws Exception { TEST_UTIL.deleteTable(TABLENAME); } @@ -139,7 +134,6 @@ public void run() { for (int i = 0; i < 10; i++) { warmupHRegion(info, htd, rs.getWAL(info), rs.getConfiguration(), rs, null); } - } catch (IOException ie) { LOG.error("Failed warming up region " + info.getRegionNameAsString(), ie); }