From ebd22669fd8e65f568346214749a68f4e1e5dbd2 Mon Sep 17 00:00:00 2001 From: liuxiaocs7 Date: Mon, 4 May 2026 18:01:05 +0800 Subject: [PATCH] HBASE-30145 Upgrade hbase-server to use junit5 Part17 --- .../TestObservedExceptionsInBatch.java | 21 ++--- .../TestOpenRegionFailedMemoryLeak.java | 32 +++----- .../TestOpenSeqNumUnexpectedIncrease.java | 24 +++--- .../hbase/regionserver/TestParallelPut.java | 45 +++++------ .../TestPerColumnFamilyFlush.java | 36 ++++----- .../hbase/regionserver/TestPriorityRpc.java | 18 ++--- .../regionserver/TestRSChoresScheduled.java | 30 +++---- .../TestRSKilledWhenInitializing.java | 27 ++----- .../hbase/regionserver/TestRSQosFunction.java | 17 ++-- .../hbase/regionserver/TestRSRpcServices.java | 15 ++-- .../regionserver/TestRSSnapshotVerifier.java | 29 +++---- .../TestReadAndWriteRegionInfoFile.java | 26 +++--- .../regionserver/TestRecoveredEdits.java | 46 +++++------ .../TestRecoveredEditsReplayAndAbort.java | 51 +++++------- .../regionserver/TestRegionFavoredNodes.java | 28 +++---- .../regionserver/TestRegionIncrement.java | 45 +++++------ .../hbase/regionserver/TestRegionInfo.java | 77 +++++++++--------- .../regionserver/TestRegionInterrupt.java | 54 ++++++------- .../TestRegionMergeTransactionOnCluster.java | 79 +++++++++---------- .../hbase/regionserver/TestRegionMove.java | 46 ++++------- .../hbase/regionserver/TestRegionOpen.java | 36 +++------ .../TestRegionReplicaFailover.java | 42 ++++------ .../TestRegionReplicaReplicationError.java | 22 ++---- ...tRegionReplicaWaitForPrimaryFlushConf.java | 44 +++++------ .../TestRegionReplicasAreDistributed.java | 26 +++--- .../TestRegionReplicasWithModifyTable.java | 67 ++++++++-------- ...estRegionReplicasWithRestartScenarios.java | 44 +++++------ .../regionserver/TestRegionServerAbort.java | 30 +++---- .../TestRegionServerAbortTimeout.java | 28 +++---- .../TestRegionServerAccounting.java | 19 ++--- .../TestRegionServerCrashDisableWAL.java | 24 +++--- .../TestRegionServerHostname.java | 52 ++++++------ .../regionserver/TestRegionServerMetrics.java | 78 ++++++++---------- .../TestRegionServerNoMaster.java | 64 +++++++-------- .../TestRegionServerOnlineConfigChange.java | 43 +++++----- .../TestRegionServerReadRequestMetrics.java | 39 ++++----- .../TestRegionServerRegionSpaceUseReport.java | 23 ++---- .../TestRegionServerRejectDuringAbort.java | 30 +++---- .../TestRegionServerReportForDuty.java | 33 ++++---- .../regionserver/TestRegionServerScan.java | 30 +++---- .../regionserver/TestRegionServerUseIp.java | 23 +++--- .../regionserver/TestRegionSplitPolicy.java | 32 +++----- .../TestRegionSplitRestriction.java | 22 ++---- .../regionserver/TestRemoveRegionMetrics.java | 30 +++---- .../regionserver/TestReplicateToReplica.java | 44 ++++------- .../TestRequestsPerSecondMetric.java | 27 +++---- .../regionserver/TestResettingCounters.java | 27 +++---- .../regionserver/TestReversibleScanners.java | 43 ++++------ .../TestRowPrefixBloomFilter.java | 39 ++++----- .../hbase/regionserver/TestRowTooBig.java | 32 ++++---- .../regionserver/TestRpcSchedulerFactory.java | 23 ++---- 51 files changed, 756 insertions(+), 1106 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestObservedExceptionsInBatch.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestObservedExceptionsInBatch.java index 89082da08604..0a4579d2a215 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestObservedExceptionsInBatch.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestObservedExceptionsInBatch.java @@ -17,30 +17,23 @@ */ package org.apache.hadoop.hbase.regionserver; -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 org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.regionserver.HRegion.ObservedExceptionsInBatch; 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; /** * Test class for {@link ObservedExceptionsInBatch}. */ -@Category(SmallTests.class) +@Tag(SmallTests.TAG) public class TestObservedExceptionsInBatch { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestObservedExceptionsInBatch.class); - private ObservedExceptionsInBatch observedExceptions; - @Before + @BeforeEach public void setup() { observedExceptions = new ObservedExceptionsInBatch(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestOpenRegionFailedMemoryLeak.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestOpenRegionFailedMemoryLeak.java index cfc9fed3dfed..39895a5f743c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestOpenRegionFailedMemoryLeak.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestOpenRegionFailedMemoryLeak.java @@ -18,7 +18,8 @@ package org.apache.hadoop.hbase.regionserver; import static org.apache.hadoop.hbase.HBaseTestingUtil.fam1; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.spy; import java.io.IOException; @@ -29,7 +30,6 @@ import java.util.concurrent.TimeUnit; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.CompatibilitySingletonFactory; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; @@ -43,27 +43,21 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManagerTestHelper; import org.apache.hadoop.hbase.util.TableDescriptorChecker; import org.apache.hadoop.metrics2.MetricsExecutor; -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({ RegionServerTests.class, LargeTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(LargeTests.TAG) public class TestOpenRegionFailedMemoryLeak { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestOpenRegionFailedMemoryLeak.class); - private static final Logger LOG = LoggerFactory.getLogger(TestOpenRegionFailedMemoryLeak.class); private static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); - @BeforeClass + @BeforeAll public static void startCluster() throws Exception { Configuration conf = TEST_UTIL.getConfiguration(); @@ -71,7 +65,7 @@ public static void startCluster() throws Exception { conf.setBoolean(TableDescriptorChecker.TABLE_SANITY_CHECKS, true); } - @AfterClass + @AfterAll public static void tearDown() throws IOException { EnvironmentEdgeManagerTestHelper.reset(); LOG.info("Cleaning test directory: " + TEST_UTIL.getDataTestDir()); @@ -108,12 +102,12 @@ public void testOpenRegionFailedMemoryLeak() throws Exception { field.setAccessible(true); BlockingQueue workQueue = (BlockingQueue) field.get(executor); // there are still two task not cancel, can not cause to memory lack - Assert.assertTrue("ScheduledExecutor#workQueue should equals 2, now is " + workQueue.size() - + ", please check region is close", 2 == workQueue.size()); + assertTrue(2 == workQueue.size(), "ScheduledExecutor#workQueue should equals 2, now is " + + workQueue.size() + " please check region is close"); found = true; } } - Assert.assertTrue("can not find workQueue, test failed", found); + assertTrue(found, "can not find workQueue, test failed"); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestOpenSeqNumUnexpectedIncrease.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestOpenSeqNumUnexpectedIncrease.java index 79bf24b08204..98bcdc0c08a5 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestOpenSeqNumUnexpectedIncrease.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestOpenSeqNumUnexpectedIncrease.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.List; @@ -26,7 +26,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.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -36,22 +35,17 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.wal.WAL; -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-20242 */ -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestOpenSeqNumUnexpectedIncrease { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestOpenSeqNumUnexpectedIncrease.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static AtomicInteger FAILED_OPEN = new AtomicInteger(0); @@ -83,7 +77,7 @@ public Map> close() throws IOException { } } - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.getConfiguration().setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, 600000); UTIL.getConfiguration().setClass(HConstants.REGION_IMPL, MockHRegion.class, HRegion.class); @@ -92,7 +86,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/regionserver/TestParallelPut.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestParallelPut.java index 55f30578f5ac..414cb498bbba 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestParallelPut.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestParallelPut.java @@ -18,13 +18,12 @@ package org.apache.hadoop.hbase.regionserver; import static org.apache.hadoop.hbase.HBaseTestingUtil.fam1; -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.io.IOException; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HConstants.OperationStatusCode; @@ -41,34 +40,27 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManagerTestHelper; -import org.junit.After; -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.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.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Testing of multiPut in parallel. */ -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestParallelPut { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestParallelPut.class); - private static final Logger LOG = LoggerFactory.getLogger(TestParallelPut.class); - @Rule - public TestName name = new TestName(); private HRegion region = null; private static HBaseTestingUtil HBTU = new HBaseTestingUtil(); private static final int THREADS100 = 100; + private String name; // Test names static byte[] tableName; @@ -80,7 +72,7 @@ public class TestParallelPut { static final byte[] row = Bytes.toBytes("rowA"); static final byte[] row2 = Bytes.toBytes("rowB"); - @BeforeClass + @BeforeAll public static void beforeClass() { // Make sure enough handlers. HBTU.getConfiguration().setInt(HConstants.REGION_SERVER_HANDLER_COUNT, THREADS100); @@ -89,12 +81,13 @@ public static void beforeClass() { /** * @see org.apache.hadoop.hbase.HBaseTestCase#setUp() */ - @Before - public void setUp() throws Exception { - tableName = Bytes.toBytes(name.getMethodName()); + @BeforeEach + public void setUp(TestInfo testInfo) throws Exception { + name = testInfo.getTestMethod().get().getName(); + tableName = Bytes.toBytes(name); } - @After + @AfterEach public void tearDown() throws Exception { EnvironmentEdgeManagerTestHelper.reset(); if (region != null) { @@ -103,7 +96,7 @@ public void tearDown() throws Exception { } public String getName() { - return name.getMethodName(); + return name; } ////////////////////////////////////////////////////////////////////////////// @@ -228,7 +221,7 @@ public void run() { assertEquals(OperationStatusCode.SUCCESS, ret[0].getOperationStatusCode()); assertGet(this.region, rowkey, fam1, qual1, value); } catch (IOException e) { - assertTrue("Thread id " + threadNumber + " operation " + i + " failed.", false); + assertTrue(false, "Thread id " + threadNumber + " operation " + i + " failed."); } } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestPerColumnFamilyFlush.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestPerColumnFamilyFlush.java index c015e630f1c5..4ff2350849c6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestPerColumnFamilyFlush.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestPerColumnFamilyFlush.java @@ -17,17 +17,16 @@ */ package org.apache.hadoop.hbase.regionserver; -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.Arrays; import java.util.List; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; @@ -55,9 +54,8 @@ import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.hbase.wal.AbstractFSWALProvider; import org.apache.hadoop.hbase.wal.WAL; -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; @@ -66,13 +64,9 @@ /** * This test verifies the correctness of the Per Column Family flushing strategy */ -@Category({ RegionServerTests.class, LargeTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(LargeTests.TAG) public class TestPerColumnFamilyFlush { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestPerColumnFamilyFlush.class); - private static final Logger LOG = LoggerFactory.getLogger(TestPerColumnFamilyFlush.class); private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); @@ -122,11 +116,11 @@ void verifyEdit(int familyNum, int putNum, Table table) throws IOException { byte[] family = FAMILIES[familyNum - 1]; byte[] qf = Bytes.toBytes("q" + familyNum); byte[] val = Bytes.toBytes("val" + familyNum + "-" + putNum); - assertNotNull(("Missing Put#" + putNum + " for CF# " + familyNum), r.getFamilyMap(family)); - assertNotNull(("Missing Put#" + putNum + " for CF# " + familyNum), - r.getFamilyMap(family).get(qf)); - assertTrue(("Incorrect value for Put#" + putNum + " for CF# " + familyNum), - Arrays.equals(r.getFamilyMap(family).get(qf), val)); + assertNotNull(r.getFamilyMap(family), "Missing Put#" + putNum + " for CF# " + familyNum); + assertNotNull(r.getFamilyMap(family).get(qf), + "Missing Put#" + putNum + " for CF# " + familyNum); + assertTrue(Arrays.equals(r.getFamilyMap(family).get(qf), val), + "Incorrect value for Put#" + putNum + " for CF# " + familyNum); } @Test @@ -369,7 +363,7 @@ private void doTestLogReplay() throws Exception { Pair desiredRegionAndServer = getRegionWithName(TABLENAME); HRegion desiredRegion = desiredRegionAndServer.getFirst(); - assertTrue("Could not find a region which hosts the new region.", desiredRegion != null); + assertTrue(desiredRegion != null, "Could not find a region which hosts the new region."); // Flush the region selectively. desiredRegion.flush(false); @@ -463,7 +457,7 @@ public void testFlushingWhenLogRolling() throws Exception { Table table = TEST_UTIL.createTable(tableName, FAMILIES); Pair desiredRegionAndServer = getRegionWithName(tableName); final HRegion desiredRegion = desiredRegionAndServer.getFirst(); - assertTrue("Could not find a region which hosts the new region.", desiredRegion != null); + assertTrue(desiredRegion != null, "Could not find a region which hosts the new region."); LOG.info("Writing to region=" + desiredRegion); // Add one row for both CFs. diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestPriorityRpc.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestPriorityRpc.java index 3b6d4398cc3c..ed5f265220b2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestPriorityRpc.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestPriorityRpc.java @@ -17,14 +17,13 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; 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.TableName; @@ -34,9 +33,8 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.Bytes; -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.apache.hbase.thirdparty.com.google.protobuf.ByteString; import org.apache.hbase.thirdparty.com.google.protobuf.UnsafeByteOperations; @@ -51,13 +49,9 @@ /** * Tests that verify certain RPCs get a higher QoS. */ -@Category({ RegionServerTests.class, SmallTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(SmallTests.TAG) public class TestPriorityRpc { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestPriorityRpc.class); - private static Configuration CONF = HBaseConfiguration.create(); @Test @@ -130,7 +124,7 @@ public void testQosFunctionForScanMethod() throws IOException { RSAnnotationReadingPriorityFunction qosFunc = new RSAnnotationReadingPriorityFunction(mockRpc); final int qos = qosFunc.getPriority(header, scanRequest, createSomeUser()); - assertEquals(Integer.toString(qos), qos, HConstants.NORMAL_QOS); + assertEquals(HConstants.NORMAL_QOS, qos, Integer.toString(qos)); // build a scan request with scannerID scanBuilder = ScanRequest.newBuilder(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSChoresScheduled.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSChoresScheduled.java index 33b23c89726e..7a1a58e568db 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSChoresScheduled.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSChoresScheduled.java @@ -17,42 +17,38 @@ */ package org.apache.hadoop.hbase.regionserver; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.lang.reflect.Field; import org.apache.hadoop.hbase.ExecutorStatusChore; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.ScheduledChore; import org.apache.hadoop.hbase.StartTestingClusterOption; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.RegionServerTests; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +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 HRegionServer default chores are scheduled */ -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestRSChoresScheduled { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRSChoresScheduled.class); - private static HRegionServer hRegionServer; private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.startMiniCluster(StartTestingClusterOption.builder().numRegionServers(1).build()); hRegionServer = UTIL.getMiniHBaseCluster().getRegionServer(0); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { UTIL.shutdownMiniCluster(); } @@ -67,8 +63,8 @@ private E getChoreObj(String fieldName) throws NoSuchFieldException, IllegalAcce } private void testIfChoreScheduled(E choreObj) { - Assert.assertNotNull(choreObj); - Assert.assertTrue(hRegionServer.getChoreService().isChoreScheduled(choreObj)); + assertNotNull(choreObj); + assertTrue(hRegionServer.getChoreService().isChoreScheduled(choreObj)); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSKilledWhenInitializing.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSKilledWhenInitializing.java index f839e45ad537..d4ed344c236f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSKilledWhenInitializing.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSKilledWhenInitializing.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.regionserver; -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.io.IOException; import java.util.List; @@ -26,7 +26,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.LocalHBaseCluster; @@ -41,12 +40,9 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread; import org.apache.hadoop.hbase.util.Threads; -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.Disabled; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,19 +52,12 @@ * Tests that a regionserver that dies after reporting for duty gets removed from list of online * regions. See HBASE-9593. */ -@Category({ RegionServerTests.class, MediumTests.class }) -@Ignore("See HBASE-19515") +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) +@Disabled("See HBASE-19515") public class TestRSKilledWhenInitializing { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRSKilledWhenInitializing.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRSKilledWhenInitializing.class); - @Rule - public TestName testName = new TestName(); - // This boolean needs to be globally available. It is used below in our // mocked up regionserver so it knows when to die. private static AtomicBoolean masterActive = new AtomicBoolean(false); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSQosFunction.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSQosFunction.java index 15ee32397e9a..59738e93209f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSQosFunction.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSQosFunction.java @@ -20,16 +20,14 @@ import static org.mockito.Mockito.when; 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.ipc.QosTestBase; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.RegionServerTests; -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.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiRequest; @@ -38,17 +36,14 @@ * Basic test that qos function is sort of working; i.e. a change in method naming style over in pb * doesn't break it. */ -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestRSQosFunction extends QosTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRSQosFunction.class); - private Configuration conf; private RSRpcServices rpcServices; private RSAnnotationReadingPriorityFunction qosFunction; - @Before + @BeforeEach public void setUp() { conf = HBaseConfiguration.create(); rpcServices = Mockito.mock(RSRpcServices.class); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSRpcServices.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSRpcServices.java index ca7e20f5869d..4ccee72b873a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSRpcServices.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSRpcServices.java @@ -17,20 +17,18 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Optional; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.client.RegionInfoBuilder; import org.apache.hadoop.hbase.ipc.RpcCall; import org.apache.hadoop.hbase.ipc.RpcServer; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.RegionServerTests; -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.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,12 +36,9 @@ /** * Test parts of {@link RSRpcServices} */ -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestRSRpcServices { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRSRpcServices.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRSRpcServices.class); /** diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSSnapshotVerifier.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSSnapshotVerifier.java index 194fbf47b977..86699391fe1b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSSnapshotVerifier.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSSnapshotVerifier.java @@ -17,12 +17,13 @@ */ package org.apache.hadoop.hbase.regionserver; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.io.IOException; import java.util.ArrayList; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.SnapshotDescription; @@ -36,25 +37,20 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.CommonFSUtils; import org.apache.hadoop.hbase.util.RegionSplitter; -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; import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos; -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestRSSnapshotVerifier { private static final Logger LOG = LoggerFactory.getLogger(TestRSSnapshotVerifier.class); - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRSSnapshotVerifier.class); - private HBaseTestingUtil TEST_UTIL; private final TableName tableName = TableName.valueOf("TestRSSnapshotVerifier"); private final byte[] cf = Bytes.toBytes("cf"); @@ -63,7 +59,7 @@ public class TestRSSnapshotVerifier { private SnapshotProtos.SnapshotDescription snapshotProto = ProtobufUtil.createHBaseProtosSnapshotDesc(snapshot); - @Before + @BeforeEach public void setup() throws Exception { TEST_UTIL = new HBaseTestingUtil(); TEST_UTIL.startMiniCluster(3); @@ -97,7 +93,7 @@ public void setup() throws Exception { manifest.consolidate(); } - @Test(expected = org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException.class) + @Test public void testVerifyStoreFile() throws Exception { RSSnapshotVerifier verifier = TEST_UTIL.getHBaseCluster().getRegionServer(0).getRsSnapshotVerifier(); @@ -106,10 +102,11 @@ public void testVerifyStoreFile() throws Exception { Path filePath = new ArrayList<>(region.getStore(cf).getStorefiles()).get(0).getPath(); TEST_UTIL.getDFSCluster().getFileSystem().delete(filePath, true); LOG.info("delete store file {}", filePath); - verifier.verifyRegion(snapshotProto, region.getRegionInfo()); + assertThrows(org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException.class, + () -> verifier.verifyRegion(snapshotProto, region.getRegionInfo())); } - @After + @AfterEach public void teardown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestReadAndWriteRegionInfoFile.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestReadAndWriteRegionInfoFile.java index 2869be090f42..dcf937631bec 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestReadAndWriteRegionInfoFile.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestReadAndWriteRegionInfoFile.java @@ -17,15 +17,14 @@ */ package org.apache.hadoop.hbase.regionserver; -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.io.IOException; import org.apache.hadoop.conf.Configuration; 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.HBaseCommonTestingUtil; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; @@ -34,19 +33,14 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.FSTableDescriptors; -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({ RegionServerTests.class, SmallTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(SmallTests.TAG) public class TestReadAndWriteRegionInfoFile { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReadAndWriteRegionInfoFile.class); - private static final HBaseCommonTestingUtil UTIL = new HBaseTestingUtil(); private static final Configuration CONF = UTIL.getConfiguration(); @@ -55,13 +49,13 @@ public class TestReadAndWriteRegionInfoFile { private static Path ROOT_DIR; - @BeforeClass + @BeforeAll public static void setUp() throws IOException { ROOT_DIR = UTIL.getDataTestDir(); FS = ROOT_DIR.getFileSystem(CONF); } - @AfterClass + @AfterAll public static void tearDown() { UTIL.cleanupTestDir(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRecoveredEdits.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRecoveredEdits.java index f04abb041a7d..68bc26a66daa 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRecoveredEdits.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRecoveredEdits.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.regionserver; -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.io.IOException; import java.util.ArrayList; @@ -29,7 +29,6 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellComparatorImpl; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MemoryCompactionPolicy; @@ -54,32 +53,25 @@ import org.apache.hadoop.hbase.wal.WALKey; import org.apache.hadoop.hbase.wal.WALSplitUtil; import org.apache.hadoop.hbase.wal.WALStreamReader; -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.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; /** * Tests around replay of recovered.edits content. */ -@Category({ MediumTests.class }) +@Tag(MediumTests.TAG) public class TestRecoveredEdits { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRecoveredEdits.class); - private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static final Logger LOG = LoggerFactory.getLogger(TestRecoveredEdits.class); private static BlockCache blockCache; - @Rule - public TestName testName = new TestName(); + private String name; /** * Path to a recovered.edits file in hbase-server test resources folder. This is a little fragile @@ -106,11 +98,16 @@ public class TestRecoveredEdits { /** * Name of table mentioned edits from recovered.edits */ - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { blockCache = BlockCacheFactory.createBlockCache(TEST_UTIL.getConfiguration()); } + @BeforeEach + public void setUp(TestInfo testInfo) { + name = testInfo.getTestMethod().get().getName(); + } + /** * HBASE-12782 ITBLL fails for me if generator does anything but 5M per maptask. Create a region. * Close it. Then copy into place a file to replay, one that is bigger than configured flush size @@ -129,9 +126,8 @@ private void testReplayWorksWithMemoryCompactionPolicy(MemoryCompactionPolicy po // Set it so we flush every 1M or so. Thats a lot. conf.setInt(HConstants.HREGION_MEMSTORE_FLUSH_SIZE, 1024 * 1024); conf.set(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY, String.valueOf(policy).toLowerCase()); - TableDescriptor tableDescriptor = - TableDescriptorBuilder.newBuilder(TableName.valueOf(testName.getMethodName())) - .setColumnFamily(RECOVEREDEDITS_CFD).build(); + TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(TableName.valueOf(name)) + .setColumnFamily(RECOVEREDEDITS_CFD).build(); RegionInfo hri = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build(); final String encodedRegionName = hri.getEncodedName(); Path hbaseRootDir = TEST_UTIL.getDataTestDir(); @@ -163,9 +159,9 @@ private void testReplayWorksWithMemoryCompactionPolicy(MemoryCompactionPolicy po // we flush at 1MB, that there are at least 3 flushed files that are there because of the // replay of edits. if (policy == MemoryCompactionPolicy.EAGER || policy == MemoryCompactionPolicy.ADAPTIVE) { - assertTrue("Files count=" + storeFiles.size(), storeFiles.size() >= 1); + assertTrue(storeFiles.size() >= 1, "Files count=" + storeFiles.size()); } else { - assertTrue("Files count=" + storeFiles.size(), storeFiles.size() > 10); + assertTrue(storeFiles.size() > 10, "Files count=" + storeFiles.size()); } // Now verify all edits made it into the region. int count = verifyAllEditsMadeItIn(fs, conf, RECOVEREDEDITS_PATH, region); @@ -232,8 +228,8 @@ public static int verifyAllEditsMadeItIn(final FileSystem fs, final Configuratio i++; } } - assertEquals("Only found " + found + " cells in region, but there are " + walCells.size() - + " cells in recover edits", found, walCells.size()); + assertEquals(found, walCells.size(), "Only found " + found + " cells in region, but there are " + + walCells.size() + " cells in recover edits"); return count; } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRecoveredEditsReplayAndAbort.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRecoveredEditsReplayAndAbort.java index 1a4ba7ac99cd..b3c4ceb6ae14 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRecoveredEditsReplayAndAbort.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRecoveredEditsReplayAndAbort.java @@ -17,11 +17,13 @@ */ package org.apache.hadoop.hbase.regionserver; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; @@ -45,14 +47,11 @@ import org.apache.hadoop.hbase.wal.WALKeyImpl; import org.apache.hadoop.hbase.wal.WALProvider; import org.apache.hadoop.hbase.wal.WALSplitUtil; -import org.junit.After; -import org.junit.Assert; -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.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,21 +60,15 @@ * HBASE-21031 If replay edits fails, we need to make sure memstore is rollbacked And if MSLAB is * used, all chunk is released too. */ -@Category({ RegionServerTests.class, SmallTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(SmallTests.TAG) public class TestRecoveredEditsReplayAndAbort { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRecoveredEditsReplayAndAbort.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRecoveredEditsReplayAndAbort.class); protected final byte[] row = Bytes.toBytes("rowA"); protected final static byte[] fam1 = Bytes.toBytes("colfamily11"); - @Rule - public TestName name = new TestName(); - // Test names protected TableName tableName; protected String method; @@ -84,15 +77,15 @@ public class TestRecoveredEditsReplayAndAbort { public static Configuration CONF; private HRegion region = null; - @Before - public void setup() throws IOException { + @BeforeEach + public void setup(TestInfo testInfo) throws IOException { TEST_UTIL = new HBaseTestingUtil(); CONF = TEST_UTIL.getConfiguration(); - method = name.getMethodName(); + method = testInfo.getTestMethod().get().getName(); tableName = TableName.valueOf(method); } - @After + @AfterEach public void tearDown() throws Exception { LOG.info("Cleaning test directory: " + TEST_UTIL.getDataTestDir()); TEST_UTIL.cleanupTestDir(); @@ -167,27 +160,25 @@ public boolean progress() { replayedEdits++; // during replay, rsAccounting should align with global memstore, because // there is only one memstore here - Assert.assertEquals(rsAccounting.getGlobalMemStoreDataSize(), - region.getMemStoreDataSize()); - Assert.assertEquals(rsAccounting.getGlobalMemStoreHeapSize(), - region.getMemStoreHeapSize()); - Assert.assertEquals(rsAccounting.getGlobalMemStoreOffHeapSize(), + assertEquals(rsAccounting.getGlobalMemStoreDataSize(), region.getMemStoreDataSize()); + assertEquals(rsAccounting.getGlobalMemStoreHeapSize(), region.getMemStoreHeapSize()); + assertEquals(rsAccounting.getGlobalMemStoreOffHeapSize(), region.getMemStoreOffHeapSize()); // abort the replay before finishing, leaving some edits in the memory return replayedEdits < totalEdits - 10; } }); - Assert.fail("Should not reach here"); + fail("Should not reach here"); } catch (IOException t) { LOG.info("Current memstore: " + region.getMemStoreDataSize() + ", " + region.getMemStoreHeapSize() + ", " + region.getMemStoreOffHeapSize()); } // After aborting replay, there should be no data in the memory - Assert.assertEquals(0, rsAccounting.getGlobalMemStoreDataSize()); - Assert.assertEquals(0, region.getMemStoreDataSize()); + assertEquals(0, rsAccounting.getGlobalMemStoreDataSize()); + assertEquals(0, region.getMemStoreDataSize()); // All the chunk in the MSLAB should be recycled, otherwise, there might be // a memory leak. - Assert.assertEquals(0, ChunkCreator.getInstance().numberOfMappedChunks()); + assertEquals(0, ChunkCreator.getInstance().numberOfMappedChunks()); } finally { HBaseTestingUtil.closeRegionAndWAL(this.region); this.region = null; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionFavoredNodes.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionFavoredNodes.java index 8a5c9fede7a6..09b6f3ed66ed 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionFavoredNodes.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionFavoredNodes.java @@ -17,7 +17,8 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.lang.reflect.Method; import java.net.InetSocketAddress; @@ -28,7 +29,6 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.permission.FsPermission; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Table; @@ -38,23 +38,17 @@ import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.util.Progressable; -import org.junit.AfterClass; -import org.junit.Assume; -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 the ability to specify favored nodes for a region. */ -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestRegionFavoredNodes { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionFavoredNodes.class); - private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static Table table; private static final TableName TABLE_NAME = TableName.valueOf("table"); @@ -64,7 +58,7 @@ public class TestRegionFavoredNodes { private static final int FLUSHES = 3; private static Method createWithFavoredNode = null; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { try { createWithFavoredNode = DistributedFileSystem.class.getDeclaredMethod("create", Path.class, @@ -78,7 +72,7 @@ public static void setUpBeforeClass() throws Exception { TEST_UTIL.waitUntilAllRegionsAssigned(TABLE_NAME); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { // guard against failure in setup if (table != null) { @@ -92,7 +86,7 @@ public static void tearDownAfterClass() throws Exception { @Test public void testFavoredNodes() throws Exception { - Assume.assumeTrue(createWithFavoredNode != null); + assumeTrue(createWithFavoredNode != null); // Get the addresses of the datanodes in the cluster. InetSocketAddress[] nodes = new InetSocketAddress[REGION_SERVERS]; List datanodes = TEST_UTIL.getDFSCluster().getDataNodes(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionIncrement.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionIncrement.java index ed1687e3c99f..aac510153ced 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionIncrement.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionIncrement.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.ArrayList; @@ -26,7 +26,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hbase.Cell; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -38,13 +37,11 @@ import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -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; @@ -57,27 +54,23 @@ * increments across two column families all on one row and the increments are connected to prove * atomicity on row. */ -@Category(MediumTests.class) +@Tag(MediumTests.TAG) public class TestRegionIncrement { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionIncrement.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionIncrement.class); - @Rule - public TestName name = new TestName(); + + private String name; private static HBaseTestingUtil TEST_UTIL; private final static byte[] INCREMENT_BYTES = Bytes.toBytes("increment"); private static final int THREAD_COUNT = 10; private static final int INCREMENT_COUNT = 10000; - @Before - public void setUp() throws Exception { + @BeforeEach + public void setUp(TestInfo testInfo) throws Exception { TEST_UTIL = new HBaseTestingUtil(); + name = testInfo.getTestMethod().get().getName(); } - @After + @AfterEach public void tearDown() throws Exception { TEST_UTIL.cleanupTestDir(); } @@ -99,7 +92,7 @@ private void closeRegion(final HRegion region) throws IOException { @Test public void testMVCCCausingMisRead() throws IOException { - final HRegion region = getRegion(TEST_UTIL.getConfiguration(), this.name.getMethodName()); + final HRegion region = getRegion(TEST_UTIL.getConfiguration(), this.name); try { // ADD TEST HERE!! } finally { @@ -177,7 +170,7 @@ public void run() { @Test public void testUnContendedSingleCellIncrement() throws IOException, InterruptedException { final HRegion region = getRegion(TEST_UTIL.getConfiguration(), - TestIncrementsFromClientSide.filterStringSoTableNameSafe(this.name.getMethodName())); + TestIncrementsFromClientSide.filterStringSoTableNameSafe(this.name)); long startTime = EnvironmentEdgeManager.currentTime(); try { SingleCellIncrementer[] threads = new SingleCellIncrementer[THREAD_COUNT]; @@ -204,8 +197,7 @@ public void testUnContendedSingleCellIncrement() throws IOException, Interrupted assertEquals(INCREMENT_COUNT * THREAD_COUNT, total); } finally { closeRegion(region); - LOG.info(this.name.getMethodName() + " " + (EnvironmentEdgeManager.currentTime() - startTime) - + "ms"); + LOG.info(this.name + " " + (EnvironmentEdgeManager.currentTime() - startTime) + "ms"); } } @@ -215,7 +207,7 @@ public void testUnContendedSingleCellIncrement() throws IOException, Interrupted @Test public void testContendedAcrossCellsIncrement() throws IOException, InterruptedException { final HRegion region = getRegion(TEST_UTIL.getConfiguration(), - TestIncrementsFromClientSide.filterStringSoTableNameSafe(this.name.getMethodName())); + TestIncrementsFromClientSide.filterStringSoTableNameSafe(this.name)); long startTime = EnvironmentEdgeManager.currentTime(); try { CrossRowCellIncrementer[] threads = new CrossRowCellIncrementer[THREAD_COUNT]; @@ -239,8 +231,7 @@ public void testContendedAcrossCellsIncrement() throws IOException, InterruptedE assertEquals(INCREMENT_COUNT * THREAD_COUNT, total); } finally { closeRegion(region); - LOG.info(this.name.getMethodName() + " " + (EnvironmentEdgeManager.currentTime() - startTime) - + "ms"); + LOG.info(this.name + " " + (EnvironmentEdgeManager.currentTime() - startTime) + "ms"); } } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionInfo.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionInfo.java index 60fe39ecc77f..563fd13c43fe 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionInfo.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionInfo.java @@ -17,18 +17,17 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -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.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -45,27 +44,25 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.FSTableDescriptors; import org.apache.hadoop.hbase.util.MD5Hash; -import org.junit.Assert; -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.apache.hbase.thirdparty.com.google.protobuf.UnsafeByteOperations; import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos; -@Category({ RegionServerTests.class, SmallTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(SmallTests.TAG) public class TestRegionInfo { + private String methodName; - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionInfo.class); - - @Rule - public TestName name = new TestName(); + @BeforeEach + public void setUp(TestInfo testInfo) { + methodName = testInfo.getTestMethod().get().getName(); + } @Test public void testIsStart() { @@ -203,7 +200,7 @@ long getModTime(final HRegion r) throws IOException { @Test public void testCreateHRegionInfoName() throws Exception { - final String tableName = name.getMethodName(); + final String tableName = methodName; final TableName tn = TableName.valueOf(tableName); String startKey = "startkey"; final byte[] sk = Bytes.toBytes(startKey); @@ -225,7 +222,7 @@ public void testCreateHRegionInfoName() throws Exception { @Test public void testContainsRange() { TableDescriptor tableDesc = - TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName())).build(); + TableDescriptorBuilder.newBuilder(TableName.valueOf(methodName)).build(); RegionInfo hri = RegionInfoBuilder.newBuilder(tableDesc.getTableName()) .setStartKey(Bytes.toBytes("a")).setEndKey(Bytes.toBytes("g")).build(); // Single row range at start of region @@ -287,7 +284,7 @@ public void testContainsRangeForMetaTable() { @Test public void testLastRegionCompare() { TableDescriptor tableDesc = - TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName())).build(); + TableDescriptorBuilder.newBuilder(TableName.valueOf(methodName)).build(); RegionInfo hrip = RegionInfoBuilder.newBuilder(tableDesc.getTableName()) .setStartKey(Bytes.toBytes("a")).build(); RegionInfo hric = RegionInfoBuilder.newBuilder(tableDesc.getTableName()) @@ -303,7 +300,7 @@ public void testMetaTables() { @SuppressWarnings("SelfComparison") @Test public void testComparator() { - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(methodName); RegionInfo older = RegionInfoBuilder.newBuilder(tableName).setRegionId(0).build(); RegionInfo newer = RegionInfoBuilder.newBuilder(tableName).setRegionId(1).build(); assertTrue(older.compareTo(newer) < 0); @@ -342,7 +339,7 @@ public void testComparator() { @Test public void testRegionNameForRegionReplicas() throws Exception { - String tableName = name.getMethodName(); + String tableName = methodName; final TableName tn = TableName.valueOf(tableName); String startKey = "startkey"; final byte[] sk = Bytes.toBytes(startKey); @@ -371,7 +368,7 @@ public void testRegionNameForRegionReplicas() throws Exception { @Test public void testParseName() throws IOException { - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(methodName); byte[] startKey = Bytes.toBytes("startKey"); long regionId = EnvironmentEdgeManager.currentTime(); int replicaId = 42; @@ -380,25 +377,25 @@ public void testParseName() throws IOException { byte[] regionName = RegionInfo.createRegionName(tableName, startKey, regionId, false); byte[][] fields = RegionInfo.parseRegionName(regionName); - assertArrayEquals(Bytes.toString(fields[0]), tableName.getName(), fields[0]); - assertArrayEquals(Bytes.toString(fields[1]), startKey, fields[1]); - assertArrayEquals(Bytes.toString(fields[2]), Bytes.toBytes(Long.toString(regionId)), fields[2]); + assertArrayEquals(tableName.getName(), fields[0], Bytes.toString(fields[0])); + assertArrayEquals(startKey, fields[1], Bytes.toString(fields[1])); + assertArrayEquals(Bytes.toBytes(Long.toString(regionId)), fields[2], Bytes.toString(fields[2])); assertEquals(3, fields.length); // test with replicaId regionName = RegionInfo.createRegionName(tableName, startKey, regionId, replicaId, false); fields = RegionInfo.parseRegionName(regionName); - assertArrayEquals(Bytes.toString(fields[0]), tableName.getName(), fields[0]); - assertArrayEquals(Bytes.toString(fields[1]), startKey, fields[1]); - assertArrayEquals(Bytes.toString(fields[2]), Bytes.toBytes(Long.toString(regionId)), fields[2]); - assertArrayEquals(Bytes.toString(fields[3]), - Bytes.toBytes(String.format(RegionInfo.REPLICA_ID_FORMAT, replicaId)), fields[3]); + assertArrayEquals(tableName.getName(), fields[0], Bytes.toString(fields[0])); + assertArrayEquals(startKey, fields[1], Bytes.toString(fields[1])); + assertArrayEquals(Bytes.toBytes(Long.toString(regionId)), fields[2], Bytes.toString(fields[2])); + assertArrayEquals(Bytes.toBytes(String.format(RegionInfo.REPLICA_ID_FORMAT, replicaId)), + fields[3], Bytes.toString(fields[3])); } @Test public void testConvert() { - final TableName tableName = TableName.valueOf("ns1:" + name.getMethodName()); + final TableName tableName = TableName.valueOf("ns1:" + methodName); byte[] startKey = Bytes.toBytes("startKey"); byte[] endKey = Bytes.toBytes("endKey"); boolean split = false; @@ -436,11 +433,11 @@ public void testRegionDetailsForDisplay() throws IOException { byte[] endKey = new byte[] { 0x01, 0x01, 0x02, 0x04 }; Configuration conf = new Configuration(); conf.setBoolean("hbase.display.keys", false); - RegionInfo h = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())) - .setStartKey(startKey).setEndKey(endKey).build(); + RegionInfo h = RegionInfoBuilder.newBuilder(TableName.valueOf(methodName)).setStartKey(startKey) + .setEndKey(endKey).build(); checkEquality(h, conf); // check HRIs with non-default replicaId - h = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())).setStartKey(startKey) + h = RegionInfoBuilder.newBuilder(TableName.valueOf(methodName)).setStartKey(startKey) .setEndKey(endKey).setRegionId(EnvironmentEdgeManager.currentTime()).setReplicaId(1).build(); checkEquality(h, conf); assertArrayEquals(RegionInfoDisplay.HIDDEN_END_KEY, @@ -487,10 +484,10 @@ private void checkEquality(RegionInfo h, Configuration conf) throws IOException // all parts should match except for [1] where in the modified one, // we should have "hidden_start_key" if (i != 1) { - Assert.assertArrayEquals(regionNameParts[i], modifiedRegionNameParts[i]); + assertArrayEquals(regionNameParts[i], modifiedRegionNameParts[i]); } else { assertNotEquals(regionNameParts[i][0], modifiedRegionNameParts[i][0]); - Assert.assertArrayEquals(modifiedRegionNameParts[1], + assertArrayEquals(modifiedRegionNameParts[1], RegionInfoDisplay.getStartKeyForDisplay(h, conf)); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionInterrupt.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionInterrupt.java index c207affc8955..c92fd6022655 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionInterrupt.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionInterrupt.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.io.InterruptedIOException; @@ -27,12 +27,10 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Cell; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.NotServingRegionException; import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.TableNameTestRule; import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Append; @@ -60,23 +58,18 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.wal.WAL; import org.apache.hadoop.hbase.wal.WALEdit; -import org.junit.After; -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.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.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ RegionServerTests.class, LargeTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(LargeTests.TAG) public class TestRegionInterrupt { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionInterrupt.class); - private static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static final Logger LOG = LoggerFactory.getLogger(TestRegionInterrupt.class); @@ -84,10 +77,7 @@ public class TestRegionInterrupt { static long sleepTime; - @Rule - public TableNameTestRule name = new TableNameTestRule(); - - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { Configuration conf = TEST_UTIL.getConfiguration(); conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1); @@ -101,19 +91,19 @@ public static void setUpBeforeClass() throws Exception { conf.setLong(HRegion.CLOSE_WAIT_TIME, sleepTime * 2); } - @Before + @BeforeEach public void setUp() throws Exception { TEST_UTIL.startMiniCluster(); } - @After + @AfterEach public void tearDown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @Test - public void testCloseInterruptScanning() throws Exception { - final TableName tableName = name.getTableName(); + public void testCloseInterruptScanning(TestInfo testInfo) throws Exception { + final TableName tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); LOG.info("Creating table " + tableName); try (Table table = TEST_UTIL.createTable(tableName, FAMILY)) { // load some data @@ -165,15 +155,15 @@ public boolean evaluate() throws Exception { scanner.join(); // When we get here the region has closed and the table is offline - assertTrue("Region operations were not interrupted", - InterruptInterceptingHRegion.wasInterrupted()); - assertTrue("Scanner did not catch expected exception", expectedExceptionCaught.get()); + assertTrue(InterruptInterceptingHRegion.wasInterrupted(), + "Region operations were not interrupted"); + assertTrue(expectedExceptionCaught.get(), "Scanner did not catch expected exception"); } } @Test - public void testCloseInterruptMutation() throws Exception { - final TableName tableName = name.getTableName(); + public void testCloseInterruptMutation(TestInfo testInfo) throws Exception { + final TableName tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); final Admin admin = TEST_UTIL.getAdmin(); // Create the test table TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName) @@ -223,9 +213,9 @@ public boolean evaluate() throws Exception { inserter.join(); // When we get here the region has closed and the table is offline - assertTrue("Region operations were not interrupted", - InterruptInterceptingHRegion.wasInterrupted()); - assertTrue("Inserter did not catch expected exception", expectedExceptionCaught.get()); + assertTrue(InterruptInterceptingHRegion.wasInterrupted(), + "Region operations were not interrupted"); + assertTrue(expectedExceptionCaught.get(), "Inserter did not catch expected exception"); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java index d55a2263ac36..b201e4e10242 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMergeTransactionOnCluster.java @@ -17,10 +17,10 @@ */ package org.apache.hadoop.hbase.regionserver; -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.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.ArrayList; @@ -34,7 +34,6 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.CatalogFamilyFormat; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.ServerName; @@ -73,13 +72,12 @@ import org.apache.hadoop.hbase.util.Threads; import org.apache.hadoop.util.StringUtils; import org.apache.zookeeper.KeeperException; -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; @@ -91,18 +89,13 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionResponse; -@Category({ RegionServerTests.class, LargeTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(LargeTests.TAG) public class TestRegionMergeTransactionOnCluster { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionMergeTransactionOnCluster.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionMergeTransactionOnCluster.class); - @Rule - public TestName name = new TestName(); + private String name; private static final int NB_SERVERS = 3; @@ -121,7 +114,7 @@ public class TestRegionMergeTransactionOnCluster { private static HMaster MASTER; private static Admin ADMIN; - @BeforeClass + @BeforeAll public static void beforeAllTests() throws Exception { // Start a cluster StartTestingClusterOption option = StartTestingClusterOption.builder() @@ -133,7 +126,12 @@ public static void beforeAllTests() throws Exception { ADMIN = TEST_UTIL.getConnection().getAdmin(); } - @AfterClass + @BeforeEach + public void setUp(TestInfo testInfo) { + name = testInfo.getTestMethod().get().getName(); + } + + @AfterAll public static void afterAllTests() throws Exception { TEST_UTIL.shutdownMiniCluster(); if (ADMIN != null) { @@ -143,8 +141,8 @@ public static void afterAllTests() throws Exception { @Test public void testWholesomeMerge() throws Exception { - LOG.info("Starting " + name.getMethodName()); - final TableName tableName = TableName.valueOf(name.getMethodName()); + LOG.info("Starting " + name); + final TableName tableName = TableName.valueOf(name); try { // Create table and load data. @@ -168,13 +166,13 @@ public void testWholesomeMerge() throws Exception { // We should not be able to assign it again, but we are able to do it here. Assertions are // poor here and missing that assign is possible here. Created HBASE-29692 for resolving this. am.assign(hri); - assertFalse("Merged region can't be assigned", - am.getRegionStates().getRegionStateNode(hri).isTransitionScheduled()); + assertFalse(am.getRegionStates().getRegionStateNode(hri).isTransitionScheduled(), + "Merged region can't be assigned"); // We should not be able to unassign it either am.unassign(hri); - assertFalse("Merged region can't be unassigned", - am.getRegionStates().getRegionStateNode(hri).isTransitionScheduled()); + assertFalse(am.getRegionStates().getRegionStateNode(hri).isTransitionScheduled(), + "Merged region can't be unassigned"); table.close(); } finally { @@ -188,7 +186,7 @@ public void testWholesomeMerge() throws Exception { */ @Test public void testMergeAndRestartingMaster() throws Exception { - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(name); try { // Create table and load data. @@ -211,9 +209,9 @@ public void testMergeAndRestartingMaster() throws Exception { @Test public void testCleanMergeReference() throws Exception { - LOG.info("Starting " + name.getMethodName()); + LOG.info("Starting " + name); ADMIN.catalogJanitorSwitch(false); - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(name); try { // Create table and load data. Table table = createTableAndLoadData(MASTER, tableName); @@ -333,8 +331,8 @@ public void testCleanMergeReference() throws Exception { */ @Test public void testMerge() throws Exception { - LOG.info("Starting " + name.getMethodName()); - final TableName tableName = TableName.valueOf(name.getMethodName()); + LOG.info("Starting " + name); + final TableName tableName = TableName.valueOf(name); final Admin admin = TEST_UTIL.getAdmin(); try { @@ -363,9 +361,8 @@ public void testMerge() throws Exception { .get(admin.mergeRegionsAsync(b.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), true)); fail("A region should not be able to merge with itself, even forcfully"); } catch (IOException ie) { - assertTrue("Exception should mention regions not online", - StringUtils.stringifyException(ie).contains("region to itself") - && ie instanceof MergeRegionException); + assertTrue(StringUtils.stringifyException(ie).contains("region to itself") + && ie instanceof MergeRegionException, "Exception should mention regions not online"); } try { @@ -373,7 +370,7 @@ public void testMerge() throws Exception { FutureUtils.get(admin.mergeRegionsAsync(Bytes.toBytes("-f1"), Bytes.toBytes("-f2"), true)); fail("Unknown region could not be merged"); } catch (IOException ie) { - assertTrue("UnknownRegionException should be thrown", ie instanceof UnknownRegionException); + assertTrue(ie instanceof UnknownRegionException, "UnknownRegionException should be thrown"); } table.close(); } finally { @@ -383,7 +380,7 @@ public void testMerge() throws Exception { @Test public void testMergeWithReplicas() throws Exception { - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(name); try { // Create table and load data. Table table = createTableAndLoadData(MASTER, tableName, 5, 2); @@ -485,7 +482,7 @@ private Table createTableAndLoadData(HMaster master, TableName tablename) throws private Table createTableAndLoadData(HMaster master, TableName tablename, int numRegions, int replication) throws Exception { - assertTrue("ROWSIZE must > numregions:" + numRegions, ROWSIZE > numRegions); + assertTrue(ROWSIZE > numRegions, "ROWSIZE must > numregions:" + numRegions); byte[][] splitRows = new byte[numRegions - 1][]; for (int i = 0; i < splitRows.length; i++) { splitRows[i] = ROWS[(i + 1) * ROWSIZE / numRegions]; @@ -507,8 +504,8 @@ private Table createTableAndLoadData(HMaster master, TableName tablename, int nu LOG.info("All regions assigned for table - " + table.getName()); tableRegions = MetaTableAccessor.getTableRegionsAndLocations(TEST_UTIL.getConnection(), tablename); - assertEquals("Wrong number of regions in table " + tablename, numRegions * replication, - tableRegions.size()); + assertEquals(numRegions * replication, tableRegions.size(), + "Wrong number of regions in table " + tablename); LOG.info(tableRegions.size() + "Regions after load: " + Joiner.on(',').join(tableRegions)); assertEquals(numRegions * replication, tableRegions.size()); return table; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMove.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMove.java index 71409c8f3e19..adac1bbc2377 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMove.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionMove.java @@ -17,15 +17,14 @@ */ package org.apache.hadoop.hbase.regionserver; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertTrue; +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.stream.Collectors; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.DoNotRetryIOException; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; @@ -35,31 +34,18 @@ import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.AfterClass; -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.ExpectedException; -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; /** * Test move fails when table disabled */ -@Category({ MediumTests.class }) +@Tag(MediumTests.TAG) public class TestRegionMove { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionMove.class); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Rule - public TestName name = new TestName(); private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); public static Configuration CONF; protected static final String F1 = "f1"; @@ -68,20 +54,20 @@ public class TestRegionMove { protected TableName tableName; protected String method; - @BeforeClass + @BeforeAll public static void startCluster() throws Exception { TEST_UTIL.startMiniCluster(2); } - @AfterClass + @AfterAll public static void stopCluster() throws Exception { TEST_UTIL.shutdownMiniCluster(); } - @Before - public void setup() throws IOException { + @BeforeEach + public void setup(TestInfo testInfo) throws IOException { CONF = TEST_UTIL.getConfiguration(); - method = name.getMethodName(); + method = testInfo.getTestMethod().get().getName(); tableName = TableName.valueOf(method); } @@ -110,8 +96,8 @@ public void testDisableAndMove() throws Exception { HRegionServer rs2 = TEST_UTIL.getOtherRegionServer(rs1); List regionsOnRS1ForTable = admin.getRegions(rs1.getServerName()).stream() .filter((regionInfo) -> regionInfo.getTable().equals(tableName)).collect(Collectors.toList()); - assertTrue("Expected to find at least one region for " + tableName + " on " - + rs1.getServerName() + ", but found none", !regionsOnRS1ForTable.isEmpty()); + assertTrue(!regionsOnRS1ForTable.isEmpty(), "Expected to find at least one region for " + + tableName + " on " + rs1.getServerName() + ", but found none"); final RegionInfo regionToMove = regionsOnRS1ForTable.get(0); // Offline the region and then try to move it. Should fail. diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionOpen.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionOpen.java index c28e90e85649..c84ac6fd1c10 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionOpen.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionOpen.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.List; @@ -26,7 +26,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.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -44,37 +43,28 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.CommonFSUtils; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -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; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MediumTests.class, RegionServerTests.class }) +@Tag(MediumTests.TAG) +@Tag(RegionServerTests.TAG) public class TestRegionOpen { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionOpen.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionOpen.class); private static final int NB_SERVERS = 1; private static final HBaseTestingUtil HTU = new HBaseTestingUtil(); - @Rule - public TestName name = new TestName(); - - @BeforeClass + @BeforeAll public static void before() throws Exception { HTU.startMiniCluster(NB_SERVERS); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { HTU.shutdownMiniCluster(); } @@ -102,8 +92,8 @@ public void testPriorityRegionIsOpenedWithSeparateThreadPool() throws Exception } @Test - public void testNonExistentRegionReplica() throws Exception { - final TableName tableName = TableName.valueOf(name.getMethodName()); + public void testNonExistentRegionReplica(TestInfo testInfo) throws Exception { + final TableName tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); final byte[] FAMILYNAME = Bytes.toBytes("fam"); FileSystem fs = HTU.getTestFileSystem(); Admin admin = HTU.getAdmin(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicaFailover.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicaFailover.java index b07f97c51afd..bf835243d41c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicaFailover.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicaFailover.java @@ -17,15 +17,14 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNull; +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 java.util.concurrent.atomic.AtomicReference; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -42,26 +41,19 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread; import org.apache.hadoop.hbase.util.ServerRegionReplicaUtil; -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; /** * Tests failover of secondary region replicas. */ -@Category(LargeTests.class) +@Tag(LargeTests.TAG) public class TestRegionReplicaFailover { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionReplicaFailover.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionReplicaFailover.class); private static final HBaseTestingUtil HTU = new HBaseTestingUtil(); @@ -76,13 +68,10 @@ public class TestRegionReplicaFailover { protected final byte[] row = Bytes.toBytes("rowA"); protected final byte[] row2 = Bytes.toBytes("rowB"); - @Rule - public TestName name = new TestName(); - private TableDescriptor htd; - @Before - public void before() throws Exception { + @BeforeEach + public void before(TestInfo testInfo) throws Exception { Configuration conf = HTU.getConfiguration(); // Up the handlers; this test needs more than usual. conf.setInt(HConstants.REGION_SERVER_HIGH_PRIORITY_HANDLER_COUNT, 10); @@ -92,14 +81,15 @@ public void before() throws Exception { conf.setBoolean("hbase.tests.use.shortcircuit.reads", false); HTU.startMiniCluster(NB_SERVERS); - htd = HTU.createModifyableTableDescriptor( - TableName.valueOf(name.getMethodName().substring(0, name.getMethodName().length() - 3)), - ColumnFamilyDescriptorBuilder.DEFAULT_MIN_VERSIONS, 3, HConstants.FOREVER, - ColumnFamilyDescriptorBuilder.DEFAULT_KEEP_DELETED).setRegionReplication(3).build(); + String name = testInfo.getTestMethod().get().getName(); + htd = + HTU.createModifyableTableDescriptor(TableName.valueOf(name.substring(0, name.length() - 3)), + ColumnFamilyDescriptorBuilder.DEFAULT_MIN_VERSIONS, 3, HConstants.FOREVER, + ColumnFamilyDescriptorBuilder.DEFAULT_KEEP_DELETED).setRegionReplication(3).build(); HTU.getAdmin().createTable(htd); } - @After + @AfterEach public void after() throws Exception { HTU.deleteTableIfAny(htd.getTableName()); HTU.shutdownMiniCluster(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicaReplicationError.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicaReplicationError.java index e0d7895e083d..adbc3eb0c07f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicaReplicationError.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicaReplicationError.java @@ -22,7 +22,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.NotServingRegionException; import org.apache.hadoop.hbase.SingleProcessHBaseCluster; @@ -41,11 +40,10 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.ConcurrentMapUtils; import org.apache.hadoop.hbase.util.ServerRegionReplicaUtil; -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.hbase.thirdparty.com.google.protobuf.ByteString; import org.apache.hbase.thirdparty.com.google.protobuf.RpcController; @@ -63,13 +61,9 @@ * when secondary replica is online, which will always make the data of the two regions in sync. So * here we need to simulate request errors. */ -@Category({ FlakeyTests.class, LargeTests.class }) +@Tag(FlakeyTests.TAG) +@Tag(LargeTests.TAG) public class TestRegionReplicaReplicationError { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionReplicaReplicationError.class); - public static final class ErrorReplayRSRpcServices extends RSRpcServices { private final ConcurrentHashMap regionToCounter = @@ -126,7 +120,7 @@ protected RSRpcServices createRpcServices() throws IOException { private static byte[] CQ = Bytes.toBytes("cq"); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { HTU.getConfiguration().setBoolean(ServerRegionReplicaUtil.REGION_REPLICA_REPLICATION_CONF_KEY, true); @@ -134,7 +128,7 @@ public static void setUp() throws Exception { StartTestingClusterOption.builder().rsClass(RSForTest.class).numRegionServers(3).build()); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { HTU.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicaWaitForPrimaryFlushConf.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicaWaitForPrimaryFlushConf.java index 12d77dc8c51d..fe4c569f0559 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicaWaitForPrimaryFlushConf.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicaWaitForPrimaryFlushConf.java @@ -17,21 +17,19 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertFalse; -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.assertFalse; +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.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.StartTestingClusterOption; import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.TableNameTestRule; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.client.TableDescriptorBuilder; @@ -41,28 +39,22 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.hbase.util.ServerRegionReplicaUtil; -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.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestRegionReplicaWaitForPrimaryFlushConf { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionReplicaWaitForPrimaryFlushConf.class); - private static final byte[] FAMILY = Bytes.toBytes("family_test"); private TableName tableName; - - @Rule - public final TableNameTestRule name = new TableNameTestRule(); private static final HBaseTestingUtil HTU = new HBaseTestingUtil(); - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { Configuration conf = HTU.getConfiguration(); conf.setBoolean(ServerRegionReplicaUtil.REGION_REPLICA_REPLICATION_CONF_KEY, true); @@ -71,11 +63,16 @@ public static void setUpBeforeClass() throws Exception { } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { HTU.shutdownMiniCluster(); } + @BeforeEach + public void setUp(TestInfo testInfo) { + tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); + } + /** * This test is for HBASE-26811,before HBASE-26811,when * {@link ServerRegionReplicaUtil#REGION_REPLICA_WAIT_FOR_PRIMARY_FLUSH_CONF_KEY} is false and set @@ -85,7 +82,6 @@ public static void tearDownAfterClass() throws Exception { */ @Test public void testSecondaryReplicaReadEnabled() throws Exception { - tableName = name.getTableName(); TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName) .setRegionReplication(2).setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)) .setRegionMemStoreReplication(true).build(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicasAreDistributed.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicasAreDistributed.java index eb2b7b0c0e20..e0c3e20dbea6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicasAreDistributed.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicasAreDistributed.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; @@ -25,7 +25,6 @@ import java.util.HashMap; import java.util.Map; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -38,21 +37,16 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.RegionSplitter; -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({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestRegionReplicasAreDistributed { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionReplicasAreDistributed.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionReplicasAreDistributed.class); private static final int NB_SERVERS = 3; @@ -65,7 +59,7 @@ public class TestRegionReplicasAreDistributed { Map> serverVsOnlineRegions3; Map> serverVsOnlineRegions4; - @BeforeClass + @BeforeAll public static void before() throws Exception { HTU.getConfiguration().setInt("hbase.master.wait.on.regionservers.mintostart", 3); @@ -94,7 +88,7 @@ private static byte[][] getSplits(int numRegions) { return split.split(numRegions); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { HRegionServer.TEST_SKIP_REPORTING_TRANSITION = false; table.close(); @@ -124,7 +118,7 @@ public void testRegionReplicasCreatedAreDistributed() throws Exception { HTU.getAdmin().enableTable(table.getName()); LOG.info("Enabled the table " + table.getName()); boolean res = checkAndAssertRegionDistribution(true); - assertTrue("Region retainment not done ", res); + assertTrue(res, "Region retainment not done "); } finally { HTU.getAdmin().disableTable(table.getName()); HTU.getAdmin().deleteTable(table.getName()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicasWithModifyTable.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicasWithModifyTable.java index 935e33dacdc4..5582b3b3b55d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicasWithModifyTable.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicasWithModifyTable.java @@ -17,67 +17,63 @@ */ package org.apache.hadoop.hbase.regionserver; -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.List; +import java.util.stream.Stream; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.TableNameTestRule; import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.RegionServerTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.RegionSplitter; -import org.junit.After; -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.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; - -@RunWith(Parameterized.class) -@Category({ RegionServerTests.class, MediumTests.class }) +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.junit.jupiter.api.TestInfo; +import org.junit.jupiter.params.Parameter; +import org.junit.jupiter.params.ParameterizedClass; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) +@ParameterizedClass(name = "{index}: disableBeforeModifying={0}") +@MethodSource("parameters") public class TestRegionReplicasWithModifyTable { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionReplicasWithModifyTable.class); - private static final int NB_SERVERS = 3; private static final HBaseTestingUtil HTU = new HBaseTestingUtil(); private static final byte[] f = HConstants.CATALOG_FAMILY; @Parameter - public boolean disableBeforeModifying; + private boolean disableBeforeModifying; - @Rule - public TableNameTestRule name = new TableNameTestRule(); + private TableName tableName; - @Parameters - public static List params() { - return Arrays.asList(new Object[] { true }, new Object[] { false }); + public static Stream parameters() { + return Stream.of(Arguments.of(true), Arguments.of(false)); } - @BeforeClass + @BeforeAll public static void before() throws Exception { HTU.startMiniCluster(NB_SERVERS); } + @BeforeEach + public void setUp(TestInfo testInfo) { + tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); + } + private void enableReplicationByModification(boolean withReplica, int initialReplicaCount, int enableReplicaCount, int splitCount) throws IOException, InterruptedException { - TableName tableName = name.getTableName(); TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName); if (withReplica) { builder.setRegionReplication(initialReplicaCount); @@ -113,20 +109,19 @@ private static byte[][] getSplits(int numRegions) { return split.split(numRegions); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { HTU.shutdownMiniCluster(); } - @After + @AfterEach public void tearDown() throws IOException { - TableName tableName = name.getTableName(); HTU.getAdmin().disableTable(tableName); HTU.getAdmin().deleteTable(tableName); } private void assertTotalRegions(int expected) { - int actual = HTU.getHBaseCluster().getRegions(name.getTableName()).size(); + int actual = HTU.getHBaseCluster().getRegions(tableName).size(); assertEquals(expected, actual); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicasWithRestartScenarios.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicasWithRestartScenarios.java index 141a7dc99966..b677016afd1c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicasWithRestartScenarios.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicasWithRestartScenarios.java @@ -17,13 +17,14 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.*; +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.ArrayList; import java.util.Collection; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -36,31 +37,22 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.RegionSplitter; -import org.junit.After; -import org.junit.AfterClass; -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.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.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestRegionReplicasWithRestartScenarios { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionReplicasWithRestartScenarios.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionReplicasWithRestartScenarios.class); - @Rule - public TestName name = new TestName(); - private static final int NB_SERVERS = 3; private Table table; private TableName tableName; @@ -68,19 +60,19 @@ public class TestRegionReplicasWithRestartScenarios { private static final HBaseTestingUtil HTU = new HBaseTestingUtil(); private static final byte[] f = HConstants.CATALOG_FAMILY; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { HTU.getConfiguration().setInt("hbase.master.wait.on.regionservers.mintostart", NB_SERVERS); HTU.startMiniCluster(NB_SERVERS); } - @Before - public void before() throws IOException { - this.tableName = TableName.valueOf(this.name.getMethodName()); + @BeforeEach + public void before(TestInfo testInfo) throws IOException { + this.tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); this.table = createTableDirectlyFromHTD(this.tableName); } - @After + @AfterEach public void after() throws IOException { this.table.close(); HTU.deleteTable(this.tableName); @@ -100,7 +92,7 @@ private static byte[][] getSplits(int numRegions) { return split.split(numRegions); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { HTU.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbort.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbort.java index feb9e0656e6f..98f9f3ae0814 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbort.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbort.java @@ -17,10 +17,10 @@ */ package org.apache.hadoop.hbase.regionserver; -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 java.io.IOException; import java.util.List; @@ -32,7 +32,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.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.SingleProcessHBaseCluster; @@ -63,24 +62,19 @@ import org.apache.hadoop.hbase.wal.WALEdit; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.MiniDFSCluster; -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; /** * Tests around regionserver shutdown and abort */ -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestRegionServerAbort { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionServerAbort.class); - private static final byte[] FAMILY_BYTES = Bytes.toBytes("f"); private static final Logger LOG = LoggerFactory.getLogger(TestRegionServerAbort.class); @@ -90,7 +84,7 @@ public class TestRegionServerAbort { private MiniDFSCluster dfsCluster; private SingleProcessHBaseCluster cluster; - @Before + @BeforeEach public void setup() throws Exception { testUtil = new HBaseTestingUtil(); conf = testUtil.getConfiguration(); @@ -111,7 +105,7 @@ public void setup() throws Exception { cluster = testUtil.startMiniHBaseCluster(option); } - @After + @AfterEach public void tearDown() throws Exception { String className = StopBlockingRegionObserver.class.getName(); for (JVMClusterUtil.RegionServerThread t : cluster.getRegionServerThreads()) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbortTimeout.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbortTimeout.java index 8cb6e3953b44..03a21b157770 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbortTimeout.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAbortTimeout.java @@ -17,14 +17,13 @@ */ package org.apache.hadoop.hbase.regionserver; -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 java.io.IOException; import java.util.Optional; import java.util.TimerTask; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.StartTestingClusterOption; import org.apache.hadoop.hbase.TableName; @@ -42,21 +41,16 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; 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({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestRegionServerAbortTimeout { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionServerAbortTimeout.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionServerAbortTimeout.class); private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); @@ -73,7 +67,7 @@ public class TestRegionServerAbortTimeout { private static volatile boolean abortTimeoutTaskScheduled = false; - @BeforeClass + @BeforeAll public static void setUp() throws Exception { Configuration conf = UTIL.getConfiguration(); // Will schedule a abort timeout task after SLEEP_TIME_WHEN_CLOSE_REGION ms @@ -88,7 +82,7 @@ public static void setUp() throws Exception { UTIL.getAdmin().createTable(td, Bytes.toBytes("0"), Bytes.toBytes("9"), REGIONS_NUM); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { UTIL.shutdownMiniCluster(); } @@ -116,7 +110,7 @@ public void testAbortTimeout() throws Exception { long timeout = REGIONS_NUM * SLEEP_TIME_WHEN_CLOSE_REGION * 10; while (EnvironmentEdgeManager.currentTime() - startTime < timeout) { if (UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().size() == 1) { - assertTrue("Abort timer task should be scheduled", abortTimeoutTaskScheduled); + assertTrue(abortTimeoutTaskScheduled, "Abort timer task should be scheduled"); return; } Threads.sleep(SLEEP_TIME_WHEN_CLOSE_REGION); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAccounting.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAccounting.java index 5870ea27661f..f710db6e5010 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAccounting.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerAccounting.java @@ -17,30 +17,23 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.io.util.MemorySizeUtil; 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; -@Category(SmallTests.class) +@Tag(SmallTests.TAG) public class TestRegionServerAccounting { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionServerAccounting.class); - private final static float DEFAULT_MEMSTORE_SIZE = 0.2f; private static Configuration conf; - @Before + @BeforeEach public void setUpConf() { conf = HBaseConfiguration.create(); conf.setFloat(MemorySizeUtil.MEMSTORE_SIZE_KEY, DEFAULT_MEMSTORE_SIZE); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerCrashDisableWAL.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerCrashDisableWAL.java index 3fad6e16bf76..0c4fe9589b77 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerCrashDisableWAL.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerCrashDisableWAL.java @@ -17,10 +17,9 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Get; @@ -33,22 +32,17 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread; import org.apache.hadoop.hbase.wal.WALFactory; -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-20742 */ -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestRegionServerCrashDisableWAL { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionServerCrashDisableWAL.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static TableName TABLE_NAME = TableName.valueOf("test"); @@ -57,7 +51,7 @@ public class TestRegionServerCrashDisableWAL { private static byte[] CQ = Bytes.toBytes("cq"); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.getConfiguration().setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 1); UTIL.getConfiguration().setBoolean(WALFactory.WAL_ENABLED, false); @@ -74,7 +68,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/regionserver/TestRegionServerHostname.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerHostname.java index 566b85b01e92..f16a5f262a86 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerHostname.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerHostname.java @@ -17,10 +17,10 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.net.InetAddress; import java.net.NetworkInterface; @@ -29,7 +29,6 @@ import java.util.List; import java.util.Locale; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.StartTestingClusterOption; @@ -38,24 +37,19 @@ import org.apache.hadoop.hbase.util.DNS; import org.apache.hadoop.hbase.zookeeper.ZKUtil; import org.apache.hadoop.hbase.zookeeper.ZKWatcher; -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; /** * Tests for the hostname specification by region server */ -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestRegionServerHostname { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionServerHostname.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionServerHostname.class); private HBaseTestingUtil TEST_UTIL; @@ -63,13 +57,13 @@ public class TestRegionServerHostname { private static final int NUM_MASTERS = 1; private static final int NUM_RS = 1; - @Before + @BeforeEach public void setup() { Configuration conf = HBaseConfiguration.create(); TEST_UTIL = new HBaseTestingUtil(conf); } - @After + @AfterEach public void teardown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -82,10 +76,10 @@ public void testInvalidRegionServerHostnameAbortsServer() throws Exception { try { hrs = new HRegionServer(TEST_UTIL.getConfiguration()); } catch (IllegalArgumentException iae) { - assertTrue(iae.getMessage(), iae.getMessage().contains("Failed resolve of " + invalidHostname) - || iae.getMessage().contains("Problem binding to " + invalidHostname)); + assertTrue(iae.getMessage().contains("Failed resolve of " + invalidHostname) + || iae.getMessage().contains("Problem binding to " + invalidHostname), iae.getMessage()); } - assertNull("Failed to validate against invalid hostname", hrs); + assertNull(hrs, "Failed to validate against invalid hostname"); } @Test @@ -114,8 +108,8 @@ public void testRegionServerHostname() throws Exception { List servers = ZKUtil.listChildrenNoWatch(zkw, zkw.getZNodePaths().rsZNode); assertEquals(NUM_RS, servers.size()); for (String server : servers) { - assertTrue("From zookeeper: " + server + " hostname: " + hostName, - server.startsWith(hostName.toLowerCase(Locale.ROOT) + ",")); + assertTrue(server.startsWith(hostName.toLowerCase(Locale.ROOT) + ","), + "From zookeeper: " + server + " hostname: " + hostName); } zkw.close(); } finally { @@ -179,14 +173,16 @@ public void testConflictRegionServerHostnameConfigurationsAbortServer() throws E } catch (Exception e) { Throwable t1 = e.getCause(); Throwable t2 = t1.getCause(); - assertTrue(t1.getMessage() + " - " + t2.getMessage(), - t2.getMessage().contains(HRegionServer.UNSAFE_RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY - + " and " + DNS.UNSAFE_RS_HOSTNAME_KEY + " are mutually exclusive")); + assertTrue( + t2.getMessage() + .contains(HRegionServer.UNSAFE_RS_HOSTNAME_DISABLE_MASTER_REVERSEDNS_KEY + " and " + + DNS.UNSAFE_RS_HOSTNAME_KEY + " are mutually exclusive"), + t1.getMessage() + " - " + t2.getMessage()); return; } finally { TEST_UTIL.shutdownMiniCluster(); } - assertTrue("Failed to validate against conflict hostname configurations", false); + assertTrue(false, "Failed to validate against conflict hostname configurations"); } } } @@ -207,7 +203,7 @@ public void testRegionServerHostnameReportedToMaster() throws Exception { private boolean ignoreNetworkInterface(NetworkInterface networkInterface) throws Exception { return networkInterface == null || networkInterface.isLoopback() || networkInterface.isVirtual() - || !networkInterface.isUp(); + || networkInterface.isPointToPoint() || !networkInterface.isUp(); } private List getValidNetworkInterfaces() throws Exception { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java index 97ee508cc29d..2c0e6d2dc501 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java @@ -17,11 +17,11 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -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.assertNotEquals; +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.ArrayList; @@ -29,7 +29,6 @@ import java.util.Optional; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.CompatibilityFactory; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionLocation; @@ -63,31 +62,22 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Threads; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -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.BeforeEach; +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.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ RegionServerTests.class, LargeTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(LargeTests.TAG) public class TestRegionServerMetrics { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionServerMetrics.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionServerMetrics.class); - @Rule - public TestName testName = new TestName(); - private static MetricsAssertHelper metricsHelper; private static SingleProcessHBaseCluster cluster; private static HRegionServer rs; @@ -104,7 +94,7 @@ public class TestRegionServerMetrics { private static byte[] val = Bytes.toBytes("val"); private static Admin admin; - @BeforeClass + @BeforeAll public static void startCluster() throws Exception { metricsHelper = CompatibilityFactory.getInstance(MetricsAssertHelper.class); TEST_UTIL = new HBaseTestingUtil(); @@ -135,7 +125,7 @@ public static void startCluster() throws Exception { serverSource = metricsRegionServer.getMetricsSource(); } - @AfterClass + @AfterAll public static void after() throws Exception { if (TEST_UTIL != null) { TEST_UTIL.shutdownMiniCluster(); @@ -145,14 +135,14 @@ public static void after() throws Exception { TableName tableName; Table table; - @Before - public void beforeTestMethod() throws Exception { + @BeforeEach + public void beforeTestMethod(TestInfo testInfo) throws Exception { metricsRegionServer.getRegionServerWrapper().forceRecompute(); - tableName = TableName.valueOf(testName.getMethodName()); + tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); table = TEST_UTIL.createTable(tableName, cf); } - @After + @AfterEach public void afterTestMethod() throws Exception { admin.disableTable(tableName); admin.deleteTable(tableName); @@ -520,7 +510,7 @@ private static Region setMobThreshold(Region region, byte[] cfName, long modThre } @Test - @Ignore + @Disabled public void testRangeCountMetrics() throws Exception { final long[] timeranges = { 1, 3, 10, 30, 100, 300, 1000, 3000, 10000, 30000, 60000, 120000, 300000, 600000 }; @@ -590,14 +580,14 @@ public void testReadBytes() throws Exception { TEST_UTIL.getAdmin().flush(tableName); metricsRegionServer.getRegionServerWrapper().forceRecompute(); - assertTrue("Total read bytes should be larger than 0", - metricsRegionServer.getRegionServerWrapper().getTotalBytesRead() > 0); - assertTrue("Total local read bytes should be larger than 0", - metricsRegionServer.getRegionServerWrapper().getLocalBytesRead() > 0); - assertEquals("Total short circuit read bytes should be equal to 0", 0, - metricsRegionServer.getRegionServerWrapper().getShortCircuitBytesRead()); - assertEquals("Total zero-byte read bytes should be equal to 0", 0, - metricsRegionServer.getRegionServerWrapper().getZeroCopyBytesRead()); + assertTrue(metricsRegionServer.getRegionServerWrapper().getTotalBytesRead() > 0, + "Total read bytes should be larger than 0"); + assertTrue(metricsRegionServer.getRegionServerWrapper().getLocalBytesRead() > 0, + "Total local read bytes should be larger than 0"); + assertEquals(0, metricsRegionServer.getRegionServerWrapper().getShortCircuitBytesRead(), + "Total short circuit read bytes should be equal to 0"); + assertEquals(0, metricsRegionServer.getRegionServerWrapper().getZeroCopyBytesRead(), + "Total zero-byte read bytes should be equal to 0"); } @Test @@ -606,14 +596,14 @@ public void testTableDescriptorHashMetric() throws Exception { metricsRegionServer.getRegionServerWrapper().forceRecompute(); HRegion region = rs.getRegions(tableName).get(0); - assertNotNull("Region should exist", region); + assertNotNull(region, "Region should exist"); try (MetricsRegionWrapperImpl wrapper = new MetricsRegionWrapperImpl(region)) { String hash = wrapper.getTableDescriptorHash(); - assertNotNull("TableDescriptorHash should not be null", hash); - assertNotEquals("TableDescriptorHash should not be 'UNKNOWN'", "UNKNOWN", hash); - assertEquals("Hash should be 8 characters (CRC32 hex)", 8, hash.length()); + assertNotNull(hash, "TableDescriptorHash should not be null"); + assertNotEquals("UNKNOWN", hash, "TableDescriptorHash should not be 'UNKNOWN'"); + assertEquals(8, hash.length(), "Hash should be 8 characters (CRC32 hex)"); } } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerNoMaster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerNoMaster.java index 522b0ea884b3..d8d693eb0a6b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerNoMaster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerNoMaster.java @@ -17,10 +17,12 @@ */ package org.apache.hadoop.hbase.regionserver; -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 static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.NotServingRegionException; @@ -39,12 +41,10 @@ import org.apache.hadoop.hbase.util.JVMClusterUtil; import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread; 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; @@ -56,13 +56,9 @@ /** * Tests on the region server, without the master. */ -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestRegionServerNoMaster { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionServerNoMaster.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionServerNoMaster.class); private static final int NB_SERVERS = 1; private static Table table; @@ -73,7 +69,7 @@ public class TestRegionServerNoMaster { private static byte[] regionName; private static final HBaseTestingUtil HTU = new HBaseTestingUtil(); - @BeforeClass + @BeforeAll public static void before() throws Exception { HTU.startMiniCluster(NB_SERVERS); final TableName tableName = TableName.valueOf(TestRegionServerNoMaster.class.getSimpleName()); @@ -131,7 +127,7 @@ public static void flushRegion(HBaseTestingUtil HTU, RegionInfo regionInfo) thro throw new IOException("Region to flush cannot be found"); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { HRegionServer.TEST_SKIP_REPORTING_TRANSITION = false; if (table != null) { @@ -150,8 +146,8 @@ public static void openRegion(HBaseTestingUtil HTU, HRegionServer rs, RegionInfo RequestConverter.buildOpenRegionRequest(rs.getServerName(), hri, null); AdminProtos.OpenRegionResponse responseOpen = rs.getRpcServices().openRegion(null, orr); - Assert.assertTrue(responseOpen.getOpeningStateCount() == 1); - Assert.assertTrue(responseOpen.getOpeningState(0) + assertTrue(responseOpen.getOpeningStateCount() == 1); + assertTrue(responseOpen.getOpeningState(0) .equals(AdminProtos.OpenRegionResponse.RegionOpeningState.OPENED)); checkRegionIsOpened(HTU, rs, hri); @@ -163,7 +159,7 @@ public static void checkRegionIsOpened(HBaseTestingUtil HTU, HRegionServer rs, R Thread.sleep(1); } - Assert.assertTrue(rs.getRegion(hri.getRegionName()).isAvailable()); + assertTrue(rs.getRegion(hri.getRegionName()).isAvailable()); } public static void closeRegion(HBaseTestingUtil HTU, HRegionServer rs, RegionInfo hri) @@ -171,7 +167,7 @@ public static void closeRegion(HBaseTestingUtil HTU, HRegionServer rs, RegionInf AdminProtos.CloseRegionRequest crr = ProtobufUtil.buildCloseRegionRequest(rs.getServerName(), hri.getRegionName()); AdminProtos.CloseRegionResponse responseClose = rs.getRpcServices().closeRegion(null, crr); - Assert.assertTrue(responseClose.getClosed()); + assertTrue(responseClose.getClosed()); checkRegionIsClosed(HTU, rs, hri); } @@ -182,7 +178,7 @@ public static void checkRegionIsClosed(HBaseTestingUtil HTU, HRegionServer rs, R } try { - Assert.assertFalse(rs.getRegion(hri.getRegionName()).isAvailable()); + assertFalse(rs.getRegion(hri.getRegionName()).isAvailable()); } catch (NotServingRegionException expected) { // That's how it work: if the region is closed we have an exception. } @@ -196,7 +192,7 @@ private void closeRegionNoZK() throws Exception { AdminProtos.CloseRegionRequest crr = ProtobufUtil.buildCloseRegionRequest(getRS().getServerName(), regionName); AdminProtos.CloseRegionResponse responseClose = getRS().getRpcServices().closeRegion(null, crr); - Assert.assertTrue(responseClose.getClosed()); + assertTrue(responseClose.getClosed()); // now waiting & checking. After a while, the transition should be done and the region closed checkRegionIsClosed(HTU, getRS(), hri); @@ -216,10 +212,10 @@ public void testMultipleCloseFromMaster() throws Exception { try { AdminProtos.CloseRegionResponse responseClose = getRS().getRpcServices().closeRegion(null, crr); - Assert.assertTrue("request " + i + " failed", - responseClose.getClosed() || responseClose.hasClosed()); + assertTrue(responseClose.getClosed() || responseClose.hasClosed(), + "request " + i + " failed"); } catch (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException se) { - Assert.assertTrue("The next queries may throw an exception.", i > 0); + assertTrue(i > 0, "The next queries may throw an exception."); } } @@ -245,12 +241,12 @@ public void testCancelOpeningWithoutZK() throws Exception { ProtobufUtil.buildCloseRegionRequest(getRS().getServerName(), regionName); try { getRS().getRpcServices().closeRegion(null, crr); - Assert.assertTrue(false); + assertTrue(false); } catch (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException expected) { } // The state in RIT should have changed to close - Assert.assertEquals(Boolean.FALSE, + assertEquals(Boolean.FALSE, getRS().getRegionsInTransitionInRS().get(hri.getEncodedNameAsBytes())); // Let's start the open handler @@ -270,7 +266,7 @@ public void testCancelOpeningWithoutZK() throws Exception { */ @Test public void testOpenCloseRegionRPCIntendedForPreviousServer() throws Exception { - Assert.assertTrue(getRS().getRegion(regionName).isAvailable()); + assertTrue(getRS().getRegion(regionName).isAvailable()); ServerName sn = getRS().getServerName(); ServerName earlierServerName = ServerName.valueOf(sn.getHostname(), sn.getPort(), 1); @@ -279,10 +275,10 @@ public void testOpenCloseRegionRPCIntendedForPreviousServer() throws Exception { CloseRegionRequest request = ProtobufUtil.buildCloseRegionRequest(earlierServerName, regionName); getRS().getRSRpcServices().closeRegion(null, request); - Assert.fail("The closeRegion should have been rejected"); + fail("The closeRegion should have been rejected"); } catch (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException se) { - Assert.assertTrue(se.getCause() instanceof IOException); - Assert.assertTrue( + assertTrue(se.getCause() instanceof IOException); + assertTrue( se.getCause().getMessage().contains("This RPC was intended for a different server")); } @@ -292,10 +288,10 @@ public void testOpenCloseRegionRPCIntendedForPreviousServer() throws Exception { AdminProtos.OpenRegionRequest orr = RequestConverter.buildOpenRegionRequest(earlierServerName, hri, null); getRS().getRSRpcServices().openRegion(null, orr); - Assert.fail("The openRegion should have been rejected"); + fail("The openRegion should have been rejected"); } catch (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException se) { - Assert.assertTrue(se.getCause() instanceof IOException); - Assert.assertTrue( + assertTrue(se.getCause() instanceof IOException); + assertTrue( se.getCause().getMessage().contains("This RPC was intended for a different server")); } finally { openRegion(HTU, getRS(), hri); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerOnlineConfigChange.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerOnlineConfigChange.java index 00890e82d55c..38bb52c4f3ab 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerOnlineConfigChange.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerOnlineConfigChange.java @@ -17,16 +17,15 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -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.assertFalse; +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.concurrent.TimeUnit; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.JMXListener; @@ -44,12 +43,11 @@ import org.apache.hadoop.hbase.regionserver.compactions.CompactionConfiguration; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; -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.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,13 +56,8 @@ * add tests for important configurations which will be changed online. */ -@Category({ MediumTests.class }) +@Tag(MediumTests.TAG) public class TestRegionServerOnlineConfigChange { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionServerOnlineConfigChange.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionServerOnlineConfigChange.class.getName()); private static final long WAIT_TIMEOUT = TimeUnit.MINUTES.toMillis(2); @@ -83,7 +76,7 @@ public class TestRegionServerOnlineConfigChange { private final static byte[] COLUMN_FAMILY1 = Bytes.toBytes(columnFamily1Str); private final static long MAX_FILE_SIZE = 20 * 1024 * 1024L; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { conf = hbaseTestingUtility.getConfiguration(); hbaseTestingUtility.startMiniCluster(2); @@ -92,12 +85,12 @@ public static void setUpBeforeClass() throws Exception { new byte[][] { COLUMN_FAMILY1 }, conf); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { hbaseTestingUtility.shutdownMiniCluster(); } - @Before + @BeforeEach public void setUp() throws Exception { try (RegionLocator locator = hbaseTestingUtility.getConnection().getRegionLocator(TABLE1)) { RegionInfo firstHRI = locator.getAllRegionLocations().get(0).getRegion(); @@ -235,8 +228,8 @@ public void testCompactionConfigurationOnlineChange() throws IOException { public void removeClosedRegionFromConfigurationManager() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf)) { Admin admin = connection.getAdmin(); - assertTrue("The open region doesn't register as a ConfigurationObserver", - rs1.getConfigurationManager().containsObserver(r1)); + assertTrue(rs1.getConfigurationManager().containsObserver(r1), + "The open region doesn't register as a ConfigurationObserver"); admin.move(r1name); hbaseTestingUtility.waitFor(WAIT_TIMEOUT, new Waiter.Predicate() { @Override @@ -244,8 +237,8 @@ public boolean evaluate() throws Exception { return rs1.getOnlineRegion(r1name) == null; } }); - assertFalse("The closed region is not removed from ConfigurationManager", - rs1.getConfigurationManager().containsObserver(r1)); + assertFalse(rs1.getConfigurationManager().containsObserver(r1), + "The closed region is not removed from ConfigurationManager"); admin.move(r1name, rs1.getServerName()); hbaseTestingUtility.waitFor(WAIT_TIMEOUT, new Waiter.Predicate() { @Override diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerReadRequestMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerReadRequestMetrics.java index 1bcb46b8daa9..9535ddabd4fb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerReadRequestMetrics.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerReadRequestMetrics.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.Collection; @@ -31,7 +31,6 @@ import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.ClusterMetrics.Option; import org.apache.hadoop.hbase.CompareOperator; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.RegionMetrics; import org.apache.hadoop.hbase.ServerMetrics; @@ -60,23 +59,17 @@ import org.apache.hadoop.hbase.filter.SingleColumnValueFilter; 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.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; -@Ignore // Depends on Master being able to host regions. Needs fixing. -@Category(MediumTests.class) +@Disabled // Depends on Master being able to host regions. Needs fixing. +@Tag(MediumTests.TAG) public class TestRegionServerReadRequestMetrics { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionServerReadRequestMetrics.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionServerReadRequestMetrics.class); private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); @@ -106,7 +99,7 @@ public class TestRegionServerReadRequestMetrics { private static Map requestsMap = new HashMap<>(); private static Map requestsMapPrev = new HashMap<>(); - @BeforeClass + @BeforeAll public static void setUpOnce() throws Exception { TEST_UTIL.startMiniCluster(); admin = TEST_UTIL.getAdmin(); @@ -115,7 +108,7 @@ public static void setUpOnce() throws Exception { table = createTable(); putData(); List regions = admin.getRegions(TABLE_NAME); - assertEquals("Table " + TABLE_NAME + " should have 1 region", 1, regions.size()); + assertEquals(1, regions.size(), "Table " + TABLE_NAME + " should have 1 region"); regionInfo = regions.get(0); for (Metric metric : Metric.values()) { @@ -246,7 +239,7 @@ private static void putTTLExpiredData() throws IOException, InterruptedException table.put(put); } - @AfterClass + @AfterAll public static void tearDownOnce() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -319,7 +312,7 @@ public void testReadRequestsCountNotFiltered() throws Exception { testReadRequests(resultCount, 1, 0); } - @Ignore // HBASE-19785 + @Disabled // HBASE-19785 @Test public void testReadRequestsCountWithFilter() throws Exception { int resultCount; @@ -366,7 +359,7 @@ public void testReadRequestsCountWithFilter() throws Exception { // testReadRequests(resultCount, 0, 1); } - @Ignore // HBASE-19785 + @Disabled // HBASE-19785 @Test public void testReadRequestsCountWithDeletedRow() throws Exception { try { @@ -404,7 +397,7 @@ public void testReadRequestsCountWithTTLExpiration() throws Exception { } } - @Ignore // See HBASE-19785 + @Disabled // See HBASE-19785 @Test public void testReadRequestsWithCoprocessor() throws Exception { TableName tableName = TableName.valueOf("testReadRequestsWithCoprocessor"); @@ -416,7 +409,7 @@ public void testReadRequestsWithCoprocessor() throws Exception { try { TEST_UTIL.waitTableAvailable(tableName); List regionInfos = admin.getRegions(tableName); - assertEquals("Table " + TABLE_NAME + " should have 1 region", 1, regionInfos.size()); + assertEquals(1, regionInfos.size(), "Table " + TABLE_NAME + " should have 1 region"); boolean success = true; int i = 0; for (; i < MAX_TRY; i++) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerRegionSpaceUseReport.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerRegionSpaceUseReport.java index 2ce0f0fa61ef..8e66bf52d35f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerRegionSpaceUseReport.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerRegionSpaceUseReport.java @@ -17,15 +17,14 @@ */ package org.apache.hadoop.hbase.regionserver; -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 static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.mock; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.RegionInfoBuilder; @@ -34,9 +33,8 @@ import org.apache.hadoop.hbase.quotas.RegionSizeStoreFactory; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.Bytes; -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.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionSpaceUse; @@ -46,13 +44,8 @@ * Test class for isolated (non-cluster) tests surrounding the report of Region space use to the * Master by RegionServers. */ -@Category(SmallTests.class) +@Tag(SmallTests.TAG) public class TestRegionServerRegionSpaceUseReport { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionServerRegionSpaceUseReport.class); - @Test public void testConversion() { TableName tn = TableName.valueOf("table1"); @@ -78,9 +71,9 @@ public void testConversion() { for (RegionSpaceUse spaceUse : requests.getSpaceUseList()) { RegionInfo hri = ProtobufUtil.toRegionInfo(spaceUse.getRegionInfo()); RegionSize expectedSize = store.remove(hri); - assertNotNull("Could not find size for HRI: " + hri, expectedSize); + assertNotNull(expectedSize, "Could not find size for HRI: " + hri); assertEquals(expectedSize.getSize(), spaceUse.getRegionSize()); } - assertTrue("Should not have any space use entries left: " + store, store.isEmpty()); + assertTrue(store.isEmpty(), "Should not have any space use entries left: " + store); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerRejectDuringAbort.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerRejectDuringAbort.java index 61da536310a8..39357cf0b874 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerRejectDuringAbort.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerRejectDuringAbort.java @@ -17,14 +17,13 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.IOException; import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionLocation; @@ -53,21 +52,16 @@ 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.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({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestRegionServerRejectDuringAbort { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionServerRejectDuringAbort.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionServerRejectDuringAbort.class); @@ -83,7 +77,7 @@ public class TestRegionServerRejectDuringAbort { private static volatile boolean shouldThrowTooBig = false; - @BeforeClass + @BeforeAll public static void setUp() throws Exception { // Will schedule a abort timeout task after SLEEP_TIME_WHEN_CLOSE_REGION ms UTIL.getConfiguration().set("hbase.ipc.server.callqueue.type", "pluggable"); @@ -114,7 +108,7 @@ public boolean offer(CallRunner callRunner) { } } - @AfterClass + @AfterAll public static void tearDown() throws Exception { UTIL.shutdownMiniCluster(); } @@ -143,8 +137,8 @@ public void testRejectRequestsOnAbort() throws Exception { } } - assertNotNull("couldn't find a server without meta, but with test table regions", - serverWithoutMeta); + assertNotNull(serverWithoutMeta, + "couldn't find a server without meta, but with test table regions"); Thread writer = new Thread(getWriterThreadRunnable(serverWithoutMeta.getServerName())); writer.setDaemon(true); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerReportForDuty.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerReportForDuty.java index ff8bdab5848a..224d379860ef 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerReportForDuty.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerReportForDuty.java @@ -18,10 +18,12 @@ package org.apache.hadoop.hbase.regionserver; import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.io.StringWriter; @@ -31,7 +33,6 @@ import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.StringUtils; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.LocalHBaseCluster; @@ -49,23 +50,17 @@ import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread; import org.apache.hadoop.hbase.util.Threads; 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; import org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder; -@Category(LargeTests.class) +@Tag(LargeTests.TAG) public class TestRegionServerReportForDuty { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionServerReportForDuty.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionServerReportForDuty.class); private static final long SLEEP_INTERVAL = 500; @@ -77,7 +72,7 @@ public class TestRegionServerReportForDuty { private MasterThread master; private MasterThread backupMaster; - @Before + @BeforeEach public void setUp() throws Exception { testUtil = new HBaseTestingUtil(); testUtil.startMiniDFSCluster(1); @@ -86,7 +81,7 @@ public void setUp() throws Exception { cluster = new LocalHBaseCluster(testUtil.getConfiguration(), 0, 0); } - @After + @AfterEach public void tearDown() throws Exception { cluster.shutdown(); cluster.join(); @@ -158,10 +153,10 @@ public void testReportForDutyBackoff() throws IOException, InterruptedException // Following asserts the actual retry number is in range (expectedRetry/2, expectedRetry*2). // Ideally we can assert the exact retry count. We relax here to tolerate contention error. int expectedRetry = (int) Math.ceil(Math.log(interval - msginterval)); - assertTrue(String.format("reportForDuty retries %d times, less than expected min %d", count, - expectedRetry / 2), count > expectedRetry / 2); - assertTrue(String.format("reportForDuty retries %d times, more than expected max %d", count, - expectedRetry * 2), count < expectedRetry * 2); + assertTrue(count > expectedRetry / 2, String.format( + "reportForDuty retries %d times, less than expected min %d", count, expectedRetry / 2)); + assertTrue(count < expectedRetry * 2, String.format( + "reportForDuty retries %d times, more than expected max %d", count, expectedRetry * 2)); } /** diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerScan.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerScan.java index 6166e76ea870..432c9e67a871 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerScan.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerScan.java @@ -17,14 +17,13 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.SingleProcessHBaseCluster.MiniHBaseClusterRegionServer; @@ -43,13 +42,10 @@ import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.RegionServerTests; import org.apache.hadoop.hbase.util.Bytes; -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; import org.apache.hbase.thirdparty.com.google.protobuf.RpcController; import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException; @@ -57,15 +53,9 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanResponse; -@Category({ RegionServerTests.class, LargeTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(LargeTests.TAG) public class TestRegionServerScan { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionServerScan.class); - - @Rule - public TestName name = new TestName(); - private static final byte[] CF = Bytes.toBytes("CF"); private static final byte[] CQ = Bytes.toBytes("CQ"); private static final byte[] VALUE = new byte[1200]; @@ -78,7 +68,7 @@ public class TestRegionServerScan { static final byte[] r1 = Bytes.toBytes("row-1"); static final byte[] r2 = Bytes.toBytes("row-2"); - @BeforeClass + @BeforeAll public static void setupBeforeClass() throws Exception { /** * Use {@link DeallocateRewriteByteBuffAllocator} to rewrite the bytebuffers right after @@ -104,7 +94,7 @@ public static void setupBeforeClass() throws Exception { admin = TEST_UTIL.getAdmin(); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerUseIp.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerUseIp.java index a2439a878882..42afbd4fc652 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerUseIp.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerUseIp.java @@ -17,11 +17,10 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.net.InetAddress; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; @@ -29,20 +28,16 @@ import org.apache.hadoop.hbase.StartTestingClusterOption; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.RegionServerTests; -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({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestRegionServerUseIp { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionServerUseIp.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRegionServerUseIp.class); private HBaseTestingUtil TEST_UTIL; @@ -51,7 +46,7 @@ public class TestRegionServerUseIp { 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 +56,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/regionserver/TestRegionSplitPolicy.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionSplitPolicy.java index 404935d3e949..f00f2393275a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionSplitPolicy.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionSplitPolicy.java @@ -17,10 +17,10 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -30,7 +30,6 @@ import java.util.List; import java.util.Optional; 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.TableName; @@ -42,24 +41,19 @@ import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -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({ RegionServerTests.class, SmallTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(SmallTests.TAG) public class TestRegionSplitPolicy { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionSplitPolicy.class); - private Configuration conf; private HRegion mockRegion; private List stores; private static final TableName TABLENAME = TableName.valueOf("t"); - @Before + @BeforeEach public void setupMocks() { conf = HBaseConfiguration.create(); RegionInfo hri = RegionInfoBuilder.newBuilder(TABLENAME).build(); @@ -280,9 +274,9 @@ public void testBusyRegionSplitPolicy() throws Exception { } private void assertWithinJitter(long maxSplitSize, long sizeToCheck) { - assertTrue("Size greater than lower bound of jitter", - (long) (maxSplitSize * 0.75) <= sizeToCheck); - assertTrue("Size less than upper bound of jitter", (long) (maxSplitSize * 1.25) >= sizeToCheck); + assertTrue((long) (maxSplitSize * 0.75) <= sizeToCheck, + "Size greater than lower bound of jitter"); + assertTrue((long) (maxSplitSize * 1.25) >= sizeToCheck, "Size less than upper bound of jitter"); } @Test diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionSplitRestriction.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionSplitRestriction.java index 890cf45bbe73..4cb08fec51ca 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionSplitRestriction.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionSplitRestriction.java @@ -17,36 +17,30 @@ */ package org.apache.hadoop.hbase.regionserver; -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 static org.mockito.Mockito.when; import java.io.IOException; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.client.TableDescriptor; import org.apache.hadoop.hbase.testclassification.RegionServerTests; 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.Mock; import org.mockito.MockitoAnnotations; -@Category({ RegionServerTests.class, SmallTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(SmallTests.TAG) public class TestRegionSplitRestriction { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionSplitRestriction.class); - Configuration conf; @Mock TableDescriptor tableDescriptor; - @Before + @BeforeEach public void setup() { MockitoAnnotations.initMocks(this); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRemoveRegionMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRemoveRegionMetrics.java index d3f27242f486..ce27cc542305 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRemoveRegionMetrics.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRemoveRegionMetrics.java @@ -20,7 +20,6 @@ import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.CompatibilityFactory; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.NamespaceDescriptor; @@ -36,29 +35,20 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Threads; -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; - -@Category({ RegionServerTests.class, LargeTests.class }) -public class TestRemoveRegionMetrics { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRemoveRegionMetrics.class); +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +@Tag(RegionServerTests.TAG) +@Tag(LargeTests.TAG) +public class TestRemoveRegionMetrics { private static SingleProcessHBaseCluster cluster; private static Configuration conf; private static HBaseTestingUtil TEST_UTIL; private static MetricsAssertHelper metricsHelper; - @Rule - public TestName name = new TestName(); - - @BeforeClass + @BeforeAll public static void startCluster() throws Exception { metricsHelper = CompatibilityFactory.getInstance(MetricsAssertHelper.class); TEST_UTIL = new HBaseTestingUtil(); @@ -79,8 +69,8 @@ public static void startCluster() throws Exception { } @Test - public void testMoveRegion() throws IOException, InterruptedException { - String tableNameString = name.getMethodName(); + public void testMoveRegion(TestInfo testInfo) throws IOException, InterruptedException { + String tableNameString = testInfo.getTestMethod().get().getName(); TableName tableName = TableName.valueOf(tableNameString); Table t = TEST_UTIL.createTable(tableName, Bytes.toBytes("D")); TEST_UTIL.waitUntilAllRegionsAssigned(t.getName()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestReplicateToReplica.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestReplicateToReplica.java index 253ca876bd34..003421e721ef 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestReplicateToReplica.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestReplicateToReplica.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.regionserver; -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 static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyList; @@ -41,12 +41,10 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.ExtendedCellScanner; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.TableNameTestRule; import org.apache.hadoop.hbase.client.AsyncClusterConnection; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; import org.apache.hadoop.hbase.client.Get; @@ -69,25 +67,20 @@ import org.apache.hadoop.hbase.util.ServerRegionReplicaUtil; import org.apache.hadoop.hbase.wal.WAL; import org.apache.hadoop.hbase.wal.WALFactory; -import org.junit.After; -import org.junit.AfterClass; -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.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.junit.jupiter.api.TestInfo; import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.ReplicateWALEntryRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.WALEntry; -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestReplicateToReplica { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicateToReplica.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static byte[] FAMILY = Bytes.toBytes("family"); @@ -96,9 +89,6 @@ public class TestReplicateToReplica { private static ExecutorService EXEC; - @Rule - public final TableNameTestRule name = new TableNameTestRule(); - private TableName tableName; private Path testDir; @@ -153,7 +143,7 @@ protected PrepareFlushResult internalPrepareFlushCache(WAL wal, long myseqid, } - @BeforeClass + @BeforeAll public static void setUpBeforeClass() { Configuration conf = UTIL.getConfiguration(); conf.setInt("hbase.region.read-replica.sink.flush.min-interval.secs", 1); @@ -167,16 +157,16 @@ public static void setUpBeforeClass() { MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_DEFAULT); } - @AfterClass + @AfterAll public static void tearDownAfterClass() { EXEC.shutdown(); UTIL.cleanupTestDir(); } - @Before - public void setUp() throws IOException { + @BeforeEach + public void setUp(TestInfo testInfo) throws IOException { TO_ADD_AFTER_PREPARE_FLUSH = new ArrayList<>(); - tableName = name.getTableName(); + tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); testDir = UTIL.getDataTestDir(tableName.getNameAsString()); Configuration conf = UTIL.getConfiguration(); conf.set(HConstants.HBASE_DIR, testDir.toString()); @@ -232,7 +222,7 @@ public void setUp() throws IOException { replicateAll(); } - @After + @AfterEach public void tearDown() throws IOException { // close region will issue a flush, which will enqueue an edit into the replication sink so we // need to complete it otherwise the test will hang. diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRequestsPerSecondMetric.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRequestsPerSecondMetric.java index 8b33912035eb..d81c4d59dd59 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRequestsPerSecondMetric.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRequestsPerSecondMetric.java @@ -17,9 +17,10 @@ */ package org.apache.hadoop.hbase.regionserver; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.IOException; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -28,35 +29,29 @@ import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.RegionServerTests; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Validate requestsPerSecond metric. */ -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestRequestsPerSecondMetric { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRequestsPerSecondMetric.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static final long METRICS_PERIOD = 2000L; private static Configuration conf; - @BeforeClass + @BeforeAll public static void setup() throws Exception { conf = UTIL.getConfiguration(); conf.setLong(HConstants.REGIONSERVER_METRICS_PERIOD, METRICS_PERIOD); UTIL.startMiniCluster(1); } - @AfterClass + @AfterAll public static void teardown() throws Exception { UTIL.shutdownMiniCluster(); } @@ -90,6 +85,6 @@ public void testNoNegativeSignAtRequestsPerSecond() throws IOException, Interrup admin.disableTable(TABLENAME); Thread.sleep(METRICS_PERIOD); metricsServer.run(); - Assert.assertTrue(metricsWrapper.getRequestsPerSecond() > -1); + assertTrue(metricsWrapper.getRequestsPerSecond() > -1); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestResettingCounters.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestResettingCounters.java index 563eec137ace..a9dd91a432a6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestResettingCounters.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestResettingCounters.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.regionserver; -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.io.IOException; import org.apache.hadoop.conf.Configuration; @@ -26,7 +26,6 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -41,28 +40,20 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.Bytes; -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.junit.jupiter.api.TestInfo; -@Category({ RegionServerTests.class, SmallTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(SmallTests.TAG) public class TestResettingCounters { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestResettingCounters.class); - - @Rule - public TestName name = new TestName(); - @Test - public void testResettingCounters() throws Exception { + public void testResettingCounters(TestInfo testInfo) throws Exception { HBaseTestingUtil htu = new HBaseTestingUtil(); Configuration conf = htu.getConfiguration(); FileSystem fs = FileSystem.get(conf); - byte[] table = Bytes.toBytes(name.getMethodName()); + byte[] table = Bytes.toBytes(testInfo.getTestMethod().get().getName()); byte[][] families = new byte[][] { Bytes.toBytes("family1"), Bytes.toBytes("family2"), Bytes.toBytes("family3") }; int numQualifiers = 10; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestReversibleScanners.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestReversibleScanners.java index ee55764b4d51..c4fa0c10ab50 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestReversibleScanners.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestReversibleScanners.java @@ -17,9 +17,9 @@ */ package org.apache.hadoop.hbase.regionserver; -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.ArrayList; @@ -32,7 +32,6 @@ import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellComparatorImpl; import org.apache.hadoop.hbase.CompareOperator; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeepDeletedCells; @@ -59,12 +58,10 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.Pair; -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.BeforeAll; +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; @@ -73,13 +70,9 @@ /** * Test cases against ReversibleKeyValueScanner */ -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestReversibleScanners { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReversibleScanners.class); - private static final Logger LOG = LoggerFactory.getLogger(TestReversibleScanners.class); HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); @@ -96,10 +89,7 @@ public class TestReversibleScanners { private static final int VALUESIZE = 3; private static byte[][] VALUES = makeN(VALUE, VALUESIZE); - @Rule - public TestName name = new TestName(); - - @BeforeClass + @BeforeAll public static void setUp() { ChunkCreator.initialize(MemStoreLAB.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null, MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_DEFAULT); @@ -314,11 +304,12 @@ public void testReversibleStoreScanner() throws IOException { } @Test - public void testReversibleRegionScanner() throws IOException { + public void testReversibleRegionScanner(TestInfo testInfo) throws IOException { byte[] FAMILYNAME2 = Bytes.toBytes("testCf2"); - TableDescriptor htd = TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName())) - .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILYNAME)) - .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILYNAME2)).build(); + TableDescriptor htd = + TableDescriptorBuilder.newBuilder(TableName.valueOf(testInfo.getTestMethod().get().getName())) + .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILYNAME)) + .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILYNAME2)).build(); HRegion region = TEST_UTIL.createLocalHRegion(htd, null, null); loadDataToRegion(region, FAMILYNAME2); @@ -439,8 +430,8 @@ private void verifyCountAndOrder(InternalScanner scanner, int expectedKVCount, kvCount += kvList.size(); if (lastResult != null) { Result curResult = Result.create(kvList); - assertEquals("LastResult:" + lastResult + "CurResult:" + curResult, forward, - Bytes.compareTo(curResult.getRow(), lastResult.getRow()) > 0); + assertEquals(forward, Bytes.compareTo(curResult.getRow(), lastResult.getRow()) > 0, + "LastResult:" + lastResult + "CurResult:" + curResult); } lastResult = Result.create(kvList); kvList.clear(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRowPrefixBloomFilter.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRowPrefixBloomFilter.java index 840d0580f978..e285c441ac8a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRowPrefixBloomFilter.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRowPrefixBloomFilter.java @@ -17,9 +17,9 @@ */ package org.apache.hadoop.hbase.regionserver; -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 static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -27,7 +27,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.HBaseTestingUtil; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; @@ -47,26 +46,19 @@ import org.apache.hadoop.hbase.util.ChecksumType; import org.apache.hadoop.hbase.util.CommonFSUtils; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -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.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Test TestRowPrefixBloomFilter */ -@Category({ RegionServerTests.class, SmallTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(SmallTests.TAG) public class TestRowPrefixBloomFilter { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRowPrefixBloomFilter.class); - private static final Logger LOG = LoggerFactory.getLogger(TestRowPrefixBloomFilter.class); private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private CacheConfig cacheConf = new CacheConfig(TEST_UTIL.getConfiguration()); @@ -87,10 +79,7 @@ public class TestRowPrefixBloomFilter { private static final int fixedLengthExpKeys = prefixRowCount; private static final BloomType bt = BloomType.ROWPREFIX_FIXED_LENGTH; - @Rule - public TestName name = new TestName(); - - @Before + @BeforeEach public void setUp() throws Exception { conf = TEST_UTIL.getConfiguration(); conf.setFloat(BloomFilterFactory.IO_STOREFILE_BLOOM_ERROR_RATE, err); @@ -117,7 +106,7 @@ public void setUp() throws Exception { } } - @After + @AfterEach public void tearDown() throws Exception { try { if (localfs) { @@ -241,10 +230,10 @@ public void testRowPrefixBloomFilter() throws Exception { } reader.close(true); // evict because we are about to delete the file fs.delete(f, true); - assertEquals("False negatives: " + falseNeg, 0, falseNeg); + assertEquals(0, falseNeg, "False negatives: " + falseNeg); int maxFalsePos = (int) (2 * expErr); - assertTrue("Too many false positives: " + falsePos + " (err=" + err + ", expected no more than " - + maxFalsePos + ")", falsePos <= maxFalsePos); + assertTrue(falsePos <= maxFalsePos, "Too many false positives: " + falsePos + " (err=" + err + + ", expected no more than " + maxFalsePos + ")"); } @Test diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRowTooBig.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRowTooBig.java index 418c1808a641..df310a3b1922 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRowTooBig.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRowTooBig.java @@ -17,9 +17,10 @@ */ package org.apache.hadoop.hbase.regionserver; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.io.IOException; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -34,36 +35,31 @@ import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.RegionServerTests; 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; /** * Test case to check HRS throws {@link org.apache.hadoop.hbase.client.RowTooBigException} when row * size exceeds configured limits. */ -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestRowTooBig { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRowTooBig.class); - private final static HBaseTestingUtil HTU = new HBaseTestingUtil(); private static Path rootRegionDir; private static final TableDescriptor TEST_TD = TableDescriptorBuilder .newBuilder(TableName.valueOf(TestRowTooBig.class.getSimpleName())).build(); - @BeforeClass + @BeforeAll public static void before() throws Exception { HTU.startMiniCluster(); HTU.getConfiguration().setLong(HConstants.TABLE_MAX_ROWSIZE_KEY, 10 * 1024 * 1024L); rootRegionDir = HTU.getDataTestDirOnTestFS("TestRowTooBig"); } - @AfterClass + @AfterAll public static void after() throws Exception { HTU.shutdownMiniCluster(); } @@ -74,7 +70,7 @@ public static void after() throws Exception { * but during seeking, as each StoreFile gets it's own scanner, and each scanner seeks after the * first KV. */ - @Test(expected = RowTooBigException.class) + @Test public void testScannersSeekOnFewLargeCells() throws IOException { byte[] row1 = Bytes.toBytes("row1"); byte[] fam1 = Bytes.toBytes("fam1"); @@ -97,7 +93,7 @@ public void testScannersSeekOnFewLargeCells() throws IOException { } Get get = new Get(row1); - region.get(get); + assertThrows(RowTooBigException.class, () -> region.get(get)); } finally { HBaseTestingUtil.closeRegionAndWAL(region); } @@ -107,7 +103,7 @@ public void testScannersSeekOnFewLargeCells() throws IOException { * Usecase: - create a row with 1M cells, 10 bytes in each - flush & run major compaction - try to * Get whole row. OOME happened in StoreScanner.next(..). */ - @Test(expected = RowTooBigException.class) + @Test public void testScanAcrossManySmallColumns() throws IOException { byte[] row1 = Bytes.toBytes("row1"); byte[] fam1 = Bytes.toBytes("fam1"); @@ -132,7 +128,7 @@ public void testScanAcrossManySmallColumns() throws IOException { region.compact(true); Get get = new Get(row1); - region.get(get); + assertThrows(RowTooBigException.class, () -> region.get(get)); } finally { HBaseTestingUtil.closeRegionAndWAL(region); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRpcSchedulerFactory.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRpcSchedulerFactory.java index 17f0dc3a7839..c05f2f59c1ed 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRpcSchedulerFactory.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRpcSchedulerFactory.java @@ -17,10 +17,9 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.ipc.FifoRpcScheduler; import org.apache.hadoop.hbase.ipc.RWQueueRpcExecutor; @@ -28,29 +27,19 @@ import org.apache.hadoop.hbase.ipc.RpcScheduler; import org.apache.hadoop.hbase.ipc.SimpleRpcScheduler; import org.apache.hadoop.hbase.testclassification.SmallTests; -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.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * A silly test that does nothing but make sure an rpcscheduler factory makes what it says it is * going to make. */ -@Category(SmallTests.class) +@Tag(SmallTests.TAG) public class TestRpcSchedulerFactory { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRpcSchedulerFactory.class); - - @Rule - public TestName testName = new TestName(); private Configuration conf; - @Before + @BeforeEach public void setUp() throws Exception { this.conf = HBaseConfiguration.create(); }