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 0a3a9ffa5139..057b12ed64a7 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 @@ import static org.apache.hadoop.hbase.HBaseTestingUtil.fam1; import static org.apache.hadoop.hbase.HBaseTestingUtil.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.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.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MultithreadedTestUtil; @@ -70,29 +69,23 @@ 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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); @@ -107,12 +100,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(); @@ -133,11 +127,11 @@ public void teardown() throws IOException { /** * 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."; @@ -157,7 +151,7 @@ public void testAppend() throws IOException { @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"; @@ -166,8 +160,8 @@ public void testAppendWithMultipleFamilies() throws IOException { 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)); @@ -182,10 +176,10 @@ public void testAppendWithMultipleFamilies() throws IOException { 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)); @@ -194,7 +188,7 @@ public void testAppendWithMultipleFamilies() throws IOException { @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)); @@ -212,7 +206,7 @@ public void testAppendWithNonExistingFamily() throws IOException { @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); @@ -237,7 +231,7 @@ public void testIncrementMultiThreads() throws IOException { 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. @@ -343,8 +337,8 @@ public void run() { 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(); @@ -357,7 +351,7 @@ public void run() { 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; @@ -421,7 +415,7 @@ public void run() { @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 @@ -512,7 +506,7 @@ public void run() { 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 @@ -639,7 +633,7 @@ public void testPutAndCheckAndPutInParallel() throws Exception { Configuration conf = TEST_UTIL.getConfiguration(); conf.setClass(HConstants.REGION_IMPL, MockHRegion.class, HeapSize.class); TableDescriptorBuilder tableDescriptorBuilder = - TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName())); + TableDescriptorBuilder.newBuilder(TableName.valueOf(name)); ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(family)).build(); tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor); 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 640ad10af230..199b8b9c513e 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.fs.Path; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; @@ -47,26 +46,26 @@ 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 @@ private Cell[] getData(String family, String row, List columns, int expB 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 @@ private void deleteFamily(String family, String row, long version) throws IOExce 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 void testBlocksRead() throws Exception { 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 void testLazySeekBlocksRead() throws Exception { 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 void testBlocksStoredWhenCachingDisabled() throws Exception { 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 void testLazySeekBlocksReadWithDelete() throws Exception { 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 682dfeb1db21..4f7657b3ea9f 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.ExtendedCell; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.KeyValueUtil; import org.apache.hadoop.hbase.TableName; @@ -43,19 +42,15 @@ 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 HBaseTestingUtil(); 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 3aac6b0f10f2..e43fccb63a86 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.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; @@ -45,27 +44,22 @@ 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. *

* 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 HBaseTestingUtil UTIL = new HBaseTestingUtil(); 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 @@ private void generateHFiles() throws IOException { } } - @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 = HBaseTestingUtil.createRegionAndWAL(RI, rootDir, UTIL.getConfiguration(), TD); generateHFiles(); @@ -131,7 +124,7 @@ public void setUp() throws IOException { } } - @After + @AfterEach public void tearDown() throws IOException { if (region != null) { HBaseTestingUtil.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 359de3a3e627..40056c70cf20 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 @@ 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; @@ -36,7 +36,6 @@ import java.util.List; import java.util.concurrent.CompletableFuture; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseRpcServicesBase; import org.apache.hadoop.hbase.ServerName; @@ -47,19 +46,15 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.FutureUtils; 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 AsyncClusterConnection conn; @@ -68,7 +63,7 @@ public class TestBootstrapNodeManager { private BootstrapNodeManager manager; - @Before + @BeforeEach public void setUp() { conf = HBaseConfiguration.create(); conf.setLong(BootstrapNodeManager.REQUEST_MASTER_INTERVAL_SECS, 5); @@ -80,7 +75,7 @@ public void setUp() { 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 57372ed0c57a..e27e28e4ff82 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.List; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; @@ -38,19 +37,15 @@ 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 HBaseTestingUtil testUtil = new HBaseTestingUtil(); 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 void setUp() throws Exception { 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 8806bb4b3e49..1ca07c3f1675 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.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> familyPaths = withFamilyPathsFor(family1); @@ -84,12 +81,12 @@ public Object answer(InvocationOnMock invocation) { 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() { @@ -108,7 +105,7 @@ public Object answer(InvocationOnMock invocation) { 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,7 +117,7 @@ public Object answer(InvocationOnMock invocation) { MultiVersionConcurrencyControl.WriteEntry we = mvcc.begin(); walKey.setWriteEntry(we); } - return 01L; + return 1L; } }); testRegionWithFamilies(family1, family2).bulkLoadHFiles(withFamilyPathsFor(family1, family2), @@ -128,7 +125,7 @@ public Object answer(InvocationOnMock invocation) { 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,7 +137,7 @@ public Object answer(InvocationOnMock invocation) { MultiVersionConcurrencyControl.WriteEntry we = mvcc.begin(); walKey.setWriteEntry(we); } - return 01L; + return 1L; } }); TableName tableName = TableName.valueOf("test", "test"); @@ -149,43 +146,46 @@ public Object answer(InvocationOnMock invocation) { 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> 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> 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 f844780fbc98..549f5f2aa1ea 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.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.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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 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 data() { - Boolean[] data = { false, true }; - return Arrays.asList(data); + public static Stream 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 @@ protected HRegion testRegionWithFamiliesAndSpecifiedTableName(TableName tableNam 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 @@ protected List> withFamilyPathsFor(byte[]... families) thro 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 @@ private String createHFileForFamilies(byte[] family) throws IOException { 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 27089a55e5ea..ded04fb52e4a 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.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.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; @@ -62,29 +68,22 @@ 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 HBaseTestingUtil UTIL; private static final byte[] CF = Bytes.toBytes("cf"); @@ -99,8 +98,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 HBaseTestingUtil(); conf = UTIL.getConfiguration(); conf.setInt(HRegion.MEMSTORE_PERIODIC_FLUSH_INTERVAL, 0); @@ -112,7 +112,7 @@ public void testScanMetricsDisabled() throws Exception { 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(); @@ -125,8 +125,8 @@ public void testScanMetricsDisabled() throws Exception { for (Result r : scanner) { rowCount++; } - Assert.assertEquals(2, rowCount); - Assert.assertNull(scanner.getScanMetrics()); + assertEquals(2, rowCount); + assertNull(scanner.getScanMetrics()); } } finally { UTIL.shutdownMiniCluster(); @@ -138,7 +138,7 @@ public void testBytesReadFromFsForSerialSeeks() throws Exception { 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); @@ -148,8 +148,8 @@ public void testBytesReadFromFsForSerialSeeks() throws Exception { KeyValue keyValue = new KeyValue(ROW2, CF, CQ, PrivateConstants.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(); } @@ -162,7 +162,7 @@ public void testBytesReadFromFsForParallelSeeks() throws Exception { 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); @@ -172,15 +172,15 @@ public void testBytesReadFromFsForParallelSeeks() throws Exception { 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, PrivateConstants.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(); } @@ -190,21 +190,21 @@ public void testBytesReadFromFsForParallelSeeks() throws Exception { 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, PrivateConstants.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(); } @@ -214,7 +214,7 @@ public void testBytesReadFromBlockCache() throws Exception { 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); @@ -224,7 +224,7 @@ public void testBytesReadFromMemstore() throws Exception { 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); @@ -233,9 +233,9 @@ public void testBytesReadFromMemstore() throws Exception { // 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(); } @@ -249,7 +249,7 @@ public void testBytesReadWithSwitchFromPReadToStream() throws Exception { 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(); @@ -263,23 +263,23 @@ public void testBytesReadWithSwitchFromPReadToStream() throws Exception { 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(); } @@ -289,7 +289,7 @@ public void testBytesReadWithSwitchFromPReadToStream() throws Exception { 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(); @@ -309,28 +309,28 @@ public void testBytesReadWhenFlushHappenedInTheMiddleOfScan() throws Exception { for (Result r : scanner) { rowCount++; } - 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(3, scanMetrics.countOfRPCcalls.get()); + assertEquals(3, scanMetrics.countOfRPCcalls.get()); } finally { UTIL.shutdownMiniCluster(); } @@ -340,7 +340,7 @@ public void testBytesReadWhenFlushHappenedInTheMiddleOfScan() throws Exception { 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(); @@ -357,14 +357,14 @@ public void testBytesReadInReverseScan() throws Exception { 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. @@ -373,14 +373,14 @@ public void testBytesReadInReverseScan() throws Exception { // 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(); } @@ -390,7 +390,7 @@ public void testBytesReadInReverseScan() throws Exception { 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)) { @@ -411,21 +411,21 @@ public void testBytesReadWithLazySeek() throws Exception { 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(); @@ -443,7 +443,7 @@ public void testConsecutiveRegionScannerNextCalls() throws Exception { 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)) { @@ -461,18 +461,18 @@ public void testConsecutiveRegionScannerNextCalls() throws Exception { 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); @@ -483,17 +483,17 @@ public void testConsecutiveRegionScannerNextCalls() throws Exception { 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); @@ -503,18 +503,18 @@ public void testConsecutiveRegionScannerNextCalls() throws Exception { 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(); @@ -537,7 +537,7 @@ private void flushAndWaitUntilFlushed(TableName tableName, boolean waitForUpdate } UTIL.flush(tableName); List 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 @@ -554,17 +554,17 @@ private void flushAndWaitUntilFlushed(TableName tableName, boolean waitForUpdate 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 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 storeFiles = store.getStorefiles(); - Assert.assertEquals(expectedStoreFileCount, storeFiles.size()); + assertEquals(expectedStoreFileCount, storeFiles.size()); int bytesReadFromFs = 0; for (HStoreFile storeFile : storeFiles) { StoreFileReader reader = storeFile.getReader(); @@ -590,12 +590,12 @@ private int getBytesReadToReadConsecutiveDataBlocks(TableName tableName, 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; } @@ -603,11 +603,11 @@ private int getBytesReadToReadConsecutiveDataBlocks(TableName tableName, private int getBytesReadFromFsForNonGetScan(TableName tableName, ScanMetrics scanMetrics, int expectedStoreFileCount) throws Exception { List 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 storeFiles = store.getStorefiles(); - Assert.assertEquals(expectedStoreFileCount, storeFiles.size()); + assertEquals(expectedStoreFileCount, storeFiles.size()); int bytesReadFromFs = 0; for (HStoreFile storeFile : storeFiles) { StoreFileReader reader = storeFile.getReader(); @@ -618,7 +618,7 @@ private int getBytesReadFromFsForNonGetScan(TableName tableName, ScanMetrics sca // 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(); @@ -626,7 +626,7 @@ private int getBytesReadFromFsForNonGetScan(TableName tableName, ScanMetrics sca 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; } @@ -645,7 +645,7 @@ private ScanMetrics readDataAndGetScanMetrics(TableName tableName, boolean isSca for (Result r : scanner) { rowCount++; } - Assert.assertEquals(1, rowCount); + assertEquals(1, rowCount); scanMetrics = scanner.getScanMetrics(); } if (isScanMetricsEnabled) { @@ -708,19 +708,19 @@ private void createTable(TableName tableName, boolean blockCacheEnabled, BloomTy private void assertBytesReadFromFs(TableName tableName, long actualBytesReadFromFs, KeyValue keyValue, long actualReadOps) throws Exception { List 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 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 bytesReadFunction = new Consumer() { @Override @@ -735,8 +735,8 @@ public void accept(HFileBlock block) { 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, @@ -761,7 +761,7 @@ private void readHFile(HFile.Reader hfileReader, CompoundBloomFilter cbf, KeyVal 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 @@ -810,24 +810,24 @@ private void readHFile(HFile.Reader hfileReader, CompoundBloomFilter cbf, KeyVal 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 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 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 bytesReadFunction = new Consumer() { @Override @@ -841,23 +841,22 @@ public void accept(HFileBlock block) { readHFile(hfileReader, cbf, keyValue, bytesReadFunction); } } - Assert.assertEquals(totalExpectedBytesReadFromBlockCache.longValue(), - actualBytesReadFromBlockCache); + assertEquals(totalExpectedBytesReadFromBlockCache.longValue(), actualBytesReadFromBlockCache); } private void assertBlockCacheWarmUp(TableName tableName, KeyValue keyValue) throws Exception { List 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 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 bytesReadFunction = new Consumer() { @Override @@ -878,9 +877,9 @@ private void assertBlockIsCached(HFile.Reader hfileReader, HFileBlock block, 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 0a19ceea6684..b7e42659f26e 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.HBaseTestingUtil; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.TableName; @@ -53,16 +51,12 @@ 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 @@ * 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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 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 @@ private static enum CacheOnWriteType { 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 TestCacheOnWriteInSchema(CacheOnWriteType cowType) { System.out.println(testDescription); } - @Parameters - public static Collection getParameters() { - List cowTypes = new ArrayList<>(); - for (CacheOnWriteType cowType : CacheOnWriteType.values()) { - cowTypes.add(new Object[] { cowType }); - } - return cowTypes; + public static Stream 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 void setUp() throws IOException { store = region.getStore(hcd.getName()); } - @After + @AfterEach public void tearDown() throws IOException { IOException ex = null; try { @@ -203,7 +186,7 @@ public void tearDown() throws IOException { } } - @Test + @TestTemplate public void testCacheOnWriteInSchema() throws IOException { // Write some random data into the store StoreFileWriter writer = store.getStoreEngine() @@ -226,7 +209,7 @@ private void readStoreFile(Path path) throws IOException { 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 @@ private void writeStoreFile(StoreFileWriter writer) throws IOException { 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 52826e2e8e23..c3c76c879c08 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.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.ExtendedCell; -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.PrivateCellUtil; @@ -43,24 +44,19 @@ 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 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; @@ -101,7 +97,7 @@ public TestCellFlatSet(String chunkType) { } } - @Before + @BeforeEach public void setUp() throws Exception { // create array of Cells to bass to the CellFlatMap under CellSet final byte[] one = Bytes.toBytes(15); @@ -141,7 +137,7 @@ public void setUp() throws Exception { } /* Create and test ascending CellSet based on CellArrayMap */ - @Test + @TestTemplate public void testCellArrayMapAsc() throws Exception { CellSet cs = new CellSet<>(ascCbOnHeap); testCellBlocks(cs); @@ -149,7 +145,7 @@ public void testCellArrayMapAsc() throws Exception { } /* Create and test ascending and descending CellSet based on CellChunkMap */ - @Test + @TestTemplate public void testCellChunkMap() throws Exception { CellSet cs = new CellSet<>(ascCCM); testCellBlocks(cs); @@ -164,14 +160,14 @@ public void testCellChunkMap() throws Exception { // 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()); @@ -265,13 +261,12 @@ private void testIterators(CellSet cs) throws Exception { // 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 d40516a501fb..f7f9daf244fb 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,9 +17,9 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Iterator; import java.util.SortedSet; @@ -27,38 +27,31 @@ import org.apache.hadoop.hbase.CellComparatorImpl; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.ExtendedCell; -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)); @@ -81,7 +74,7 @@ public void testAdd() throws Exception { @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; @@ -117,7 +110,7 @@ public void testIterator() throws Exception { @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; @@ -155,7 +148,7 @@ public void testDescendingIterator() throws Exception { @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 55109ec8a7de..252ff79cb521 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.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -37,26 +36,21 @@ 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 HBaseTestingUtil 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 HBaseTestingUtil(); // Set the scanner lease to 20min, so the scanner can't be closed by RegionServer @@ -82,12 +76,12 @@ public static void beforeClass() throws Exception { 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 void before() throws Exception { 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 @@ private void testCleanupAfterFailover(int compactNum) throws Exception { } } 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 @@ private void testCleanupAfterFailover(int compactNum) throws Exception { // 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 @@ private void testCleanupAfterFailover(int compactNum) throws Exception { 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 60e285286279..2df65d507810 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.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; @@ -38,22 +37,17 @@ 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 HBaseTestingUtil util; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { util = new HBaseTestingUtil(); util.getConfiguration().setInt(CompactionConfiguration.HBASE_HSTORE_COMPACTION_MIN_KEY, 100); @@ -63,7 +57,7 @@ public static void beforeClass() throws Exception { util.startMiniCluster(2); } - @AfterClass + @AfterAll public static void afterclass() throws Exception { util.shutdownMiniCluster(); } @@ -132,8 +126,8 @@ public void testCleanupOnClose() throws Exception { 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 2884d5c3a03f..a2b16b4dc374 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.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -31,32 +30,28 @@ 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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); - @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 d592abd43395..fade7bdbabad 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.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.SingleProcessHBaseCluster; @@ -38,24 +39,18 @@ 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 SingleProcessHBaseCluster 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 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 void setup() throws Exception { 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 void testClearBlockCache() throws Exception { 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 void testClearBlockCacheFromAdmin() throws Exception { 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 8289fc64dae8..fee073661994 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.HBaseCommonTestingUtil; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; @@ -35,32 +34,28 @@ 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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 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 81b817f266a8..0126ad757c39 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.List; import java.util.Set; import org.apache.hadoop.hbase.Cell; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValueTestUtil; @@ -45,23 +44,24 @@ 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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static final Logger LOG = LoggerFactory.getLogger(TestColumnSeeking.class); @@ -71,7 +71,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); ColumnFamilyDescriptor familyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(familyBytes) .setMaxVersions(1000).setMaxVersions(3).build(); @@ -181,7 +181,7 @@ public void testDuplicateVersions() throws IOException { public void testReseeking() throws IOException { String family = "Family"; byte[] familyBytes = Bytes.toBytes("Family"); - TableName table = TableName.valueOf(name.getMethodName()); + TableName table = TableName.valueOf(name); TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(table); ColumnFamilyDescriptor columnFamilyDescriptor = 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 769eea773881..58995620bc05 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.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; @@ -35,23 +35,14 @@ 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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private final TableName tableName = TableName.valueOf(getClass().getSimpleName()); private final byte[] family = Bytes.toBytes("f"); @@ -63,7 +54,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); @@ -90,7 +81,7 @@ private static void setupConf(Configuration conf) { conf.setInt(CompactSplit.SPLIT_THREADS, 5); } - @After + @AfterEach public void cleanupTest() throws Exception { try { TEST_UTIL.shutdownMiniCluster(); @@ -120,11 +111,8 @@ public void testThreadPoolSizeTuning() throws Exception { 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()); @@ -135,11 +123,8 @@ public void testThreadPoolSizeTuning() throws Exception { 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 1178ddc309fc..c3fd95281d94 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; @@ -34,7 +34,6 @@ import org.apache.hadoop.hbase.CellComparator; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.ExtendedCell; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; @@ -59,11 +58,9 @@ 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.AfterEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -71,37 +68,27 @@ /** * 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 + @AfterEach public void tearDown() 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); @@ -117,7 +104,10 @@ protected void compactingSetUp() throws Exception { ThreadPoolExecutor pool = (ThreadPoolExecutor) Executors.newFixedThreadPool(1); Mockito.when(regionServicesForStores.getInMemoryCompactionPool()).thenReturn(pool); this.store = new HStore(region, familyDescriptor, conf, false); + } + @Override + protected void createChunkCreator() { long globalMemStoreLimit = (long) (ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax() * MemorySizeUtil.getGlobalMemStoreHeapPercent(conf, false)); @@ -127,6 +117,13 @@ protected void compactingSetUp() throws Exception { 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 */ @@ -203,7 +200,7 @@ public void testSnapshotting() throws IOException { 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"); } } @@ -248,9 +245,9 @@ public void testGetNextRow() throws Exception { 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()); + assertTrue(CellComparator.getInstance().compareRows(left, row1, 0, row1.length) == 0, + "Row name"); + assertEquals(QUALIFIER_COUNT, results.size(), "Count of columns"); List row = new ArrayList<>(); for (Cell kv : results) { row.add(kv); @@ -384,13 +381,13 @@ private long runSnapshot(final AbstractMemStore hmc, boolean useForce) throws IO 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); + assertTrue(t == Long.MAX_VALUE, "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); + assertTrue(t == prevTimeStamp, "Time of oldest edit didn't remain the same"); } return prevTimeStamp; } @@ -399,12 +396,12 @@ private void isExpectedRowWithoutTimestamps(final int rowIndex, List kvs) 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/TestCompactingToCellFlatMapMemStore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactingToCellFlatMapMemStore.java index a178065baa4a..c769c16ab625 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 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 void setUp() throws Exception { // 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 void testCompaction1Bucket() throws IOException { } @Override + @Test public void testCompaction2Buckets() throws IOException { if (toCellChunkMap) { // set memstore to flat into CellChunkMap @@ -205,6 +207,7 @@ public void testCompaction2Buckets() throws IOException { } @Override + @Test public void testCompaction3Buckets() throws IOException { if (toCellChunkMap) { // set memstore to flat into CellChunkMap @@ -462,7 +465,7 @@ public void testCountOfCellsAfterFlatteningByScan() throws IOException { 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 void testCountOfCellsAfterFlatteningByIterator() throws IOException { } finally { itr.close(); } - assertEquals("the count should be ", 150, cnt); + assertEquals(150, cnt, "the count should be "); } private void addRowsByKeysWith50Cols(AbstractMemStore hmc, String[] keys) { @@ -828,7 +831,7 @@ public void testFlatteningToJumboCellChunkMap() throws IOException { * 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> @@ -891,7 +894,7 @@ public void testForceCopyOfBigCellIntoImmutableSegment() throws IOException { 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 7f738db4f3ce..1fa15695fe32 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.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.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.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; @@ -92,15 +91,13 @@ 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; @@ -109,15 +106,12 @@ /** * 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); + private String name; - @Rule - public TestName name = new TestName(); private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); protected Configuration conf = UTIL.getConfiguration(); @@ -149,10 +143,11 @@ public TestCompaction() { (byte) (thirdRowBytes[START_KEY_BYTES.length - 1] + 2); } - @Before - public void setUp() throws Exception { - TableDescriptorBuilder builder = UTIL.createModifyableTableDescriptor(name.getMethodName()); - if (name.getMethodName().equals("testCompactionSeqId")) { + @BeforeEach + public void setUp(TestInfo testInfo) throws Exception { + this.name = testInfo.getTestMethod().get().getName(); + TableDescriptorBuilder builder = UTIL.createModifyableTableDescriptor(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()); @@ -161,8 +156,8 @@ public void setUp() throws Exception { builder.setColumnFamily(familyDescriptor); } if ( - name.getMethodName().equals("testCompactionWithCorruptBlock") - || name.getMethodName().equals("generateHFileForCorruptBlockTest") + name.equals("testCompactionWithCorruptBlock") + || name.equals("generateHFileForCorruptBlockTest") ) { UTIL.getConfiguration().setBoolean("hbase.hstore.validate.read_fully", true); ColumnFamilyDescriptor familyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(FAMILY) @@ -173,7 +168,7 @@ public void setUp() throws Exception { this.r = UTIL.createLocalHRegion(tableDescriptor, null, null); } - @After + @AfterEach public void tearDown() throws Exception { WAL wal = r.getWAL(); this.r.close(); @@ -395,7 +390,7 @@ public void testCompactionWithCorruptResult() throws Exception { * 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)); @@ -534,10 +529,11 @@ public void testCompactionFailure() throws Exception { 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 + ")"); } } @@ -563,9 +559,8 @@ public void testStopStartCompaction() throws IOException { 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. @@ -747,7 +742,7 @@ public List compact(ThroughputController throughputController, User user) 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 bfbbf3d85dc7..7033d6e30f62 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.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 @@ protected HRegion testRegionWithFamiliesAndSpecifiedTableName(TableName tableNam 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 Object answer(InvocationOnMock invocation) { } } - @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 c9f8d3a1dced..ce58ce19140d 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; @@ -30,7 +30,6 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.Stoppable; import org.apache.hadoop.hbase.TableName; @@ -47,26 +46,21 @@ 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 HBaseTestingUtil testUtil; private Path testDir; @@ -74,12 +68,11 @@ public class TestCompactionArchiveConcurrentClose { // Static field to track archived state for the static inner class private static final AtomicBoolean STATIC_ARCHIVED = new AtomicBoolean(); + 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 HBaseTestingUtil(); testDir = testUtil.getDataTestDir("TestStoreFileRefresherChore"); CommonFSUtils.setRootDir(testUtil.getConfiguration(), testDir); @@ -90,7 +83,7 @@ public void setup() throws Exception { STATIC_ARCHIVED.set(false); } - @After + @AfterEach public void tearDown() throws Exception { testUtil.cleanupTestDir(); } @@ -101,7 +94,7 @@ public void testStoreCloseAndDischargeRunningInParallel() throws Exception { 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 844dda8f7d8d..4b36b279023a 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.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.HBaseTestingUtil; import org.apache.hadoop.hbase.Stoppable; import org.apache.hadoop.hbase.TableName; @@ -51,13 +50,11 @@ 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 @@ /** * 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 HBaseTestingUtil 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 HBaseTestingUtil(); 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 void testRemoveCompactedFilesWithException() throws Exception { 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 dedab583c516..3c91720721dc 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.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Waiter; @@ -34,29 +31,20 @@ 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 HBaseTestingUtil util = new HBaseTestingUtil(); 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) { @@ -188,16 +176,7 @@ public void testCompactionAfterRefresh() throws Exception { 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 64454ab268fa..15785975cc11 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.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -43,15 +43,11 @@ 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 @@ * 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 HBaseTestingUtil UTIL = new HBaseTestingUtil(); @@ -94,16 +87,17 @@ protected void tryRegionServerReport(long reportStartTime, long reportEndTime) } } - @Parameter - public Class walProvider; + private final Class walProvider; + + public TestCompactionInDeadRegionServer(Class walProvider) { + this.walProvider = walProvider; + } - @Parameters(name = "{index}: wal={0}") - public static List params() { - return Arrays.asList(new Object[] { FSHLogProvider.class }, - new Object[] { AsyncFSWALProvider.class }); + public static Stream 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 void setUp() throws Exception { 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 c7bced997f70..40cfc6502e91 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 @@ 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.Type; import org.apache.hadoop.hbase.CellBuilderFactory; import org.apache.hadoop.hbase.CellBuilderType; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -53,26 +52,22 @@ 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 HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static final TableName NAME = @@ -134,18 +129,18 @@ public void postCompact(ObserverContext } } - @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) @@ -175,7 +170,7 @@ public void setUp() throws IOException { assertEquals(0, region.getStore(CF2).getStorefilesCount()); } - @After + @AfterEach public void tearDown() throws IOException { region = null; TRACKER = null; @@ -267,7 +262,7 @@ public void testRequestOnStore() throws IOException, InterruptedException { // 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 05c58fde3095..6955503c601b 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; @@ -40,15 +43,15 @@ 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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); @@ -66,7 +69,7 @@ public class TestCompactionPolicy { private FSHLog hlog; private HRegion region; - @Before + @BeforeEach public void setUp() throws Exception { config(); initialize(); @@ -120,7 +123,7 @@ protected void initialize() throws IOException { fs.createNewFile(TEST_FILE); } - @After + @AfterEach public void tearDown() throws IOException { IOException ex = null; try { @@ -206,9 +209,9 @@ void compactEquals(List candidates, boolean forcemajor, boolean isOf .selectCompaction(candidates, new ArrayList<>(), false, isOffPeak, forcemajor); List 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 aa94cc545792..d25d9461b28d 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.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; @@ -37,33 +36,32 @@ 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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); + 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 @@ enum StateSource { @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 3c91425330e8..f3ec025caa82 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.util.ArrayList; import java.util.List; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -35,21 +34,13 @@ 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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 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 static void setupBeforeClass() throws Exception { admin = TEST_UTIL.getAdmin(); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionWithCoprocessor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestCompactionWithCoprocessor.java index 5f2f5d8a72e5..bf478bab9a2e 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 8f909767d7dd..280187dec4c8 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.concurrent.atomic.AtomicInteger; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.ExtendedCell; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -41,37 +40,36 @@ 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); - protected final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 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 static void tearDownAfterClass() throws Exception { @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 08bbed6e18ed..9590aa612e6a 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 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.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue.KeyOnlyKeyValue; @@ -39,16 +40,15 @@ 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 HBaseTestingUtil UTIL = new HBaseTestingUtil(); @@ -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 static void setUp() throws Exception { UTIL.startMiniCluster(); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { IS_LAST_CELL_ON_HEAP.set(false); UTIL.shutdownMiniCluster(); @@ -89,16 +88,16 @@ public static void tearDown() throws Exception { private void assertMajorCompactionOK(TableName tableName) { List regions = UTIL.getHBaseCluster().getRegionServerThreads().get(0).getRegionServer() .getRegions(tableName); - Assert.assertEquals(regions.size(), 1); + assertEquals(regions.size(), 1); HRegion region = regions.get(0); - Assert.assertEquals(region.getStores().size(), 1); + assertEquals(region.getStores().size(), 1); HStore store = region.getStore(FAMILY); - Assert.assertEquals(store.getStorefilesCount(), 1); + assertEquals(store.getStorefilesCount(), 1); } @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 void testMemLeak() throws IOException, InterruptedException { 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 { 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 3976a92a6afa..8e4ef43d1c3f 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.Path; import org.apache.hadoop.hbase.CellComparatorImpl; import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValueUtil; @@ -53,23 +52,19 @@ 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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 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 @@ private void readStoreFile(int t, BloomType bt, List kvs, Path sfPath) 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 @@ private void readStoreFile(int t, BloomType bt, List kvs, Path sfPath) 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 1f0d78b9fffa..7de9a00cf4db 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 @@ 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 org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; @@ -69,20 +68,20 @@ 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. - * + *

* 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 @@ * @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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 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 void testPrefetchWhenDataTieringEnabled() throws IOException { // Since we have one cold file among four files, only three should get prefetched. Optional>> 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 c89e99197179..2dc6f8e4da89 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.UUID; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; @@ -42,17 +41,13 @@ 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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 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 888231c9b177..78fae86c8d8a 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,11 +22,9 @@ 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.HBaseTestingUtil; import org.apache.hadoop.hbase.KeyValue; -import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.io.compress.Compression; import org.apache.hadoop.hbase.io.hfile.HFileContext; import org.apache.hadoop.hbase.io.hfile.HFileContextBuilder; @@ -34,21 +32,17 @@ import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Test DataBlockEncodingTool. */ -@Category({ MiscTests.class, SmallTests.class }) +@Tag(MiscTests.TAG) +@Tag(SmallTests.TAG) public class TestDataBlockEncodingTool { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestDataBlockEncodingTool.class); - private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 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(); } @@ -88,15 +82,17 @@ private void createHFileWithTags(Path path, boolean useTags, boolean allTags) th if (useTags) { if (allTags) { // Write cells with tags to HFile. - Tag[] tags = new Tag[] { new ArrayBackedTag((byte) 0, Bytes.toString(b)), - new ArrayBackedTag((byte) 0, Bytes.toString(b)) }; + org.apache.hadoop.hbase.Tag[] tags = + new org.apache.hadoop.hbase.Tag[] { new ArrayBackedTag((byte) 0, Bytes.toString(b)), + new ArrayBackedTag((byte) 0, Bytes.toString(b)) }; kv = new KeyValue(b, FAMILY, QUALIFIER, now, b, tags); } else { // Write half cells with tags and half without tags to HFile. if ((e - 'a') % 2 == 0) { kv = new KeyValue(b, FAMILY, QUALIFIER, now, b); } else { - Tag[] tags = new Tag[] { new ArrayBackedTag((byte) 0, Bytes.toString(b)), + org.apache.hadoop.hbase.Tag[] tags = new org.apache.hadoop.hbase.Tag[] { + new ArrayBackedTag((byte) 0, Bytes.toString(b)), new ArrayBackedTag((byte) 0, Bytes.toString(b)) }; kv = new KeyValue(b, FAMILY, QUALIFIER, now, b, tags); } 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 7ef7ce0884bb..9bfe848d9682 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 @@ 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 org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; @@ -71,10 +70,9 @@ 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,13 +95,10 @@ * @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 Logger LOG = LoggerFactory.getLogger(TestDataTieringManager.class); private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static final long DAY = 24 * 60 * 60 * 1000; @@ -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 void testGracePeriodMakesColdFileHot() throws IOException, DataTieringExc 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 void testFileIsColdWithoutGracePeriod() throws IOException, DataTieringEx 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 void testPrefetchWhenDataTieringEnabled() throws IOException { // Since we have one cold file among four files, only three should get prefetched. Optional>> 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 void testRegionColdDataSizeRecordColdHFile() throws IOException { 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, Long>> coldByRegion = dataTieringManager.getRegionColdDataSize(); assertTrue(coldByRegion.containsKey(region)); @@ -450,8 +445,9 @@ public void testUpdateRegionColdDataSizeRemovesCompactedColdAddsNewHot() throws Pair, 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 void testUpdateRegionColdDataSizeRemovesCompactedColdAddsNewCold() throws 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, 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 475454d67636..3d6e2cceff80 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 172fece66561..2f599bb35a51 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 @@ 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 99809b84775e..5f62071fc579 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 76faae6d3491..ba49b464a7d5 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 void testCompactionEmptyHFile() throws IOException { 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 af3902c9aa1e..656030ff9b7a 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,10 @@ */ package org.apache.hadoop.hbase.regionserver; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; @@ -36,7 +36,6 @@ import org.apache.hadoop.hbase.CellComparatorImpl; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.ExtendedCell; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; @@ -62,15 +61,12 @@ 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; @@ -79,16 +75,12 @@ 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; @@ -96,26 +88,46 @@ 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(); + @BeforeEach + public void setUp(TestInfo testInfo) throws Exception { + this.name = getTestName(testInfo); + internalSetUp(); + createChunkCreator(); + createMemStore(); } - @Before - public void setUp() throws Exception { - internalSetUp(); + 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(); } - @After + @AfterEach public void tearDown() throws Exception { this.memstore.close(); } - @AfterClass + @AfterAll public static void tearDownClass() throws Exception { ChunkCreator.getInstance().clearChunkIds(); } @@ -126,7 +138,7 @@ protected void internalSetUp() 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"); @@ -134,12 +146,12 @@ public void testPutSameKey() { 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); @@ -228,7 +240,7 @@ public void testScanAcrossSnapshot() throws IOException { // 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(); @@ -320,9 +332,8 @@ protected void assertScannerResults(KeyValueScanner scanner, KeyValue[] expected 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()); } @@ -393,7 +404,7 @@ private long getBytesReadFromMemstore() throws IOException { public void testBytesReadFromMemstore() throws IOException { ThreadLocalServerSideScanMetrics.setScanMetricsEnabled(true); long totalCellSize = getBytesReadFromMemstore(); - Assert.assertEquals(totalCellSize, + assertEquals(totalCellSize, ThreadLocalServerSideScanMetrics.getBytesReadFromMemstoreAndReset()); } @@ -401,7 +412,7 @@ public void testBytesReadFromMemstore() throws IOException { public void testBytesReadFromMemstoreWithScanMetricsDisabled() throws IOException { ThreadLocalServerSideScanMetrics.setScanMetricsEnabled(false); getBytesReadFromMemstore(); - Assert.assertEquals(0, ThreadLocalServerSideScanMetrics.getBytesReadFromMemstoreAndReset()); + assertEquals(0, ThreadLocalServerSideScanMetrics.getBytesReadFromMemstoreAndReset()); } /** @@ -550,8 +561,8 @@ private void internalRun() throws IOException { 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"); } } } @@ -587,7 +598,7 @@ public void testSnapshotting() throws IOException { 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"); } } @@ -607,8 +618,8 @@ public void testMultipleVersionsSimple() throws Exception { m.add(key1, null); m.add(key2, null); - assertTrue("Expected memstore to hold 3 values, actually has " + m.getActive().getCellsCount(), - m.getActive().getCellsCount() == 3); + assertTrue(m.getActive().getCellsCount() == 3, + "Expected memstore to hold 3 values, actually has " + m.getActive().getCellsCount()); } ////////////////////////////////////////////////////////////////////////////// @@ -651,9 +662,9 @@ public void testGetNextRow() throws Exception { 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()); + assertTrue(CellComparatorImpl.COMPARATOR.compareRows(left, row1, 0, row1.length) == 0, + "Row name"); + assertEquals(QUALIFIER_COUNT, results.size(), "Count of columns"); List row = new ArrayList<>(); for (Cell kv : results) { row.add(kv); @@ -1003,9 +1014,7 @@ public void testShouldFlushMeta() throws Exception { 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(); @@ -1083,10 +1092,10 @@ private long runSnapshot(final AbstractMemStore hmc) throws UnexpectedStateExcep 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; } @@ -1095,12 +1104,12 @@ private void isExpectedRowWithoutTimestamps(final int rowIndex, List kvs) 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 e951289d6de4..6a2124dbecf5 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 void testCustomParts() throws Exception { 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 948f1d33a6a1..6a94c1d66ef4 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.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; @@ -39,35 +44,32 @@ 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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 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 @@ private Table createTableWithOneFile(TableDescriptor tableDescriptor) throws IOE @Test public void testDeleteMobTable() throws Exception { - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(name); TableDescriptor tableDescriptor = createTableDescriptor(tableName, true); ColumnFamilyDescriptor familyDescriptor = tableDescriptor.getColumnFamily(FAMILY); @@ -120,49 +122,49 @@ public void testDeleteMobTable() throws Exception { Table table = createTableWithOneFile(tableDescriptor); try { // the mob file exists - Assert.assertEquals(1, countMobFiles(tableName, familyDescriptor.getNameAsString())); - Assert.assertEquals(0, countArchiveMobFiles(tableName, familyDescriptor.getNameAsString())); + assertEquals(1, countMobFiles(tableName, familyDescriptor.getNameAsString())); + assertEquals(0, countArchiveMobFiles(tableName, familyDescriptor.getNameAsString())); fileName = assertHasOneMobRow(table, tableName, familyDescriptor.getNameAsString()); - Assert.assertFalse(mobArchiveExist(tableName, familyDescriptor.getNameAsString(), fileName)); - Assert.assertTrue(mobTableDirExist(tableName)); + assertFalse(mobArchiveExist(tableName, familyDescriptor.getNameAsString(), fileName)); + assertTrue(mobTableDirExist(tableName)); } finally { table.close(); TEST_UTIL.deleteTable(tableName); } - Assert.assertFalse(TEST_UTIL.getAdmin().tableExists(tableName)); - Assert.assertEquals(0, countMobFiles(tableName, familyDescriptor.getNameAsString())); - Assert.assertEquals(1, countArchiveMobFiles(tableName, familyDescriptor.getNameAsString())); - Assert.assertTrue(mobArchiveExist(tableName, familyDescriptor.getNameAsString(), fileName)); - Assert.assertFalse(mobTableDirExist(tableName)); + assertFalse(TEST_UTIL.getAdmin().tableExists(tableName)); + assertEquals(0, countMobFiles(tableName, familyDescriptor.getNameAsString())); + assertEquals(1, countArchiveMobFiles(tableName, familyDescriptor.getNameAsString())); + assertTrue(mobArchiveExist(tableName, familyDescriptor.getNameAsString(), fileName)); + assertFalse(mobTableDirExist(tableName)); } @Test public void testDeleteNonMobTable() throws Exception { - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(name); TableDescriptor htd = createTableDescriptor(tableName, false); ColumnFamilyDescriptor hcd = htd.getColumnFamily(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); TableDescriptor tableDescriptor = createTableDescriptor(tableName, true); ColumnFamilyDescriptor familyDescriptor = tableDescriptor.getColumnFamily(FAMILY); tableDescriptor = TableDescriptorBuilder.newBuilder(tableDescriptor) @@ -171,18 +173,18 @@ public void testMobFamilyDelete() throws Exception { Table table = createTableWithOneFile(tableDescriptor); try { // the mob file exists - Assert.assertEquals(1, countMobFiles(tableName, familyDescriptor.getNameAsString())); - Assert.assertEquals(0, countArchiveMobFiles(tableName, familyDescriptor.getNameAsString())); + assertEquals(1, countMobFiles(tableName, familyDescriptor.getNameAsString())); + assertEquals(0, countArchiveMobFiles(tableName, familyDescriptor.getNameAsString())); String fileName = assertHasOneMobRow(table, tableName, familyDescriptor.getNameAsString()); - Assert.assertFalse(mobArchiveExist(tableName, familyDescriptor.getNameAsString(), fileName)); - Assert.assertTrue(mobTableDirExist(tableName)); + assertFalse(mobArchiveExist(tableName, familyDescriptor.getNameAsString(), fileName)); + assertTrue(mobTableDirExist(tableName)); TEST_UTIL.getAdmin().deleteColumnFamily(tableName, FAMILY); - Assert.assertEquals(0, countMobFiles(tableName, familyDescriptor.getNameAsString())); - Assert.assertEquals(1, countArchiveMobFiles(tableName, familyDescriptor.getNameAsString())); - Assert.assertTrue(mobArchiveExist(tableName, familyDescriptor.getNameAsString(), fileName)); - Assert.assertFalse(mobColumnFamilyDirExist(tableName, familyDescriptor.getNameAsString())); + assertEquals(0, countMobFiles(tableName, familyDescriptor.getNameAsString())); + assertEquals(1, countArchiveMobFiles(tableName, familyDescriptor.getNameAsString())); + assertTrue(mobArchiveExist(tableName, familyDescriptor.getNameAsString(), fileName)); + assertFalse(mobColumnFamilyDirExist(tableName, familyDescriptor.getNameAsString())); } finally { table.close(); TEST_UTIL.deleteTable(tableName); @@ -235,14 +237,14 @@ private String assertHasOneMobRow(Table table, TableName tn, String familyName) 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 2d7d4b92a2e2..97dc3464c7ab 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.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Put; @@ -41,41 +40,40 @@ 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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 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(); } - @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 void testSplitStoreDir() throws Exception { @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 void testMergeStoreFile() throws Exception { @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 void testCommitDaughterRegionNoFiles() throws Exception { @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 void testCommitDaughterRegionWithFiles() throws Exception { @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 6ab78e5974c4..8b1460121306 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.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -31,29 +33,20 @@ 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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 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, MockAesKeyProvider.class.getName()); @@ -65,7 +58,7 @@ public static void setUp() throws Exception { TEST_UTIL.startMiniCluster(1); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -83,9 +76,9 @@ public void testEncryptedTableShouldNotBeCreatedWhenEncryptionDisabled() throws 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 2b2da6125b2c..6b0958f66343 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 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.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -50,28 +49,27 @@ 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; -@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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 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 @@ -83,7 +81,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, MockAesKeyProvider.class.getName()); @@ -93,7 +91,7 @@ public static void setUp() throws Exception { TEST_UTIL.startMiniCluster(1); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -102,7 +100,7 @@ public static void tearDown() throws Exception { public void testCFKeyRotation() throws Exception { // Create the table schema TableDescriptorBuilder tableDescriptorBuilder = - TableDescriptorBuilder.newBuilder(TableName.valueOf("default", name.getMethodName())); + TableDescriptorBuilder.newBuilder(TableName.valueOf("default", name)); ColumnFamilyDescriptorBuilder columnFamilyDescriptorBuilder = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf")); String algorithm = conf.get(HConstants.CRYPTO_KEY_ALGORITHM_CONF_KEY, HConstants.CIPHER_AES); @@ -119,8 +117,8 @@ public void testCFKeyRotation() throws Exception { final List initialPaths = findStorefilePaths(tableDescriptor.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 @@ -144,14 +142,14 @@ public boolean evaluate() throws IOException { List pathsAfterCompaction = findStorefilePaths(tableDescriptor.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 compactedPaths = findCompactedStorefilePaths(tableDescriptor.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"); } } @@ -159,7 +157,7 @@ public boolean evaluate() throws IOException { public void testMasterKeyRotation() throws Exception { // Create the table schema TableDescriptorBuilder tableDescriptorBuilder = - TableDescriptorBuilder.newBuilder(TableName.valueOf("default", name.getMethodName())); + TableDescriptorBuilder.newBuilder(TableName.valueOf("default", name)); ColumnFamilyDescriptorBuilder columnFamilyDescriptorBuilder = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf")); String algorithm = conf.get(HConstants.CRYPTO_KEY_ALGORITHM_CONF_KEY, HConstants.CIPHER_AES); @@ -176,8 +174,8 @@ public void testMasterKeyRotation() throws Exception { List storeFilePaths = findStorefilePaths(tableDescriptor.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 @@ -195,8 +193,8 @@ public void testMasterKeyRotation() throws Exception { storeFilePaths = findStorefilePaths(tableDescriptor.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"); } } @@ -249,9 +247,9 @@ private static byte[] extractHFileKey(Path path) throws Exception { 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 bfdd6211ec43..9499dc75a69c 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.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -40,19 +39,15 @@ 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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static Configuration conf = TEST_UTIL.getConfiguration(); private static TableDescriptorBuilder tdb; @@ -75,7 +70,7 @@ private static byte[] extractHFileKey(Path path) throws Exception { 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 @@ private static byte[] extractHFileKey(Path path) throws Exception { } } - @BeforeClass + @BeforeAll public static void setUp() throws Exception { conf.setInt("hfile.format.version", 3); conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, MockAesKeyProvider.class.getName()); @@ -121,7 +116,7 @@ public static void setUp() throws Exception { TEST_UTIL.getAdmin().flush(tdb.build().getTableName()); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -132,7 +127,7 @@ public void testRandomKeying() throws Exception { final List initialPaths = findStorefilePaths(tdb.build().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 897152f8b6dd..1ca3acd06b29 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; @@ -34,7 +34,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.CatalogFamilyFormat; import org.apache.hadoop.hbase.ChoreService; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionLocation; @@ -63,13 +62,12 @@ 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; @@ -77,27 +75,26 @@ 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 HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 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(); } @@ -138,8 +135,8 @@ public void testCanSplitJustAfterASplit() throws Exception { 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); @@ -147,8 +144,8 @@ public void testCanSplitJustAfterASplit() throws Exception { 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 { @@ -172,7 +169,7 @@ public void testCanSplitJustAfterASplit() throws Exception { @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 @@ -345,22 +342,21 @@ void verifyStartEndKeys(Pair keys) { 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 f0daedd62579..ce2aa38fa3c3 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.FilterFileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.PositionedReadable; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; @@ -51,12 +50,11 @@ 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; @@ -64,19 +62,19 @@ * 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); HBaseTestingUtil util = new HBaseTestingUtil(); + 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 @@ -185,7 +183,7 @@ public void testStoreFileScannerThrowsErrors() throws IOException { 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. @@ -194,7 +192,7 @@ public void testFullSystemBubblesFSErrors() throws Exception { 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 c6cf13939785..8ba9a8c4888f 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; @@ -34,7 +34,6 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.DroppedSnapshotException; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.Server; @@ -51,13 +50,11 @@ 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; @@ -65,16 +62,11 @@ /** * 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); @@ -88,18 +80,19 @@ 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 = new HBaseTestingUtil(); CONF = TEST_UTIL.getConfiguration(); // Disable block cache. CONF.setFloat(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, 0f); CONF.setLong(AbstractFSWAL.WAL_SYNC_TIMEOUT_MS, 10000); 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()); @@ -107,7 +100,7 @@ public void tearDown() throws Exception { } String getName() { - return name.getMethodName(); + return name; } // Dodgy WAL. Will throw exceptions when flags set. @@ -302,9 +295,9 @@ public void testLockupAroundBadAssignSync() throws IOException { } } 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 70c63bed005d..ebf993767b68 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 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.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -45,24 +44,20 @@ 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 HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static final TableName NAME = @@ -168,17 +163,17 @@ public synchronized void await() throws InterruptedException { } } - @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 void setUp() throws IOException { 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 a5eb7a593b45..5e994b76d0c9 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.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 a435b9d9b239..adfe015ac822 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.fs.Path; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MetaTableAccessor; @@ -49,11 +48,10 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.FSTableDescriptors; 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; @@ -62,15 +60,17 @@ * 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); + private String testName; + + @BeforeEach + public void setTestName(TestInfo testInfo) { + this.testName = testInfo.getTestMethod().get().getName(); + } - @Rule - public TestName testName = new TestName(); private static final Logger LOG = LoggerFactory.getLogger(TestGetClosestAtOrBefore.class); private static final byte[] T00 = Bytes.toBytes("000"); @@ -203,7 +203,7 @@ public void testGetClosestRowBefore3() throws IOException { byte[] c0 = HBaseTestingUtil.COLUMNS[0]; byte[] c1 = HBaseTestingUtil.COLUMNS[1]; try { - TableName tn = TableName.valueOf(testName.getMethodName()); + TableName tn = TableName.valueOf(testName); TableDescriptor htd = UTIL.createTableDescriptor(tn); region = UTIL.createLocalHRegion(htd, null, null); @@ -313,7 +313,7 @@ public void testGetClosestRowBefore2() throws IOException { HRegion region = null; byte[] c0 = HBaseTestingUtil.COLUMNS[0]; try { - TableName tn = TableName.valueOf(testName.getMethodName()); + TableName tn = TableName.valueOf(testName); TableDescriptor htd = UTIL.createTableDescriptor(tn); region = UTIL.createLocalHRegion(htd, null, null);