diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java index 5fd3186a0c15..d0131d314e8c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; @@ -44,50 +43,49 @@ 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.generated.HBaseProtos; -@Category({ RegionServerTests.class, SmallTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(SmallTests.TAG) public class TestHRegionInfo { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestHRegionInfo.class); + private String methodName; - @Rule - public TestName name = new TestName(); + @BeforeEach + public void setUp(TestInfo testInfo) { + methodName = testInfo.getTestMethod().get().getName(); + } @Test public void testIsStart() { assertTrue(RegionInfoBuilder.FIRST_META_REGIONINFO.isFirst()); - org.apache.hadoop.hbase.client.RegionInfo ri = org.apache.hadoop.hbase.client.RegionInfoBuilder - .newBuilder(TableName.META_TABLE_NAME).setStartKey(Bytes.toBytes("not_start")).build(); + RegionInfo ri = RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME) + .setStartKey(Bytes.toBytes("not_start")).build(); assertFalse(ri.isFirst()); } @Test public void testIsEnd() { assertTrue(RegionInfoBuilder.FIRST_META_REGIONINFO.isFirst()); - org.apache.hadoop.hbase.client.RegionInfo ri = org.apache.hadoop.hbase.client.RegionInfoBuilder - .newBuilder(TableName.META_TABLE_NAME).setEndKey(Bytes.toBytes("not_end")).build(); + RegionInfo ri = RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME) + .setEndKey(Bytes.toBytes("not_end")).build(); assertFalse(ri.isLast()); } @Test public void testIsNext() { byte[] bytes = Bytes.toBytes("row"); - org.apache.hadoop.hbase.client.RegionInfo ri = org.apache.hadoop.hbase.client.RegionInfoBuilder - .newBuilder(TableName.META_TABLE_NAME).setEndKey(bytes).build(); - org.apache.hadoop.hbase.client.RegionInfo ri2 = org.apache.hadoop.hbase.client.RegionInfoBuilder - .newBuilder(TableName.META_TABLE_NAME).setStartKey(bytes).build(); + RegionInfo ri = + RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).setEndKey(bytes).build(); + RegionInfo ri2 = + RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).setStartKey(bytes).build(); assertFalse(ri.isNext(RegionInfoBuilder.FIRST_META_REGIONINFO)); assertTrue(ri.isNext(ri2)); } @@ -98,20 +96,15 @@ public void testIsOverlap() { byte[] b = Bytes.toBytes("b"); byte[] c = Bytes.toBytes("c"); byte[] d = Bytes.toBytes("d"); - org.apache.hadoop.hbase.client.RegionInfo all = RegionInfoBuilder.FIRST_META_REGIONINFO; - org.apache.hadoop.hbase.client.RegionInfo ari = org.apache.hadoop.hbase.client.RegionInfoBuilder - .newBuilder(TableName.META_TABLE_NAME).setEndKey(a).build(); - org.apache.hadoop.hbase.client.RegionInfo abri = - org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME) - .setStartKey(a).setEndKey(b).build(); - org.apache.hadoop.hbase.client.RegionInfo adri = - org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME) - .setStartKey(a).setEndKey(d).build(); - org.apache.hadoop.hbase.client.RegionInfo cdri = - org.apache.hadoop.hbase.client.RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME) - .setStartKey(c).setEndKey(d).build(); - org.apache.hadoop.hbase.client.RegionInfo dri = org.apache.hadoop.hbase.client.RegionInfoBuilder - .newBuilder(TableName.META_TABLE_NAME).setStartKey(d).build(); + RegionInfo all = RegionInfoBuilder.FIRST_META_REGIONINFO; + RegionInfo ari = RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).setEndKey(a).build(); + RegionInfo abri = + RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).setStartKey(a).setEndKey(b).build(); + RegionInfo adri = + RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).setStartKey(a).setEndKey(d).build(); + RegionInfo cdri = + RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).setStartKey(c).setEndKey(d).build(); + RegionInfo dri = RegionInfoBuilder.newBuilder(TableName.META_TABLE_NAME).setStartKey(d).build(); assertTrue(all.isOverlap(all)); assertTrue(all.isOverlap(abri)); assertFalse(abri.isOverlap(cdri)); @@ -127,7 +120,7 @@ public void testIsOverlap() { } /** - * Tests {@link RegionInfo#isOverlap(RegionInfo[])} + * Tests {@link RegionInfo#isOverlap(RegionInfo)} */ @Test public void testIsOverlaps() { @@ -197,7 +190,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); @@ -218,7 +211,7 @@ public void testCreateHRegionInfoName() throws Exception { @Test public void testContainsRange() { - HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(name.getMethodName())); + HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(methodName)); HRegionInfo hri = new HRegionInfo(tableDesc.getTableName(), Bytes.toBytes("a"), Bytes.toBytes("g")); // Single row range at start of region @@ -278,7 +271,7 @@ public void testContainsRangeForMetaTable() { @Test public void testLastRegionCompare() { - HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(name.getMethodName())); + HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(methodName)); HRegionInfo hrip = new HRegionInfo(tableDesc.getTableName(), Bytes.toBytes("a"), new byte[0]); HRegionInfo hric = new HRegionInfo(tableDesc.getTableName(), Bytes.toBytes("a"), Bytes.toBytes("b")); @@ -293,7 +286,7 @@ public void testMetaTables() { @SuppressWarnings("SelfComparison") @Test public void testComparator() { - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(methodName); byte[] empty = new byte[0]; HRegionInfo older = new HRegionInfo(tableName, empty, empty, false, 0L); HRegionInfo newer = new HRegionInfo(tableName, empty, empty, false, 1L); @@ -327,7 +320,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); @@ -356,7 +349,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; @@ -365,25 +358,25 @@ public void testParseName() throws IOException { byte[] regionName = HRegionInfo.createRegionName(tableName, startKey, regionId, false); byte[][] fields = HRegionInfo.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 = HRegionInfo.createRegionName(tableName, startKey, regionId, replicaId, false); fields = HRegionInfo.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(HRegionInfo.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(HRegionInfo.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; @@ -420,15 +413,14 @@ public void testRegionDetailsForDisplay() throws IOException { byte[] endKey = new byte[] { 0x01, 0x01, 0x02, 0x04 }; Configuration conf = new Configuration(); conf.setBoolean("hbase.display.keys", false); - HRegionInfo h = new HRegionInfo(TableName.valueOf(name.getMethodName()), startKey, endKey); + HRegionInfo h = new HRegionInfo(TableName.valueOf(methodName), startKey, endKey); checkEquality(h, conf); // check HRIs with non-default replicaId - h = new HRegionInfo(TableName.valueOf(name.getMethodName()), startKey, endKey, false, + h = new HRegionInfo(TableName.valueOf(methodName), startKey, endKey, false, EnvironmentEdgeManager.currentTime(), 1); checkEquality(h, conf); - Assert.assertArrayEquals(HRegionInfo.HIDDEN_END_KEY, HRegionInfo.getEndKeyForDisplay(h, conf)); - Assert.assertArrayEquals(HRegionInfo.HIDDEN_START_KEY, - HRegionInfo.getStartKeyForDisplay(h, conf)); + assertArrayEquals(HRegionInfo.HIDDEN_END_KEY, HRegionInfo.getEndKeyForDisplay(h, conf)); + assertArrayEquals(HRegionInfo.HIDDEN_START_KEY, HRegionInfo.getStartKeyForDisplay(h, conf)); RegionState state = RegionState.createForTesting(h, RegionState.State.OPEN); String descriptiveNameForDisplay = @@ -436,9 +428,9 @@ public void testRegionDetailsForDisplay() throws IOException { checkDescriptiveNameEquality(descriptiveNameForDisplay, state.toDescriptiveString(), startKey); conf.setBoolean("hbase.display.keys", true); - Assert.assertArrayEquals(endKey, HRegionInfo.getEndKeyForDisplay(h, conf)); - Assert.assertArrayEquals(startKey, HRegionInfo.getStartKeyForDisplay(h, conf)); - Assert.assertEquals(state.toDescriptiveString(), + assertArrayEquals(endKey, HRegionInfo.getEndKeyForDisplay(h, conf)); + assertArrayEquals(startKey, HRegionInfo.getStartKeyForDisplay(h, conf)); + assertEquals(state.toDescriptiveString(), HRegionInfo.getDescriptiveNameFromRegionStateForDisplay(state, conf)); } @@ -469,11 +461,10 @@ private void checkEquality(HRegionInfo 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], - HRegionInfo.getStartKeyForDisplay(h, conf)); + assertArrayEquals(modifiedRegionNameParts[1], HRegionInfo.getStartKeyForDisplay(h, conf)); } } } 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..b3e35c005c2e 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,24 @@ */ 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 324de146e0e0..d281f9677bc1 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,9 @@ package org.apache.hadoop.hbase.regionserver; import static org.apache.hadoop.hbase.HBaseTestingUtility.fam1; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.spy; import java.io.IOException; @@ -29,7 +31,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.HBaseTestingUtility; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; @@ -43,27 +44,22 @@ 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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); - @BeforeClass + @BeforeAll public static void startCluster() throws Exception { Configuration conf = TEST_UTIL.getConfiguration(); @@ -71,7 +67,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 +104,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()); + assertEquals(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 0939df7d722e..633d68a57756 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -36,22 +35,18 @@ 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); private static AtomicInteger FAILED_OPEN = new AtomicInteger(0); @@ -83,7 +78,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 +87,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 e785901a4da5..a5caf8647a5f 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,13 @@ package org.apache.hadoop.hbase.regionserver; import static org.apache.hadoop.hbase.HBaseTestingUtility.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 static org.junit.jupiter.api.Assertions.fail; 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; @@ -39,34 +39,28 @@ 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 HBaseTestingUtility HBTU = new HBaseTestingUtility(); private static final int THREADS100 = 100; + private String methodName; // Test names static byte[] tableName; @@ -78,21 +72,19 @@ 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); } - /** - * @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 { + methodName = testInfo.getTestMethod().get().getName(); + tableName = Bytes.toBytes(methodName); } - @After + @AfterEach public void tearDown() throws Exception { EnvironmentEdgeManagerTestHelper.reset(); if (region != null) { @@ -100,8 +92,8 @@ public void tearDown() throws Exception { } } - public String getName() { - return name.getMethodName(); + public String getMethodName() { + return methodName; } ////////////////////////////////////////////////////////////////////////////// @@ -115,7 +107,7 @@ public String getName() { @Test public void testPut() throws IOException { LOG.info("Starting testPut"); - this.region = initHRegion(tableName, getName(), fam1); + this.region = initHRegion(tableName, getMethodName(), fam1); long value = 1L; @@ -134,7 +126,7 @@ public void testParallelPuts() throws IOException { LOG.info("Starting testParallelPuts"); - this.region = initHRegion(tableName, getName(), fam1); + this.region = initHRegion(tableName, getMethodName(), fam1); int numOps = 1000; // these many operations per thread // create 100 threads, each will do its own puts @@ -224,7 +216,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); + fail("Thread id " + threadNumber + " operation " + i + " failed.", e); } } } 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 a36b25592084..4839c149fd3b 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; @@ -52,9 +51,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; @@ -63,13 +61,10 @@ /** * 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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); @@ -119,11 +114,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 @@ -372,7 +367,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); + assertNotNull(desiredRegion, "Could not find a region which hosts the new region."); // Flush the region selectively. desiredRegion.flush(false); @@ -472,7 +467,7 @@ public void testFlushingWhenLogRolling() throws Exception { } Pair desiredRegionAndServer = getRegionWithName(tableName); final HRegion desiredRegion = desiredRegionAndServer.getFirst(); - assertTrue("Could not find a region which hosts the new region.", desiredRegion != null); + assertNotNull(desiredRegion, "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 732eb71373ef..1f064445257f 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,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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -31,11 +30,10 @@ 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; import org.mockito.Mockito; import org.apache.hbase.thirdparty.com.google.protobuf.ByteString; @@ -51,26 +49,23 @@ /** * Tests that verify certain RPCs get a higher QoS. */ -@Category({ RegionServerTests.class, MediumTests.class }) +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) public class TestPriorityRpc { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestPriorityRpc.class); - private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); private static HRegionServer RS = null; private static PriorityFunction PRIORITY = null; - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.startMiniCluster(1); RS = UTIL.getHBaseCluster().getRegionServer(0); PRIORITY = RS.rpcServices.getPriority(); } - @AfterClass + @AfterAll public static void tearDown() throws IOException { UTIL.shutdownMiniCluster(); } @@ -147,7 +142,7 @@ public void testQosFunctionForScanMethod() throws IOException { // Presume type. ((AnnotationReadingPriorityFunction) PRIORITY).setRegionServer(mockRS); final int qos = PRIORITY.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/TestQosFunction.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestQosFunction.java index b3b71842c267..890acc3bf6e0 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestQosFunction.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestQosFunction.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.QosTestHelper; 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,18 +36,15 @@ * 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 TestQosFunction extends QosTestHelper { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestQosFunction.class); - private Configuration conf; private RSRpcServices rpcServices; private AnnotationReadingPriorityFunction qosFunction; - @Before + @BeforeEach public void setUp() { conf = HBaseConfiguration.create(); rpcServices = Mockito.mock(RSRpcServices.class); @@ -66,7 +61,6 @@ public void testPriority() { // Check multi works. checkMethod(conf, "Multi", HConstants.NORMAL_QOS, qosFunction, MultiRequest.getDefaultInstance()); - } @Test 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 0ec8b70545df..de3d5b51afff 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,41 +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.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.ScheduledChore; import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.RegionServerTests; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.startMiniCluster(StartMiniClusterOption.builder().numRegionServers(1).build()); hRegionServer = UTIL.getMiniHBaseCluster().getRegionServer(0); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { UTIL.shutdownMiniCluster(); } @@ -66,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 35e84a36aae8..dc34938d27b5 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.HBaseTestingUtility; import org.apache.hadoop.hbase.LocalHBaseCluster; @@ -42,12 +41,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; @@ -57,19 +53,13 @@ * 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/TestRSRpcServices.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRSRpcServices.java index ca7e20f5869d..27880eb4cedf 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,11 +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 da7af7c07015..df51d93d6870 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.HBaseTestingUtility; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.SnapshotDescription; @@ -36,24 +37,21 @@ 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 static final Logger LOG = LoggerFactory.getLogger(TestRSSnapshotVerifier.class); private HBaseTestingUtility TEST_UTIL; private final TableName tableName = TableName.valueOf("TestRSSnapshotVerifier"); @@ -63,7 +61,7 @@ public class TestRSSnapshotVerifier { private SnapshotProtos.SnapshotDescription snapshotProto = ProtobufUtil.createHBaseProtosSnapshotDesc(snapshot); - @Before + @BeforeEach public void setup() throws Exception { TEST_UTIL = new HBaseTestingUtility(); TEST_UTIL.startMiniCluster(3); @@ -97,7 +95,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 +104,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 497be06c15ab..b6add9639a7b 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.HBaseCommonTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.TableName; @@ -34,19 +33,15 @@ 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 HBaseCommonTestingUtility UTIL = new HBaseTestingUtility(); private static final Configuration CONF = UTIL.getConfiguration(); @@ -55,13 +50,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 15209baff9da..60fa4233182a 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MemoryCompactionPolicy; @@ -54,32 +53,26 @@ 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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private static final Logger LOG = LoggerFactory.getLogger(TestRecoveredEdits.class); private static BlockCache blockCache; - @Rule - public TestName testName = new TestName(); + private String methodName; /** * Path to a recovered.edits file in hbase-server test resources folder. This is a little fragile @@ -106,11 +99,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) { + methodName = 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 +127,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(methodName)).setColumnFamily(RECOVEREDEDITS_CFD).build(); RegionInfo hri = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build(); final String encodedRegionName = hri.getEncodedName(); Path hbaseRootDir = TEST_UTIL.getDataTestDir(); @@ -163,9 +160,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 +229,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 e854909504de..505d0a3ca387 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; @@ -44,14 +46,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; @@ -60,11 +59,9 @@ * 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); @@ -72,9 +69,6 @@ public class TestRecoveredEditsReplayAndAbort { protected final static byte[] fam1 = Bytes.toBytes("colfamily11"); - @Rule - public TestName name = new TestName(); - // Test names protected TableName tableName; protected String method; @@ -84,16 +78,16 @@ public class TestRecoveredEditsReplayAndAbort { private static FileSystem FILESYSTEM; private HRegion region = null; - @Before - public void setup() throws IOException { + @BeforeEach + public void setup(TestInfo testInfo) throws IOException { TEST_UTIL = new HBaseTestingUtility(); FILESYSTEM = TEST_UTIL.getTestFileSystem(); 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 +161,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 { HBaseTestingUtility.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 d7411c2a0eb1..0cb404a9681b 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.HBaseTestingUtility; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Table; @@ -38,23 +38,18 @@ 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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private static Table table; private static final TableName TABLE_NAME = TableName.valueOf("table"); @@ -64,7 +59,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 +73,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 +87,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 47a77749fad7..c6fe133849fa 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.client.Durability; @@ -37,13 +36,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; @@ -56,27 +53,24 @@ * 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 HBaseTestingUtility 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 = HBaseTestingUtility.createLocalHTU(); + name = testInfo.getTestMethod().get().getName(); } - @After + @AfterEach public void tearDown() throws Exception { TEST_UTIL.cleanupTestDir(); } @@ -99,7 +93,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 +171,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 +198,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 +208,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 +232,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/TestRegionInterrupt.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionInterrupt.java index 10fa509e265b..8d46f36f598a 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,14 +27,12 @@ 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HTableDescriptor; 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,19 @@ 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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private static final Logger LOG = LoggerFactory.getLogger(TestRegionInterrupt.class); @@ -84,10 +78,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 +92,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 +156,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 HTableDescriptor htd = new HTableDescriptor(tableName); @@ -223,9 +214,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 200386d1c7cd..6a22e4d2e8d2 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.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.MiniHBaseCluster; @@ -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,14 @@ 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 methodName; private static final int NB_SERVERS = 3; @@ -121,7 +115,7 @@ public class TestRegionMergeTransactionOnCluster { private static HMaster MASTER; private static Admin ADMIN; - @BeforeClass + @BeforeAll public static void beforeAllTests() throws Exception { // Start a cluster StartMiniClusterOption option = StartMiniClusterOption.builder().masterClass(MyMaster.class) @@ -133,7 +127,12 @@ public static void beforeAllTests() throws Exception { ADMIN = TEST_UTIL.getConnection().getAdmin(); } - @AfterClass + @BeforeEach + public void setUp(TestInfo testInfo) { + methodName = testInfo.getTestMethod().get().getName(); + } + + @AfterAll public static void afterAllTests() throws Exception { TEST_UTIL.shutdownMiniCluster(); if (ADMIN != null) { @@ -143,8 +142,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 " + methodName); + final TableName tableName = TableName.valueOf(methodName); try { // Create table and load data. @@ -168,13 +167,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 +187,7 @@ public void testWholesomeMerge() throws Exception { */ @Test public void testMergeAndRestartingMaster() throws Exception { - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(methodName); try { // Create table and load data. @@ -211,9 +210,9 @@ public void testMergeAndRestartingMaster() throws Exception { @Test public void testCleanMergeReference() throws Exception { - LOG.info("Starting " + name.getMethodName()); + LOG.info("Starting " + methodName); ADMIN.enableCatalogJanitor(false); - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(methodName); try { // Create table and load data. Table table = createTableAndLoadData(MASTER, tableName); @@ -333,8 +332,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 " + methodName); + final TableName tableName = TableName.valueOf(methodName); final Admin admin = TEST_UTIL.getAdmin(); final int syncWaitTimeout = 10 * 60000; // 10min @@ -364,9 +363,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 { @@ -374,7 +372,7 @@ public void testMerge() throws Exception { 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 { @@ -384,7 +382,7 @@ public void testMerge() throws Exception { @Test public void testMergeWithReplicas() throws Exception { - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(methodName); try { // Create table and load data. Table table = createTableAndLoadData(MASTER, tableName, 5, 2); @@ -486,7 +484,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]; @@ -508,8 +506,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 2196a6fe943e..ac8a68fa624c 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.HBaseTestingUtility; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; @@ -35,31 +34,19 @@ 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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); public static Configuration CONF; protected static final String F1 = "f1"; @@ -68,20 +55,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 +97,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 706864cfb8bf..5b7312568e71 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; @@ -42,38 +41,29 @@ 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); - - @SuppressWarnings("unused") private static final Logger LOG = LoggerFactory.getLogger(TestRegionOpen.class); private static final int NB_SERVERS = 1; private static final HBaseTestingUtility HTU = new HBaseTestingUtility(); - @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(); } @@ -101,8 +91,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 c77a8d2d2402..832cccad10be 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,14 +17,14 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.*; +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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HTableDescriptor; @@ -40,26 +40,20 @@ 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 HBaseTestingUtility HTU = new HBaseTestingUtility(); @@ -74,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 HTableDescriptor 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); @@ -90,13 +81,13 @@ public void before() throws Exception { conf.setBoolean("hbase.tests.use.shortcircuit.reads", false); HTU.startMiniCluster(NB_SERVERS); - htd = HTU - .createTableDescriptor(name.getMethodName().substring(0, name.getMethodName().length() - 3)); + String name = testInfo.getTestMethod().get().getName(); + htd = HTU.createTableDescriptor(TableName.valueOf(name.substring(0, name.length() - 3))); htd.setRegionReplication(3); HTU.getAdmin().createTable(htd); } - @After + @AfterEach public void after() throws Exception { HTU.deleteTableIfAny(htd.getTableName()); HTU.shutdownMiniCluster(); @@ -295,7 +286,7 @@ public void run() { } catch (Throwable e) { ex.compareAndSet(null, e); } - }; + } }; aborter.start(); 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 e90868dfc3f8..3b95de100743 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.HBaseTestingUtility; import org.apache.hadoop.hbase.StartMiniClusterOption; 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,24 @@ 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; - -@Category({ RegionServerTests.class, MediumTests.class }) +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; + +@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 HBaseTestingUtility HTU = new HBaseTestingUtility(); - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { Configuration conf = HTU.getConfiguration(); conf.setBoolean(ServerRegionReplicaUtil.REGION_REPLICA_REPLICATION_CONF_KEY, true); @@ -71,11 +65,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 +84,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 e28e676e28de..d1d141278d9e 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HTableDescriptor; @@ -37,21 +36,17 @@ 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; @@ -64,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); @@ -93,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(); @@ -123,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 99f8eec269c6..0b6c0ed7c7f8 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,64 @@ */ 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.HBaseParameterizedTestTemplate; import org.apache.hadoop.hbase.HBaseTestingUtility; 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.TestInfo; +import org.junit.jupiter.api.TestTemplate; +import org.junit.jupiter.params.provider.Arguments; + +@Tag(RegionServerTests.TAG) +@Tag(MediumTests.TAG) +@HBaseParameterizedTestTemplate(name = "{index}: disableBeforeModifying={0}") public class TestRegionReplicasWithModifyTable { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionReplicasWithModifyTable.class); - private static final int NB_SERVERS = 3; private static final HBaseTestingUtility HTU = new HBaseTestingUtility(); private static final byte[] f = HConstants.CATALOG_FAMILY; - @Parameter - public boolean disableBeforeModifying; + private final boolean disableBeforeModifying; + + private TableName tableName; - @Rule - public TableNameTestRule name = new TableNameTestRule(); + public static Stream parameters() { + return Stream.of(Arguments.of(true), Arguments.of(false)); + } - @Parameters - public static List params() { - return Arrays.asList(new Object[] { true }, new Object[] { false }); + public TestRegionReplicasWithModifyTable(boolean disableBeforeModifying) { + this.disableBeforeModifying = disableBeforeModifying; } - @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,50 +110,49 @@ 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); } - @Test + @TestTemplate public void testRegionReplicasUsingEnableTable() throws Exception { enableReplicationByModification(false, 0, 3, 0); } - @Test + @TestTemplate public void testRegionReplicasUsingEnableTableForMultipleRegions() throws Exception { enableReplicationByModification(false, 0, 3, 10); } - @Test + @TestTemplate public void testRegionReplicasByEnableTableWhenReplicaCountIsIncreased() throws Exception { enableReplicationByModification(true, 2, 3, 0); } - @Test + @TestTemplate public void testRegionReplicasByEnableTableWhenReplicaCountIsDecreased() throws Exception { enableReplicationByModification(true, 3, 2, 0); } - @Test + @TestTemplate public void testRegionReplicasByEnableTableWhenReplicaCountIsDecreasedWithMultipleRegions() throws Exception { enableReplicationByModification(true, 3, 2, 20); } - @Test + @TestTemplate public void testRegionReplicasByEnableTableWhenReplicaCountIsIncreasedWithMultipleRegions() throws Exception { enableReplicationByModification(true, 2, 3, 15); 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 524c02e35307..97f8ebdc52fa 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.HBaseTestingUtility; 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 HBaseTestingUtility HTU = new HBaseTestingUtility(); 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 60fbd27f76fb..4100536ec0c1 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MiniHBaseCluster; @@ -64,24 +63,20 @@ 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); @@ -91,7 +86,7 @@ public class TestRegionServerAbort { private MiniDFSCluster dfsCluster; private MiniHBaseCluster cluster; - @Before + @BeforeEach public void setup() throws Exception { testUtil = new HBaseTestingUtility(); conf = testUtil.getConfiguration(); @@ -111,7 +106,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 f0a513bddcce..d0757626d3ac 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.HBaseTestingUtility; import org.apache.hadoop.hbase.StartMiniClusterOption; import org.apache.hadoop.hbase.TableName; @@ -42,21 +41,17 @@ 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); @@ -73,7 +68,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 @@ -87,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(); } @@ -115,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..7d9772ee5ef6 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,24 @@ */ 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 b2add22b1a03..9bc68502d0b4 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.HBaseTestingUtility; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Get; @@ -33,22 +32,18 @@ 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); private static TableName TABLE_NAME = TableName.valueOf("test"); @@ -57,7 +52,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 +69,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 3e4269a6d27a..044c8185ba07 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,11 @@ */ 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.junit.jupiter.api.Assertions.fail; import java.net.InetAddress; import java.net.NetworkInterface; @@ -29,7 +30,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.HBaseTestingUtility; import org.apache.hadoop.hbase.StartMiniClusterOption; @@ -39,24 +39,20 @@ 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 HBaseTestingUtility TEST_UTIL; @@ -64,13 +60,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 HBaseTestingUtility(conf); } - @After + @AfterEach public void teardown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -83,10 +79,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 @@ -117,8 +113,8 @@ public void testRegionServerHostname() throws Exception { assertTrue(servers.size() == NUM_RS + (LoadBalancer.isTablesOnMaster(TEST_UTIL.getConfiguration()) ? 1 : 0)); 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 { @@ -182,14 +178,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); + fail("Failed to validate against conflict hostname configurations"); } } } 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 5f75391f0e2b..c051c0f2cca6 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,10 +17,10 @@ */ 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.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; @@ -28,7 +28,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.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; @@ -65,31 +64,23 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; 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 MiniHBaseCluster cluster; private static HRegionServer rs; @@ -107,7 +98,7 @@ public class TestRegionServerMetrics { private static Admin admin; private static boolean TABLES_ON_MASTER; - @BeforeClass + @BeforeAll public static void startCluster() throws Exception { metricsHelper = CompatibilityFactory.getInstance(MetricsAssertHelper.class); TEST_UTIL = new HBaseTestingUtility(); @@ -139,7 +130,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(); @@ -149,14 +140,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); @@ -571,7 +562,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 }; @@ -641,14 +632,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 @@ -657,14 +648,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 0a3cf332d15d..348ccab89343 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,8 +17,13 @@ */ package org.apache.hadoop.hbase.regionserver; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; @@ -38,12 +43,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; @@ -55,13 +58,10 @@ /** * 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; @@ -72,7 +72,7 @@ public class TestRegionServerNoMaster { private static byte[] regionName; private static final HBaseTestingUtility HTU = new HBaseTestingUtility(); - @BeforeClass + @BeforeAll public static void before() throws Exception { HTU.startMiniCluster(NB_SERVERS); final TableName tableName = TableName.valueOf(TestRegionServerNoMaster.class.getSimpleName()); @@ -131,7 +131,7 @@ public static void flushRegion(HBaseTestingUtility HTU, RegionInfo regionInfo) 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 +150,8 @@ public static void openRegion(HBaseTestingUtility HTU, HRegionServer rs, HRegion RequestConverter.buildOpenRegionRequest(rs.getServerName(), hri, null); AdminProtos.OpenRegionResponse responseOpen = rs.rpcServices.openRegion(null, orr); - Assert.assertTrue(responseOpen.getOpeningStateCount() == 1); - Assert.assertTrue(responseOpen.getOpeningState(0) + assertEquals(1, responseOpen.getOpeningStateCount()); + assertTrue(responseOpen.getOpeningState(0) .equals(AdminProtos.OpenRegionResponse.RegionOpeningState.OPENED)); checkRegionIsOpened(HTU, rs, hri); @@ -163,7 +163,7 @@ public static void checkRegionIsOpened(HBaseTestingUtility HTU, HRegionServer rs Thread.sleep(1); } - Assert.assertTrue(rs.getRegion(hri.getRegionName()).isAvailable()); + assertTrue(rs.getRegion(hri.getRegionName()).isAvailable()); } public static void closeRegion(HBaseTestingUtility HTU, HRegionServer rs, HRegionInfo hri) @@ -171,7 +171,7 @@ public static void closeRegion(HBaseTestingUtility HTU, HRegionServer rs, HRegio AdminProtos.CloseRegionRequest crr = ProtobufUtil.buildCloseRegionRequest(rs.getServerName(), hri.getRegionName()); AdminProtos.CloseRegionResponse responseClose = rs.rpcServices.closeRegion(null, crr); - Assert.assertTrue(responseClose.getClosed()); + assertTrue(responseClose.getClosed()); checkRegionIsClosed(HTU, rs, hri); } @@ -182,7 +182,7 @@ public static void checkRegionIsClosed(HBaseTestingUtility HTU, HRegionServer rs } 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 +196,7 @@ private void closeRegionNoZK() throws Exception { AdminProtos.CloseRegionRequest crr = ProtobufUtil.buildCloseRegionRequest(getRS().getServerName(), regionName); AdminProtos.CloseRegionResponse responseClose = getRS().rpcServices.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); @@ -215,10 +215,10 @@ public void testMultipleCloseFromMaster() throws Exception { ProtobufUtil.buildCloseRegionRequest(getRS().getServerName(), regionName, null); try { AdminProtos.CloseRegionResponse responseClose = getRS().rpcServices.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."); } } @@ -242,14 +242,12 @@ public void testCancelOpeningWithoutZK() throws Exception { // That's a close without ZK. AdminProtos.CloseRegionRequest crr = ProtobufUtil.buildCloseRegionRequest(getRS().getServerName(), regionName); - try { + assertThrows(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException.class, () -> { getRS().rpcServices.closeRegion(null, crr); - Assert.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 @@ -269,7 +267,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); @@ -278,10 +276,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")); } @@ -291,10 +289,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); @@ -304,6 +302,6 @@ public void testOpenCloseRegionRPCIntendedForPreviousServer() throws Exception { @Test public void testInstallShutdownHook() { // Test for HBASE-26977 - Assert.assertTrue(HTU.getMiniHBaseCluster().getRegionServer(0).isShutdownHookInstalled()); + assertTrue(HTU.getMiniHBaseCluster().getRegionServer(0).isShutdownHookInstalled()); } } 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 de6f926f71a1..d15b38627f28 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,14 +17,13 @@ */ 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.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 java.io.IOException; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; @@ -38,11 +37,10 @@ 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.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,13 +49,9 @@ * 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 HBaseTestingUtility hbaseTestingUtility = new HBaseTestingUtility(); @@ -75,8 +69,8 @@ public class TestRegionServerOnlineConfigChange { private final static byte[] COLUMN_FAMILY1 = Bytes.toBytes(columnFamily1Str); private final static long MAX_FILE_SIZE = 20 * 1024 * 1024L; - @BeforeClass - public static void setUp() throws Exception { + @BeforeAll + public static void setUpBeforeClass() throws Exception { conf = hbaseTestingUtility.getConfiguration(); hbaseTestingUtility.startMiniCluster(); t1 = hbaseTestingUtility.createTable( @@ -92,7 +86,7 @@ public static void setUp() throws Exception { } } - @AfterClass + @AfterAll public static void tearDown() throws Exception { hbaseTestingUtility.shutdownMiniCluster(); } 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 a090f3308852..a0fd939d2890 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; @@ -30,7 +30,6 @@ import java.util.Optional; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.ClusterMetrics.Option; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.RegionLoad; import org.apache.hadoop.hbase.ServerLoad; @@ -61,23 +60,18 @@ import org.apache.hadoop.hbase.master.LoadBalancer; 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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); @@ -107,7 +101,7 @@ public class TestRegionServerReadRequestMetrics { private static Map requestsMap = new HashMap<>(); private static Map requestsMapPrev = new HashMap<>(); - @BeforeClass + @BeforeAll public static void setUpOnce() throws Exception { // Default starts one regionserver only. TEST_UTIL.getConfiguration().setBoolean(LoadBalancer.TABLES_ON_MASTER, true); @@ -119,7 +113,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()) { @@ -256,7 +250,7 @@ private static void putTTLExpiredData() throws IOException, InterruptedException table.put(put); } - @AfterClass + @AfterAll public static void tearDownOnce() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -329,7 +323,7 @@ public void testReadRequestsCountNotFiltered() throws Exception { testReadRequests(resultCount, 1, 0); } - @Ignore // HBASE-19785 + @Disabled // HBASE-19785 @Test public void testReadRequestsCountWithFilter() throws Exception { int resultCount; @@ -376,7 +370,7 @@ public void testReadRequestsCountWithFilter() throws Exception { // testReadRequests(resultCount, 0, 1); } - @Ignore // HBASE-19785 + @Disabled // HBASE-19785 @Test public void testReadRequestsCountWithDeletedRow() throws Exception { try { @@ -414,7 +408,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"); @@ -426,7 +420,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..b8451c360e17 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,9 @@ * 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 +72,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 c7f910431e80..c0254064f3c3 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionLocation; @@ -53,21 +52,17 @@ 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 +78,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"); @@ -113,7 +108,7 @@ public boolean offer(CallRunner callRunner) { } } - @AfterClass + @AfterAll public static void tearDown() throws Exception { UTIL.shutdownMiniCluster(); } @@ -142,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 c088aa83dde2..a1088eb85908 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.LocalHBaseCluster; @@ -50,23 +51,18 @@ 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; @@ -78,7 +74,7 @@ public class TestRegionServerReportForDuty { private MasterThread master; private MasterThread backupMaster; - @Before + @BeforeEach public void setUp() throws Exception { testUtil = new HBaseTestingUtility(); testUtil.startMiniDFSCluster(1); @@ -87,7 +83,7 @@ public void setUp() throws Exception { cluster = new LocalHBaseCluster(testUtil.getConfiguration(), 0, 0); } - @After + @AfterEach public void tearDown() throws Exception { cluster.shutdown(); cluster.join(); @@ -159,10 +155,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 0c0ac56d625c..d85bb9e34bc8 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MiniHBaseCluster.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,14 +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"); @@ -78,7 +69,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 +95,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 6c390fee9a5a..b321ea1a4109 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; @@ -29,19 +28,16 @@ import org.apache.hadoop.hbase.StartMiniClusterOption; 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); @@ -51,7 +47,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 +57,7 @@ public void setup() throws Exception { CLUSTER = TEST_UTIL.startMiniCluster(option); } - @After + @AfterEach public void teardown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionSplitPolicy.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionSplitPolicy.java index ba481c89ff33..c0c211b606ef 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,20 @@ 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(); @@ -281,9 +276,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..2730ccbae514 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,32 @@ */ 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 85c831901b88..24abbe4080f7 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; @@ -36,29 +35,21 @@ 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 { +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRemoveRegionMetrics.class); +@Tag(RegionServerTests.TAG) +@Tag(LargeTests.TAG) +public class TestRemoveRegionMetrics { private static MiniHBaseCluster cluster; private static Configuration conf; private static HBaseTestingUtility 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 HBaseTestingUtility(); @@ -79,8 +70,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/TestRequestsPerSecondMetric.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRequestsPerSecondMetric.java index f68b58b5e487..1e3a92d86461 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -28,35 +29,30 @@ 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 HBaseTestingUtility UTIL = new HBaseTestingUtility(); 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 +86,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 e66f9e679738..3d565a92a9b2 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; @@ -39,29 +38,21 @@ 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 { HBaseTestingUtility htu = new HBaseTestingUtility(); 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 df32897876c0..c5be39a10e1b 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; @@ -31,7 +31,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.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; @@ -58,12 +57,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; @@ -72,13 +69,10 @@ /** * 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); HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); @@ -95,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); @@ -313,10 +304,11 @@ public void testReversibleStoreScanner() throws IOException { } @Test - public void testReversibleRegionScanner() throws IOException { + public void testReversibleRegionScanner(TestInfo testInfo) throws IOException { byte[] FAMILYNAME2 = Bytes.toBytes("testCf2"); - HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName())) - .addFamily(new HColumnDescriptor(FAMILYNAME)).addFamily(new HColumnDescriptor(FAMILYNAME2)); + HTableDescriptor htd = + new HTableDescriptor(TableName.valueOf(testInfo.getTestMethod().get().getName())) + .addFamily(new HColumnDescriptor(FAMILYNAME)).addFamily(new HColumnDescriptor(FAMILYNAME2)); HRegion region = TEST_UTIL.createLocalHRegion(htd, null, null); loadDataToRegion(region, FAMILYNAME2); @@ -437,8 +429,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 b77fae0677d5..497a13609cea 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.HBaseTestingUtility; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; @@ -47,26 +46,20 @@ 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 HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private CacheConfig cacheConf = new CacheConfig(TEST_UTIL.getConfiguration()); @@ -87,10 +80,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 +107,7 @@ public void setUp() throws Exception { } } - @After + @AfterEach public void tearDown() throws Exception { try { if (localfs) { @@ -241,10 +231,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 ade5a5be55b3..b324afd2ac29 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.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; @@ -32,36 +33,32 @@ 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 HBaseTestingUtility HTU = HBaseTestingUtility.createLocalHTU(); private static Path rootRegionDir; private static final HTableDescriptor TEST_HTD = new HTableDescriptor(TableName.valueOf(TestRowTooBig.class.getSimpleName())); - @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(); } @@ -72,7 +69,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"); @@ -101,7 +98,7 @@ public void testScannersSeekOnFewLargeCells() throws IOException { } Get get = new Get(row1); - region.get(get); + assertThrows(RowTooBigException.class, () -> region.get(get)); } finally { HBaseTestingUtility.closeRegionAndWAL(region); } @@ -111,7 +108,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"); @@ -142,7 +139,7 @@ public void testScanAcrossManySmallColumns() throws IOException { region.compact(true); Get get = new Get(row1); - region.get(get); + assertThrows(RowTooBigException.class, () -> region.get(get)); } finally { HBaseTestingUtility.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..0cef202502f6 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,20 @@ 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(); }