diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtil.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtil.java index 84c992eed6f4..365855bbd3cf 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtil.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtil.java @@ -17,9 +17,9 @@ */ package org.apache.hadoop.hbase; -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 edu.umd.cs.findbugs.annotations.Nullable; import java.io.Closeable; @@ -2013,11 +2013,11 @@ public void verifyNumericRows(Table table, final byte[] f, int startRow, int end get.setReplicaId(replicaId); get.setConsistency(Consistency.TIMELINE); Result result = table.get(get); - assertTrue(failMsg, result.containsColumn(f, null)); - assertEquals(failMsg, 1, result.getColumnCells(f, null).size()); + assertTrue(result.containsColumn(f, null), failMsg); + assertEquals(1, result.getColumnCells(f, null).size(), failMsg); Cell cell = result.getColumnLatestCell(f, null); - assertTrue(failMsg, Bytes.equals(data, 0, data.length, cell.getValueArray(), - cell.getValueOffset(), cell.getValueLength())); + assertTrue(Bytes.equals(data, 0, data.length, cell.getValueArray(), cell.getValueOffset(), + cell.getValueLength()), failMsg); } } @@ -2044,14 +2044,14 @@ public void verifyNumericRows(HRegion region, final byte[] f, int startRow, int Result result = region.get(new Get(data)); boolean hasResult = result != null && !result.isEmpty(); - assertEquals(failMsg + result, present, hasResult); + assertEquals(present, hasResult, failMsg + result); if (!present) continue; - assertTrue(failMsg, result.containsColumn(f, null)); - assertEquals(failMsg, 1, result.getColumnCells(f, null).size()); + assertTrue(result.containsColumn(f, null), failMsg); + assertEquals(1, result.getColumnCells(f, null).size(), failMsg); Cell cell = result.getColumnLatestCell(f, null); - assertTrue(failMsg, Bytes.equals(data, 0, data.length, cell.getValueArray(), - cell.getValueOffset(), cell.getValueLength())); + assertTrue(Bytes.equals(data, 0, data.length, cell.getValueArray(), cell.getValueOffset(), + cell.getValueLength()), failMsg); } } @@ -3408,8 +3408,8 @@ public void assertRegionOnlyOnServer(final RegionInfo hri, final ServerName serv } Collection hrs = rs.getOnlineRegionsLocalContext(); for (HRegion r : hrs) { - assertTrue("Region should not be double assigned", - r.getRegionInfo().getRegionId() != hri.getRegionId()); + assertTrue(r.getRegionInfo().getRegionId() != hri.getRegionId(), + "Region should not be double assigned"); } } return; // good, we are happy diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCacheEviction.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCacheEviction.java index dd74f5e6f5b0..9ba13f3ab663 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCacheEviction.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCacheEviction.java @@ -23,7 +23,7 @@ import static org.apache.hadoop.hbase.io.hfile.CacheConfig.EVICT_BLOCKS_ON_CLOSE_KEY; import static org.apache.hadoop.hbase.io.hfile.CacheConfig.EVICT_BLOCKS_ON_SPLIT_KEY; import static org.apache.hadoop.hbase.io.hfile.CacheConfig.PREFETCH_BLOCKS_ON_OPEN_KEY; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; @@ -42,26 +42,18 @@ import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Pair; -import org.junit.Before; -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; - -@Category({ MiscTests.class, LargeTests.class }) -public class TestCacheEviction { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestCacheEviction.class); +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; - private static final Logger LOG = LoggerFactory.getLogger(TestCacheEviction.class); +@Tag(MiscTests.TAG) +@Tag(LargeTests.TAG) +public class TestCacheEviction { private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT, 1000); UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2); @@ -71,7 +63,7 @@ public static void setUp() throws Exception { UTIL.getConfiguration().set(StoreFileTrackerFactory.TRACKER_IMPL, "FILE"); } - @Before + @BeforeEach public void testSetup() { UTIL.getConfiguration().set(BUCKET_CACHE_IOENGINE_KEY, "file:" + UTIL.getDataTestDir() + "/bucketcache"); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCachedClusterId.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCachedClusterId.java index 88de0e43a200..03f8b090aae2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCachedClusterId.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCachedClusterId.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.hbase; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.MultithreadedTestUtil.TestContext; @@ -25,17 +25,15 @@ import org.apache.hadoop.hbase.master.CachedClusterId; import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.testclassification.MediumTests; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.apache.hadoop.hbase.testclassification.MiscTests; +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(MiscTests.TAG) +@Tag(MediumTests.TAG) public class TestCachedClusterId { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestCachedClusterId.class); private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); @@ -57,7 +55,7 @@ public void doWork() throws Exception { } } - @BeforeClass + @BeforeAll public static void setUp() throws Exception { TEST_UTIL.startMiniCluster(1); activeMaster = TEST_UTIL.getHBaseCluster().getMaster(); @@ -65,7 +63,7 @@ public static void setUp() throws Exception { standByMaster = TEST_UTIL.getHBaseCluster().startMaster().getMaster(); } - @AfterClass + @AfterAll public static void tearDown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCheckTestClasses.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCheckTestClasses.java index c2b007280b4f..961bc83763f7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCheckTestClasses.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestCheckTestClasses.java @@ -28,7 +28,10 @@ /** * Checks tests are categorized. + *

+ * @deprecated Will be removed after we fully upgrade to junit5, so keep it as is. */ +@Deprecated @Category({ MiscTests.class, SmallTests.class }) public class TestCheckTestClasses { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientClusterStatus.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientClusterStatus.java index 273bd3aef1cb..590d1889d56b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientClusterStatus.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientClusterStatus.java @@ -17,6 +17,10 @@ */ package org.apache.hadoop.hbase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.IOException; import java.util.EnumSet; import java.util.List; @@ -34,25 +38,21 @@ import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.regionserver.HRegionServer; import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread; import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Test the ClusterStatus. */ -@Category(MediumTests.class) +@Tag(MiscTests.TAG) +@Tag(MediumTests.TAG) public class TestClientClusterStatus { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestClientClusterStatus.class); - private static HBaseTestingUtil UTIL; private static Admin ADMIN; private final static int SLAVES = 5; @@ -60,7 +60,7 @@ public class TestClientClusterStatus { private static SingleProcessHBaseCluster CLUSTER; private static HRegionServer DEAD; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { Configuration conf = HBaseConfiguration.create(); conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, MyObserver.class.getName()); @@ -87,8 +87,7 @@ public void testNone() throws Exception { ClusterMetrics status1 = ADMIN.getClusterMetrics(EnumSet.noneOf(Option.class)); // Do a rough compare. More specific compares can fail because all regions not deployed yet // or more requests than expected. - Assert.assertEquals(status0.getLiveServerMetrics().size(), - status1.getLiveServerMetrics().size()); + assertEquals(status0.getLiveServerMetrics().size(), status1.getLiveServerMetrics().size()); } @Test @@ -108,7 +107,7 @@ public void testLiveAndDeadServersStatus() throws Exception { @Override public boolean evaluate() throws Exception { ClusterMetrics status = ADMIN.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)); - Assert.assertNotNull(status); + assertNotNull(status); return status.getRegionCount() > 0; } }); @@ -116,21 +115,21 @@ public boolean evaluate() throws Exception { EnumSet