You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by li...@apache.org on 2026/06/01 05:57:48 UTC
(hbase) branch branch-2.6 updated: HBASE-30136 Upgrade hbase-server to use junit5 Part15 (#8291)
This is an automated email from the ASF dual-hosted git repository.
liuxiaocs7 pushed a commit to branch branch-2.6
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.6 by this push:
new 11bc55a4417 HBASE-30136 Upgrade hbase-server to use junit5 Part15 (#8291)
11bc55a4417 is described below
commit 11bc55a44177cfe8780681406d7301fe802e484a
Author: Xiao Liu <li...@apache.org>
AuthorDate: Mon Jun 1 13:57:42 2026 +0800
HBASE-30136 Upgrade hbase-server to use junit5 Part15 (#8291)
Signed-off-by: Duo Zhang <zh...@apache.org>
(cherry picked from commit c3ff57d70dc88e5eabbbe70a624da49b481f2941)
(cherry picked from commit 5d5c0f1054b59a001d0aa0a753bc555e5601a6d5)
---
.../hbase/regionserver/TestAtomicOperation.java | 78 ++++---
.../hadoop/hbase/regionserver/TestBlocksRead.java | 59 +++--
.../hbase/regionserver/TestBlocksScanned.java | 19 +-
.../hbase/regionserver/TestBloomFilterFaulty.java | 45 ++--
.../regionserver/TestBootstrapNodeManager.java | 23 +-
.../regionserver/TestBrokenStoreFileCleaner.java | 27 +--
.../hadoop/hbase/regionserver/TestBulkLoad.java | 70 +++---
.../hbase/regionserver/TestBulkloadBase.java | 51 ++---
.../TestBytesReadServerSideScanMetrics.java | 239 ++++++++++-----------
.../regionserver/TestCacheOnWriteInSchema.java | 66 +++---
.../hadoop/hbase/regionserver/TestCellFlatSet.java | 53 +++--
.../hbase/regionserver/TestCellSkipListSet.java | 41 ++--
.../TestCleanupCompactedFileAfterFailover.java | 38 ++--
.../TestCleanupCompactedFileOnRegionClose.java | 32 ++-
.../hbase/regionserver/TestCleanupMetaWAL.java | 25 +--
.../regionserver/TestClearRegionBlockCache.java | 51 +++--
.../hadoop/hbase/regionserver/TestClusterId.java | 25 +--
.../hbase/regionserver/TestColumnSeeking.java | 32 +--
.../hbase/regionserver/TestCompactSplitThread.java | 43 ++--
.../hbase/regionserver/TestCompactingMemStore.java | 89 ++++----
.../TestCompactingToCellFlatMapMemStore.java | 59 ++---
.../hadoop/hbase/regionserver/TestCompaction.java | 70 +++---
.../regionserver/TestCompactionAfterBulkLoad.java | 26 ++-
.../TestCompactionArchiveConcurrentClose.java | 36 ++--
.../TestCompactionArchiveIOException.java | 40 ++--
.../regionserver/TestCompactionFileNotFound.java | 43 +---
.../TestCompactionInDeadRegionServer.java | 50 ++---
.../TestCompactionLifeCycleTracker.java | 39 ++--
.../hbase/regionserver/TestCompactionPolicy.java | 17 +-
.../hbase/regionserver/TestCompactionState.java | 54 +++--
.../regionserver/TestCompactionWithByteBuff.java | 23 +-
.../TestCompactionWithCoprocessor.java | 11 +-
.../TestCompactionWithShippingCoprocessor.java | 36 ++--
.../hbase/regionserver/TestCompactorMemLeak.java | 48 ++---
.../regionserver/TestCompoundBloomFilter.java | 31 ++-
.../TestCustomCellDataTieringManager.java | 38 ++--
.../TestCustomCellTieredCompactionPolicy.java | 19 +-
.../regionserver/TestDataBlockEncodingTool.java | 16 +-
.../hbase/regionserver/TestDataTieringManager.java | 56 +++--
.../TestDateTieredCompactionPolicy.java | 13 +-
...TieredCompactionPolicyHeterogeneousStorage.java | 12 +-
.../TestDateTieredCompactionPolicyOverflow.java | 13 +-
.../regionserver/TestDefaultCompactSelection.java | 17 +-
.../hbase/regionserver/TestDefaultMemStore.java | 158 +++++++-------
.../hbase/regionserver/TestDefaultStoreEngine.java | 24 +--
.../hbase/regionserver/TestDeleteMobTable.java | 100 ++++-----
.../regionserver/TestDirectStoreSplitsMerges.java | 46 ++--
.../hbase/regionserver/TestEncryptionDisabled.java | 36 ++--
.../regionserver/TestEncryptionKeyRotation.java | 64 +++---
.../regionserver/TestEncryptionRandomKeying.java | 29 ++-
.../regionserver/TestEndToEndSplitTransaction.java | 65 +++---
.../hbase/regionserver/TestFSErrorsExposed.java | 36 ++--
.../regionserver/TestFailedAppendAndSync.java | 43 ++--
.../regionserver/TestFlushLifeCycleTracker.java | 39 ++--
.../hbase/regionserver/TestFlushRegionEntry.java | 37 ++--
.../regionserver/TestGetClosestAtOrBefore.java | 35 ++-
56 files changed, 1169 insertions(+), 1416 deletions(-)
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestAtomicOperation.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestAtomicOperation.java
index 7d3bd65ab5a..9edeee47c2f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestAtomicOperation.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestAtomicOperation.java
@@ -19,10 +19,10 @@ package org.apache.hadoop.hbase.regionserver;
import static org.apache.hadoop.hbase.HBaseTestingUtility.fam1;
import static org.apache.hadoop.hbase.HBaseTestingUtility.fam2;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.util.ArrayList;
@@ -38,7 +38,6 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.CompareOperator;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
@@ -69,29 +68,23 @@ import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.VerySlowRegionServerTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.wal.WAL;
-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;
/**
* Testing of HRegion.incrementColumnValue, HRegion.increment, and HRegion.append
*/
-@Category({ VerySlowRegionServerTests.class, LargeTests.class }) // Starts 100 threads
+@Tag(VerySlowRegionServerTests.TAG)
+@Tag(LargeTests.TAG) // Starts 100 threads
public class TestAtomicOperation {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestAtomicOperation.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestAtomicOperation.class);
- @Rule
- public TestName name = new TestName();
+ private String name;
HRegion region = null;
private HBaseTestingUtility TEST_UTIL = HBaseTestingUtility.createLocalHTU();
@@ -106,12 +99,13 @@ public class TestAtomicOperation {
static final byte[] row = Bytes.toBytes("rowA");
static final byte[] row2 = Bytes.toBytes("rowB");
- @Before
- public void setup() {
- tableName = Bytes.toBytes(name.getMethodName());
+ @BeforeEach
+ public void setup(TestInfo testInfo) {
+ this.name = testInfo.getTestMethod().get().getName();
+ tableName = Bytes.toBytes(name);
}
- @After
+ @AfterEach
public void teardown() throws IOException {
if (region != null) {
CacheConfig cacheConfig = region.getStores().get(0).getCacheConfig();
@@ -132,11 +126,11 @@ public class TestAtomicOperation {
/**
* Test basic append operation. More tests in
- * @see org.apache.hadoop.hbase.client.TestFromClientSide#testAppend()
+ * {@link org.apache.hadoop.hbase.client.FromClientSideTest5#testAppend()}.
*/
@Test
public void testAppend() throws IOException {
- initHRegion(tableName, name.getMethodName(), fam1);
+ initHRegion(tableName, name, fam1);
String v1 =
"Ultimate Answer to the Ultimate Question of Life," + " The Universe, and Everything";
String v2 = " is... 42.";
@@ -156,7 +150,7 @@ public class TestAtomicOperation {
@Test
public void testAppendWithMultipleFamilies() throws IOException {
final byte[] fam3 = Bytes.toBytes("colfamily31");
- initHRegion(tableName, name.getMethodName(), fam1, fam2, fam3);
+ initHRegion(tableName, name, fam1, fam2, fam3);
String v1 = "Appended";
String v2 = "Value";
@@ -165,8 +159,8 @@ public class TestAtomicOperation {
a.addColumn(fam1, qual1, Bytes.toBytes(v1));
a.addColumn(fam2, qual2, Bytes.toBytes(v2));
Result result = region.append(a, HConstants.NO_NONCE, HConstants.NO_NONCE);
- assertTrue("Expected an empty result but result contains " + result.size() + " keys",
- result.isEmpty());
+ assertTrue(result.isEmpty(),
+ "Expected an empty result but result contains " + result.size() + " keys");
a = new Append(row);
a.addColumn(fam2, qual2, Bytes.toBytes(v1));
@@ -181,10 +175,10 @@ public class TestAtomicOperation {
byte[] actualValue3 = result.getValue(fam3, qual3);
byte[] actualValue4 = result.getValue(fam1, qual2);
- assertNotNull("Value1 should bot be null", actualValue1);
- assertNotNull("Value2 should bot be null", actualValue2);
- assertNotNull("Value3 should bot be null", actualValue3);
- assertNotNull("Value4 should bot be null", actualValue4);
+ assertNotNull(actualValue1, "Value1 should bot be null");
+ assertNotNull(actualValue2, "Value2 should bot be null");
+ assertNotNull(actualValue3, "Value3 should bot be null");
+ assertNotNull(actualValue4, "Value4 should bot be null");
assertEquals(0, Bytes.compareTo(Bytes.toBytes(v1 + v2), actualValue1));
assertEquals(0, Bytes.compareTo(Bytes.toBytes(v2 + v1), actualValue2));
assertEquals(0, Bytes.compareTo(Bytes.toBytes(v2), actualValue3));
@@ -193,7 +187,7 @@ public class TestAtomicOperation {
@Test
public void testAppendWithNonExistingFamily() throws IOException {
- initHRegion(tableName, name.getMethodName(), fam1);
+ initHRegion(tableName, name, fam1);
final String v1 = "Value";
final Append a = new Append(row);
a.addColumn(fam1, qual1, Bytes.toBytes(v1));
@@ -211,7 +205,7 @@ public class TestAtomicOperation {
@Test
public void testIncrementWithNonExistingFamily() throws IOException {
- initHRegion(tableName, name.getMethodName(), fam1);
+ initHRegion(tableName, name, fam1);
final Increment inc = new Increment(row);
inc.addColumn(fam1, qual1, 1);
inc.addColumn(fam2, qual2, 1);
@@ -236,7 +230,7 @@ public class TestAtomicOperation {
boolean fast = true;
LOG.info("Starting test testIncrementMultiThreads");
// run a with mixed column families (1 and 3 versions)
- initHRegion(tableName, name.getMethodName(), new int[] { 1, 3 }, fam1, fam2);
+ initHRegion(tableName, name, new int[] { 1, 3 }, fam1, fam2);
// Create 100 threads, each will increment by its own quantity. All 100 threads update the
// same row over two column families.
@@ -339,8 +333,8 @@ public class TestAtomicOperation {
Bytes.toLong(result.getValue(fam1, qual2)));
long fam1Increment = Bytes.toLong(result.getValue(fam1, qual1)) * 3;
long fam2Increment = Bytes.toLong(result.getValue(fam2, qual3));
- assertEquals("fam1=" + fam1Increment + ", fam2=" + fam2Increment, fam1Increment,
- fam2Increment);
+ assertEquals(fam1Increment, fam2Increment,
+ "fam1=" + fam1Increment + ", fam2=" + fam2Increment);
}
} catch (IOException e) {
e.printStackTrace();
@@ -353,7 +347,7 @@ public class TestAtomicOperation {
public void testAppendMultiThreads() throws IOException {
LOG.info("Starting test testAppendMultiThreads");
// run a with mixed column families (1 and 3 versions)
- initHRegion(tableName, name.getMethodName(), new int[] { 1, 3 }, fam1, fam2);
+ initHRegion(tableName, name, new int[] { 1, 3 }, fam1, fam2);
int numThreads = 100;
int opsPerThread = 100;
@@ -417,7 +411,7 @@ public class TestAtomicOperation {
@Test
public void testRowMutationMultiThreads() throws IOException {
LOG.info("Starting test testRowMutationMultiThreads");
- initHRegion(tableName, name.getMethodName(), fam1);
+ initHRegion(tableName, name, fam1);
// create 10 threads, each will alternate between adding and
// removing a column
@@ -508,7 +502,7 @@ public class TestAtomicOperation {
public void testMultiRowMutationMultiThreads() throws IOException {
LOG.info("Starting test testMultiRowMutationMultiThreads");
- initHRegion(tableName, name.getMethodName(), fam1);
+ initHRegion(tableName, name, fam1);
// create 10 threads, each will alternate between adding and
// removing a column
@@ -634,8 +628,8 @@ public class TestAtomicOperation {
public void testPutAndCheckAndPutInParallel() throws Exception {
Configuration conf = TEST_UTIL.getConfiguration();
conf.setClass(HConstants.REGION_IMPL, MockHRegion.class, HeapSize.class);
- HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName()))
- .addFamily(new HColumnDescriptor(family));
+ HTableDescriptor htd =
+ new HTableDescriptor(TableName.valueOf(name)).addFamily(new HColumnDescriptor(family));
this.region = TEST_UTIL.createLocalHRegion(htd, null, null);
Put[] puts = new Put[1];
Put put = new Put(Bytes.toBytes("r1"));
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBlocksRead.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBlocksRead.java
index 5e92d02d67e..a189b3ac794 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBlocksRead.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBlocksRead.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.regionserver;
-import static junit.framework.TestCase.assertTrue;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
@@ -28,7 +28,6 @@ import org.apache.hadoop.conf.Configuration;
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.TableName;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
@@ -47,26 +46,26 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManagerTestHelper;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
public class TestBlocksRead {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBlocksRead.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestBlocksRead.class);
- @Rule
- public TestName testName = new TestName();
+ private String testName;
+
+ @BeforeEach
+ public void setTestName(TestInfo testInfo) {
+ this.testName = testInfo.getTestMethod().get().getName();
+ }
static final BloomType[] BLOOM_TYPE =
new BloomType[] { BloomType.ROWCOL, BloomType.ROW, BloomType.NONE };
@@ -76,13 +75,13 @@ public class TestBlocksRead {
private final String DIR = TEST_UTIL.getDataTestDir("TestBlocksRead").toString();
private Configuration conf = TEST_UTIL.getConfiguration();
- @BeforeClass
+ @BeforeAll
public static void setUp() throws Exception {
// disable compactions in this test.
TEST_UTIL.getConfiguration().setInt("hbase.hstore.compactionThreshold", 10000);
}
- @AfterClass
+ @AfterAll
public static void tearDown() throws Exception {
EnvironmentEdgeManagerTestHelper.reset();
}
@@ -164,8 +163,8 @@ public class TestBlocksRead {
kvs = region.get(get).rawCells();
long blocksEnd = getBlkAccessCount(cf);
if (expBlocks[i] != -1) {
- assertEquals("Blocks Read Check for Bloom: " + bloomType, expBlocks[i],
- blocksEnd - blocksStart);
+ assertEquals(expBlocks[i], blocksEnd - blocksStart,
+ "Blocks Read Check for Bloom: " + bloomType);
}
System.out.println("Blocks Read for Bloom: " + bloomType + " = " + (blocksEnd - blocksStart)
+ "Expected = " + expBlocks[i]);
@@ -194,11 +193,11 @@ public class TestBlocksRead {
private static void verifyData(Cell kv, String expectedRow, String expectedCol,
long expectedVersion) {
- assertTrue("RowCheck", CellUtil.matchingRows(kv, Bytes.toBytes(expectedRow)));
- assertTrue("ColumnCheck", CellUtil.matchingQualifier(kv, Bytes.toBytes(expectedCol)));
- assertEquals("TSCheck", expectedVersion, kv.getTimestamp());
- assertTrue("ValueCheck",
- CellUtil.matchingValue(kv, genValue(expectedRow, expectedCol, expectedVersion)));
+ assertTrue(CellUtil.matchingRows(kv, Bytes.toBytes(expectedRow)), "RowCheck");
+ assertTrue(CellUtil.matchingQualifier(kv, Bytes.toBytes(expectedCol)), "ColumnCheck");
+ assertEquals(expectedVersion, kv.getTimestamp(), "TSCheck");
+ assertTrue(CellUtil.matchingValue(kv, genValue(expectedRow, expectedCol, expectedVersion)),
+ "ValueCheck");
}
private static long getBlkAccessCount(byte[] cf) {
@@ -213,7 +212,7 @@ public class TestBlocksRead {
byte[] TABLE = Bytes.toBytes("testBlocksRead");
String FAMILY = "cf1";
Cell[] kvs;
- this.region = initHRegion(TABLE, testName.getMethodName(), conf, FAMILY);
+ this.region = initHRegion(TABLE, testName, conf, FAMILY);
try {
putData(FAMILY, "row", "col1", 1);
@@ -267,7 +266,7 @@ public class TestBlocksRead {
byte[] TABLE = Bytes.toBytes("testLazySeekBlocksRead");
String FAMILY = "cf1";
Cell[] kvs;
- this.region = initHRegion(TABLE, testName.getMethodName(), conf, FAMILY);
+ this.region = initHRegion(TABLE, testName, conf, FAMILY);
try {
// File 1
@@ -373,7 +372,7 @@ public class TestBlocksRead {
String FAMILY = "cf1";
BlockCache blockCache = BlockCacheFactory.createBlockCache(conf);
- this.region = initHRegion(TABLE, testName.getMethodName(), conf, FAMILY, blockCache);
+ this.region = initHRegion(TABLE, testName, conf, FAMILY, blockCache);
try {
putData(FAMILY, "row", "col1", 1);
@@ -417,7 +416,7 @@ public class TestBlocksRead {
byte[] TABLE = Bytes.toBytes("testLazySeekBlocksReadWithDelete");
String FAMILY = "cf1";
Cell[] kvs;
- this.region = initHRegion(TABLE, testName.getMethodName(), conf, FAMILY);
+ this.region = initHRegion(TABLE, testName, conf, FAMILY);
try {
deleteFamily(FAMILY, "row", 200);
for (int i = 0; i < 100; i++) {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBlocksScanned.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBlocksScanned.java
index c749c566bde..17a5e60df78 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBlocksScanned.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBlocksScanned.java
@@ -18,14 +18,13 @@
package org.apache.hadoop.hbase.regionserver;
import static org.apache.hadoop.hbase.HTestConst.addContent;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.conf.Configuration;
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.HTableDescriptor;
@@ -43,19 +42,15 @@ import org.apache.hadoop.hbase.io.hfile.CacheStats;
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;
@SuppressWarnings("deprecation")
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
public class TestBlocksScanned {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBlocksScanned.class);
-
private static byte[] FAMILY = Bytes.toBytes("family");
private static byte[] COL = Bytes.toBytes("col");
private static byte[] START_KEY = Bytes.toBytes("aaa");
@@ -66,7 +61,7 @@ public class TestBlocksScanned {
private Configuration conf;
private Path testDir;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
TEST_UTIL = new HBaseTestingUtility();
conf = TEST_UTIL.getConfiguration();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBloomFilterFaulty.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBloomFilterFaulty.java
index 8af41f5a55b..18a7a5e8712 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBloomFilterFaulty.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBloomFilterFaulty.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.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 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.ColumnFamilyDescriptorBuilder;
@@ -45,27 +44,22 @@ 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.EnvironmentEdgeManager;
-import org.junit.After;
-import org.junit.AfterClass;
-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.AfterAll;
+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;
/**
* A UT to make sure that everything is fine when we fail to load bloom filter.
* <p>
* See HBASE-27936 for more details.
*/
-@Category({ RegionServerTests.class, MediumTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(MediumTests.TAG)
public class TestBloomFilterFaulty {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBloomFilterFaulty.class);
-
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
private static final byte[] FAMILY = Bytes.toBytes("family");
@@ -81,15 +75,13 @@ public class TestBloomFilterFaulty {
private static final RegionInfo RI = RegionInfoBuilder.newBuilder(TD.getTableName()).build();
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
UTIL.cleanupTestDir();
}
private HRegion region;
-
- @Rule
- public final TestName name = new TestName();
+ private String name;
private void generateHFiles() throws IOException {
for (int i = 0; i < 4; i++) {
@@ -115,9 +107,10 @@ public class TestBloomFilterFaulty {
}
}
- @Before
- public void setUp() throws IOException {
- Path rootDir = UTIL.getDataTestDir(name.getMethodName());
+ @BeforeEach
+ public void setUp(TestInfo testInfo) throws IOException {
+ this.name = testInfo.getTestMethod().get().getName();
+ Path rootDir = UTIL.getDataTestDir(name);
// generate some hfiles so we can have StoreFileReader which has bloomfilters
region = HBaseTestingUtility.createRegionAndWAL(RI, rootDir, UTIL.getConfiguration(), TD);
generateHFiles();
@@ -131,7 +124,7 @@ public class TestBloomFilterFaulty {
}
}
- @After
+ @AfterEach
public void tearDown() throws IOException {
if (region != null) {
HBaseTestingUtility.closeRegionAndWAL(region);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBootstrapNodeManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBootstrapNodeManager.java
index efd28b9c87c..657d99ae32a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBootstrapNodeManager.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBootstrapNodeManager.java
@@ -19,7 +19,7 @@ package org.apache.hadoop.hbase.regionserver;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.atLeast;
@@ -35,7 +35,6 @@ import java.io.IOException;
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.HBaseConfiguration;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.Waiter;
@@ -44,19 +43,15 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.zookeeper.MasterAddressTracker;
-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;
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
public class TestBootstrapNodeManager {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBootstrapNodeManager.class);
-
private Configuration conf;
private ClusterConnection conn;
@@ -65,7 +60,7 @@ public class TestBootstrapNodeManager {
private BootstrapNodeManager manager;
- @Before
+ @BeforeEach
public void setUp() {
conf = HBaseConfiguration.create();
conf.setLong(BootstrapNodeManager.REQUEST_MASTER_INTERVAL_SECS, 5);
@@ -77,7 +72,7 @@ public class TestBootstrapNodeManager {
tracker = mock(MasterAddressTracker.class);
}
- @After
+ @AfterEach
public void tearDown() {
if (manager != null) {
manager.stop();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBrokenStoreFileCleaner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBrokenStoreFileCleaner.java
index 11a1276e497..d450bc24de8 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBrokenStoreFileCleaner.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBrokenStoreFileCleaner.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;
@@ -28,7 +28,6 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
@@ -38,19 +37,15 @@ import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFac
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ MediumTests.class, RegionServerTests.class })
+@Tag(MediumTests.TAG)
+@Tag(RegionServerTests.TAG)
public class TestBrokenStoreFileCleaner {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBrokenStoreFileCleaner.class);
-
private final HBaseTestingUtility testUtil = new HBaseTestingUtility();
private final static byte[] fam = Bytes.toBytes("cf_1");
private final static byte[] qual1 = Bytes.toBytes("qf_1");
@@ -58,7 +53,7 @@ public class TestBrokenStoreFileCleaner {
private final static String junkFileName = "409fad9a751c4e8c86d7f32581bdc156";
TableName tableName;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
testUtil.getConfiguration().set(StoreFileTrackerFactory.TRACKER_IMPL,
"org.apache.hadoop.hbase.regionserver.storefiletracker.FileBasedStoreFileTracker");
@@ -71,7 +66,7 @@ public class TestBrokenStoreFileCleaner {
testUtil.startMiniCluster(1);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
testUtil.shutdownMiniCluster();
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBulkLoad.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBulkLoad.java
index 85a5b5d920f..1ca07c3f167 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBulkLoad.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBulkLoad.java
@@ -18,6 +18,7 @@
package org.apache.hadoop.hbase.regionserver;
import static java.util.Arrays.asList;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.verify;
@@ -30,33 +31,29 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.DoNotRetryIOException;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.wal.WALEdit;
import org.apache.hadoop.hbase.wal.WALKeyImpl;
-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.TestTemplate;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
/**
* This class attempts to unit test bulk HLog loading.
*/
-@Category(SmallTests.class)
+@Tag(SmallTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: useFileBasedSFT={0}")
public class TestBulkLoad extends TestBulkloadBase {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBulkLoad.class);
-
public TestBulkLoad(boolean useFileBasedSFT) {
super(useFileBasedSFT);
}
- @Test
+ @TestTemplate
public void verifyBulkLoadEvent() throws IOException {
TableName tableName = TableName.valueOf("test", "test");
List<Pair<byte[], String>> familyPaths = withFamilyPathsFor(family1);
@@ -77,19 +74,19 @@ public class TestBulkLoad extends TestBulkloadBase {
walKey.setWriteEntry(we);
}
return 01L;
- };
+ }
});
testRegionWithFamiliesAndSpecifiedTableName(tableName, family1).bulkLoadHFiles(familyPaths,
false, null);
verify(log).sync(anyLong());
}
- @Test
+ @TestTemplate
public void bulkHLogShouldThrowNoErrorAndWriteMarkerWithBlankInput() throws IOException {
testRegionWithFamilies(family1).bulkLoadHFiles(new ArrayList<>(), false, null);
}
- @Test
+ @TestTemplate
public void shouldBulkLoadSingleFamilyHLog() throws IOException {
when(log.appendMarker(any(), any(), argThat(bulkLogWalEditType(WALEdit.BULK_LOAD))))
.thenAnswer(new Answer() {
@@ -102,13 +99,13 @@ public class TestBulkLoad extends TestBulkloadBase {
walKey.setWriteEntry(we);
}
return 01L;
- };
+ }
});
testRegionWithFamilies(family1).bulkLoadHFiles(withFamilyPathsFor(family1), false, null);
verify(log).sync(anyLong());
}
- @Test
+ @TestTemplate
public void shouldBulkLoadManyFamilyHLog() throws IOException {
when(log.appendMarker(any(), any(), argThat(bulkLogWalEditType(WALEdit.BULK_LOAD))))
.thenAnswer(new Answer() {
@@ -120,15 +117,15 @@ public class TestBulkLoad extends TestBulkloadBase {
MultiVersionConcurrencyControl.WriteEntry we = mvcc.begin();
walKey.setWriteEntry(we);
}
- return 01L;
- };
+ return 1L;
+ }
});
testRegionWithFamilies(family1, family2).bulkLoadHFiles(withFamilyPathsFor(family1, family2),
false, null);
verify(log).sync(anyLong());
}
- @Test
+ @TestTemplate
public void shouldBulkLoadManyFamilyHLogEvenWhenTableNameNamespaceSpecified() throws IOException {
when(log.appendMarker(any(), any(), argThat(bulkLogWalEditType(WALEdit.BULK_LOAD))))
.thenAnswer(new Answer() {
@@ -140,8 +137,8 @@ public class TestBulkLoad extends TestBulkloadBase {
MultiVersionConcurrencyControl.WriteEntry we = mvcc.begin();
walKey.setWriteEntry(we);
}
- return 01L;
- };
+ return 1L;
+ }
});
TableName tableName = TableName.valueOf("test", "test");
testRegionWithFamiliesAndSpecifiedTableName(tableName, family1, family2)
@@ -149,43 +146,46 @@ public class TestBulkLoad extends TestBulkloadBase {
verify(log).sync(anyLong());
}
- @Test(expected = DoNotRetryIOException.class)
+ @TestTemplate
public void shouldCrashIfBulkLoadFamiliesNotInTable() throws IOException {
- testRegionWithFamilies(family1).bulkLoadHFiles(withFamilyPathsFor(family1, family2), false,
- null);
+ assertThrows(DoNotRetryIOException.class, () -> testRegionWithFamilies(family1)
+ .bulkLoadHFiles(withFamilyPathsFor(family1, family2), false, null));
}
// after HBASE-24021 will throw DoNotRetryIOException, not MultipleIOException
- @Test(expected = DoNotRetryIOException.class)
+ @TestTemplate
public void shouldCrashIfBulkLoadMultiFamiliesNotInTable() throws IOException {
- testRegionWithFamilies(family1).bulkLoadHFiles(withFamilyPathsFor(family1, family2, family3),
- false, null);
+ assertThrows(DoNotRetryIOException.class, () -> testRegionWithFamilies(family1)
+ .bulkLoadHFiles(withFamilyPathsFor(family1, family2, family3), false, null));
}
- @Test(expected = DoNotRetryIOException.class)
+ @TestTemplate
public void bulkHLogShouldThrowErrorWhenFamilySpecifiedAndHFileExistsButNotInTableDescriptor()
throws IOException {
- testRegionWithFamilies().bulkLoadHFiles(withFamilyPathsFor(family1), false, null);
+ assertThrows(DoNotRetryIOException.class,
+ () -> testRegionWithFamilies().bulkLoadHFiles(withFamilyPathsFor(family1), false, null));
}
- @Test(expected = DoNotRetryIOException.class)
+ @TestTemplate
public void shouldThrowErrorIfBadFamilySpecifiedAsFamilyPath() throws IOException {
- testRegionWithFamilies()
- .bulkLoadHFiles(asList(withInvalidColumnFamilyButProperHFileLocation(family1)), false, null);
+ assertThrows(DoNotRetryIOException.class, () -> testRegionWithFamilies()
+ .bulkLoadHFiles(asList(withInvalidColumnFamilyButProperHFileLocation(family1)), false, null));
}
- @Test(expected = FileNotFoundException.class)
+ @TestTemplate
public void shouldThrowErrorIfHFileDoesNotExist() throws IOException {
List<Pair<byte[], String>> list = asList(withMissingHFileForFamily(family1));
- testRegionWithFamilies(family1).bulkLoadHFiles(list, false, null);
+ assertThrows(FileNotFoundException.class,
+ () -> testRegionWithFamilies(family1).bulkLoadHFiles(list, false, null));
}
// after HBASE-24021 will throw FileNotFoundException, not MultipleIOException
- @Test(expected = FileNotFoundException.class)
+ @TestTemplate
public void shouldThrowErrorIfMultiHFileDoesNotExist() throws IOException {
List<Pair<byte[], String>> list = new ArrayList<>();
list.addAll(asList(withMissingHFileForFamily(family1)));
list.addAll(asList(withMissingHFileForFamily(family2)));
- testRegionWithFamilies(family1, family2).bulkLoadHFiles(list, false, null);
+ assertThrows(FileNotFoundException.class,
+ () -> testRegionWithFamilies(family1, family2).bulkLoadHFiles(list, false, null));
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBulkloadBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBulkloadBase.java
index 6f35ec5408b..a65ba729a21 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBulkloadBase.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBulkloadBase.java
@@ -17,9 +17,9 @@
*/
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.Mockito.mock;
import java.io.File;
@@ -27,9 +27,9 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
import java.util.UUID;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.Path;
@@ -54,21 +54,18 @@ import org.apache.hadoop.hbase.wal.WALEdit;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.rules.TemporaryFolder;
-import org.junit.rules.TestName;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.provider.Arguments;
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos;
-@RunWith(Parameterized.class)
public class TestBulkloadBase {
- @ClassRule
- public static TemporaryFolder testFolder = new TemporaryFolder();
+
+ @TempDir
+ public static File testFolder;
private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
protected final WAL log = mock(WAL.class);
protected final Configuration conf = HBaseConfiguration.create();
@@ -78,22 +75,19 @@ public class TestBulkloadBase {
protected final byte[] family3 = Bytes.toBytes("family3");
protected Boolean useFileBasedSFT;
-
- @Rule
- public TestName name = new TestName();
+ private String name;
public TestBulkloadBase(boolean useFileBasedSFT) {
this.useFileBasedSFT = useFileBasedSFT;
}
- @Parameterized.Parameters
- public static Collection<Boolean> data() {
- Boolean[] data = { false, true };
- return Arrays.asList(data);
+ public static Stream<Arguments> parameters() {
+ return Stream.of(Arguments.of(false), Arguments.of(true));
}
- @Before
- public void before() throws IOException {
+ @BeforeEach
+ public void before(TestInfo testInfo) throws IOException {
+ this.name = testInfo.getTestMethod().get().getName();
Bytes.random(randomBytes);
if (useFileBasedSFT) {
conf.set(StoreFileTrackerFactory.TRACKER_IMPL,
@@ -129,14 +123,13 @@ public class TestBulkloadBase {
ChunkCreator.initialize(MemStoreLAB.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null,
MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_DEFAULT);
// TODO We need a way to do this without creating files
- return HRegion.createHRegion(hRegionInfo, new Path(testFolder.newFolder().toURI()), conf,
- builder.build(), log);
+ return HRegion.createHRegion(hRegionInfo,
+ new Path(new File(testFolder, generateUniqueName(null)).toURI()), conf, builder.build(), log);
}
protected HRegion testRegionWithFamilies(byte[]... families) throws IOException {
- TableName tableName =
- TableName.valueOf(name.getMethodName().substring(0, name.getMethodName().indexOf("[")));
+ TableName tableName = TableName.valueOf(name);
return testRegionWithFamiliesAndSpecifiedTableName(tableName, families);
}
@@ -155,7 +148,7 @@ public class TestBulkloadBase {
private String createHFileForFamilies(byte[] family) throws IOException {
HFile.WriterFactory hFileFactory = HFile.getWriterFactoryNoCache(conf);
// TODO We need a way to do this without creating files
- File hFileLocation = testFolder.newFile(generateUniqueName(null));
+ File hFileLocation = new File(testFolder, generateUniqueName(null));
FSDataOutputStream out = new FSDataOutputStream(new FileOutputStream(hFileLocation), null);
try {
hFileFactory.withOutputStream(out);
@@ -174,7 +167,7 @@ public class TestBulkloadBase {
return hFileLocation.getAbsoluteFile().getAbsolutePath();
}
- private static String generateUniqueName(final String suffix) {
+ protected static String generateUniqueName(final String suffix) {
String name = UUID.randomUUID().toString().replaceAll("-", "");
if (suffix != null) name += suffix;
return name;
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBytesReadServerSideScanMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBytesReadServerSideScanMetrics.java
index ff4b63e399c..04078ac8f47 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBytesReadServerSideScanMetrics.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBytesReadServerSideScanMetrics.java
@@ -17,6 +17,13 @@
*/
package org.apache.hadoop.hbase.regionserver;
+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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -29,7 +36,6 @@ import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.CellComparator;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
@@ -61,29 +67,22 @@ import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.BloomFilter;
import org.apache.hadoop.hbase.util.BloomFilterUtil;
import org.apache.hadoop.hbase.util.Bytes;
-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.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({ IOTests.class, LargeTests.class })
+@Tag(IOTests.TAG)
+@Tag(LargeTests.TAG)
public class TestBytesReadServerSideScanMetrics {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestBytesReadServerSideScanMetrics.class);
-
- @Rule
- public TestName name = new TestName();
-
private static final Logger LOG =
LoggerFactory.getLogger(TestBytesReadServerSideScanMetrics.class);
+ private String name;
+
private HBaseTestingUtility UTIL;
private static final byte[] CF = Bytes.toBytes("cf");
@@ -98,8 +97,9 @@ public class TestBytesReadServerSideScanMetrics {
private Configuration conf;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ public void setUp(TestInfo testInfo) throws Exception {
+ this.name = testInfo.getTestMethod().get().getName();
UTIL = new HBaseTestingUtility();
conf = UTIL.getConfiguration();
conf.setInt(HRegion.MEMSTORE_PERIODIC_FLUSH_INTERVAL, 0);
@@ -111,7 +111,7 @@ public class TestBytesReadServerSideScanMetrics {
conf.setInt(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, 0);
UTIL.startMiniCluster();
try {
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(name);
createTable(tableName, false, BloomType.NONE);
writeData(tableName, true);
Scan scan = new Scan();
@@ -124,8 +124,8 @@ public class TestBytesReadServerSideScanMetrics {
for (Result r : scanner) {
rowCount++;
}
- Assert.assertEquals(2, rowCount);
- Assert.assertNull(scanner.getScanMetrics());
+ assertEquals(2, rowCount);
+ assertNull(scanner.getScanMetrics());
}
} finally {
UTIL.shutdownMiniCluster();
@@ -137,7 +137,7 @@ public class TestBytesReadServerSideScanMetrics {
conf.setInt(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, 0);
UTIL.startMiniCluster();
try {
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(name);
createTable(tableName, false, BloomType.ROW);
writeData(tableName, true);
ScanMetrics scanMetrics = readDataAndGetScanMetrics(tableName, true);
@@ -147,8 +147,8 @@ public class TestBytesReadServerSideScanMetrics {
KeyValue keyValue = new KeyValue(ROW2, CF, CQ, HConstants.OLDEST_TIMESTAMP, VALUE);
assertBytesReadFromFs(tableName, scanMetrics.bytesReadFromFs.get(), keyValue,
scanMetrics.blockReadOpsCount.get());
- Assert.assertEquals(0, scanMetrics.bytesReadFromBlockCache.get());
- Assert.assertEquals(0, scanMetrics.bytesReadFromMemstore.get());
+ assertEquals(0, scanMetrics.bytesReadFromBlockCache.get());
+ assertEquals(0, scanMetrics.bytesReadFromMemstore.get());
} finally {
UTIL.shutdownMiniCluster();
}
@@ -161,7 +161,7 @@ public class TestBytesReadServerSideScanMetrics {
conf.setBoolean(StoreScanner.STORESCANNER_PARALLEL_SEEK_ENABLE, true);
UTIL.startMiniCluster();
try {
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(name);
createTable(tableName, false, BloomType.NONE);
writeData(tableName, true);
HRegionServer server = UTIL.getMiniHBaseCluster().getRegionServer(0);
@@ -171,15 +171,15 @@ public class TestBytesReadServerSideScanMetrics {
ScanMetrics scanMetrics = readDataAndGetScanMetrics(tableName, true);
long tasksCompletedAfterRead = executor.getCompletedTaskCount();
// Assert both of the HFiles were read using parallel seek executor
- Assert.assertEquals(2, tasksCompletedAfterRead - tasksCompletedBeforeRead);
+ assertEquals(2, tasksCompletedAfterRead - tasksCompletedBeforeRead);
// Use oldest timestamp to make sure the fake key is not less than the first key in
// the file containing key: row2
KeyValue keyValue = new KeyValue(ROW2, CF, CQ, HConstants.OLDEST_TIMESTAMP, VALUE);
assertBytesReadFromFs(tableName, scanMetrics.bytesReadFromFs.get(), keyValue,
scanMetrics.blockReadOpsCount.get());
- Assert.assertEquals(0, scanMetrics.bytesReadFromBlockCache.get());
- Assert.assertEquals(0, scanMetrics.bytesReadFromMemstore.get());
+ assertEquals(0, scanMetrics.bytesReadFromBlockCache.get());
+ assertEquals(0, scanMetrics.bytesReadFromMemstore.get());
} finally {
UTIL.shutdownMiniCluster();
}
@@ -189,21 +189,21 @@ public class TestBytesReadServerSideScanMetrics {
public void testBytesReadFromBlockCache() throws Exception {
UTIL.startMiniCluster();
try {
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(name);
createTable(tableName, true, BloomType.NONE);
HRegionServer server = UTIL.getMiniHBaseCluster().getRegionServer(0);
LruBlockCache blockCache = (LruBlockCache) server.getBlockCache().get();
// Assert that acceptable size of LRU block cache is greater than 1MB
- Assert.assertTrue(blockCache.acceptableSize() > 1024 * 1024);
+ assertTrue(blockCache.acceptableSize() > 1024 * 1024);
writeData(tableName, true);
readDataAndGetScanMetrics(tableName, false);
KeyValue keyValue = new KeyValue(ROW2, CF, CQ, HConstants.OLDEST_TIMESTAMP, VALUE);
assertBlockCacheWarmUp(tableName, keyValue);
ScanMetrics scanMetrics = readDataAndGetScanMetrics(tableName, true);
- Assert.assertEquals(0, scanMetrics.bytesReadFromFs.get());
+ assertEquals(0, scanMetrics.bytesReadFromFs.get());
assertBytesReadFromBlockCache(tableName, scanMetrics.bytesReadFromBlockCache.get(), keyValue);
- Assert.assertEquals(0, scanMetrics.bytesReadFromMemstore.get());
+ assertEquals(0, scanMetrics.bytesReadFromMemstore.get());
} finally {
UTIL.shutdownMiniCluster();
}
@@ -213,7 +213,7 @@ public class TestBytesReadServerSideScanMetrics {
public void testBytesReadFromMemstore() throws Exception {
UTIL.startMiniCluster();
try {
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(name);
createTable(tableName, false, BloomType.NONE);
writeData(tableName, false);
ScanMetrics scanMetrics = readDataAndGetScanMetrics(tableName, true);
@@ -223,7 +223,7 @@ public class TestBytesReadServerSideScanMetrics {
for (HRegion region : regions) {
HStore store = region.getStore(CF);
// Assert no HFile is there
- Assert.assertEquals(0, store.getStorefiles().size());
+ assertEquals(0, store.getStorefiles().size());
}
KeyValue keyValue = new KeyValue(ROW2, CF, CQ, HConstants.LATEST_TIMESTAMP, VALUE);
@@ -232,9 +232,9 @@ public class TestBytesReadServerSideScanMetrics {
// there are no more cells in the row. We don't count key values read on SegmentScanner
// instance creation.
int totalKeyValueSize = 2 * singleKeyValueSize;
- Assert.assertEquals(0, scanMetrics.bytesReadFromFs.get());
- Assert.assertEquals(0, scanMetrics.bytesReadFromBlockCache.get());
- Assert.assertEquals(totalKeyValueSize, scanMetrics.bytesReadFromMemstore.get());
+ assertEquals(0, scanMetrics.bytesReadFromFs.get());
+ assertEquals(0, scanMetrics.bytesReadFromBlockCache.get());
+ assertEquals(totalKeyValueSize, scanMetrics.bytesReadFromMemstore.get());
} finally {
UTIL.shutdownMiniCluster();
}
@@ -248,7 +248,7 @@ public class TestBytesReadServerSideScanMetrics {
configuration.put(StoreScanner.STORESCANNER_PREAD_MAX_BYTES, "3");
UTIL.startMiniCluster();
try {
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(name);
createTable(tableName, true, BloomType.ROW, configuration);
writeData(tableName, true);
Scan scan = new Scan();
@@ -262,23 +262,23 @@ public class TestBytesReadServerSideScanMetrics {
try (Table table = UTIL.getConnection().getTable(tableName);
ResultScanner scanner = table.getScanner(scan)) {
int rowCount = 0;
- Assert.assertFalse(StoreScanner.hasSwitchedToStreamRead());
+ assertFalse(StoreScanner.hasSwitchedToStreamRead());
for (Result r : scanner) {
rowCount++;
}
- Assert.assertTrue(StoreScanner.hasSwitchedToStreamRead());
- Assert.assertEquals(2, rowCount);
+ assertTrue(StoreScanner.hasSwitchedToStreamRead());
+ assertEquals(2, rowCount);
scanMetrics = scanner.getScanMetrics();
}
int bytesReadFromFs = getBytesReadFromFsForNonGetScan(tableName, scanMetrics, 2);
- Assert.assertEquals(bytesReadFromFs, scanMetrics.bytesReadFromFs.get());
- Assert.assertEquals(0, scanMetrics.bytesReadFromBlockCache.get());
- Assert.assertEquals(0, scanMetrics.bytesReadFromMemstore.get());
+ assertEquals(bytesReadFromFs, scanMetrics.bytesReadFromFs.get());
+ assertEquals(0, scanMetrics.bytesReadFromBlockCache.get());
+ assertEquals(0, scanMetrics.bytesReadFromMemstore.get());
// There are 2 HFiles so, 1 read op per HFile was done by actual scan to read data block.
// No bloom blocks will be read as this is non Get scan and only bloom filter type is ROW.
- Assert.assertEquals(2, scanMetrics.blockReadOpsCount.get());
+ assertEquals(2, scanMetrics.blockReadOpsCount.get());
// With scan caching set to 1 and 2 rows being scanned, 2 RPC calls will be needed.
- Assert.assertEquals(2, scanMetrics.countOfRPCcalls.get());
+ assertEquals(2, scanMetrics.countOfRPCcalls.get());
} finally {
UTIL.shutdownMiniCluster();
}
@@ -288,7 +288,7 @@ public class TestBytesReadServerSideScanMetrics {
public void testBytesReadWhenFlushHappenedInTheMiddleOfScan() throws Exception {
UTIL.startMiniCluster();
try {
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(name);
createTable(tableName, true, BloomType.ROW);
writeData(tableName, false);
Scan scan = new Scan();
@@ -307,28 +307,28 @@ public class TestBytesReadServerSideScanMetrics {
flushAndWaitUntilFlushed(tableName, true);
}
}
- Assert.assertEquals(2, rowCount);
+ assertEquals(2, rowCount);
scanMetrics = scanner.getScanMetrics();
}
// Only 1 HFile will be created and it will have only one data block.
int bytesReadFromFs = getBytesReadFromFsForNonGetScan(tableName, scanMetrics, 1);
- Assert.assertEquals(bytesReadFromFs, scanMetrics.bytesReadFromFs.get());
+ assertEquals(bytesReadFromFs, scanMetrics.bytesReadFromFs.get());
- Assert.assertEquals(0, scanMetrics.bytesReadFromBlockCache.get());
+ assertEquals(0, scanMetrics.bytesReadFromBlockCache.get());
// Flush happens after first row is returned from server but before second row is returned.
// So, 2 cells will be read from memstore i.e. the cell for the first row and the next cell
// at which scanning will stop. Per row we have 1 cell.
int bytesReadFromMemstore =
Segment.getCellLength(new KeyValue(ROW2, CF, CQ, HConstants.LATEST_TIMESTAMP, VALUE));
- Assert.assertEquals(2 * bytesReadFromMemstore, scanMetrics.bytesReadFromMemstore.get());
+ assertEquals(2 * bytesReadFromMemstore, scanMetrics.bytesReadFromMemstore.get());
// There will be 1 read op to read the only data block present in the HFile.
- Assert.assertEquals(1, scanMetrics.blockReadOpsCount.get());
+ assertEquals(1, scanMetrics.blockReadOpsCount.get());
// More than 1 RPC call should be there
- Assert.assertEquals(2, scanMetrics.countOfRPCcalls.get());
+ assertEquals(2, scanMetrics.countOfRPCcalls.get());
} finally {
UTIL.shutdownMiniCluster();
}
@@ -338,7 +338,7 @@ public class TestBytesReadServerSideScanMetrics {
public void testBytesReadInReverseScan() throws Exception {
UTIL.startMiniCluster();
try {
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(name);
createTable(tableName, true, BloomType.ROW);
writeData(tableName, true);
Scan scan = new Scan();
@@ -355,14 +355,14 @@ public class TestBytesReadServerSideScanMetrics {
for (Result r : scanner) {
rowCount++;
}
- Assert.assertEquals(2, rowCount);
+ assertEquals(2, rowCount);
scanMetrics = scanner.getScanMetrics();
System.out.println("Scan metrics: " + scanMetrics.toString());
}
// 1 data block per HFile was read.
int bytesReadFromFs = getBytesReadFromFsForNonGetScan(tableName, scanMetrics, 2);
- Assert.assertEquals(bytesReadFromFs, scanMetrics.bytesReadFromFs.get());
+ assertEquals(bytesReadFromFs, scanMetrics.bytesReadFromFs.get());
// For the HFile containing both the rows, the data block will be read from block cache when
// KeyValueHeap.next() will be called to read the second row.
@@ -371,14 +371,14 @@ public class TestBytesReadServerSideScanMetrics {
// kvNext will be null and call to StoreFileScanner.seekToPreviousRow() will be made. As the
// curBlock of HFileScanner is null so, StoreFileScanner.seekToPreviousRow() will load data
// block from BlockCache. So, 1 data block will be read from block cache.
- Assert.assertEquals(bytesReadFromFs / 2, scanMetrics.bytesReadFromBlockCache.get());
- Assert.assertEquals(0, scanMetrics.bytesReadFromMemstore.get());
+ assertEquals(bytesReadFromFs / 2, scanMetrics.bytesReadFromBlockCache.get());
+ assertEquals(0, scanMetrics.bytesReadFromMemstore.get());
// 1 read op per HFile was done by actual scan to read data block.
- Assert.assertEquals(2, scanMetrics.blockReadOpsCount.get());
+ assertEquals(2, scanMetrics.blockReadOpsCount.get());
// 2 RPC calls will be there
- Assert.assertEquals(2, scanMetrics.countOfRPCcalls.get());
+ assertEquals(2, scanMetrics.countOfRPCcalls.get());
} finally {
UTIL.shutdownMiniCluster();
}
@@ -388,7 +388,7 @@ public class TestBytesReadServerSideScanMetrics {
public void testBytesReadWithLazySeek() throws Exception {
UTIL.startMiniCluster();
try {
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(name);
createTable(tableName, true, BloomType.NONE);
writeData(tableName, true);
try (Table table = UTIL.getConnection().getTable(tableName)) {
@@ -409,21 +409,21 @@ public class TestBytesReadServerSideScanMetrics {
int rowCount = 0;
for (Result r : scanner) {
rowCount++;
- Assert.assertArrayEquals(newValue, r.getValue(CF, CQ));
+ assertArrayEquals(newValue, r.getValue(CF, CQ));
}
- Assert.assertEquals(1, rowCount);
+ assertEquals(1, rowCount);
scanMetrics = scanner.getScanMetrics();
}
// No real seek should be done on the HFile.
- Assert.assertEquals(0, scanMetrics.bytesReadFromFs.get());
- Assert.assertEquals(0, scanMetrics.bytesReadFromBlockCache.get());
- Assert.assertEquals(0, scanMetrics.blockReadOpsCount.get());
+ assertEquals(0, scanMetrics.bytesReadFromFs.get());
+ assertEquals(0, scanMetrics.bytesReadFromBlockCache.get());
+ assertEquals(0, scanMetrics.blockReadOpsCount.get());
// The cell should be coming purely from memstore.
int cellSize =
Segment.getCellLength(new KeyValue(ROW2, CF, CQ, HConstants.LATEST_TIMESTAMP, newValue));
- Assert.assertEquals(cellSize, scanMetrics.bytesReadFromMemstore.get());
- Assert.assertEquals(1, scanMetrics.countOfRPCcalls.get());
+ assertEquals(cellSize, scanMetrics.bytesReadFromMemstore.get());
+ assertEquals(1, scanMetrics.countOfRPCcalls.get());
}
} finally {
UTIL.shutdownMiniCluster();
@@ -441,7 +441,7 @@ public class TestBytesReadServerSideScanMetrics {
configuration.put(StoreScanner.STORESCANNER_PREAD_MAX_BYTES, Integer.toString(64 * 1024));
UTIL.startMiniCluster();
try {
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(name);
// Set the block size to 4 bytes to get 1 row per data block in HFile.
createTable(tableName, true, BloomType.NONE, 4, configuration);
try (Table table = UTIL.getConnection().getTable(tableName)) {
@@ -459,18 +459,18 @@ public class TestBytesReadServerSideScanMetrics {
for (Result r : scanner) {
rowCount++;
}
- Assert.assertEquals(2, rowCount);
+ assertEquals(2, rowCount);
scanMetrics = scanner.getScanMetrics();
}
// Assert that rows were read from only memstore and involved 2 RPC calls.
int cellSize =
Segment.getCellLength(new KeyValue(ROW2, CF, CQ, HConstants.LATEST_TIMESTAMP, VALUE));
- Assert.assertEquals(0, scanMetrics.bytesReadFromFs.get());
- Assert.assertEquals(0, scanMetrics.bytesReadFromBlockCache.get());
- Assert.assertEquals(0, scanMetrics.blockReadOpsCount.get());
- Assert.assertEquals(2, scanMetrics.countOfRPCcalls.get());
- Assert.assertEquals(3 * cellSize, scanMetrics.bytesReadFromMemstore.get());
+ assertEquals(0, scanMetrics.bytesReadFromFs.get());
+ assertEquals(0, scanMetrics.bytesReadFromBlockCache.get());
+ assertEquals(0, scanMetrics.blockReadOpsCount.get());
+ assertEquals(2, scanMetrics.countOfRPCcalls.get());
+ assertEquals(3 * cellSize, scanMetrics.bytesReadFromMemstore.get());
// Flush the table and make sure that the rows are read from HFiles.
flushAndWaitUntilFlushed(tableName, false);
@@ -481,17 +481,17 @@ public class TestBytesReadServerSideScanMetrics {
for (Result r : scanner) {
rowCount++;
}
- Assert.assertEquals(2, rowCount);
+ assertEquals(2, rowCount);
scanMetrics = scanner.getScanMetrics();
}
// Assert that rows were read from HFiles and involved 2 RPC calls.
int bytesReadFromFs = getBytesReadToReadConsecutiveDataBlocks(tableName, 1, 3, true);
- Assert.assertEquals(bytesReadFromFs, scanMetrics.bytesReadFromFs.get());
- Assert.assertEquals(0, scanMetrics.bytesReadFromBlockCache.get());
- Assert.assertEquals(3, scanMetrics.blockReadOpsCount.get());
- Assert.assertEquals(2, scanMetrics.countOfRPCcalls.get());
- Assert.assertEquals(0, scanMetrics.bytesReadFromMemstore.get());
+ assertEquals(bytesReadFromFs, scanMetrics.bytesReadFromFs.get());
+ assertEquals(0, scanMetrics.bytesReadFromBlockCache.get());
+ assertEquals(3, scanMetrics.blockReadOpsCount.get());
+ assertEquals(2, scanMetrics.countOfRPCcalls.get());
+ assertEquals(0, scanMetrics.bytesReadFromMemstore.get());
// Make sure that rows are read from Blockcache now.
scan = createScanToReadOneRowAtATimeFromServer(ROW2, ROW3);
@@ -501,18 +501,18 @@ public class TestBytesReadServerSideScanMetrics {
for (Result r : scanner) {
rowCount++;
}
- Assert.assertEquals(2, rowCount);
+ assertEquals(2, rowCount);
scanMetrics = scanner.getScanMetrics();
}
// Assert that rows were read from Blockcache and involved 2 RPC calls.
int bytesReadFromBlockCache =
getBytesReadToReadConsecutiveDataBlocks(tableName, 1, 3, false);
- Assert.assertEquals(bytesReadFromBlockCache, scanMetrics.bytesReadFromBlockCache.get());
- Assert.assertEquals(0, scanMetrics.bytesReadFromFs.get());
- Assert.assertEquals(0, scanMetrics.blockReadOpsCount.get());
- Assert.assertEquals(2, scanMetrics.countOfRPCcalls.get());
- Assert.assertEquals(0, scanMetrics.bytesReadFromMemstore.get());
+ assertEquals(bytesReadFromBlockCache, scanMetrics.bytesReadFromBlockCache.get());
+ assertEquals(0, scanMetrics.bytesReadFromFs.get());
+ assertEquals(0, scanMetrics.blockReadOpsCount.get());
+ assertEquals(2, scanMetrics.countOfRPCcalls.get());
+ assertEquals(0, scanMetrics.bytesReadFromMemstore.get());
}
} finally {
UTIL.shutdownMiniCluster();
@@ -535,7 +535,7 @@ public class TestBytesReadServerSideScanMetrics {
}
UTIL.flush(tableName);
List<HRegion> regions = UTIL.getMiniHBaseCluster().getRegions(tableName);
- Assert.assertEquals(1, regions.size());
+ assertEquals(1, regions.size());
HRegion region = regions.get(0);
HStore store = region.getStore(CF);
// In milliseconds
@@ -552,17 +552,17 @@ public class TestBytesReadServerSideScanMetrics {
throw new Exception("Store files not flushed after " + maxWaitTime + "ms");
}
}
- Assert.assertEquals(1, store.getStorefiles().size());
+ assertEquals(1, store.getStorefiles().size());
}
private int getBytesReadToReadConsecutiveDataBlocks(TableName tableName,
int expectedStoreFileCount, int expectedDataBlockCount, boolean isReadFromFs) throws Exception {
List<HRegion> regions = UTIL.getMiniHBaseCluster().getRegions(tableName);
- Assert.assertEquals(1, regions.size());
+ assertEquals(1, regions.size());
HRegion region = regions.get(0);
HStore store = region.getStore(CF);
Collection<HStoreFile> storeFiles = store.getStorefiles();
- Assert.assertEquals(expectedStoreFileCount, storeFiles.size());
+ assertEquals(expectedStoreFileCount, storeFiles.size());
int bytesReadFromFs = 0;
for (HStoreFile storeFile : storeFiles) {
StoreFileReader reader = storeFile.getReader();
@@ -588,12 +588,12 @@ public class TestBytesReadServerSideScanMetrics {
bytesReadFromFs += block.headerSize();
readNextBlock = true;
}
- Assert.assertTrue(block.getBlockType().isData());
+ assertTrue(block.getBlockType().isData());
}
blockIterator.freeBlocks();
// No intermediate or leaf index blocks are expected.
- Assert.assertEquals(1, dataIndexLevels);
- Assert.assertEquals(expectedDataBlockCount, blockCount);
+ assertEquals(1, dataIndexLevels);
+ assertEquals(expectedDataBlockCount, blockCount);
}
return bytesReadFromFs;
}
@@ -601,11 +601,11 @@ public class TestBytesReadServerSideScanMetrics {
private int getBytesReadFromFsForNonGetScan(TableName tableName, ScanMetrics scanMetrics,
int expectedStoreFileCount) throws Exception {
List<HRegion> regions = UTIL.getMiniHBaseCluster().getRegions(tableName);
- Assert.assertEquals(1, regions.size());
+ assertEquals(1, regions.size());
HRegion region = regions.get(0);
HStore store = region.getStore(CF);
Collection<HStoreFile> storeFiles = store.getStorefiles();
- Assert.assertEquals(expectedStoreFileCount, storeFiles.size());
+ assertEquals(expectedStoreFileCount, storeFiles.size());
int bytesReadFromFs = 0;
for (HStoreFile storeFile : storeFiles) {
StoreFileReader reader = storeFile.getReader();
@@ -616,7 +616,7 @@ public class TestBytesReadServerSideScanMetrics {
// Read the first block of the HFile. First block is always expected to be a DATA block and
// the HFile is expected to have only one DATA block.
HFileBlock block = blockReader.readBlockData(0, -1, true, true, true);
- Assert.assertTrue(block.getBlockType().isData());
+ assertTrue(block.getBlockType().isData());
bytesReadFromFs += block.getOnDiskSizeWithHeader();
if (block.getNextBlockOnDiskSize() > 0) {
bytesReadFromFs += block.headerSize();
@@ -624,7 +624,7 @@ public class TestBytesReadServerSideScanMetrics {
block.release();
// Each of the HFiles is expected to have only root index but no intermediate or leaf index
// blocks.
- Assert.assertEquals(1, dataIndexLevels);
+ assertEquals(1, dataIndexLevels);
}
return bytesReadFromFs;
}
@@ -643,7 +643,7 @@ public class TestBytesReadServerSideScanMetrics {
for (Result r : scanner) {
rowCount++;
}
- Assert.assertEquals(1, rowCount);
+ assertEquals(1, rowCount);
scanMetrics = scanner.getScanMetrics();
}
if (isScanMetricsEnabled) {
@@ -706,19 +706,19 @@ public class TestBytesReadServerSideScanMetrics {
private void assertBytesReadFromFs(TableName tableName, long actualBytesReadFromFs,
KeyValue keyValue, long actualReadOps) throws Exception {
List<HRegion> regions = UTIL.getMiniHBaseCluster().getRegions(tableName);
- Assert.assertEquals(1, regions.size());
+ assertEquals(1, regions.size());
MutableInt totalExpectedBytesReadFromFs = new MutableInt(0);
MutableInt totalExpectedReadOps = new MutableInt(0);
for (HRegion region : regions) {
- Assert.assertNull(region.getBlockCache());
+ assertNull(region.getBlockCache());
HStore store = region.getStore(CF);
Collection<HStoreFile> storeFiles = store.getStorefiles();
- Assert.assertEquals(2, storeFiles.size());
+ assertEquals(2, storeFiles.size());
for (HStoreFile storeFile : storeFiles) {
StoreFileReader reader = storeFile.getReader();
HFile.Reader hfileReader = reader.getHFileReader();
BloomFilter bloomFilter = reader.getGeneralBloomFilter();
- Assert.assertTrue(bloomFilter == null || bloomFilter instanceof CompoundBloomFilter);
+ assertTrue(bloomFilter == null || bloomFilter instanceof CompoundBloomFilter);
CompoundBloomFilter cbf = bloomFilter == null ? null : (CompoundBloomFilter) bloomFilter;
Consumer<HFileBlock> bytesReadFunction = new Consumer<HFileBlock>() {
@Override
@@ -733,8 +733,8 @@ public class TestBytesReadServerSideScanMetrics {
readHFile(hfileReader, cbf, keyValue, bytesReadFunction);
}
}
- Assert.assertEquals(totalExpectedBytesReadFromFs.longValue(), actualBytesReadFromFs);
- Assert.assertEquals(totalExpectedReadOps.longValue(), actualReadOps);
+ assertEquals(totalExpectedBytesReadFromFs.longValue(), actualBytesReadFromFs);
+ assertEquals(totalExpectedReadOps.longValue(), actualReadOps);
}
private void readHFile(HFile.Reader hfileReader, CompoundBloomFilter cbf, KeyValue keyValue,
@@ -759,7 +759,7 @@ public class TestBytesReadServerSideScanMetrics {
bloomBlock.getUncompressedSizeWithoutHeader(), cbf.getHash(), cbf.getHashCount());
bytesReadFunction.accept(bloomBlock);
// Asser that the block read is a bloom block
- Assert.assertEquals(bloomBlock.getBlockType(), BlockType.BLOOM_CHUNK);
+ assertEquals(bloomBlock.getBlockType(), BlockType.BLOOM_CHUNK);
bloomBlock.release();
if (!fileContainsKey) {
// Key is not in th file, so we don't need to read the data block
@@ -808,24 +808,24 @@ public class TestBytesReadServerSideScanMetrics {
block.release();
blockIter.freeBlocks();
- Assert.assertEquals(blockLevelsRead, trailer.getNumDataIndexLevels() + 1);
+ assertEquals(blockLevelsRead, trailer.getNumDataIndexLevels() + 1);
}
private void assertBytesReadFromBlockCache(TableName tableName,
long actualBytesReadFromBlockCache, KeyValue keyValue) throws Exception {
List<HRegion> regions = UTIL.getMiniHBaseCluster().getRegions(tableName);
- Assert.assertEquals(1, regions.size());
+ assertEquals(1, regions.size());
MutableInt totalExpectedBytesReadFromBlockCache = new MutableInt(0);
for (HRegion region : regions) {
- Assert.assertNotNull(region.getBlockCache());
+ assertNotNull(region.getBlockCache());
HStore store = region.getStore(CF);
Collection<HStoreFile> storeFiles = store.getStorefiles();
- Assert.assertEquals(2, storeFiles.size());
+ assertEquals(2, storeFiles.size());
for (HStoreFile storeFile : storeFiles) {
StoreFileReader reader = storeFile.getReader();
HFile.Reader hfileReader = reader.getHFileReader();
BloomFilter bloomFilter = reader.getGeneralBloomFilter();
- Assert.assertTrue(bloomFilter == null || bloomFilter instanceof CompoundBloomFilter);
+ assertTrue(bloomFilter == null || bloomFilter instanceof CompoundBloomFilter);
CompoundBloomFilter cbf = bloomFilter == null ? null : (CompoundBloomFilter) bloomFilter;
Consumer<HFileBlock> bytesReadFunction = new Consumer<HFileBlock>() {
@Override
@@ -839,23 +839,22 @@ public class TestBytesReadServerSideScanMetrics {
readHFile(hfileReader, cbf, keyValue, bytesReadFunction);
}
}
- Assert.assertEquals(totalExpectedBytesReadFromBlockCache.longValue(),
- actualBytesReadFromBlockCache);
+ assertEquals(totalExpectedBytesReadFromBlockCache.longValue(), actualBytesReadFromBlockCache);
}
private void assertBlockCacheWarmUp(TableName tableName, KeyValue keyValue) throws Exception {
List<HRegion> regions = UTIL.getMiniHBaseCluster().getRegions(tableName);
- Assert.assertEquals(1, regions.size());
+ assertEquals(1, regions.size());
for (HRegion region : regions) {
- Assert.assertNotNull(region.getBlockCache());
+ assertNotNull(region.getBlockCache());
HStore store = region.getStore(CF);
Collection<HStoreFile> storeFiles = store.getStorefiles();
- Assert.assertEquals(2, storeFiles.size());
+ assertEquals(2, storeFiles.size());
for (HStoreFile storeFile : storeFiles) {
StoreFileReader reader = storeFile.getReader();
HFile.Reader hfileReader = reader.getHFileReader();
BloomFilter bloomFilter = reader.getGeneralBloomFilter();
- Assert.assertTrue(bloomFilter == null || bloomFilter instanceof CompoundBloomFilter);
+ assertTrue(bloomFilter == null || bloomFilter instanceof CompoundBloomFilter);
CompoundBloomFilter cbf = bloomFilter == null ? null : (CompoundBloomFilter) bloomFilter;
Consumer<HFileBlock> bytesReadFunction = new Consumer<HFileBlock>() {
@Override
@@ -876,9 +875,9 @@ public class TestBytesReadServerSideScanMetrics {
Path path = hfileReader.getPath();
BlockCacheKey key = new BlockCacheKey(path, block.getOffset(), true, block.getBlockType());
HFileBlock cachedBlock = (HFileBlock) blockCache.getBlock(key, true, false, true);
- Assert.assertNotNull(cachedBlock);
- Assert.assertEquals(block.getOnDiskSizeWithHeader(), cachedBlock.getOnDiskSizeWithHeader());
- Assert.assertEquals(block.getNextBlockOnDiskSize(), cachedBlock.getNextBlockOnDiskSize());
+ assertNotNull(cachedBlock);
+ assertEquals(block.getOnDiskSizeWithHeader(), cachedBlock.getOnDiskSizeWithHeader());
+ assertEquals(block.getNextBlockOnDiskSize(), cachedBlock.getNextBlockOnDiskSize());
cachedBlock.release();
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCacheOnWriteInSchema.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCacheOnWriteInSchema.java
index 6ac3c4e07d2..bd61bb87a70 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCacheOnWriteInSchema.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCacheOnWriteInSchema.java
@@ -17,17 +17,15 @@
*/
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;
-import java.util.Collection;
-import java.util.List;
import java.util.Random;
+import java.util.stream.Stream;
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.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.TableName;
@@ -53,16 +51,12 @@ import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CommonFSUtils;
import org.apache.hadoop.hbase.wal.AbstractFSWALProvider;
-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.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -70,28 +64,22 @@ import org.slf4j.LoggerFactory;
* Tests {@link HFile} cache-on-write functionality for data blocks, non-root index blocks, and
* Bloom filter blocks, as specified by the column family.
*/
-@RunWith(Parameterized.class)
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: cacheOnWrite={0}")
public class TestCacheOnWriteInSchema {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCacheOnWriteInSchema.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestCacheOnWriteInSchema.class);
- @Rule
- public TestName name = new TestName();
private static final HBaseTestingUtility TEST_UTIL = HBaseTestingUtility.createLocalHTU();
private static final String DIR = TEST_UTIL.getDataTestDir("TestCacheOnWriteInSchema").toString();
- private static byte[] table;
private static byte[] family = Bytes.toBytes("family");
private static final int NUM_KV = 25000;
private static final Random rand = new Random(12983177L);
/** The number of valid key types possible in a store file */
private static final int NUM_VALID_KEY_TYPES = KeyValue.Type.values().length - 2;
- private static enum CacheOnWriteType {
+ private enum CacheOnWriteType {
DATA_BLOCKS(BlockType.DATA, BlockType.ENCODED_DATA),
BLOOM_BLOCKS(BlockType.BLOOM_CHUNK),
INDEX_BLOCKS(BlockType.LEAF_INDEX, BlockType.INTERMEDIATE_INDEX);
@@ -99,11 +87,11 @@ public class TestCacheOnWriteInSchema {
private final BlockType blockType1;
private final BlockType blockType2;
- private CacheOnWriteType(BlockType blockType) {
+ CacheOnWriteType(BlockType blockType) {
this(blockType, blockType);
}
- private CacheOnWriteType(BlockType blockType1, BlockType blockType2) {
+ CacheOnWriteType(BlockType blockType1, BlockType blockType2) {
this.blockType1 = blockType1;
this.blockType2 = blockType2;
}
@@ -141,19 +129,14 @@ public class TestCacheOnWriteInSchema {
System.out.println(testDescription);
}
- @Parameters
- public static Collection<Object[]> getParameters() {
- List<Object[]> cowTypes = new ArrayList<>();
- for (CacheOnWriteType cowType : CacheOnWriteType.values()) {
- cowTypes.add(new Object[] { cowType });
- }
- return cowTypes;
+ public static Stream<Arguments> parameters() {
+ return Stream.of(CacheOnWriteType.values()).map(Arguments::of);
}
- @Before
- public void setUp() throws IOException {
- // parameterized tests add [#] suffix get rid of [ and ].
- table = Bytes.toBytes(name.getMethodName().replaceAll("[\\[\\]]", "_"));
+ @BeforeEach
+ public void setUp(TestInfo testInfo) throws IOException {
+ String name = testInfo.getTestMethod().get().getName() + "_" + cowType;
+ byte[] table = Bytes.toBytes(name);
conf = TEST_UTIL.getConfiguration();
conf.setInt(HFile.FORMAT_VERSION_KEY, HFile.MAX_FORMAT_VERSION);
@@ -183,7 +166,7 @@ public class TestCacheOnWriteInSchema {
store = region.getStore(hcd.getName());
}
- @After
+ @AfterEach
public void tearDown() throws IOException {
IOException ex = null;
try {
@@ -203,7 +186,7 @@ public class TestCacheOnWriteInSchema {
}
}
- @Test
+ @TestTemplate
public void testCacheOnWriteInSchema() throws IOException {
// Write some random data into the store
StoreFileWriter writer = store.getStoreEngine()
@@ -226,7 +209,7 @@ public class TestCacheOnWriteInSchema {
try {
// Open a scanner with (on read) caching disabled
HFileScanner scanner = reader.getScanner(conf, false, false);
- assertTrue(testDescription, scanner.seekTo());
+ assertTrue(scanner.seekTo(), testDescription);
// Cribbed from io.hfile.TestCacheOnWrite
long offset = 0;
while (offset < reader.getTrailer().getLoadOnOpenDataOffset()) {
@@ -279,5 +262,4 @@ public class TestCacheOnWriteInSchema {
writer.append(kv);
}
}
-
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCellFlatSet.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCellFlatSet.java
index efad9d38e0c..7a0b428c946 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCellFlatSet.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCellFlatSet.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.lang.management.ManagementFactory;
import java.nio.ByteBuffer;
@@ -28,11 +28,12 @@ import java.util.Iterator;
import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.SortedSet;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellComparator;
import org.apache.hadoop.hbase.CellUtil;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValueUtil;
import org.apache.hadoop.hbase.io.util.MemorySizeUtil;
@@ -42,24 +43,19 @@ import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.ByteBufferUtils;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.ClassSize;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-@Category({ RegionServerTests.class, SmallTests.class })
-@RunWith(Parameterized.class)
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
+
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: chunkType={0}")
public class TestCellFlatSet {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCellFlatSet.class);
-
- @Parameterized.Parameters
- public static Object[] data() {
- return new Object[] { "SMALL_CHUNKS", "NORMAL_CHUNKS" }; // test with different chunk sizes
+ public static Stream<Arguments> parameters() {
+ // test with different chunk sizes
+ return Stream.of(Arguments.of("SMALL_CHUNKS"), Arguments.of("NORMAL_CHUNKS"));
}
private static final int NUM_OF_CELLS = 4;
@@ -98,7 +94,7 @@ public class TestCellFlatSet {
}
}
- @Before
+ @BeforeEach
public void setUp() throws Exception {
// create array of Cells to bass to the CellFlatMap under CellSet
final byte[] one = Bytes.toBytes(15);
@@ -136,7 +132,7 @@ public class TestCellFlatSet {
}
/* Create and test ascending CellSet based on CellArrayMap */
- @Test
+ @TestTemplate
public void testCellArrayMapAsc() throws Exception {
CellSet cs = new CellSet(ascCbOnHeap);
testCellBlocks(cs);
@@ -144,7 +140,7 @@ public class TestCellFlatSet {
}
/* Create and test ascending and descending CellSet based on CellChunkMap */
- @Test
+ @TestTemplate
public void testCellChunkMap() throws Exception {
CellSet cs = new CellSet(ascCCM);
testCellBlocks(cs);
@@ -159,14 +155,14 @@ public class TestCellFlatSet {
// testSubSet(cs);
}
- @Test
+ @TestTemplate
public void testAsc() throws Exception {
CellSet ascCs = new CellSet(ascCbOnHeap);
assertEquals(NUM_OF_CELLS, ascCs.size());
testSubSet(ascCs);
}
- @Test
+ @TestTemplate
public void testDesc() throws Exception {
CellSet descCs = new CellSet(descCbOnHeap);
assertEquals(NUM_OF_CELLS, descCs.size());
@@ -260,13 +256,12 @@ public class TestCellFlatSet {
// Assert that we have NUM_OF_CELLS values and that they are in order
int count = 0;
for (Cell kv : cs) {
- assertEquals(
+ assertEquals(ascCells[count], kv,
"\n\n-------------------------------------------------------------------\n"
+ "Comparing iteration number " + (count + 1) + " the returned cell: " + kv
+ ", the first Cell in the CellBlocksMap: " + ascCells[count]
+ ", and the same transformed to String: " + ascCells[count].toString()
- + "\n-------------------------------------------------------------------\n",
- ascCells[count], kv);
+ + "\n-------------------------------------------------------------------\n");
count++;
}
assertEquals(NUM_OF_CELLS, count);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCellSkipListSet.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCellSkipListSet.java
index b8ee022c9c2..772c82bb759 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCellSkipListSet.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCellSkipListSet.java
@@ -17,47 +17,40 @@
*/
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.util.Iterator;
import java.util.SortedSet;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellComparatorImpl;
import org.apache.hadoop.hbase.CellUtil;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.KeyValue;
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.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;
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCellSkipListSet {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCellSkipListSet.class);
-
private final CellSet csls = new CellSet(CellComparatorImpl.COMPARATOR);
+ private String name;
- @Rule
- public TestName name = new TestName();
-
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ public void setUp(TestInfo testInfo) throws Exception {
+ this.name = testInfo.getTestMethod().get().getName();
this.csls.clear();
}
@Test
public void testAdd() throws Exception {
- byte[] bytes = Bytes.toBytes(name.getMethodName());
+ byte[] bytes = Bytes.toBytes(name);
KeyValue kv = new KeyValue(bytes, bytes, bytes, bytes);
this.csls.add(kv);
assertTrue(this.csls.contains(kv));
@@ -80,7 +73,7 @@ public class TestCellSkipListSet {
@Test
public void testIterator() throws Exception {
- byte[] bytes = Bytes.toBytes(name.getMethodName());
+ byte[] bytes = Bytes.toBytes(name);
byte[] value1 = Bytes.toBytes("1");
byte[] value2 = Bytes.toBytes("2");
final int total = 3;
@@ -116,7 +109,7 @@ public class TestCellSkipListSet {
@Test
public void testDescendingIterator() throws Exception {
- byte[] bytes = Bytes.toBytes(name.getMethodName());
+ byte[] bytes = Bytes.toBytes(name);
byte[] value1 = Bytes.toBytes("1");
byte[] value2 = Bytes.toBytes("2");
final int total = 3;
@@ -154,7 +147,7 @@ public class TestCellSkipListSet {
@Test
public void testHeadTail() throws Exception {
- byte[] bytes = Bytes.toBytes(name.getMethodName());
+ byte[] bytes = Bytes.toBytes(name);
byte[] value1 = Bytes.toBytes("1");
byte[] value2 = Bytes.toBytes("2");
final int total = 3;
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCleanupCompactedFileAfterFailover.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCleanupCompactedFileAfterFailover.java
index 6ae5a2fdb15..d309d4a8692 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCleanupCompactedFileAfterFailover.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCleanupCompactedFileAfterFailover.java
@@ -17,12 +17,11 @@
*/
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.util.ArrayList;
import java.util.List;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
@@ -37,26 +36,21 @@ import org.apache.hadoop.hbase.regionserver.compactions.CompactionConfiguration;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.JVMClusterUtil;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category({ LargeTests.class })
+@Tag(LargeTests.TAG)
public class TestCleanupCompactedFileAfterFailover {
private static final Logger LOG =
LoggerFactory.getLogger(TestCleanupCompactedFileAfterFailover.class);
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCleanupCompactedFileAfterFailover.class);
-
private static HBaseTestingUtility TEST_UTIL;
private static Admin admin;
private static Table table;
@@ -68,7 +62,7 @@ public class TestCleanupCompactedFileAfterFailover {
private static byte[] VALUE = Bytes.toBytes("value");
private static final int RS_NUMBER = 5;
- @BeforeClass
+ @BeforeAll
public static void beforeClass() throws Exception {
TEST_UTIL = new HBaseTestingUtility();
// Set the scanner lease to 20min, so the scanner can't be closed by RegionServer
@@ -82,12 +76,12 @@ public class TestCleanupCompactedFileAfterFailover {
admin = TEST_UTIL.getAdmin();
}
- @AfterClass
+ @AfterAll
public static void afterClass() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
- @Before
+ @BeforeEach
public void before() throws Exception {
TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TABLE_NAME);
builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY));
@@ -96,7 +90,7 @@ public class TestCleanupCompactedFileAfterFailover {
table = TEST_UTIL.getConnection().getTable(TABLE_NAME);
}
- @After
+ @AfterEach
public void after() throws Exception {
admin.disableTable(TABLE_NAME);
admin.deleteTable(TABLE_NAME);
@@ -129,7 +123,7 @@ public class TestCleanupCompactedFileAfterFailover {
}
}
assertNotNull(rsServedTable);
- assertEquals("Table should only have one region", 1, regions.size());
+ assertEquals(1, regions.size(), "Table should only have one region");
HRegion region = regions.get(0);
HStore store = region.getStore(FAMILY);
@@ -159,7 +153,7 @@ public class TestCleanupCompactedFileAfterFailover {
// Flush again
region.flush(true);
// The WAL which contains compaction event marker should be archived
- assertEquals("The old WAL should be archived", walNum, rsServedTable.getWALs().size());
+ assertEquals(walNum, rsServedTable.getWALs().size(), "The old WAL should be archived");
rsServedTable.kill();
// Sleep to wait failover
@@ -174,7 +168,7 @@ public class TestCleanupCompactedFileAfterFailover {
regions.addAll(rs.getRegions(TABLE_NAME));
}
}
- assertEquals("Table should only have one region", 1, regions.size());
+ assertEquals(1, regions.size(), "Table should only have one region");
region = regions.get(0);
store = region.getStore(FAMILY);
// The compacted storefile should be cleaned and only have 1 storefile
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCleanupCompactedFileOnRegionClose.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCleanupCompactedFileOnRegionClose.java
index 8e63da5a6b8..ab20da41389 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCleanupCompactedFileOnRegionClose.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCleanupCompactedFileOnRegionClose.java
@@ -17,13 +17,12 @@
*/
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.util.Collection;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Delete;
@@ -38,22 +37,17 @@ import org.apache.hadoop.hbase.master.cleaner.TimeToLiveHFileCleaner;
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;
-@Category({ MediumTests.class })
+@Tag(MediumTests.TAG)
public class TestCleanupCompactedFileOnRegionClose {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCleanupCompactedFileOnRegionClose.class);
-
private static HBaseTestingUtility util;
- @BeforeClass
+ @BeforeAll
public static void beforeClass() throws Exception {
util = new HBaseTestingUtility();
util.getConfiguration().setInt(CompactionConfiguration.HBASE_HSTORE_COMPACTION_MIN_KEY, 100);
@@ -63,7 +57,7 @@ public class TestCleanupCompactedFileOnRegionClose {
util.startMiniCluster(2);
}
- @AfterClass
+ @AfterAll
public static void afterclass() throws Exception {
util.shutdownMiniCluster();
}
@@ -132,8 +126,8 @@ public class TestCleanupCompactedFileOnRegionClose {
hBaseAdmin.assign(region.getRegionInfo().getRegionName());
util.waitUntilNoRegionsInTransition(10000);
- assertFalse("Deleted row should not exist",
- table.exists(new Get(Bytes.toBytes(refSFCount - 1))));
+ assertFalse(table.exists(new Get(Bytes.toBytes(refSFCount - 1))),
+ "Deleted row should not exist");
rs = util.getRSForFirstRegionInTable(tableName);
region = rs.getRegions(tableName).get(0);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCleanupMetaWAL.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCleanupMetaWAL.java
index f6f91fa7729..5e27b642b3d 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCleanupMetaWAL.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCleanupMetaWAL.java
@@ -18,11 +18,10 @@
package org.apache.hadoop.hbase.regionserver;
import static org.apache.hadoop.hbase.wal.AbstractFSWALProvider.SPLITTING_EXT;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.fail;
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.TableName;
@@ -31,32 +30,28 @@ import org.apache.hadoop.hbase.master.MasterFileSystem;
import org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.CommonFSUtils;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category(MediumTests.class)
+@Tag(MediumTests.TAG)
public class TestCleanupMetaWAL {
+
private static final Logger LOG = LoggerFactory.getLogger(TestCleanupMetaWAL.class);
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCleanupMetaWAL.class);
-
- @BeforeClass
+ @BeforeAll
public static void before() throws Exception {
TEST_UTIL.startMiniCluster(2);
}
- @AfterClass
+ @AfterAll
public static void after() throws Exception {
- TEST_UTIL.shutdownMiniZKCluster();
+ TEST_UTIL.shutdownMiniCluster();
}
@Test
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestClearRegionBlockCache.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestClearRegionBlockCache.java
index 6076f12d06c..3c1d35b4bbe 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestClearRegionBlockCache.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestClearRegionBlockCache.java
@@ -17,14 +17,15 @@
*/
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;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CacheEvictionStats;
import org.apache.hadoop.hbase.Cell;
-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.MiniHBaseCluster;
@@ -38,24 +39,18 @@ import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.io.hfile.BlockCache;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category(LargeTests.class)
-@RunWith(Parameterized.class)
+@Tag(LargeTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: {0}")
public class TestClearRegionBlockCache {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestClearRegionBlockCache.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestClearRegionBlockCache.class);
private static final TableName TABLE_NAME = TableName.valueOf("testClearRegionBlockCache");
private static final byte[] FAMILY = Bytes.toBytes("family");
@@ -69,15 +64,17 @@ public class TestClearRegionBlockCache {
private HRegionServer rs1, rs2;
private MiniHBaseCluster cluster;
- @Parameterized.Parameter
- public String cacheType;
+ private final String cacheType;
+
+ public TestClearRegionBlockCache(String cacheType) {
+ this.cacheType = cacheType;
+ }
- @Parameterized.Parameters(name = "{index}: {0}")
- public static Object[] data() {
- return new Object[] { "lru", "bucket" };
+ public static Stream<Arguments> parameters() {
+ return Stream.of(Arguments.of("lru"), Arguments.of("bucket"));
}
- @Before
+ @BeforeEach
public void setup() throws Exception {
if (cacheType.equals("bucket")) {
CONF.set(HConstants.BUCKET_CACHE_IOENGINE_KEY, "offheap");
@@ -95,12 +92,12 @@ public class TestClearRegionBlockCache {
HTU.flush(TABLE_NAME);
}
- @After
+ @AfterEach
public void teardown() throws Exception {
HTU.shutdownMiniCluster();
}
- @Test
+ @TestTemplate
public void testClearBlockCache() throws Exception {
BlockCache blockCache1 = rs1.getBlockCache().get();
BlockCache blockCache2 = rs2.getBlockCache().get();
@@ -119,11 +116,11 @@ public class TestClearRegionBlockCache {
HTU.getNumHFilesForRS(rs2, TABLE_NAME, FAMILY));
clearRegionBlockCache(rs2);
- assertEquals("" + blockCache1.getBlockCount(), initialBlockCount1, blockCache1.getBlockCount());
- assertEquals("" + blockCache2.getBlockCount(), initialBlockCount2, blockCache2.getBlockCount());
+ assertEquals(initialBlockCount1, blockCache1.getBlockCount(), "" + blockCache1.getBlockCount());
+ assertEquals(initialBlockCount2, blockCache2.getBlockCount(), "" + blockCache2.getBlockCount());
}
- @Test
+ @TestTemplate
public void testClearBlockCacheFromAdmin() throws Exception {
Admin admin = HTU.getAdmin();
@@ -147,7 +144,7 @@ public class TestClearRegionBlockCache {
assertEquals(initialBlockCount2, blockCache2.getBlockCount());
}
- @Test
+ @TestTemplate
public void testClearBlockCacheFromAsyncAdmin() throws Exception {
try (AsyncConnection conn =
ConnectionFactory.createAsyncConnection(HTU.getConfiguration()).get()) {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestClusterId.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestClusterId.java
index eae020f9559..ad7260d5b11 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestClusterId.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestClusterId.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 org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
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.HConstants;
@@ -36,32 +35,28 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.util.CommonFSUtils;
import org.apache.hadoop.hbase.util.JVMClusterUtil;
import org.apache.hadoop.hbase.zookeeper.ZKClusterId;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* Test metrics incremented on region server operations.
*/
-@Category({ RegionServerTests.class, MediumTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(MediumTests.TAG)
public class TestClusterId {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestClusterId.class);
-
private final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private JVMClusterUtil.RegionServerThread rst;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
TEST_UTIL.getConfiguration().setBoolean(ShutdownHook.RUN_SHUTDOWN_HOOK, false);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
TEST_UTIL.shutdownMiniCluster();
if (rst != null && rst.getRegionServer() != null) {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestColumnSeeking.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestColumnSeeking.java
index d73f82b9897..72480e3b173 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestColumnSeeking.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestColumnSeeking.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;
@@ -28,7 +28,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
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.HRegionInfo;
@@ -42,23 +41,24 @@ import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
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.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 TestColumnSeeking {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestColumnSeeking.class);
+ private String name;
+
+ @BeforeEach
+ public void setTestName(TestInfo testInfo) {
+ this.name = testInfo.getTestMethod().get().getName();
+ }
- @Rule
- public TestName name = new TestName();
private final static HBaseTestingUtility TEST_UTIL = HBaseTestingUtility.createLocalHTU();
private static final Logger LOG = LoggerFactory.getLogger(TestColumnSeeking.class);
@@ -68,7 +68,7 @@ public class TestColumnSeeking {
public void testDuplicateVersions() throws IOException {
String family = "Family";
byte[] familyBytes = Bytes.toBytes("Family");
- TableName table = TableName.valueOf(name.getMethodName());
+ TableName table = TableName.valueOf(name);
HColumnDescriptor hcd = new HColumnDescriptor(familyBytes).setMaxVersions(1000);
hcd.setMaxVersions(3);
@@ -178,7 +178,7 @@ public class TestColumnSeeking {
public void testReseeking() throws IOException {
String family = "Family";
byte[] familyBytes = Bytes.toBytes("Family");
- TableName table = TableName.valueOf(name.getMethodName());
+ TableName table = TableName.valueOf(name);
HTableDescriptor htd = new HTableDescriptor(table);
HColumnDescriptor hcd = new HColumnDescriptor(family);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactSplitThread.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactSplitThread.java
index 975b1fb631a..f70e47f0dfd 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactSplitThread.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactSplitThread.java
@@ -17,13 +17,13 @@
*/
package org.apache.hadoop.hbase.regionserver;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Collection;
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.HTableDescriptor;
@@ -36,23 +36,14 @@ import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CommonFSUtils;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Category(MediumTests.class)
-public class TestCompactSplitThread {
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCompactSplitThread.class);
+@Tag(MediumTests.TAG)
+public class TestCompactSplitThread {
- private static final Logger LOG = LoggerFactory.getLogger(TestCompactSplitThread.class);
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private final TableName tableName = TableName.valueOf(getClass().getSimpleName());
private final byte[] family = Bytes.toBytes("f");
@@ -64,7 +55,7 @@ public class TestCompactSplitThread {
/**
* Setup the config for the cluster
*/
- @Before
+ @BeforeEach
public void setupCluster() throws Exception {
setupConf(TEST_UTIL.getConfiguration());
TEST_UTIL.startMiniCluster(NUM_RS);
@@ -91,7 +82,7 @@ public class TestCompactSplitThread {
conf.setInt(CompactSplit.SPLIT_THREADS, 5);
}
- @After
+ @AfterEach
public void cleanupTest() throws Exception {
try {
TEST_UTIL.shutdownMiniCluster();
@@ -121,11 +112,8 @@ public class TestCompactSplitThread {
conf.setInt(CompactSplit.LARGE_COMPACTION_THREADS, 4);
conf.setInt(CompactSplit.SMALL_COMPACTION_THREADS, 5);
conf.setInt(CompactSplit.SPLIT_THREADS, 6);
- try {
- regionServer.getCompactSplitThread().onConfigurationChange(conf);
- } catch (IllegalArgumentException iae) {
- Assert.fail("Update bigger configuration failed!");
- }
+ assertDoesNotThrow(() -> regionServer.getCompactSplitThread().onConfigurationChange(conf),
+ "Update bigger configuration failed!");
// check again after online update
assertEquals(4, regionServer.getCompactSplitThread().getLargeCompactionThreadNum());
@@ -136,11 +124,8 @@ public class TestCompactSplitThread {
conf.setInt(CompactSplit.LARGE_COMPACTION_THREADS, 2);
conf.setInt(CompactSplit.SMALL_COMPACTION_THREADS, 3);
conf.setInt(CompactSplit.SPLIT_THREADS, 4);
- try {
- regionServer.getCompactSplitThread().onConfigurationChange(conf);
- } catch (IllegalArgumentException iae) {
- Assert.fail("Update smaller configuration failed!");
- }
+ assertDoesNotThrow(() -> regionServer.getCompactSplitThread().onConfigurationChange(conf),
+ "Update smaller configuration failed!");
// check again after online update
assertEquals(2, regionServer.getCompactSplitThread().getLargeCompactionThreadNum());
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingMemStore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingMemStore.java
index 46c65bed817..c4df1dd0f25 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingMemStore.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingMemStore.java
@@ -17,11 +17,11 @@
*/
package org.apache.hadoop.hbase.regionserver;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.lang.management.ManagementFactory;
@@ -33,7 +33,6 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellComparator;
import org.apache.hadoop.hbase.CellUtil;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
@@ -55,11 +54,8 @@ import org.apache.hadoop.hbase.util.EnvironmentEdge;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.wal.WAL;
-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.Tag;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -67,37 +63,26 @@ import org.slf4j.LoggerFactory;
/**
* compacted memstore test case
*/
-@Category({ RegionServerTests.class, MediumTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(MediumTests.TAG)
public class TestCompactingMemStore extends TestDefaultMemStore {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCompactingMemStore.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestCompactingMemStore.class);
protected static ChunkCreator chunkCreator;
protected HRegion region;
protected RegionServicesForStores regionServicesForStores;
protected HStore store;
+ private Configuration conf;
- @After
- public void tearDown() throws Exception {
+ @Override
+ protected void internalTearDown() throws Exception {
chunkCreator.clearChunksInPool();
- super.tearDown();
}
@Override
- @Before
- public void setUp() throws Exception {
- compactingSetUp();
- this.memstore = new MyCompactingMemStore(HBaseConfiguration.create(),
- CellComparator.getInstance(), store, regionServicesForStores, MemoryCompactionPolicy.EAGER);
- ((CompactingMemStore) memstore).setIndexType(CompactingMemStore.IndexType.ARRAY_MAP);
- }
-
- protected void compactingSetUp() throws Exception {
+ protected void internalSetUp() throws Exception {
super.internalSetUp();
- Configuration conf = new Configuration();
+ conf = new Configuration();
conf.setBoolean(MemStoreLAB.USEMSLAB_KEY, true);
conf.setFloat(MemStoreLAB.CHUNK_POOL_MAXSIZE_KEY, 0.2f);
conf.setInt(HRegion.MEMSTORE_PERIODIC_FLUSH_INTERVAL, 1000);
@@ -112,7 +97,10 @@ public class TestCompactingMemStore extends TestDefaultMemStore {
ThreadPoolExecutor pool = (ThreadPoolExecutor) Executors.newFixedThreadPool(1);
Mockito.when(regionServicesForStores.getInMemoryCompactionPool()).thenReturn(pool);
this.store = new HStore(region, hcd, conf, false);
+ }
+ @Override
+ protected void createChunkCreator() {
long globalMemStoreLimit =
(long) (ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax()
* MemorySizeUtil.getGlobalMemStoreHeapPercent(conf, false));
@@ -122,6 +110,13 @@ public class TestCompactingMemStore extends TestDefaultMemStore {
assertNotNull(chunkCreator);
}
+ @Override
+ protected void createMemStore() throws IOException {
+ this.memstore = new MyCompactingMemStore(HBaseConfiguration.create(),
+ CellComparator.getInstance(), store, regionServicesForStores, MemoryCompactionPolicy.EAGER);
+ ((CompactingMemStore) memstore).setIndexType(CompactingMemStore.IndexType.ARRAY_MAP);
+ }
+
/**
* A simple test which flush in memory affect timeOfOldestEdit
*/
@@ -198,7 +193,7 @@ public class TestCompactingMemStore extends TestDefaultMemStore {
for (int i = 0; i < snapshotCount; i++) {
addRows(this.memstore);
runSnapshot(this.memstore, true);
- assertEquals("History not being cleared", 0, this.memstore.getSnapshot().getCellsCount());
+ assertEquals(0, this.memstore.getSnapshot().getCellsCount(), "History not being cleared");
}
}
@@ -217,16 +212,16 @@ public class TestCompactingMemStore extends TestDefaultMemStore {
Thread.sleep(1);
addRows(this.memstore);
Cell closestToEmpty = ((CompactingMemStore) this.memstore).getNextRow(KeyValue.LOWESTKEY);
- assertTrue(CellComparator.getInstance().compareRows(closestToEmpty,
- new KeyValue(Bytes.toBytes(0), EnvironmentEdgeManager.currentTime())) == 0);
+ assertEquals(0, CellComparator.getInstance().compareRows(closestToEmpty,
+ new KeyValue(Bytes.toBytes(0), EnvironmentEdgeManager.currentTime())));
for (int i = 0; i < ROW_COUNT; i++) {
Cell nr = ((CompactingMemStore) this.memstore)
.getNextRow(new KeyValue(Bytes.toBytes(i), EnvironmentEdgeManager.currentTime()));
if (i + 1 == ROW_COUNT) {
assertNull(nr);
} else {
- assertTrue(CellComparator.getInstance().compareRows(nr,
- new KeyValue(Bytes.toBytes(i + 1), EnvironmentEdgeManager.currentTime())) == 0);
+ assertEquals(0, CellComparator.getInstance().compareRows(nr,
+ new KeyValue(Bytes.toBytes(i + 1), EnvironmentEdgeManager.currentTime())));
}
}
// starting from each row, validate results should contain the starting row
@@ -243,9 +238,9 @@ public class TestCompactingMemStore extends TestDefaultMemStore {
int rowId = startRowId + i;
Cell left = results.get(0);
byte[] row1 = Bytes.toBytes(rowId);
- assertTrue("Row name",
- CellComparator.getInstance().compareRows(left, row1, 0, row1.length) == 0);
- assertEquals("Count of columns", QUALIFIER_COUNT, results.size());
+ assertEquals(0, CellComparator.getInstance().compareRows(left, row1, 0, row1.length),
+ "Row name");
+ assertEquals(QUALIFIER_COUNT, results.size(), "Count of columns");
List<Cell> row = new ArrayList<>();
for (Cell kv : results) {
row.add(kv);
@@ -346,7 +341,7 @@ public class TestCompactingMemStore extends TestDefaultMemStore {
// test the case that the timeOfOldestEdit is updated after a KV add
memstore.add(KeyValueTestUtil.create("r", "f", "q", 100, "v"), null);
t = memstore.timeOfOldestEdit();
- assertTrue(t == 1234);
+ assertEquals(1234, t);
// The method will also assert
// the value is reset to Long.MAX_VALUE
t = runSnapshot(memstore, true);
@@ -354,7 +349,7 @@ public class TestCompactingMemStore extends TestDefaultMemStore {
// test the case that the timeOfOldestEdit is updated after a KV delete
memstore.add(KeyValueTestUtil.create("r", "f", "q", 100, KeyValue.Type.Delete, "v"), null);
t = memstore.timeOfOldestEdit();
- assertTrue(t == 1234);
+ assertEquals(1234, t);
t = runSnapshot(memstore, true);
// test the case that the timeOfOldestEdit is updated after a KV upsert
@@ -364,7 +359,7 @@ public class TestCompactingMemStore extends TestDefaultMemStore {
l.add(kv1);
memstore.upsert(l, 1000, null);
t = memstore.timeOfOldestEdit();
- assertTrue(t == 1234);
+ assertEquals(1234, t);
} finally {
EnvironmentEdgeManager.reset();
}
@@ -379,13 +374,13 @@ public class TestCompactingMemStore extends TestDefaultMemStore {
MemStoreSnapshot snapshot = hmc.snapshot();
if (useForce) {
// Make some assertions about what just happened.
- assertTrue("History size has not increased", oldHistorySize < snapshot.getDataSize());
+ assertTrue(oldHistorySize < snapshot.getDataSize(), "History size has not increased");
long t = hmc.timeOfOldestEdit();
- assertTrue("Time of oldest edit is not Long.MAX_VALUE", t == Long.MAX_VALUE);
+ assertEquals(Long.MAX_VALUE, t, "Time of oldest edit is not Long.MAX_VALUE");
hmc.clearSnapshot(snapshot.getId());
} else {
long t = hmc.timeOfOldestEdit();
- assertTrue("Time of oldest edit didn't remain the same", t == prevTimeStamp);
+ assertEquals(t, prevTimeStamp, "Time of oldest edit didn't remain the same");
}
return prevTimeStamp;
}
@@ -394,12 +389,12 @@ public class TestCompactingMemStore extends TestDefaultMemStore {
int i = 0;
for (Cell kv : kvs) {
byte[] expectedColname = makeQualifier(rowIndex, i++);
- assertTrue("Column name", CellUtil.matchingQualifier(kv, expectedColname));
+ assertTrue(CellUtil.matchingQualifier(kv, expectedColname), "Column name");
// Value is column name as bytes. Usually result is
// 100 bytes in size at least. This is the default size
// for BytesWriteable. For comparison, convert bytes to
// String and trim to remove trailing null bytes.
- assertTrue("Content", CellUtil.matchingValue(kv, expectedColname));
+ assertTrue(CellUtil.matchingValue(kv, expectedColname), "Content");
}
}
@@ -477,7 +472,7 @@ public class TestCompactingMemStore extends TestDefaultMemStore {
}
memstore.clearSnapshot(snapshot.getId());
- assertTrue(chunkCreator.getPoolSize() == 0);
+ assertEquals(0, chunkCreator.getPoolSize());
// Chunks will be put back to pool after close scanners;
for (KeyValueScanner scanner : scanners) {
@@ -558,7 +553,7 @@ public class TestCompactingMemStore extends TestDefaultMemStore {
memstore.add(new KeyValue(row, fam, qf1, 3, val), null);
assertEquals(3, memstore.getActive().getCellsCount());
- assertTrue(chunkCreator.getPoolSize() == 0);
+ assertEquals(0, chunkCreator.getPoolSize());
// Chunks will be put back to pool after close scanners;
for (KeyValueScanner scanner : scanners) {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingToCellFlatMapMemStore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingToCellFlatMapMemStore.java
index e73c40f69b9..2c85dac5f33 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingToCellFlatMapMemStore.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingToCellFlatMapMemStore.java
@@ -17,70 +17,70 @@
*/
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;
import java.util.List;
+import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellComparatorImpl;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.MemoryCompactionPolicy;
-import org.apache.hadoop.hbase.testclassification.LargeTests;
+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.ClassSize;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.Threads;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedClass;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* compacted memstore test case
*/
-@Category({ RegionServerTests.class, LargeTests.class })
-@RunWith(Parameterized.class)
+@Tag(RegionServerTests.TAG)
+@Tag(MediumTests.TAG)
+@ParameterizedClass(name = "{index}: type={0}")
+@MethodSource("parameters")
public class TestCompactingToCellFlatMapMemStore extends TestCompactingMemStore {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCompactingToCellFlatMapMemStore.class);
+ private static final Logger LOG =
+ LoggerFactory.getLogger(TestCompactingToCellFlatMapMemStore.class);
- @Parameterized.Parameters
- public static Object[] data() {
- return new Object[] { "CHUNK_MAP", "ARRAY_MAP" }; // test different immutable indexes
+ public static Stream<Arguments> parameters() {
+ // test different immutable indexes
+ return Stream.of(Arguments.of("CHUNK_MAP"), Arguments.of("ARRAY_MAP"));
}
- private static final Logger LOG =
- LoggerFactory.getLogger(TestCompactingToCellFlatMapMemStore.class);
public final boolean toCellChunkMap;
+ private final String type;
Configuration conf;
//////////////////////////////////////////////////////////////////////////////
// Helpers
//////////////////////////////////////////////////////////////////////////////
public TestCompactingToCellFlatMapMemStore(String type) {
+ this.type = type;
toCellChunkMap = "CHUNK_MAP".equals(type);
}
@Override
- public void tearDown() throws Exception {
- chunkCreator.clearChunksInPool();
- super.tearDown();
+ protected String getParameterizedTestNameSuffix() {
+ return "_" + type;
}
@Override
- public void setUp() throws Exception {
- compactingSetUp();
+ protected void createMemStore() throws IOException {
this.conf = HBaseConfiguration.create();
// set memstore to do data compaction
@@ -95,6 +95,7 @@ public class TestCompactingToCellFlatMapMemStore extends TestCompactingMemStore
// Compaction tests
//////////////////////////////////////////////////////////////////////////////
@Override
+ @Test
public void testCompaction1Bucket() throws IOException {
int counter = 0;
String[] keys1 = { "A", "A", "B", "C" }; // A1, A2, B3, C4
@@ -142,6 +143,7 @@ public class TestCompactingToCellFlatMapMemStore extends TestCompactingMemStore
}
@Override
+ @Test
public void testCompaction2Buckets() throws IOException {
if (toCellChunkMap) {
// set memstore to flat into CellChunkMap
@@ -205,6 +207,7 @@ public class TestCompactingToCellFlatMapMemStore extends TestCompactingMemStore
}
@Override
+ @Test
public void testCompaction3Buckets() throws IOException {
if (toCellChunkMap) {
// set memstore to flat into CellChunkMap
@@ -462,7 +465,7 @@ public class TestCompactingToCellFlatMapMemStore extends TestCompactingMemStore
count++;
}
}
- assertEquals("the count should be ", 150, count);
+ assertEquals(150, count, "the count should be ");
for (int i = 0; i < scanners.size(); i++) {
scanners.get(i).close();
}
@@ -489,7 +492,7 @@ public class TestCompactingToCellFlatMapMemStore extends TestCompactingMemStore
} finally {
itr.close();
}
- assertEquals("the count should be ", 150, cnt);
+ assertEquals(150, cnt, "the count should be ");
}
private void addRowsByKeysWith50Cols(AbstractMemStore hmc, String[] keys) {
@@ -830,7 +833,7 @@ public class TestCompactingToCellFlatMapMemStore extends TestCompactingMemStore
* testForceCopyOfBigCellIntoImmutableSegment checks that the ImmutableMemStoreLAB's
* forceCopyOfBigCellInto does what it's supposed to do.
*/
- @org.junit.Ignore
+ @Disabled
@Test // Flakey. Disabled by HBASE-24128. HBASE-24129 is for reenable.
// TestCompactingToCellFlatMapMemStore.testForceCopyOfBigCellIntoImmutableSegment:902 i=1
// expected:<8389924> but was:<8389992>
@@ -893,7 +896,7 @@ public class TestCompactingToCellFlatMapMemStore extends TestCompactingMemStore
totalHeapSize -= (4 * CellChunkImmutableSegment.DEEP_OVERHEAD_CCM);
totalHeapSize = ClassSize.align(totalHeapSize);
}
- assertEquals("i=" + i, totalHeapSize, ((CompactingMemStore) memstore).heapSize());
+ assertEquals(totalHeapSize, ((CompactingMemStore) memstore).heapSize(), "i=" + i);
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompaction.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompaction.java
index 45396e8fa2f..1cbcf3f3c97 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompaction.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompaction.java
@@ -29,11 +29,11 @@ import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.notNullValue;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThrows;
-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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
@@ -61,7 +61,6 @@ import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.ChoreService;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
@@ -90,15 +89,13 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.wal.WAL;
import org.apache.hadoop.io.IOUtils;
-import org.junit.After;
-import org.junit.Assume;
-import org.junit.Before;
-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.AfterEach;
+import org.junit.jupiter.api.Assumptions;
+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.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -107,15 +104,10 @@ import org.slf4j.LoggerFactory;
/**
* Test compaction framework and common functions
*/
-@Category({ RegionServerTests.class, LargeTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(LargeTests.TAG)
public class TestCompaction {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCompaction.class);
-
- @Rule
- public TestName name = new TestName();
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
protected Configuration conf = UTIL.getConfiguration();
@@ -128,6 +120,7 @@ public class TestCompaction {
private byte[] secondRowBytes, thirdRowBytes;
private static final long MAX_FILES_TO_COMPACT = 10;
private final byte[] FAMILY = Bytes.toBytes("cf");
+ private String name;
/** constructor */
public TestCompaction() {
@@ -147,10 +140,11 @@ public class TestCompaction {
(byte) (thirdRowBytes[START_KEY_BYTES.length - 1] + 2);
}
- @Before
- public void setUp() throws Exception {
- this.htd = UTIL.createTableDescriptor(name.getMethodName());
- if (name.getMethodName().equals("testCompactionSeqId")) {
+ @BeforeEach
+ public void setUp(TestInfo testInfo) throws Exception {
+ this.name = testInfo.getTestMethod().get().getName();
+ this.htd = UTIL.createTableDescriptor(name);
+ if (name.equals("testCompactionSeqId")) {
UTIL.getConfiguration().set("hbase.hstore.compaction.kv.max", "10");
UTIL.getConfiguration().set(DefaultStoreEngine.DEFAULT_COMPACTOR_CLASS_KEY,
DummyCompactor.class.getName());
@@ -159,8 +153,8 @@ public class TestCompaction {
this.htd.addFamily(hcd);
}
if (
- name.getMethodName().equals("testCompactionWithCorruptBlock")
- || name.getMethodName().equals("generateHFileForCorruptBlockTest")
+ name.equals("testCompactionWithCorruptBlock")
+ || name.equals("generateHFileForCorruptBlockTest")
) {
UTIL.getConfiguration().setBoolean("hbase.hstore.validate.read_fully", true);
HColumnDescriptor hcd = new HColumnDescriptor(FAMILY);
@@ -170,7 +164,7 @@ public class TestCompaction {
this.r = UTIL.createLocalHRegion(htd, null, null);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
WAL wal = r.getWAL();
this.r.close();
@@ -392,7 +386,7 @@ public class TestCompaction {
* be hand-edited to corrupt the first data block (zero out the GZip magic bytes at offset 33)
* before being placed into the test resources directory.
*/
- @Ignore("Not a test; utility for regenerating testCompactionWithCorruptBlock resource file")
+ @Disabled("Not a test; utility for regenerating testCompactionWithCorruptBlock resource file")
@Test
public void generateHFileForCorruptBlockTest() throws Exception {
createStoreFile(r, Bytes.toString(FAMILY));
@@ -531,10 +525,11 @@ public class TestCompaction {
long postCompletedCount = metricsWrapper.getNumCompactionsCompleted();
long postFailedCount = metricsWrapper.getNumCompactionsFailed();
- assertTrue("Completed count should have increased (pre=" + preCompletedCount + ", post="
- + postCompletedCount + ")", postCompletedCount > preCompletedCount);
- assertTrue("Failed count should have increased (pre=" + preFailedCount + ", post="
- + postFailedCount + ")", postFailedCount > preFailedCount);
+ assertTrue(postCompletedCount > preCompletedCount,
+ "Completed count should have increased (pre=" + preCompletedCount + ", post="
+ + postCompletedCount + ")");
+ assertTrue(postFailedCount > preFailedCount, "Failed count should have increased (pre="
+ + preFailedCount + ", post=" + postFailedCount + ")");
}
}
@@ -560,9 +555,8 @@ public class TestCompaction {
assertFalse(thread.isCompactionsEnabled());
int longCompactions = thread.getLongCompactions().getActiveCount();
int shortCompactions = thread.getShortCompactions().getActiveCount();
- assertEquals(
- "longCompactions=" + longCompactions + "," + "shortCompactions=" + shortCompactions, 0,
- longCompactions + shortCompactions);
+ assertEquals(0, longCompactions + shortCompactions,
+ "longCompactions=" + longCompactions + "," + "shortCompactions=" + shortCompactions);
thread.switchCompaction(true);
assertTrue(thread.isCompactionsEnabled());
// Make sure no compactions have run.
@@ -744,7 +738,7 @@ public class TestCompaction {
this.wait();
}
} catch (InterruptedException e) {
- Assume.assumeNoException(e);
+ Assumptions.abort(e.getMessage());
}
return new ArrayList<>();
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionAfterBulkLoad.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionAfterBulkLoad.java
index bfbbf3d85dc..7033d6e30f6 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionAfterBulkLoad.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionAfterBulkLoad.java
@@ -18,20 +18,21 @@
package org.apache.hadoop.hbase.regionserver;
import static org.apache.hadoop.hbase.regionserver.HRegion.COMPACTION_AFTER_BULKLOAD_ENABLE;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
+import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
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.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
import org.apache.hadoop.hbase.client.RegionInfo;
@@ -44,19 +45,15 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.wal.WALEdit;
import org.apache.hadoop.hbase.wal.WALKeyImpl;
-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.TestTemplate;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-@Category(SmallTests.class)
+@Tag(SmallTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: useFileBasedSFT={0}")
public class TestCompactionAfterBulkLoad extends TestBulkloadBase {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCompactionAfterBulkLoad.class);
-
private final RegionServerServices regionServerServices = mock(RegionServerServices.class);
public static AtomicInteger called = new AtomicInteger(0);
@@ -76,12 +73,13 @@ public class TestCompactionAfterBulkLoad extends TestBulkloadBase {
ChunkCreator.initialize(MemStoreLAB.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null,
MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_DEFAULT);
// TODO We need a way to do this without creating files
- return HRegion.createHRegion(hRegionInfo, new Path(testFolder.newFolder().toURI()), conf,
- builder.build(), log, true, regionServerServices);
+ return HRegion.createHRegion(hRegionInfo,
+ new Path(new File(testFolder, generateUniqueName(null)).toURI()), conf, builder.build(), log,
+ true, regionServerServices);
}
- @Test
+ @TestTemplate
public void shouldRequestCompactAllStoresAfterBulkLoad() throws IOException {
final CompactSplit compactSplit = new TestCompactSplit(HBaseConfiguration.create());
called.set(0);
@@ -116,7 +114,7 @@ public class TestCompactionAfterBulkLoad extends TestBulkloadBase {
}
}
- @Test
+ @TestTemplate
public void testAvoidRepeatedlyRequestCompactAfterBulkLoad() throws IOException {
final CompactSplit compactSplit = new TestFamily1UnderCompact(HBaseConfiguration.create());
called.set(0);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionArchiveConcurrentClose.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionArchiveConcurrentClose.java
index 9f87bfa707a..2eabdfdfe12 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionArchiveConcurrentClose.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionArchiveConcurrentClose.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.regionserver;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.Mockito.mock;
import java.io.IOException;
@@ -31,7 +31,6 @@ import java.util.concurrent.atomic.AtomicReference;
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.Stoppable;
import org.apache.hadoop.hbase.TableName;
@@ -46,42 +45,37 @@ import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CommonFSUtils;
import org.apache.hadoop.hbase.wal.WALFactory;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.mockito.Mockito;
/**
* Tests a race condition between archiving of compacted files in CompactedHFilesDischarger chore
* and HRegion.close();
*/
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCompactionArchiveConcurrentClose {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCompactionArchiveConcurrentClose.class);
-
private HBaseTestingUtility testUtil;
private Path testDir;
private AtomicBoolean archived = new AtomicBoolean();
- @Rule
- public TestName name = new TestName();
+ private String name;
- @Before
- public void setup() throws Exception {
+ @BeforeEach
+ public void setup(TestInfo testInfo) throws Exception {
+ this.name = testInfo.getTestMethod().get().getName();
testUtil = HBaseTestingUtility.createLocalHTU();
testDir = testUtil.getDataTestDir("TestStoreFileRefresherChore");
CommonFSUtils.setRootDir(testUtil.getConfiguration(), testDir);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
testUtil.cleanupTestDir();
}
@@ -92,7 +86,7 @@ public class TestCompactionArchiveConcurrentClose {
byte[] col = Bytes.toBytes("c");
byte[] val = Bytes.toBytes("val");
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(name);
TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName)
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(fam)).build();
RegionInfo info = RegionInfoBuilder.newBuilder(tableName).build();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionArchiveIOException.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionArchiveIOException.java
index 72a3e2a97ae..14f7ff92bc9 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionArchiveIOException.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionArchiveIOException.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 static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doThrow;
@@ -35,7 +35,6 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
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.Stoppable;
import org.apache.hadoop.hbase.TableName;
@@ -51,13 +50,11 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CommonFSUtils;
import org.apache.hadoop.hbase.wal.WALFactory;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.mockito.Mockito;
import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList;
@@ -65,31 +62,26 @@ import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList;
/**
* Tests that archiving compacted files behaves correctly when encountering exceptions.
*/
-@Category(MediumTests.class)
+@Tag(MediumTests.TAG)
public class TestCompactionArchiveIOException {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCompactionArchiveIOException.class);
-
private static final String ERROR_FILE = "fffffffffffffffffdeadbeef";
public HBaseTestingUtility testUtil;
private Path testDir;
+ private String name;
- @Rule
- public TestName name = new TestName();
-
- @Before
- public void setup() throws Exception {
+ @BeforeEach
+ public void setup(TestInfo testInfo) throws Exception {
+ this.name = testInfo.getTestMethod().get().getName();
testUtil = new HBaseTestingUtility();
testUtil.startMiniDFSCluster(1);
testDir = testUtil.getDataTestDirOnTestFS();
CommonFSUtils.setRootDir(testUtil.getConfiguration(), testDir);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
testUtil.cleanupTestDir();
testUtil.shutdownMiniDFSCluster();
@@ -101,7 +93,7 @@ public class TestCompactionArchiveIOException {
byte[] col = Bytes.toBytes("c");
byte[] val = Bytes.toBytes("val");
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(name);
TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName)
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(fam)).build();
RegionInfo info = RegionInfoBuilder.newBuilder(tableName).build();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionFileNotFound.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionFileNotFound.java
index 4efbecaa2eb..9d45354fe03 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionFileNotFound.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionFileNotFound.java
@@ -17,13 +17,10 @@
*/
package org.apache.hadoop.hbase.regionserver;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.io.FileNotFoundException;
-import java.io.IOException;
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.TableName;
import org.apache.hadoop.hbase.Waiter;
@@ -34,29 +31,20 @@ import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
-import org.junit.After;
-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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* This class tests the scenario where a store refresh happens due to a file not found during scan,
* after a compaction but before the compacted files are archived. At this state we test for a split
* and compaction
*/
-@Category(MediumTests.class)
+@Tag(MediumTests.TAG)
public class TestCompactionFileNotFound {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCompactionFileNotFound.class);
-
- private static final Logger LOG = LoggerFactory.getLogger(TestCompactionFileNotFound.class);
private static final HBaseTestingUtility util = new HBaseTestingUtility();
private static final TableName TEST_TABLE = TableName.valueOf("test");
@@ -74,19 +62,19 @@ public class TestCompactionFileNotFound {
private Table table;
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
Configuration conf = util.getConfiguration();
conf.setInt("hbase.hfile.compaction.discharger.interval", Integer.MAX_VALUE);
util.startMiniCluster(3);
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
util.shutdownMiniCluster();
}
- @After
+ @AfterEach
public void after() throws Exception {
try {
if (table != null) {
@@ -187,16 +175,7 @@ public class TestCompactionFileNotFound {
for (HStore store : hr1.getStores()) {
store.closeAndArchiveCompactedFiles();
}
- try {
- hr1.compact(false);
- } catch (IOException e) {
- LOG.error("Got an exception during compaction", e);
- if (e instanceof FileNotFoundException) {
- Assert.fail("Got a FNFE during compaction");
- } else {
- Assert.fail();
- }
- }
+ hr1.compact(false);
} finally {
if (admin != null) {
admin.close();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionInDeadRegionServer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionInDeadRegionServer.java
index 1a2db17c685..479cfdfae44 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionInDeadRegionServer.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionInDeadRegionServer.java
@@ -17,14 +17,14 @@
*/
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.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;
@@ -43,15 +43,11 @@ import org.apache.hadoop.hbase.wal.WALFactory;
import org.apache.hadoop.hbase.wal.WALProvider;
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.apache.hadoop.hbase.zookeeper.ZNodePaths;
-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.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameter;
-import org.junit.runners.Parameterized.Parameters;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.params.provider.Arguments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -59,14 +55,11 @@ import org.slf4j.LoggerFactory;
* This testcase is used to ensure that the compaction marker will fail a compaction if the RS is
* already dead. It can not eliminate FNFE when scanning but it does reduce the possibility a lot.
*/
-@RunWith(Parameterized.class)
-@Category({ RegionServerTests.class, LargeTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(LargeTests.TAG)
+@HBaseParameterizedTestTemplate(name = "{index}: wal={0}")
public class TestCompactionInDeadRegionServer {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCompactionInDeadRegionServer.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestCompactionInDeadRegionServer.class);
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
@@ -94,16 +87,17 @@ public class TestCompactionInDeadRegionServer {
}
}
- @Parameter
- public Class<? extends WALProvider> walProvider;
+ private final Class<? extends WALProvider> walProvider;
+
+ public TestCompactionInDeadRegionServer(Class<? extends WALProvider> walProvider) {
+ this.walProvider = walProvider;
+ }
- @Parameters(name = "{index}: wal={0}")
- public static List<Object[]> params() {
- return Arrays.asList(new Object[] { FSHLogProvider.class },
- new Object[] { AsyncFSWALProvider.class });
+ public static Stream<Arguments> parameters() {
+ return Stream.of(Arguments.of(FSHLogProvider.class), Arguments.of(AsyncFSWALProvider.class));
}
- @Before
+ @BeforeEach
public void setUp() throws Exception {
UTIL.getConfiguration().setClass(WALFactory.WAL_PROVIDER, walProvider, WALProvider.class);
UTIL.getConfiguration().setInt(HConstants.ZK_SESSION_TIMEOUT, 2000);
@@ -121,12 +115,12 @@ public class TestCompactionInDeadRegionServer {
UTIL.getAdmin().flush(TABLE_NAME);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
UTIL.shutdownMiniCluster();
}
- @Test
+ @TestTemplate
public void test() throws Exception {
HRegionServer regionSvr = UTIL.getRSForFirstRegionInTable(TABLE_NAME);
HRegion region = regionSvr.getRegions(TABLE_NAME).get(0);
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionLifeCycleTracker.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionLifeCycleTracker.java
index 0a994a91516..42752b08d90 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionLifeCycleTracker.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionLifeCycleTracker.java
@@ -19,9 +19,9 @@ package org.apache.hadoop.hbase.regionserver;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
@@ -31,7 +31,6 @@ import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.Cell.Type;
import org.apache.hadoop.hbase.CellBuilderFactory;
import org.apache.hadoop.hbase.CellBuilderType;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
@@ -53,26 +52,22 @@ import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
-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.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* Confirm that the function of CompactionLifeCycleTracker is OK as we do not use it in our own
* code.
*/
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestCompactionLifeCycleTracker {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCompactionLifeCycleTracker.class);
-
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
private static final TableName NAME =
@@ -133,18 +128,18 @@ public class TestCompactionLifeCycleTracker {
}
}
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
UTIL.getConfiguration().setInt(CompactionConfiguration.HBASE_HSTORE_COMPACTION_MIN_KEY, 2);
UTIL.startMiniCluster(3);
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
UTIL.shutdownMiniCluster();
}
- @Before
+ @BeforeEach
public void setUp() throws IOException {
UTIL.getAdmin()
.createTable(TableDescriptorBuilder.newBuilder(NAME)
@@ -174,7 +169,7 @@ public class TestCompactionLifeCycleTracker {
assertEquals(0, region.getStore(CF2).getStorefilesCount());
}
- @After
+ @AfterEach
public void tearDown() throws IOException {
region = null;
TRACKER = null;
@@ -266,7 +261,7 @@ public class TestCompactionLifeCycleTracker {
// This test assumes that compaction wouldn't happen with null user.
// But null user means system generated compaction so compaction should happen
// even if the space quota is violated. So this test should be removed/ignored.
- @Ignore
+ @Disabled
@Test
public void testSpaceQuotaViolation() throws IOException, InterruptedException {
region.getRegionServerServices().getRegionServerSpaceQuotaManager().enforceViolationPolicy(NAME,
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionPolicy.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionPolicy.java
index a9d48e23608..74567795f24 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionPolicy.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionPolicy.java
@@ -17,6 +17,9 @@
*/
package org.apache.hadoop.hbase.regionserver;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -37,15 +40,15 @@ import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFor
import org.apache.hadoop.hbase.regionserver.wal.FSHLog;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CommonFSUtils;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
public class TestCompactionPolicy {
+
private final static Logger LOG = LoggerFactory.getLogger(TestCompactionPolicy.class);
protected final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
@@ -63,7 +66,7 @@ public class TestCompactionPolicy {
private FSHLog hlog;
private HRegion region;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
config();
initialize();
@@ -113,7 +116,7 @@ public class TestCompactionPolicy {
fs.createNewFile(TEST_FILE);
}
- @After
+ @AfterEach
public void tearDown() throws IOException {
IOException ex = null;
try {
@@ -199,9 +202,9 @@ public class TestCompactionPolicy {
.selectCompaction(candidates, new ArrayList<>(), false, isOffPeak, forcemajor);
List<HStoreFile> actual = new ArrayList<>(result.getFiles());
if (isOffPeak && !forcemajor) {
- Assert.assertTrue(result.isOffPeak());
+ assertTrue(result.isOffPeak());
}
- Assert.assertEquals(Arrays.toString(expected), Arrays.toString(getSizes(actual)));
+ assertEquals(Arrays.toString(expected), Arrays.toString(getSizes(actual)));
store.forceMajor = false;
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionState.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionState.java
index 39d474636ba..b8c9b59a6cc 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionState.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionState.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 java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
-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;
@@ -37,33 +36,32 @@ import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.VerySlowRegionServerTests;
import org.apache.hadoop.hbase.util.Bytes;
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.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
/** Unit tests to test retrieving table/region compaction state */
-@Category({ VerySlowRegionServerTests.class, LargeTests.class })
+@Tag(VerySlowRegionServerTests.TAG)
+@Tag(LargeTests.TAG)
public class TestCompactionState {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCompactionState.class);
-
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
+ private String name;
- @Rule
- public TestName name = new TestName();
+ @BeforeEach
+ public void setTestName(TestInfo testInfo) {
+ this.name = testInfo.getTestMethod().get().getName();
+ }
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.startMiniCluster();
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
@@ -75,49 +73,49 @@ public class TestCompactionState {
@Test
public void testMajorCompactionStateFromAdmin() throws IOException, InterruptedException {
- compaction(name.getMethodName(), 8, CompactionState.MAJOR, false, StateSource.ADMIN);
+ compaction(name, 8, CompactionState.MAJOR, false, StateSource.ADMIN);
}
@Test
public void testMinorCompactionStateFromAdmin() throws IOException, InterruptedException {
- compaction(name.getMethodName(), 15, CompactionState.MINOR, false, StateSource.ADMIN);
+ compaction(name, 15, CompactionState.MINOR, false, StateSource.ADMIN);
}
@Test
public void testMajorCompactionOnFamilyStateFromAdmin() throws IOException, InterruptedException {
- compaction(name.getMethodName(), 8, CompactionState.MAJOR, true, StateSource.ADMIN);
+ compaction(name, 8, CompactionState.MAJOR, true, StateSource.ADMIN);
}
@Test
public void testMinorCompactionOnFamilyStateFromAdmin() throws IOException, InterruptedException {
- compaction(name.getMethodName(), 15, CompactionState.MINOR, true, StateSource.ADMIN);
+ compaction(name, 15, CompactionState.MINOR, true, StateSource.ADMIN);
}
@Test
public void testMajorCompactionStateFromMaster() throws IOException, InterruptedException {
- compaction(name.getMethodName(), 8, CompactionState.MAJOR, false, StateSource.MASTER);
+ compaction(name, 8, CompactionState.MAJOR, false, StateSource.MASTER);
}
@Test
public void testMinorCompactionStateFromMaster() throws IOException, InterruptedException {
- compaction(name.getMethodName(), 15, CompactionState.MINOR, false, StateSource.MASTER);
+ compaction(name, 15, CompactionState.MINOR, false, StateSource.MASTER);
}
@Test
public void testMajorCompactionOnFamilyStateFromMaster()
throws IOException, InterruptedException {
- compaction(name.getMethodName(), 8, CompactionState.MAJOR, true, StateSource.MASTER);
+ compaction(name, 8, CompactionState.MAJOR, true, StateSource.MASTER);
}
@Test
public void testMinorCompactionOnFamilyStateFromMaster()
throws IOException, InterruptedException {
- compaction(name.getMethodName(), 15, CompactionState.MINOR, true, StateSource.MASTER);
+ compaction(name, 15, CompactionState.MINOR, true, StateSource.MASTER);
}
@Test
public void testInvalidColumnFamily() throws IOException, InterruptedException {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(name);
byte[] family = Bytes.toBytes("family");
byte[] fakecf = Bytes.toBytes("fakecf");
boolean caughtMinorCompact = false;
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionWithByteBuff.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionWithByteBuff.java
index 530dbdabc0e..6d2d332f3f2 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionWithByteBuff.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionWithByteBuff.java
@@ -21,7 +21,6 @@ import java.io.IOException;
import java.util.ArrayList;
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.HConstants;
import org.apache.hadoop.hbase.TableName;
@@ -35,21 +34,13 @@ import org.apache.hadoop.hbase.io.ByteBuffAllocator;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.JVMClusterUtil;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category(LargeTests.class)
+@Tag(LargeTests.TAG)
public class TestCompactionWithByteBuff {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCompactionWithByteBuff.class);
- @Rule
- public TestName name = new TestName();
private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static Configuration conf = TEST_UTIL.getConfiguration();
@@ -61,7 +52,7 @@ public class TestCompactionWithByteBuff {
private static final int ROW_LENGTH = 20;
private static final int VALUE_LENGTH = 5000;
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
conf.setBoolean(ByteBuffAllocator.ALLOCATOR_POOL_ENABLED_KEY, true);
conf.setInt(ByteBuffAllocator.BUFFER_SIZE_KEY, 1024 * 5);
@@ -73,7 +64,7 @@ public class TestCompactionWithByteBuff {
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/TestCompactionWithCoprocessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionWithCoprocessor.java
index 5f2f5d8a72e..bf478bab9a2 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionWithCoprocessor.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionWithCoprocessor.java
@@ -17,24 +17,19 @@
*/
package org.apache.hadoop.hbase.regionserver;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
-import org.junit.ClassRule;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
/**
* Make sure compaction tests still pass with the preFlush and preCompact overridden to implement
* the default behavior
*/
-@Category({ RegionServerTests.class, LargeTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(LargeTests.TAG)
public class TestCompactionWithCoprocessor extends TestCompaction {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCompactionWithCoprocessor.class);
-
/** constructor */
public TestCompactionWithCoprocessor() throws Exception {
super();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionWithShippingCoprocessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionWithShippingCoprocessor.java
index eeb1fd5a013..48dc6b6c097 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionWithShippingCoprocessor.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionWithShippingCoprocessor.java
@@ -25,7 +25,6 @@ import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.hadoop.conf.Configuration;
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.TableName;
@@ -41,37 +40,36 @@ import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.hamcrest.Matchers;
-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;
-
-@Category({ MediumTests.class, CoprocessorTests.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(MediumTests.TAG)
+@Tag(CoprocessorTests.TAG)
public class TestCompactionWithShippingCoprocessor {
private static final AtomicInteger SHIPPED_COUNT = new AtomicInteger();
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCompactionWithShippingCoprocessor.class);
-
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final byte[] FAMILY = Bytes.toBytes("testFamily");
+ private String name;
- @Rule
- public TestName name = new TestName();
+ @BeforeEach
+ public void setTestName(TestInfo testInfo) {
+ this.name = testInfo.getTestMethod().get().getName();
+ }
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
Configuration conf = TEST_UTIL.getConfiguration();
conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 0);// do not retry
TEST_UTIL.startMiniCluster(1);
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
@@ -83,7 +81,7 @@ public class TestCompactionWithShippingCoprocessor {
@Test
public void testCoprocScannersExtendingShipperGetShipped() throws Exception {
int shippedCountBefore = SHIPPED_COUNT.get();
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(name);
// Create a table with block size as 1024
final Table table = TEST_UTIL.createTable(tableName, new byte[][] { FAMILY }, 1, 1024,
CompactionObserver.class.getName());
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactorMemLeak.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactorMemLeak.java
index fcf198717cf..8c954460677 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactorMemLeak.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactorMemLeak.java
@@ -18,6 +18,8 @@
package org.apache.hadoop.hbase.regionserver;
import static org.apache.hadoop.hbase.regionserver.DefaultStoreEngine.DEFAULT_COMPACTOR_CLASS_KEY;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.List;
@@ -25,7 +27,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.hadoop.conf.Configuration;
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.HConstants;
import org.apache.hadoop.hbase.KeyValue.KeyOnlyKeyValue;
@@ -39,16 +40,15 @@ import org.apache.hadoop.hbase.regionserver.compactions.DefaultCompactor;
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.Assert;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
-
-@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 TestCompactorMemLeak {
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
@@ -57,15 +57,14 @@ public class TestCompactorMemLeak {
private static final byte[] FAMILY = Bytes.toBytes("f");
private static final byte[] QUALIFIER = Bytes.toBytes("q");
private static final byte[] VALUE = Bytes.toBytes("value");
+ private String name;
- @Rule
- public TestName name = new TestName();
-
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCompactorMemLeak.class);
+ @BeforeEach
+ public void setTestName(TestInfo testInfo) {
+ this.name = testInfo.getTestMethod().get().getName();
+ }
- @BeforeClass
+ @BeforeAll
public static void setUp() throws Exception {
IS_LAST_CELL_ON_HEAP.set(false);
// Must use the ByteBuffAllocator here
@@ -80,7 +79,7 @@ public class TestCompactorMemLeak {
UTIL.startMiniCluster();
}
- @AfterClass
+ @AfterAll
public static void tearDown() throws Exception {
IS_LAST_CELL_ON_HEAP.set(false);
UTIL.shutdownMiniCluster();
@@ -89,16 +88,16 @@ public class TestCompactorMemLeak {
private void assertMajorCompactionOK(TableName tableName) {
List<HRegion> regions = UTIL.getHBaseCluster().getRegionServerThreads().get(0).getRegionServer()
.getRegions(tableName);
- Assert.assertEquals(regions.size(), 1);
+ assertEquals(1, regions.size());
HRegion region = regions.get(0);
- Assert.assertEquals(region.getStores().size(), 1);
+ assertEquals(1, region.getStores().size());
HStore store = region.getStore(FAMILY);
- Assert.assertEquals(store.getStorefilesCount(), 1);
+ assertEquals(1, store.getStorefilesCount());
}
@Test
public void testMemLeak() throws IOException, InterruptedException {
- TableName tableName = TableName.valueOf(name.getMethodName());
+ TableName tableName = TableName.valueOf(name);
Table table = UTIL.createTable(tableName, FAMILY);
// Put and Flush #1
@@ -117,7 +116,7 @@ public class TestCompactorMemLeak {
assertMajorCompactionOK(tableName);
// The last cell before Compactor#commitWriter must be an heap one.
- Assert.assertTrue(IS_LAST_CELL_ON_HEAP.get());
+ assertTrue(IS_LAST_CELL_ON_HEAP.get());
}
public static class MyCompactor extends DefaultCompactor {
@@ -136,5 +135,4 @@ public class TestCompactorMemLeak {
return super.commitWriter(writer, fd, request);
}
}
-
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompoundBloomFilter.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompoundBloomFilter.java
index 6f708d26f3a..ea17808500b 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompoundBloomFilter.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompoundBloomFilter.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.regionserver;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -33,7 +33,6 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.CellComparatorImpl;
import org.apache.hadoop.hbase.CellUtil;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValueUtil;
@@ -53,23 +52,19 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.util.BloomFilterFactory;
import org.apache.hadoop.hbase.util.BloomFilterUtil;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Tests writing Bloom filter blocks in the same part of the file as data blocks.
*/
-@Category({ RegionServerTests.class, LargeTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(LargeTests.TAG)
public class TestCompoundBloomFilter {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCompoundBloomFilter.class);
-
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final Logger LOG = LoggerFactory.getLogger(TestCompoundBloomFilter.class);
@@ -130,7 +125,7 @@ public class TestCompoundBloomFilter {
private BlockCache blockCache;
- @Before
+ @BeforeEach
public void setUp() throws IOException {
conf = TEST_UTIL.getConfiguration();
@@ -210,8 +205,8 @@ public class TestCompoundBloomFilter {
for (KeyValue kv : kvs) {
byte[] row = CellUtil.cloneRow(kv);
boolean present = isInBloom(scanner, row, CellUtil.cloneQualifier(kv));
- assertTrue(testIdMsg + " Bloom filter false negative on row " + Bytes.toStringBinary(row)
- + " after " + numChecked + " successful checks", present);
+ assertTrue(present, testIdMsg + " Bloom filter false negative on row "
+ + Bytes.toStringBinary(row) + " after " + numChecked + " successful checks");
++numChecked;
}
}
@@ -241,8 +236,8 @@ public class TestCompoundBloomFilter {
nTrials, falsePosRate) + fakeLookupModeStr);
// Check for obvious Bloom filter crashes.
- assertTrue("False positive is too high: " + falsePosRate + " (greater " + "than "
- + TOO_HIGH_ERROR_RATE + ")" + fakeLookupModeStr, falsePosRate < TOO_HIGH_ERROR_RATE);
+ assertTrue(falsePosRate < TOO_HIGH_ERROR_RATE, "False positive is too high: " + falsePosRate
+ + " (greater " + "than " + TOO_HIGH_ERROR_RATE + ")" + fakeLookupModeStr);
// Now a more precise check to see if the false positive rate is not
// too high. The reason we use a relaxed restriction for the real-world
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCustomCellDataTieringManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCustomCellDataTieringManager.java
index febf88d6f6f..6ff6cc51be2 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCustomCellDataTieringManager.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCustomCellDataTieringManager.java
@@ -19,12 +19,12 @@ package org.apache.hadoop.hbase.regionserver;
import static org.apache.hadoop.hbase.HConstants.BUCKET_CACHE_SIZE_KEY;
import static org.apache.hadoop.hbase.io.hfile.bucket.BucketCache.DEFAULT_ERROR_TOLERATION_DURATION;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.util.ArrayList;
@@ -38,7 +38,6 @@ import java.util.Set;
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.KeyValue;
@@ -69,20 +68,20 @@ import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CommonFSUtils;
import org.apache.hadoop.hbase.util.Pair;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This class is used to test the functionality of the DataTieringManager.
- *
+ * <p>
* The mock online regions are stored in {@link TestCustomCellDataTieringManager#testOnlineRegions}.
* For all tests, the setup of
* {@link TestCustomCellDataTieringManager#testOnlineRegions} occurs only once.
- * Please refer to {@link TestCustomCellDataTieringManager#setupOnlineRegions()} for the structure.
+ * Please refer to {@link TestCustomCellDataTieringManager#setupOnlineRegions(BlockCache)} for the
+ * structure.
* Additionally, a list of all store files is
* maintained in {@link TestCustomCellDataTieringManager#hStoreFiles}.
* The characteristics of these store files are listed below:
@@ -97,13 +96,10 @@ import org.slf4j.LoggerFactory;
* @formatter:on
*/
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCustomCellDataTieringManager {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCustomCellDataTieringManager.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestCustomCellDataTieringManager.class);
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final long DAY = 24 * 60 * 60 * 1000;
@@ -124,7 +120,7 @@ public class TestCustomCellDataTieringManager {
*/
private static String rowKeyString;
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
testDir = TEST_UTIL.getDataTestDir(TestCustomCellDataTieringManager.class.getSimpleName());
defaultConf = TEST_UTIL.getConfiguration();
@@ -225,9 +221,9 @@ public class TestCustomCellDataTieringManager {
// Since we have one cold file among four files, only three should get prefetched.
Optional<Map<String, Pair<String, Long>>> fullyCachedFiles = blockCache.getFullyCachedFiles();
- assertTrue("We should get the fully cached files from the cache", fullyCachedFiles.isPresent());
+ assertTrue(fullyCachedFiles.isPresent(), "We should get the fully cached files from the cache");
Waiter.waitFor(defaultConf, 10000, () -> fullyCachedFiles.get().size() == 3);
- assertEquals("Number of fully cached files are incorrect", 3, fullyCachedFiles.get().size());
+ assertEquals(3, fullyCachedFiles.get().size(), "Number of fully cached files are incorrect");
}
private void setPrefetchBlocksOnOpen() {
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCustomCellTieredCompactionPolicy.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCustomCellTieredCompactionPolicy.java
index 3796e3e5b8d..9348e039871 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCustomCellTieredCompactionPolicy.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCustomCellTieredCompactionPolicy.java
@@ -18,9 +18,9 @@
package org.apache.hadoop.hbase.regionserver;
import static org.apache.hadoop.hbase.regionserver.CustomTieringMultiFileWriter.CUSTOM_TIERING_TIME_RANGE;
-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;
@@ -29,7 +29,6 @@ import java.util.ArrayList;
import java.util.UUID;
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.client.ColumnFamilyDescriptorBuilder;
@@ -42,17 +41,13 @@ import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.ManualEnvironmentEdge;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
public class TestCustomCellTieredCompactionPolicy {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestCustomCellTieredCompactionPolicy.class);
-
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
public static final byte[] FAMILY = Bytes.toBytes("cf");
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDataBlockEncodingTool.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDataBlockEncodingTool.java
index 7298948ff25..51575cecfa8 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDataBlockEncodingTool.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDataBlockEncodingTool.java
@@ -22,7 +22,6 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.ArrayBackedTag;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.KeyValue;
@@ -34,21 +33,16 @@ import org.apache.hadoop.hbase.testclassification.MiscTests;
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.Test;
/**
* Test DataBlockEncodingTool.
*/
-@Category({ MiscTests.class, SmallTests.class })
+@org.junit.jupiter.api.Tag(MiscTests.TAG)
+@org.junit.jupiter.api.Tag(SmallTests.TAG)
public class TestDataBlockEncodingTool {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestDataBlockEncodingTool.class);
-
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final String ROOT_DIR =
TEST_UTIL.getDataTestDir("TestDataBlockEncodingTool").toString();
@@ -56,7 +50,7 @@ public class TestDataBlockEncodingTool {
private static FileSystem fs;
private static StoreFileWriter sfw;
- @Before
+ @BeforeEach
public void setUp() throws IOException {
fs = TEST_UTIL.getTestFileSystem();
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDataTieringManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDataTieringManager.java
index 0e523d8eba7..1d28e1afa9a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDataTieringManager.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDataTieringManager.java
@@ -19,12 +19,12 @@ package org.apache.hadoop.hbase.regionserver;
import static org.apache.hadoop.hbase.HConstants.BUCKET_CACHE_SIZE_KEY;
import static org.apache.hadoop.hbase.io.hfile.bucket.BucketCache.DEFAULT_ERROR_TOLERATION_DURATION;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.util.ArrayList;
@@ -39,7 +39,6 @@ import java.util.Set;
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.KeyValue;
@@ -71,10 +70,9 @@ import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CommonFSUtils;
import org.apache.hadoop.hbase.util.Pair;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -97,15 +95,12 @@ import org.slf4j.LoggerFactory;
* @formatter:on
*/
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
public class TestDataTieringManager {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestDataTieringManager.class);
-
- private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final Logger LOG = LoggerFactory.getLogger(TestDataTieringManager.class);
+ private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final long DAY = 24 * 60 * 60 * 1000;
private static Configuration defaultConf;
private static FileSystem fs;
@@ -124,7 +119,7 @@ public class TestDataTieringManager {
*/
private static String rowKeyString;
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() throws Exception {
testDir = TEST_UTIL.getDataTestDir(TestDataTieringManager.class.getSimpleName());
defaultConf = TEST_UTIL.getConfiguration();
@@ -195,7 +190,7 @@ public class TestDataTieringManager {
testOnlineRegions.put(region.getRegionInfo().getEncodedName(), region);
Path hFilePath = file.getPath();
BlockCacheKey key = new BlockCacheKey(hFilePath, 0, true, BlockType.DATA);
- assertTrue("File should be hot due to grace period", dataTieringManager.isHotData(key));
+ assertTrue(dataTieringManager.isHotData(key), "File should be hot due to grace period");
}
@Test
@@ -221,7 +216,7 @@ public class TestDataTieringManager {
Path hFilePath = file.getPath();
BlockCacheKey key = new BlockCacheKey(hFilePath, 0, true, BlockType.DATA);
- assertFalse("File should be cold without grace period", dataTieringManager.isHotData(key));
+ assertFalse(dataTieringManager.isHotData(key), "File should be cold without grace period");
}
@Test
@@ -238,9 +233,9 @@ public class TestDataTieringManager {
// Since we have one cold file among four files, only three should get prefetched.
Optional<Map<String, Pair<String, Long>>> fullyCachedFiles = blockCache.getFullyCachedFiles();
- assertTrue("We should get the fully cached files from the cache", fullyCachedFiles.isPresent());
+ assertTrue(fullyCachedFiles.isPresent(), "We should get the fully cached files from the cache");
Waiter.waitFor(defaultConf, 10000, () -> fullyCachedFiles.get().size() == 3);
- assertEquals("Number of fully cached files are incorrect", 3, fullyCachedFiles.get().size());
+ assertEquals(3, fullyCachedFiles.get().size(), "Number of fully cached files are incorrect");
}
private void setPrefetchBlocksOnOpen() {
@@ -363,8 +358,8 @@ public class TestDataTieringManager {
HStoreFile coldFile = hStoreFiles.get(3);
String region = coldFile.getPath().getParent().getParent().getName();
- assertFalse("fixture file should be cold for TIME_RANGE tiering", dataTieringManager
- .isHotData(coldFile.getFileInfo().getHFileInfo(), coldFile.getFileInfo().getConf()));
+ assertFalse(dataTieringManager.isHotData(coldFile.getFileInfo().getHFileInfo(),
+ coldFile.getFileInfo().getConf()), "fixture file should be cold for TIME_RANGE tiering");
Map<String, Pair<List<String>, Long>> coldByRegion = dataTieringManager.getRegionColdDataSize();
assertTrue(coldByRegion.containsKey(region));
@@ -450,8 +445,9 @@ public class TestDataTieringManager {
Pair<List<String>, Long> after = dataTieringManager.getRegionColdDataSize().get(regionName);
assertNotNull(after);
- assertTrue("Cold compacted file should be removed from tracking",
- after.getFirst().isEmpty() || !after.getFirst().contains(coldFile.getPath().getName()));
+ assertTrue(
+ after.getFirst().isEmpty() || !after.getFirst().contains(coldFile.getPath().getName()),
+ "Cold compacted file should be removed from tracking");
assertEquals(0L, (long) after.getSecond());
}
@@ -480,16 +476,16 @@ public class TestDataTieringManager {
newFile.initReader();
hStore.refreshStoreFiles();
- assertFalse("new store file must be cold for this scenario", dataTieringManager
- .isHotData(newFile.getFileInfo().getHFileInfo(), newFile.getFileInfo().getConf()));
+ assertFalse(dataTieringManager.isHotData(newFile.getFileInfo().getHFileInfo(),
+ newFile.getFileInfo().getConf()), "new store file must be cold for this scenario");
dataTieringManager.updateRegionColdDataSize(regionName, Collections.singletonList(coldFile),
Collections.singletonList(newFile));
Pair<List<String>, Long> after = dataTieringManager.getRegionColdDataSize().get(regionName);
assertNotNull(after);
- assertFalse("compacted cold file should no longer be tracked",
- after.getFirst().contains(coldFile.getPath().getName()));
+ assertFalse(after.getFirst().contains(coldFile.getPath().getName()),
+ "compacted cold file should no longer be tracked");
assertEquals(1, after.getFirst().size());
assertTrue(after.getFirst().contains(newFile.getPath().getName()));
long expectedNew = Bytes.toLong(newFile.getFileInfo().getHFileInfo().get(HFileInfo.FILE_SIZE));
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDateTieredCompactionPolicy.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDateTieredCompactionPolicy.java
index 475454d6763..3d6e2cceff8 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDateTieredCompactionPolicy.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDateTieredCompactionPolicy.java
@@ -18,23 +18,18 @@
package org.apache.hadoop.hbase.regionserver;
import java.io.IOException;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.regionserver.compactions.CompactionConfiguration;
import org.apache.hadoop.hbase.regionserver.compactions.ExponentialCompactionWindowFactory;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
public class TestDateTieredCompactionPolicy extends AbstractTestDateTieredCompactionPolicy {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestDateTieredCompactionPolicy.class);
-
@Override
protected void config() {
super.config();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDateTieredCompactionPolicyHeterogeneousStorage.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDateTieredCompactionPolicyHeterogeneousStorage.java
index 172fece6656..2f599bb35a5 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDateTieredCompactionPolicyHeterogeneousStorage.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDateTieredCompactionPolicyHeterogeneousStorage.java
@@ -20,22 +20,18 @@ package org.apache.hadoop.hbase.regionserver;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.regionserver.compactions.CompactionConfiguration;
import org.apache.hadoop.hbase.regionserver.compactions.ExponentialCompactionWindowFactory;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
public class TestDateTieredCompactionPolicyHeterogeneousStorage
extends AbstractTestDateTieredCompactionPolicy {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestDateTieredCompactionPolicyHeterogeneousStorage.class);
public static final String HOT_WINDOW_SP = "ALL_SSD";
public static final String WARM_WINDOW_SP = "ONE_SSD";
public static final String COLD_WINDOW_SP = "HOT";
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDateTieredCompactionPolicyOverflow.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDateTieredCompactionPolicyOverflow.java
index 99809b84775..5f62071fc57 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDateTieredCompactionPolicyOverflow.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDateTieredCompactionPolicyOverflow.java
@@ -18,23 +18,18 @@
package org.apache.hadoop.hbase.regionserver;
import java.io.IOException;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.regionserver.compactions.CompactionConfiguration;
import org.apache.hadoop.hbase.regionserver.compactions.ExponentialCompactionWindowFactory;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
public class TestDateTieredCompactionPolicyOverflow extends AbstractTestDateTieredCompactionPolicy {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestDateTieredCompactionPolicyOverflow.class);
-
@Override
protected void config() {
super.config();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultCompactSelection.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultCompactSelection.java
index 76faae6d349..ba49b464a7d 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultCompactSelection.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultCompactSelection.java
@@ -17,28 +17,23 @@
*/
package org.apache.hadoop.hbase.regionserver;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.regionserver.compactions.CompactionRequestImpl;
import org.apache.hadoop.hbase.regionserver.compactions.RatioBasedCompactionPolicy;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.TimeOffsetEnvironmentEdge;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category(SmallTests.class)
+@Tag(SmallTests.TAG)
public class TestDefaultCompactSelection extends TestCompactionPolicy {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestDefaultCompactSelection.class);
-
@Override
protected void config() {
super.config();
@@ -184,7 +179,7 @@ public class TestDefaultCompactSelection extends TestCompactionPolicy {
CompactionRequestImpl result =
((RatioBasedCompactionPolicy) store.storeEngine.getCompactionPolicy())
.selectCompaction(candidates, new ArrayList<>(), false, false, false);
- Assert.assertTrue(result.getFiles().isEmpty());
+ assertTrue(result.getFiles().isEmpty());
store.setScanInfo(oldScanInfo);
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java
index acac15f49c7..2b0381d9c09 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java
@@ -17,10 +17,11 @@
*/
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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
@@ -35,7 +36,6 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellComparatorImpl;
import org.apache.hadoop.hbase.CellUtil;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
@@ -61,15 +61,12 @@ import org.apache.hadoop.hbase.util.EnvironmentEdge;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.FSTableDescriptors;
import org.apache.hadoop.hbase.wal.WALFactory;
-import org.junit.After;
-import org.junit.AfterClass;
-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.AfterAll;
+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;
@@ -78,16 +75,12 @@ import org.apache.hbase.thirdparty.com.google.common.collect.Iterables;
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
/** memstore test case */
-@Category({ RegionServerTests.class, MediumTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(MediumTests.TAG)
public class TestDefaultMemStore {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestDefaultMemStore.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestDefaultMemStore.class);
- @Rule
- public TestName name = new TestName();
+
protected AbstractMemStore memstore;
protected static final int ROW_COUNT = 10;
protected static final int SCAN_ROW_COUNT = 25000;
@@ -95,37 +88,61 @@ public class TestDefaultMemStore {
protected static final byte[] FAMILY = Bytes.toBytes("column");
protected MultiVersionConcurrencyControl mvcc;
protected ChunkCreator chunkCreator;
+ protected String name;
- private String getName() {
- return this.name.getMethodName();
- }
-
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ public void setUp(TestInfo testInfo) throws Exception {
+ this.name = getTestName(testInfo);
internalSetUp();
- // no pool
- this.chunkCreator = ChunkCreator.initialize(MemStoreLAB.CHUNK_SIZE_DEFAULT, false, 0, 0, 0,
- null, MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_DEFAULT);
- this.memstore = new DefaultMemStore();
+ createChunkCreator();
+ createMemStore();
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
+ internalTearDown();
this.memstore.close();
}
- @AfterClass
- public static void tearDownClass() throws Exception {
+ @AfterAll
+ public static void tearDownClass() {
ChunkCreator.getInstance().clearChunkIds();
}
+ protected String getTestName(TestInfo testInfo) {
+ String methodName = testInfo.getTestMethod().get().getName();
+ String displayName = testInfo.getDisplayName();
+ String name = methodName + getParameterizedTestNameSuffix();
+ if (!displayName.equals(methodName) && !displayName.equals(methodName + "()")) {
+ name += "_" + displayName;
+ }
+ return name.replaceAll("[^A-Za-z0-9_.-]", "_");
+ }
+
+ protected String getParameterizedTestNameSuffix() {
+ return "";
+ }
+
+ protected void createChunkCreator() {
+ // no pool
+ this.chunkCreator = ChunkCreator.initialize(MemStoreLAB.CHUNK_SIZE_DEFAULT, false, 0, 0, 0,
+ null, MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_DEFAULT);
+ }
+
+ protected void createMemStore() throws IOException {
+ this.memstore = new DefaultMemStore();
+ }
+
protected void internalSetUp() throws Exception {
this.mvcc = new MultiVersionConcurrencyControl();
}
+ protected void internalTearDown() throws Exception {
+ }
+
@Test
public void testPutSameKey() {
- byte[] bytes = Bytes.toBytes(getName());
+ byte[] bytes = Bytes.toBytes(this.name);
KeyValue kv = new KeyValue(bytes, bytes, bytes, bytes);
this.memstore.add(kv, null);
byte[] other = Bytes.toBytes("somethingelse");
@@ -133,12 +150,12 @@ public class TestDefaultMemStore {
this.memstore.add(samekey, null);
Cell found = this.memstore.getActive().first();
assertEquals(1, this.memstore.getActive().getCellsCount());
- assertTrue(Bytes.toString(found.getValueArray()), CellUtil.matchingValue(samekey, found));
+ assertTrue(CellUtil.matchingValue(samekey, found), Bytes.toString(found.getValueArray()));
}
@Test
public void testPutSameCell() {
- byte[] bytes = Bytes.toBytes(getName());
+ byte[] bytes = Bytes.toBytes(this.name);
KeyValue kv = new KeyValue(bytes, bytes, bytes, bytes);
MemStoreSizing sizeChangeForFirstCell = new NonThreadSafeMemStoreSizing();
this.memstore.add(kv, sizeChangeForFirstCell);
@@ -227,7 +244,7 @@ public class TestDefaultMemStore {
// Assert the stuff is coming out in right order.
assertTrue(CellUtil.matchingRows(result.get(0), Bytes.toBytes(count)));
// Row count is same as column count.
- assertEquals("count=" + count + ", result=" + result, rowCount, result.size());
+ assertEquals(rowCount, result.size(), "count=" + count + ", result=" + result);
count++;
if (count == snapshotIndex) {
MemStoreSnapshot snapshot = this.memstore.snapshot();
@@ -303,8 +320,8 @@ public class TestDefaultMemStore {
scanner0.seek(KeyValueUtil.createFirstOnRow(HConstants.EMPTY_START_ROW));
Cell n0 = scanner0.next();
Cell n1 = scanner0.next();
- assertTrue(kv1.equals(n0));
- assertTrue(kv2.equals(n1));
+ assertEquals(kv1, n0);
+ assertEquals(kv2, n1);
assertNull(scanner0.next());
}
@@ -319,9 +336,8 @@ public class TestDefaultMemStore {
returned.add(next);
}
- assertTrue(
- "Got:\n" + Joiner.on("\n").join(returned) + "\nExpected:\n" + Joiner.on("\n").join(expected),
- Iterables.elementsEqual(Arrays.asList(expected), returned));
+ assertTrue(Iterables.elementsEqual(Arrays.asList(expected), returned),
+ "Got:\n" + Joiner.on("\n").join(returned) + "\nExpected:\n" + Joiner.on("\n").join(expected));
assertNull(scanner.peek());
}
@@ -392,7 +408,7 @@ public class TestDefaultMemStore {
public void testBytesReadFromMemstore() throws IOException {
ThreadLocalServerSideScanMetrics.setScanMetricsEnabled(true);
long totalCellSize = getBytesReadFromMemstore();
- Assert.assertEquals(totalCellSize,
+ assertEquals(totalCellSize,
ThreadLocalServerSideScanMetrics.getBytesReadFromMemstoreAndReset());
}
@@ -400,7 +416,7 @@ public class TestDefaultMemStore {
public void testBytesReadFromMemstoreWithScanMetricsDisabled() throws IOException {
ThreadLocalServerSideScanMetrics.setScanMetricsEnabled(false);
getBytesReadFromMemstore();
- Assert.assertEquals(0, ThreadLocalServerSideScanMetrics.getBytesReadFromMemstoreAndReset());
+ assertEquals(0, ThreadLocalServerSideScanMetrics.getBytesReadFromMemstoreAndReset());
}
/**
@@ -549,8 +565,8 @@ public class TestDefaultMemStore {
s.seek(kv);
Cell ret = s.next();
- assertNotNull("Didnt find own write at all", ret);
- assertEquals("Didnt read own writes", kv.getTimestamp(), ret.getTimestamp());
+ assertNotNull(ret, "Didnt find own write at all");
+ assertEquals(kv.getTimestamp(), ret.getTimestamp(), "Didnt read own writes");
}
}
}
@@ -586,7 +602,7 @@ public class TestDefaultMemStore {
for (int i = 0; i < snapshotCount; i++) {
addRows(this.memstore);
runSnapshot(this.memstore);
- assertEquals("History not being cleared", 0, this.memstore.getSnapshot().getCellsCount());
+ assertEquals(0, this.memstore.getSnapshot().getCellsCount(), "History not being cleared");
}
}
@@ -606,8 +622,8 @@ public class TestDefaultMemStore {
m.add(key1, null);
m.add(key2, null);
- assertTrue("Expected memstore to hold 3 values, actually has " + m.getActive().getCellsCount(),
- m.getActive().getCellsCount() == 3);
+ assertEquals(3, m.getActive().getCellsCount(),
+ "Expected memstore to hold 3 values, actually has " + m.getActive().getCellsCount());
}
//////////////////////////////////////////////////////////////////////////////
@@ -624,16 +640,16 @@ public class TestDefaultMemStore {
Thread.sleep(1);
addRows(this.memstore);
Cell closestToEmpty = ((DefaultMemStore) this.memstore).getNextRow(KeyValue.LOWESTKEY);
- assertTrue(CellComparatorImpl.COMPARATOR.compareRows(closestToEmpty,
- new KeyValue(Bytes.toBytes(0), EnvironmentEdgeManager.currentTime())) == 0);
+ assertEquals(0, CellComparatorImpl.COMPARATOR.compareRows(closestToEmpty,
+ new KeyValue(Bytes.toBytes(0), EnvironmentEdgeManager.currentTime())));
for (int i = 0; i < ROW_COUNT; i++) {
Cell nr = ((DefaultMemStore) this.memstore)
.getNextRow(new KeyValue(Bytes.toBytes(i), EnvironmentEdgeManager.currentTime()));
if (i + 1 == ROW_COUNT) {
assertNull(nr);
} else {
- assertTrue(CellComparatorImpl.COMPARATOR.compareRows(nr,
- new KeyValue(Bytes.toBytes(i + 1), EnvironmentEdgeManager.currentTime())) == 0);
+ assertEquals(0, CellComparatorImpl.COMPARATOR.compareRows(nr,
+ new KeyValue(Bytes.toBytes(i + 1), EnvironmentEdgeManager.currentTime())));
}
}
// starting from each row, validate results should contain the starting row
@@ -650,9 +666,9 @@ public class TestDefaultMemStore {
int rowId = startRowId + i;
Cell left = results.get(0);
byte[] row1 = Bytes.toBytes(rowId);
- assertTrue("Row name",
- CellComparatorImpl.COMPARATOR.compareRows(left, row1, 0, row1.length) == 0);
- assertEquals("Count of columns", QUALIFIER_COUNT, results.size());
+ assertEquals(0, CellComparatorImpl.COMPARATOR.compareRows(left, row1, 0, row1.length),
+ "Row name");
+ assertEquals(QUALIFIER_COUNT, results.size(), "Count of columns");
List<Cell> row = new ArrayList<>();
for (Cell kv : results) {
row.add(kv);
@@ -923,7 +939,7 @@ public class TestDefaultMemStore {
// test the case that the timeOfOldestEdit is updated after a KV add
memstore.add(KeyValueTestUtil.create("r", "f", "q", 100, "v"), null);
t = memstore.timeOfOldestEdit();
- assertTrue(t == 1234);
+ assertEquals(1234, t);
// snapshot() will reset timeOfOldestEdit. The method will also assert the
// value is reset to Long.MAX_VALUE
t = runSnapshot(memstore);
@@ -931,7 +947,7 @@ public class TestDefaultMemStore {
// test the case that the timeOfOldestEdit is updated after a KV delete
memstore.add(KeyValueTestUtil.create("r", "f", "q", 100, KeyValue.Type.Delete, "v"), null);
t = memstore.timeOfOldestEdit();
- assertTrue(t == 1234);
+ assertEquals(1234, t);
t = runSnapshot(memstore);
// test the case that the timeOfOldestEdit is updated after a KV upsert
@@ -941,7 +957,7 @@ public class TestDefaultMemStore {
l.add(kv1);
memstore.upsert(l, 1000, null);
t = memstore.timeOfOldestEdit();
- assertTrue(t == 1234);
+ assertEquals(1234, t);
} finally {
EnvironmentEdgeManager.reset();
}
@@ -977,9 +993,9 @@ public class TestDefaultMemStore {
region.put(p);
edge.setCurrentTimeMillis(1234 + 100);
StringBuilder sb = new StringBuilder();
- assertTrue(!region.shouldFlush(sb));
+ assertFalse(region.shouldFlush(sb));
edge.setCurrentTimeMillis(1234 + 10000);
- assertTrue(region.shouldFlush(sb) == expected);
+ assertEquals(expected, region.shouldFlush(sb));
} finally {
EnvironmentEdgeManager.reset();
}
@@ -1002,9 +1018,7 @@ public class TestDefaultMemStore {
FSTableDescriptors.tryUpdateMetaTableDescriptor(conf);
HRegion meta = HRegion.createHRegion(RegionInfoBuilder.FIRST_META_REGIONINFO, testDir, conf,
tds.get(TableName.META_TABLE_NAME), wFactory.getWAL(RegionInfoBuilder.FIRST_META_REGIONINFO));
- // parameterized tests add [#] suffix get rid of [ and ].
- TableDescriptor desc = TableDescriptorBuilder
- .newBuilder(TableName.valueOf(name.getMethodName().replaceAll("[\\[\\]]", "_")))
+ TableDescriptor desc = TableDescriptorBuilder.newBuilder(TableName.valueOf(name))
.setColumnFamily(ColumnFamilyDescriptorBuilder.of("foo")).build();
RegionInfo hri = RegionInfoBuilder.newBuilder(desc.getTableName())
.setStartKey(Bytes.toBytes("row_0200")).setEndKey(Bytes.toBytes("row_0300")).build();
@@ -1012,9 +1026,9 @@ public class TestDefaultMemStore {
addRegionToMETA(meta, r);
edge.setCurrentTimeMillis(1234 + 100);
StringBuilder sb = new StringBuilder();
- assertTrue(meta.shouldFlush(sb) == false);
+ assertFalse(meta.shouldFlush(sb));
edge.setCurrentTimeMillis(edge.currentTime() + HRegion.SYSTEM_CACHE_FLUSH_INTERVAL + 1);
- assertTrue(meta.shouldFlush(sb) == true);
+ assertTrue(meta.shouldFlush(sb));
}
/**
@@ -1082,10 +1096,10 @@ public class TestDefaultMemStore {
int oldHistorySize = hmc.getSnapshot().getCellsCount();
MemStoreSnapshot snapshot = hmc.snapshot();
// Make some assertions about what just happened.
- assertTrue("History size has not increased",
- oldHistorySize < hmc.getSnapshot().getCellsCount());
+ assertTrue(oldHistorySize < hmc.getSnapshot().getCellsCount(),
+ "History size has not increased");
long t = memstore.timeOfOldestEdit();
- assertTrue("Time of oldest edit is not Long.MAX_VALUE", t == Long.MAX_VALUE);
+ assertEquals(Long.MAX_VALUE, t, "Time of oldest edit is not Long.MAX_VALUE");
hmc.clearSnapshot(snapshot.getId());
return t;
}
@@ -1094,12 +1108,12 @@ public class TestDefaultMemStore {
int i = 0;
for (Cell kv : kvs) {
byte[] expectedColname = makeQualifier(rowIndex, i++);
- assertTrue("Column name", CellUtil.matchingQualifier(kv, expectedColname));
+ assertTrue(CellUtil.matchingQualifier(kv, expectedColname), "Column name");
// Value is column name as bytes. Usually result is
// 100 bytes in size at least. This is the default size
// for BytesWriteable. For comparison, convert bytes to
// String and trim to remove trailing null bytes.
- assertTrue("Content", CellUtil.matchingValue(kv, expectedColname));
+ assertTrue(CellUtil.matchingValue(kv, expectedColname), "Content");
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultStoreEngine.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultStoreEngine.java
index e951289d6de..6a2124dbecf 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultStoreEngine.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultStoreEngine.java
@@ -17,28 +17,24 @@
*/
package org.apache.hadoop.hbase.regionserver;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CellComparatorImpl;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.RegionInfoBuilder;
import org.apache.hadoop.hbase.regionserver.compactions.DefaultCompactor;
import org.apache.hadoop.hbase.regionserver.compactions.RatioBasedCompactionPolicy;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.Assert;
-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;
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
public class TestDefaultStoreEngine {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestDefaultStoreEngine.class);
-
public static class DummyStoreFlusher extends DefaultStoreFlusher {
public DummyStoreFlusher(Configuration conf, HStore store) {
super(conf, store);
@@ -70,9 +66,9 @@ public class TestDefaultStoreEngine {
Mockito.when(mockStore.getRegionInfo()).thenReturn(RegionInfoBuilder.FIRST_META_REGIONINFO);
Mockito.when(mockStore.getHRegion()).thenReturn(mockRegion);
StoreEngine<?, ?, ?, ?> se = StoreEngine.create(mockStore, conf, CellComparatorImpl.COMPARATOR);
- Assert.assertTrue(se instanceof DefaultStoreEngine);
- Assert.assertTrue(se.getCompactionPolicy() instanceof DummyCompactionPolicy);
- Assert.assertTrue(se.getStoreFlusher() instanceof DummyStoreFlusher);
- Assert.assertTrue(se.getCompactor() instanceof DummyCompactor);
+ assertTrue(se instanceof DefaultStoreEngine);
+ assertTrue(se.getCompactionPolicy() instanceof DummyCompactionPolicy);
+ assertTrue(se.getStoreFlusher() instanceof DummyStoreFlusher);
+ assertTrue(se.getCompactor() instanceof DummyCompactor);
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDeleteMobTable.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDeleteMobTable.java
index 0af8e256156..d0fe86369c9 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDeleteMobTable.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDeleteMobTable.java
@@ -17,10 +17,15 @@
*/
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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
import java.io.IOException;
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.HTableDescriptor;
@@ -37,35 +42,32 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.CommonFSUtils;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.HFileArchiveUtil;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
-
-@Category(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(MediumTests.TAG)
public class TestDeleteMobTable {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestDeleteMobTable.class);
-
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private final static byte[] FAMILY = Bytes.toBytes("family");
private final static byte[] QF = Bytes.toBytes("qualifier");
+ private String name;
- @Rule
- public TestName name = new TestName();
+ @BeforeEach
+ public void setTestName(TestInfo testInfo) {
+ this.name = testInfo.getTestMethod().get().getName();
+ }
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.startMiniCluster(1);
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
@@ -112,7 +114,7 @@ public class TestDeleteMobTable {
@Test
public void testDeleteMobTable() throws Exception {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(name);
HTableDescriptor htd = createTableDescriptor(tableName, true);
HColumnDescriptor hcd = htd.getFamily(FAMILY);
@@ -120,49 +122,49 @@ public class TestDeleteMobTable {
Table table = createTableWithOneFile(htd);
try {
// the mob file exists
- Assert.assertEquals(1, countMobFiles(tableName, hcd.getNameAsString()));
- Assert.assertEquals(0, countArchiveMobFiles(tableName, hcd.getNameAsString()));
+ assertEquals(1, countMobFiles(tableName, hcd.getNameAsString()));
+ assertEquals(0, countArchiveMobFiles(tableName, hcd.getNameAsString()));
fileName = assertHasOneMobRow(table, tableName, hcd.getNameAsString());
- Assert.assertFalse(mobArchiveExist(tableName, hcd.getNameAsString(), fileName));
- Assert.assertTrue(mobTableDirExist(tableName));
+ assertFalse(mobArchiveExist(tableName, hcd.getNameAsString(), fileName));
+ assertTrue(mobTableDirExist(tableName));
} finally {
table.close();
TEST_UTIL.deleteTable(tableName);
}
- Assert.assertFalse(TEST_UTIL.getAdmin().tableExists(tableName));
- Assert.assertEquals(0, countMobFiles(tableName, hcd.getNameAsString()));
- Assert.assertEquals(1, countArchiveMobFiles(tableName, hcd.getNameAsString()));
- Assert.assertTrue(mobArchiveExist(tableName, hcd.getNameAsString(), fileName));
- Assert.assertFalse(mobTableDirExist(tableName));
+ assertFalse(TEST_UTIL.getAdmin().tableExists(tableName));
+ assertEquals(0, countMobFiles(tableName, hcd.getNameAsString()));
+ assertEquals(1, countArchiveMobFiles(tableName, hcd.getNameAsString()));
+ assertTrue(mobArchiveExist(tableName, hcd.getNameAsString(), fileName));
+ assertFalse(mobTableDirExist(tableName));
}
@Test
public void testDeleteNonMobTable() throws Exception {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(name);
HTableDescriptor htd = createTableDescriptor(tableName, false);
HColumnDescriptor hcd = htd.getFamily(FAMILY);
Table table = createTableWithOneFile(htd);
try {
// the mob file doesn't exist
- Assert.assertEquals(0, countMobFiles(tableName, hcd.getNameAsString()));
- Assert.assertEquals(0, countArchiveMobFiles(tableName, hcd.getNameAsString()));
- Assert.assertFalse(mobTableDirExist(tableName));
+ assertEquals(0, countMobFiles(tableName, hcd.getNameAsString()));
+ assertEquals(0, countArchiveMobFiles(tableName, hcd.getNameAsString()));
+ assertFalse(mobTableDirExist(tableName));
} finally {
table.close();
TEST_UTIL.deleteTable(tableName);
}
- Assert.assertFalse(TEST_UTIL.getAdmin().tableExists(tableName));
- Assert.assertEquals(0, countMobFiles(tableName, hcd.getNameAsString()));
- Assert.assertEquals(0, countArchiveMobFiles(tableName, hcd.getNameAsString()));
- Assert.assertFalse(mobTableDirExist(tableName));
+ assertFalse(TEST_UTIL.getAdmin().tableExists(tableName));
+ assertEquals(0, countMobFiles(tableName, hcd.getNameAsString()));
+ assertEquals(0, countArchiveMobFiles(tableName, hcd.getNameAsString()));
+ assertFalse(mobTableDirExist(tableName));
}
@Test
public void testMobFamilyDelete() throws Exception {
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(name);
HTableDescriptor htd = createTableDescriptor(tableName, true);
HColumnDescriptor hcd = htd.getFamily(FAMILY);
htd.addFamily(new HColumnDescriptor(Bytes.toBytes("family2")));
@@ -170,18 +172,18 @@ public class TestDeleteMobTable {
Table table = createTableWithOneFile(htd);
try {
// the mob file exists
- Assert.assertEquals(1, countMobFiles(tableName, hcd.getNameAsString()));
- Assert.assertEquals(0, countArchiveMobFiles(tableName, hcd.getNameAsString()));
+ assertEquals(1, countMobFiles(tableName, hcd.getNameAsString()));
+ assertEquals(0, countArchiveMobFiles(tableName, hcd.getNameAsString()));
String fileName = assertHasOneMobRow(table, tableName, hcd.getNameAsString());
- Assert.assertFalse(mobArchiveExist(tableName, hcd.getNameAsString(), fileName));
- Assert.assertTrue(mobTableDirExist(tableName));
+ assertFalse(mobArchiveExist(tableName, hcd.getNameAsString(), fileName));
+ assertTrue(mobTableDirExist(tableName));
TEST_UTIL.getAdmin().deleteColumnFamily(tableName, FAMILY);
- Assert.assertEquals(0, countMobFiles(tableName, hcd.getNameAsString()));
- Assert.assertEquals(1, countArchiveMobFiles(tableName, hcd.getNameAsString()));
- Assert.assertTrue(mobArchiveExist(tableName, hcd.getNameAsString(), fileName));
- Assert.assertFalse(mobColumnFamilyDirExist(tableName, hcd.getNameAsString()));
+ assertEquals(0, countMobFiles(tableName, hcd.getNameAsString()));
+ assertEquals(1, countArchiveMobFiles(tableName, hcd.getNameAsString()));
+ assertTrue(mobArchiveExist(tableName, hcd.getNameAsString(), fileName));
+ assertFalse(mobColumnFamilyDirExist(tableName, hcd.getNameAsString()));
} finally {
table.close();
TEST_UTIL.deleteTable(tableName);
@@ -234,14 +236,14 @@ public class TestDeleteMobTable {
scan.setAttribute(MobConstants.MOB_SCAN_RAW, Bytes.toBytes(Boolean.TRUE));
ResultScanner rs = table.getScanner(scan);
Result r = rs.next();
- Assert.assertNotNull(r);
+ assertNotNull(r);
String fileName = MobUtils.getMobFileName(r.getColumnLatestCell(FAMILY, QF));
Path filePath =
new Path(MobUtils.getMobFamilyPath(TEST_UTIL.getConfiguration(), tn, familyName), fileName);
FileSystem fs = TEST_UTIL.getTestFileSystem();
- Assert.assertTrue(fs.exists(filePath));
+ assertTrue(fs.exists(filePath));
r = rs.next();
- Assert.assertNull(r);
+ assertNull(r);
return fileName;
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDirectStoreSplitsMerges.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDirectStoreSplitsMerges.java
index 795262a8486..1b65ace80ee 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDirectStoreSplitsMerges.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDirectStoreSplitsMerges.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 java.util.ArrayList;
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.HBaseTestingUtility;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Put;
@@ -41,41 +40,40 @@ import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.util.Bytes;
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.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
-@Category({ RegionServerTests.class, LargeTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(LargeTests.TAG)
public class TestDirectStoreSplitsMerges {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestDirectStoreSplitsMerges.class);
-
private static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
public static final byte[] FAMILY_NAME = Bytes.toBytes("info");
+ private String name;
- @Rule
- public TestName name = new TestName();
+ @BeforeEach
+ public void setTestName(TestInfo testInfo) {
+ this.name = testInfo.getTestMethod().get().getName();
+ }
- @BeforeClass
+ @BeforeAll
public static void setup() throws Exception {
TEST_UTIL.startMiniCluster(1);
}
- @AfterClass
+ @AfterAll
public static void after() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
@Test
public void testSplitStoreDir() throws Exception {
- TableName table = TableName.valueOf(name.getMethodName());
+ TableName table = TableName.valueOf(name);
TEST_UTIL.createTable(table, FAMILY_NAME);
// first put some data in order to have a store file created
putThreeRowsAndFlush(table);
@@ -101,7 +99,7 @@ public class TestDirectStoreSplitsMerges {
@Test
public void testMergeStoreFile() throws Exception {
- TableName table = TableName.valueOf(name.getMethodName());
+ TableName table = TableName.valueOf(name);
TEST_UTIL.createTable(table, FAMILY_NAME);
// splitting the table first
TEST_UTIL.getAdmin().split(table, Bytes.toBytes("002"));
@@ -135,7 +133,7 @@ public class TestDirectStoreSplitsMerges {
@Test
public void testCommitDaughterRegionNoFiles() throws Exception {
- TableName table = TableName.valueOf(name.getMethodName());
+ TableName table = TableName.valueOf(name);
TEST_UTIL.createTable(table, FAMILY_NAME);
HRegion region = TEST_UTIL.getHBaseCluster().getRegions(table).get(0);
HRegionFileSystem regionFS = region.getStores().get(0).getRegionFileSystem();
@@ -153,7 +151,7 @@ public class TestDirectStoreSplitsMerges {
@Test
public void testCommitDaughterRegionWithFiles() throws Exception {
- TableName table = TableName.valueOf(name.getMethodName());
+ TableName table = TableName.valueOf(name);
TEST_UTIL.createTable(table, FAMILY_NAME);
// first put some data in order to have a store file created
putThreeRowsAndFlush(table);
@@ -189,7 +187,7 @@ public class TestDirectStoreSplitsMerges {
@Test
public void testCommitMergedRegion() throws Exception {
- TableName table = TableName.valueOf(name.getMethodName());
+ TableName table = TableName.valueOf(name);
TEST_UTIL.createTable(table, FAMILY_NAME);
// splitting the table first
TEST_UTIL.getAdmin().split(table, Bytes.toBytes("002"));
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionDisabled.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionDisabled.java
index 166ee98956c..3274c2a5b4f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionDisabled.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionDisabled.java
@@ -17,9 +17,11 @@
*/
package org.apache.hadoop.hbase.regionserver;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
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.HConstants;
import org.apache.hadoop.hbase.TableName;
@@ -31,29 +33,21 @@ import org.apache.hadoop.hbase.testclassification.MasterTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.TableDescriptorChecker;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
-@Category({ MasterTests.class, MediumTests.class })
+@Tag(MasterTests.TAG)
+@Tag(MediumTests.TAG)
public class TestEncryptionDisabled {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestEncryptionDisabled.class);
-
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
+
private static Configuration conf = TEST_UTIL.getConfiguration();
private static TableDescriptorBuilder tdb;
- @BeforeClass
+ @BeforeAll
public static void setUp() throws Exception {
conf.setInt("hfile.format.version", 3);
conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName());
@@ -65,7 +59,7 @@ public class TestEncryptionDisabled {
TEST_UTIL.startMiniCluster(1);
}
- @AfterClass
+ @AfterAll
public static void tearDown() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
@@ -83,9 +77,9 @@ public class TestEncryptionDisabled {
tdb.setColumnFamily(columnFamilyDescriptorBuilder.build());
// Create the test table, we expect to get back an exception
- exception.expect(DoNotRetryIOException.class);
- exception.expectMessage("encryption is disabled on the cluster");
- TEST_UTIL.getAdmin().createTable(tdb.build());
+ DoNotRetryIOException exception = assertThrows(DoNotRetryIOException.class,
+ () -> TEST_UTIL.getAdmin().createTable(tdb.build()));
+ assertTrue(exception.getMessage().contains("encryption is disabled on the cluster"));
}
@Test
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionKeyRotation.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionKeyRotation.java
index e70cc709727..5a4ec15abc9 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionKeyRotation.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionKeyRotation.java
@@ -17,8 +17,8 @@
*/
package org.apache.hadoop.hbase.regionserver;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.security.Key;
@@ -28,7 +28,6 @@ import java.util.List;
import javax.crypto.spec.SecretKeySpec;
import org.apache.hadoop.conf.Configuration;
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;
@@ -48,31 +47,30 @@ import org.apache.hadoop.hbase.security.User;
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.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Category({ RegionServerTests.class, MediumTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(MediumTests.TAG)
public class TestEncryptionKeyRotation {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestEncryptionKeyRotation.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestEncryptionKeyRotation.class);
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final Configuration conf = TEST_UTIL.getConfiguration();
private static final Key initialCFKey;
private static final Key secondCFKey;
+ private String name;
- @Rule
- public TestName name = new TestName();
+ @BeforeEach
+ public void setTestName(TestInfo testInfo) {
+ this.name = testInfo.getTestMethod().get().getName();
+ }
static {
// Create the test encryption keys
@@ -84,7 +82,7 @@ public class TestEncryptionKeyRotation {
secondCFKey = new SecretKeySpec(keyBytes, algorithm);
}
- @BeforeClass
+ @BeforeAll
public static void setUp() throws Exception {
conf.setInt("hfile.format.version", 3);
conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName());
@@ -94,7 +92,7 @@ public class TestEncryptionKeyRotation {
TEST_UTIL.startMiniCluster(1);
}
- @AfterClass
+ @AfterAll
public static void tearDown() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
@@ -102,7 +100,7 @@ public class TestEncryptionKeyRotation {
@Test
public void testCFKeyRotation() throws Exception {
// Create the table schema
- HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("default", name.getMethodName()));
+ HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("default", name));
HColumnDescriptor hcd = new HColumnDescriptor("cf");
String algorithm = conf.get(HConstants.CRYPTO_KEY_ALGORITHM_CONF_KEY, HConstants.CIPHER_AES);
hcd.setEncryptionType(algorithm);
@@ -116,8 +114,8 @@ public class TestEncryptionKeyRotation {
final List<Path> initialPaths = findStorefilePaths(htd.getTableName());
assertTrue(initialPaths.size() > 0);
for (Path path : initialPaths) {
- assertTrue("Store file " + path + " has incorrect key",
- Bytes.equals(initialCFKey.getEncoded(), extractHFileKey(path)));
+ assertTrue(Bytes.equals(initialCFKey.getEncoded(), extractHFileKey(path)),
+ "Store file " + path + " has incorrect key");
}
// Update the schema with a new encryption key
@@ -140,21 +138,21 @@ public class TestEncryptionKeyRotation {
List<Path> pathsAfterCompaction = findStorefilePaths(htd.getTableName());
assertTrue(pathsAfterCompaction.size() > 0);
for (Path path : pathsAfterCompaction) {
- assertTrue("Store file " + path + " has incorrect key",
- Bytes.equals(secondCFKey.getEncoded(), extractHFileKey(path)));
+ assertTrue(Bytes.equals(secondCFKey.getEncoded(), extractHFileKey(path)),
+ "Store file " + path + " has incorrect key");
}
List<Path> compactedPaths = findCompactedStorefilePaths(htd.getTableName());
assertTrue(compactedPaths.size() > 0);
for (Path path : compactedPaths) {
- assertTrue("Store file " + path + " retains initial key",
- Bytes.equals(initialCFKey.getEncoded(), extractHFileKey(path)));
+ assertTrue(Bytes.equals(initialCFKey.getEncoded(), extractHFileKey(path)),
+ "Store file " + path + " retains initial key");
}
}
@Test
public void testMasterKeyRotation() throws Exception {
// Create the table schema
- HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("default", name.getMethodName()));
+ HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("default", name));
HColumnDescriptor hcd = new HColumnDescriptor("cf");
String algorithm = conf.get(HConstants.CRYPTO_KEY_ALGORITHM_CONF_KEY, HConstants.CIPHER_AES);
hcd.setEncryptionType(algorithm);
@@ -168,8 +166,8 @@ public class TestEncryptionKeyRotation {
List<Path> storeFilePaths = findStorefilePaths(htd.getTableName());
assertTrue(storeFilePaths.size() > 0);
for (Path path : storeFilePaths) {
- assertTrue("Store file " + path + " has incorrect key",
- Bytes.equals(initialCFKey.getEncoded(), extractHFileKey(path)));
+ assertTrue(Bytes.equals(initialCFKey.getEncoded(), extractHFileKey(path)),
+ "Store file " + path + " has incorrect key");
}
// Now shut down the HBase cluster
@@ -187,8 +185,8 @@ public class TestEncryptionKeyRotation {
storeFilePaths = findStorefilePaths(htd.getTableName());
assertTrue(storeFilePaths.size() > 0);
for (Path path : storeFilePaths) {
- assertTrue("Store file " + path + " has incorrect key",
- Bytes.equals(initialCFKey.getEncoded(), extractHFileKey(path)));
+ assertTrue(Bytes.equals(initialCFKey.getEncoded(), extractHFileKey(path)),
+ "Store file " + path + " has incorrect key");
}
}
@@ -241,9 +239,9 @@ public class TestEncryptionKeyRotation {
HFile.createReader(TEST_UTIL.getTestFileSystem(), path, new CacheConfig(conf), true, conf);
try {
Encryption.Context cryptoContext = reader.getFileContext().getEncryptionContext();
- assertNotNull("Reader has a null crypto context", cryptoContext);
+ assertNotNull(cryptoContext, "Reader has a null crypto context");
Key key = cryptoContext.getKey();
- assertNotNull("Crypto context has no key", key);
+ assertNotNull(key, "Crypto context has no key");
return key.getEncoded();
} finally {
reader.close();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionRandomKeying.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionRandomKeying.java
index 8510dde3651..e1c6df40123 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionRandomKeying.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionRandomKeying.java
@@ -17,15 +17,14 @@
*/
package org.apache.hadoop.hbase.regionserver;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.security.Key;
import java.util.ArrayList;
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.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
@@ -40,19 +39,15 @@ import org.apache.hadoop.hbase.io.hfile.HFile;
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;
-@Category({ RegionServerTests.class, MediumTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(MediumTests.TAG)
public class TestEncryptionRandomKeying {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestEncryptionRandomKeying.class);
-
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static Configuration conf = TEST_UTIL.getConfiguration();
private static HTableDescriptor htd;
@@ -75,7 +70,7 @@ public class TestEncryptionRandomKeying {
HFile.createReader(TEST_UTIL.getTestFileSystem(), path, new CacheConfig(conf), true, conf);
try {
Encryption.Context cryptoContext = reader.getFileContext().getEncryptionContext();
- assertNotNull("Reader has a null crypto context", cryptoContext);
+ assertNotNull(cryptoContext, "Reader has a null crypto context");
Key key = cryptoContext.getKey();
if (key == null) {
return null;
@@ -86,7 +81,7 @@ public class TestEncryptionRandomKeying {
}
}
- @BeforeClass
+ @BeforeAll
public static void setUp() throws Exception {
conf.setInt("hfile.format.version", 3);
conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName());
@@ -118,7 +113,7 @@ public class TestEncryptionRandomKeying {
TEST_UTIL.getAdmin().flush(htd.getTableName());
}
- @AfterClass
+ @AfterAll
public static void tearDown() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
@@ -129,7 +124,7 @@ public class TestEncryptionRandomKeying {
final List<Path> initialPaths = findStorefilePaths(htd.getTableName());
assertTrue(initialPaths.size() > 0);
for (Path path : initialPaths) {
- assertNotNull("Store file " + path + " is not encrypted", extractHFileKey(path));
+ assertNotNull(extractHFileKey(path), "Store file " + path + " is not encrypted");
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEndToEndSplitTransaction.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEndToEndSplitTransaction.java
index 7f5d529d6bf..a5dd9e15c81 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEndToEndSplitTransaction.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEndToEndSplitTransaction.java
@@ -17,10 +17,10 @@
*/
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.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
@@ -33,7 +33,6 @@ import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.ChoreService;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionLocation;
@@ -62,13 +61,12 @@ import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.util.PairOfSameType;
import org.apache.hadoop.hbase.util.StoppableImplementation;
import org.apache.hadoop.hbase.util.Threads;
-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;
@@ -76,27 +74,26 @@ import org.apache.hbase.thirdparty.com.google.common.collect.Iterators;
import org.apache.hbase.thirdparty.com.google.common.collect.Maps;
import org.apache.hbase.thirdparty.com.google.common.io.Closeables;
-@Category(LargeTests.class)
+@Tag(LargeTests.TAG)
public class TestEndToEndSplitTransaction {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestEndToEndSplitTransaction.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestEndToEndSplitTransaction.class);
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final Configuration CONF = TEST_UTIL.getConfiguration();
+ private String name;
- @Rule
- public TestName name = new TestName();
+ @BeforeEach
+ public void setTestName(TestInfo testInfo) {
+ this.name = testInfo.getTestMethod().get().getName();
+ }
- @BeforeClass
+ @BeforeAll
public static void beforeAllTests() throws Exception {
TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 5);
TEST_UTIL.startMiniCluster(1);
}
- @AfterClass
+ @AfterAll
public static void afterAllTests() throws Exception {
TEST_UTIL.shutdownMiniCluster();
}
@@ -137,8 +134,8 @@ public class TestEndToEndSplitTransaction {
LOG.info("Got reference to file = " + sf.getPath() + ",for region = "
+ r.getRegionInfo().getEncodedName());
}));
- assertTrue("Regions did not split properly", regions.size() > 1);
- assertTrue("Could not get reference any of the store file", scanner.size() > 1);
+ assertTrue(regions.size() > 1, "Regions did not split properly");
+ assertTrue(scanner.size() > 1, "Could not get reference any of the store file");
compactSplit.setCompactionsEnabled(true);
for (HRegion region : regions) {
region.compact(true);
@@ -146,8 +143,8 @@ public class TestEndToEndSplitTransaction {
regions.stream()
.filter(region -> scanner.containsKey(region.getRegionInfo().getEncodedName()))
- .forEach(r -> assertFalse("Contains an open file reference which can be split",
- r.getStores().get(0).canSplit()));
+ .forEach(r -> assertFalse(r.getStores().get(0).canSplit(),
+ "Contains an open file reference which can be split"));
} finally {
scanner.values().forEach(s -> {
try {
@@ -171,7 +168,7 @@ public class TestEndToEndSplitTransaction {
@Test
public void testFromClientSideWhileSplitting() throws Throwable {
LOG.info("Starting testFromClientSideWhileSplitting");
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(name);
final byte[] FAMILY = Bytes.toBytes("family");
// SplitTransaction will update the meta table by offlining the parent region, and adding info
@@ -257,7 +254,6 @@ public class TestEndToEndSplitTransaction {
admin.splitRegion(region.getRegionName(), splitPoint);
// wait until the split is complete
blockUntilRegionSplit(CONF, 50000, region.getRegionName(), true);
-
} catch (NotServingRegionException ex) {
// ignore
}
@@ -345,22 +341,21 @@ public class TestEndToEndSplitTransaction {
byte[][] startKeys = keys.getFirst();
byte[][] endKeys = keys.getSecond();
assertEquals(startKeys.length, endKeys.length);
- assertTrue("Found 0 regions for the table", startKeys.length > 0);
+ assertTrue(startKeys.length > 0, "Found 0 regions for the table");
- assertArrayEquals("Start key for the first region is not byte[0]", HConstants.EMPTY_START_ROW,
- startKeys[0]);
+ assertArrayEquals(HConstants.EMPTY_START_ROW, startKeys[0],
+ "Start key for the first region is not byte[0]");
byte[] prevEndKey = HConstants.EMPTY_START_ROW;
// ensure that we do not have any gaps
for (int i = 0; i < startKeys.length; i++) {
- assertArrayEquals(
+ assertArrayEquals(prevEndKey, startKeys[i],
"Hole in hbase:meta is detected. prevEndKey=" + Bytes.toStringBinary(prevEndKey)
- + " ,regionStartKey=" + Bytes.toStringBinary(startKeys[i]),
- prevEndKey, startKeys[i]);
+ + " ,regionStartKey=" + Bytes.toStringBinary(startKeys[i]));
prevEndKey = endKeys[i];
}
- assertArrayEquals("End key for the last region is not byte[0]", HConstants.EMPTY_END_ROW,
- endKeys[endKeys.length - 1]);
+ assertArrayEquals(HConstants.EMPTY_END_ROW, endKeys[endKeys.length - 1],
+ "End key for the last region is not byte[0]");
}
@Override
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFSErrorsExposed.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFSErrorsExposed.java
index a0886123c16..6dd4af68367 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFSErrorsExposed.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFSErrorsExposed.java
@@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.regionserver;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.io.InputStream;
@@ -32,7 +32,6 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FilterFileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PositionedReadable;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
@@ -50,12 +49,11 @@ import org.apache.hadoop.hbase.io.hfile.HFileScanner;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.Assume;
-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.Assumptions;
+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;
@@ -63,19 +61,19 @@ import org.slf4j.LoggerFactory;
* Test cases that ensure that file system level errors are bubbled up appropriately to clients,
* rather than swallowed.
*/
-@Category({ RegionServerTests.class, LargeTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(LargeTests.TAG)
public class TestFSErrorsExposed {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestFSErrorsExposed.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestFSErrorsExposed.class);
HBaseTestingUtility util = new HBaseTestingUtility();
+ private String name;
- @Rule
- public TestName name = new TestName();
+ @BeforeEach
+ public void setTestName(TestInfo testInfo) {
+ this.name = testInfo.getTestMethod().get().getName();
+ }
/**
* Injects errors into the pread calls of an on-disk file, and makes sure those bubble up to the
@@ -179,7 +177,7 @@ public class TestFSErrorsExposed {
public void testFullSystemBubblesFSErrors() throws Exception {
// We won't have an error if the datanode is not there if we use short circuit
// it's a known 'feature'.
- Assume.assumeTrue(!util.isReadShortCircuitOn());
+ Assumptions.assumeTrue(!util.isReadShortCircuitOn());
try {
// Make it fail faster.
@@ -188,7 +186,7 @@ public class TestFSErrorsExposed {
util.getConfiguration().setInt("hbase.lease.recovery.timeout", 10000);
util.getConfiguration().setInt("hbase.lease.recovery.dfs.timeout", 1000);
util.startMiniCluster(1);
- final TableName tableName = TableName.valueOf(name.getMethodName());
+ final TableName tableName = TableName.valueOf(name);
byte[] fam = Bytes.toBytes("fam");
Admin admin = util.getAdmin();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFailedAppendAndSync.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFailedAppendAndSync.java
index a460aa49220..d9beae7a85e 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFailedAppendAndSync.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFailedAppendAndSync.java
@@ -17,8 +17,8 @@
*/
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 static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.atLeast;
@@ -35,7 +35,6 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.Abortable;
import org.apache.hadoop.hbase.DroppedSnapshotException;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
@@ -50,13 +49,11 @@ import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.wal.WAL;
import org.apache.hadoop.hbase.wal.WALProvider.Writer;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.mockito.exceptions.verification.WantedButNotInvoked;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -64,16 +61,11 @@ import org.slf4j.LoggerFactory;
/**
* Testing sync/append failures. Copied from TestHRegion.
*/
-@Category({ SmallTests.class })
+@Tag(SmallTests.TAG)
public class TestFailedAppendAndSync {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestFailedAppendAndSync.class);
-
private static final Logger LOG = LoggerFactory.getLogger(TestFailedAppendAndSync.class);
- @Rule
- public TestName name = new TestName();
+ private String name;
private static final String COLUMN_FAMILY = "MyCF";
private static final byte[] COLUMN_FAMILY_BYTES = Bytes.toBytes(COLUMN_FAMILY);
@@ -87,17 +79,18 @@ public class TestFailedAppendAndSync {
// Test names
protected TableName tableName;
- @Before
- public void setup() throws IOException {
+ @BeforeEach
+ public void setup(TestInfo testInfo) throws IOException {
+ this.name = testInfo.getTestMethod().get().getName();
TEST_UTIL = HBaseTestingUtility.createLocalHTU();
CONF = TEST_UTIL.getConfiguration();
// Disable block cache.
CONF.setFloat(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, 0f);
dir = TEST_UTIL.getDataTestDir("TestHRegion").toString();
- tableName = TableName.valueOf(name.getMethodName());
+ tableName = TableName.valueOf(name);
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
EnvironmentEdgeManagerTestHelper.reset();
LOG.info("Cleaning test directory: " + TEST_UTIL.getDataTestDir());
@@ -105,7 +98,7 @@ public class TestFailedAppendAndSync {
}
String getName() {
- return name.getMethodName();
+ return name;
}
/**
@@ -303,9 +296,9 @@ public class TestFailedAppendAndSync {
}
}
if (dodgyWAL != null) dodgyWAL.close();
- assertTrue("The regionserver should have thrown an exception", threwOnBoth);
- assertTrue("The regionserver should have thrown an exception", threwOnAppend);
- assertTrue("The regionserver should have thrown an exception", threwOnSync);
+ assertTrue(threwOnBoth, "The regionserver should have thrown an exception");
+ assertTrue(threwOnAppend, "The regionserver should have thrown an exception");
+ assertTrue(threwOnSync, "The regionserver should have thrown an exception");
}
}
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFlushLifeCycleTracker.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFlushLifeCycleTracker.java
index b3bc61229f0..d59e91b3b23 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFlushLifeCycleTracker.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFlushLifeCycleTracker.java
@@ -17,11 +17,11 @@
*/
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.assertSame;
-import static org.junit.Assert.assertTrue;
+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.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.io.InterruptedIOException;
@@ -30,7 +30,6 @@ import java.util.concurrent.CountDownLatch;
import org.apache.hadoop.hbase.Cell.Type;
import org.apache.hadoop.hbase.CellBuilderFactory;
import org.apache.hadoop.hbase.CellBuilderType;
-import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
@@ -45,24 +44,20 @@ import org.apache.hadoop.hbase.coprocessor.RegionObserver;
import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
/**
* Confirm that the function of FlushLifeCycleTracker is OK as we do not use it in our own code.
*/
-@Category({ CoprocessorTests.class, MediumTests.class })
+@Tag(CoprocessorTests.TAG)
+@Tag(MediumTests.TAG)
public class TestFlushLifeCycleTracker {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestFlushLifeCycleTracker.class);
-
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
private static final TableName NAME =
@@ -168,17 +163,17 @@ public class TestFlushLifeCycleTracker {
}
}
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
UTIL.startMiniCluster(3);
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() throws Exception {
UTIL.shutdownMiniCluster();
}
- @Before
+ @BeforeEach
public void setUp() throws IOException {
UTIL.getAdmin()
.createTable(TableDescriptorBuilder.newBuilder(NAME)
@@ -187,7 +182,7 @@ public class TestFlushLifeCycleTracker {
region = UTIL.getHBaseCluster().getRegions(NAME).get(0);
}
- @After
+ @AfterEach
public void tearDown() throws IOException {
region = null;
TRACKER = null;
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFlushRegionEntry.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFlushRegionEntry.java
index a5eb7a593b4..5e994b76d0c 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFlushRegionEntry.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestFlushRegionEntry.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 static org.mockito.Mockito.doReturn;
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;
@@ -30,40 +29,40 @@ import org.apache.hadoop.hbase.testclassification.RegionServerTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.ManualEnvironmentEdge;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
public class TestFlushRegionEntry {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestFlushRegionEntry.class);
+ private String name;
- @Rule
- public TestName name = new TestName();
+ @BeforeEach
+ public void setTestName(TestInfo testInfo) {
+ this.name = testInfo.getTestMethod().get().getName();
+ }
- @BeforeClass
+ @BeforeAll
public static void setUp() throws Exception {
ManualEnvironmentEdge edge = new ManualEnvironmentEdge();
edge.setValue(12345);
EnvironmentEdgeManager.injectEdge(edge);
}
- @AfterClass
+ @AfterAll
public static void teardown() {
EnvironmentEdgeManager.reset();
}
@Test
public void testFlushRegionEntryEquality() {
- RegionInfo hri = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName()))
- .setRegionId(1).setReplicaId(0).build();
+ RegionInfo hri =
+ RegionInfoBuilder.newBuilder(TableName.valueOf(name)).setRegionId(1).setReplicaId(0).build();
HRegion r = mock(HRegion.class);
doReturn(hri).when(r).getRegionInfo();
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestGetClosestAtOrBefore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestGetClosestAtOrBefore.java
index 33c4b913163..ed1c3972f6f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestGetClosestAtOrBefore.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestGetClosestAtOrBefore.java
@@ -17,8 +17,8 @@
*/
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.nio.charset.StandardCharsets;
@@ -28,7 +28,6 @@ import org.apache.hadoop.conf.Configuration;
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.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
@@ -48,11 +47,10 @@ import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.wal.WAL;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -61,15 +59,10 @@ import org.slf4j.LoggerFactory;
* test a method since removed, getClosestAtOrBefore but the test is retained because it runs some
* interesting exercises.
*/
-@Category({ RegionServerTests.class, SmallTests.class })
+@Tag(RegionServerTests.TAG)
+@Tag(SmallTests.TAG)
public class TestGetClosestAtOrBefore {
- @ClassRule
- public static final HBaseClassTestRule CLASS_RULE =
- HBaseClassTestRule.forClass(TestGetClosestAtOrBefore.class);
-
- @Rule
- public TestName testName = new TestName();
private static final Logger LOG = LoggerFactory.getLogger(TestGetClosestAtOrBefore.class);
private static final byte[] T00 = Bytes.toBytes("000");
@@ -84,6 +77,12 @@ public class TestGetClosestAtOrBefore {
private static HBaseTestingUtility UTIL = new HBaseTestingUtility();
private static Configuration conf = UTIL.getConfiguration();
+ private String testName;
+
+ @BeforeEach
+ public void setTestName(TestInfo testInfo) {
+ this.testName = testInfo.getTestMethod().get().getName();
+ }
@Test
public void testUsingMetaAndBinary() throws IOException {
@@ -160,7 +159,7 @@ public class TestGetClosestAtOrBefore {
}
}
- /*
+ /**
* @param answer Pass -1 if we're not to find anything.
* @return Row found.
*/
@@ -200,7 +199,7 @@ public class TestGetClosestAtOrBefore {
byte[] c0 = UTIL.COLUMNS[0];
byte[] c1 = UTIL.COLUMNS[1];
try {
- TableName tn = TableName.valueOf(testName.getMethodName());
+ TableName tn = TableName.valueOf(testName);
HTableDescriptor htd = UTIL.createTableDescriptor(tn);
region = UTIL.createLocalHRegion(htd, null, null);
@@ -310,7 +309,7 @@ public class TestGetClosestAtOrBefore {
HRegion region = null;
byte[] c0 = UTIL.COLUMNS[0];
try {
- TableName tn = TableName.valueOf(testName.getMethodName());
+ TableName tn = TableName.valueOf(testName);
HTableDescriptor htd = UTIL.createTableDescriptor(tn);
region = UTIL.createLocalHRegion(htd, null, null);