diff --git a/hbase-server/pom.xml b/hbase-server/pom.xml index cea04d0bb2d2..80353e14185f 100644 --- a/hbase-server/pom.xml +++ b/hbase-server/pom.xml @@ -309,7 +309,7 @@ org.mockito - mockito-core + mockito-junit-jupiter test diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MasterStateStoreTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MasterStateStoreTestBase.java index 9cf69775a30e..d77c02cbd01e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MasterStateStoreTestBase.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/MasterStateStoreTestBase.java @@ -43,8 +43,8 @@ import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory; import org.apache.hadoop.hbase.util.CommonFSUtils; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; public abstract class MasterStateStoreTestBase { @@ -62,7 +62,7 @@ public abstract class MasterStateStoreTestBase { TableDescriptorBuilder.newBuilder(TableName.valueOf("test:local")) .setColumnFamily(ColumnFamilyDescriptorBuilder.of(MasterRegionFactory.STATE_FAMILY)).build(); - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { Configuration conf = UTIL.getConfiguration(); conf.setBoolean(MemStoreLAB.USEMSLAB_KEY, false); @@ -93,7 +93,7 @@ public static void setUpBeforeClass() throws Exception { UTIL.startMiniZKCluster(); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws IOException { REGION.close(true); HFILE_CLEANER_POOL.shutdownNow(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitOrMergeStateStore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitOrMergeStateStore.java index 8055d468c844..85ec0c03cc74 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitOrMergeStateStore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestSplitOrMergeStateStore.java @@ -17,32 +17,27 @@ */ package org.apache.hadoop.hbase.master; -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 org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.client.MasterSwitchType; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.zookeeper.ZKUtil; import org.apache.hadoop.hbase.zookeeper.ZNodePaths; -import org.junit.After; -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.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestSplitOrMergeStateStore extends MasterStateStoreTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestSplitOrMergeStateStore.class); - - @After + @AfterEach public void tearDown() throws Exception { cleanup(); ZKUtil.deleteNodeRecursively(UTIL.getZooKeeperWatcher(), diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerConditionalsTestUtil.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerConditionalsTestUtil.java index 8a7169b09309..c72e37d16e60 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerConditionalsTestUtil.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/BalancerConditionalsTestUtil.java @@ -17,9 +17,9 @@ */ package org.apache.hadoop.hbase.master.balancer; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import java.io.IOException; import java.util.HashSet; @@ -130,16 +130,15 @@ static void validateReplicaDistribution(Connection connection, TableName tableNa Set startKeys = new HashSet<>(); for (RegionInfo regionInfo : regionInfos) { // each region should have a distinct start key - assertFalse( + assertFalse(startKeys.contains(regionInfo.getStartKey()), "Each region should have its own start key, " - + "demonstrating it is not a replica of any others on this host", - startKeys.contains(regionInfo.getStartKey())); + + "demonstrating it is not a replica of any others on this host"); startKeys.add(regionInfo.getStartKey()); } } } else { // Ensure all replicas are on the same server - assertEquals("All regions should share one server", 1, serverToRegions.size()); + assertEquals(1, serverToRegions.size(), "All regions should share one server"); } } @@ -153,19 +152,19 @@ static void validateRegionLocations(Map> tableToServe if (shouldBeBalanced) { for (ServerName server : productServers) { - assertNotEquals("Meta table and product table should not share servers", server, - metaServer); - assertNotEquals("Quota table and product table should not share servers", server, - quotaServer); + assertNotEquals(server, metaServer, + "Meta table and product table should not share servers"); + assertNotEquals(server, quotaServer, + "Quota table and product table should not share servers"); } - assertNotEquals("The meta server and quotas server should be different", metaServer, - quotaServer); + assertNotEquals(metaServer, quotaServer, + "The meta server and quotas server should be different"); } else { for (ServerName server : productServers) { - assertEquals("Meta table and product table must share servers", server, metaServer); - assertEquals("Quota table and product table must share servers", server, quotaServer); + assertEquals(server, metaServer, "Meta table and product table must share servers"); + assertEquals(server, quotaServer, "Quota table and product table must share servers"); } - assertEquals("The meta server and quotas server must be the same", metaServer, quotaServer); + assertEquals(metaServer, quotaServer, "The meta server and quotas server must be the same"); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/RSGroupableBalancerTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/RSGroupableBalancerTestBase.java index ab76f1c7add4..057585dda420 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/RSGroupableBalancerTestBase.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/RSGroupableBalancerTestBase.java @@ -17,9 +17,10 @@ */ package org.apache.hadoop.hbase.master.balancer; -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.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -56,9 +57,6 @@ import org.apache.hadoop.hbase.rsgroup.RSGroupInfo; import org.apache.hadoop.hbase.rsgroup.RSGroupInfoManager; import org.apache.hadoop.hbase.util.Bytes; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; import org.apache.hbase.thirdparty.com.google.common.collect.ArrayListMultimap; import org.apache.hbase.thirdparty.com.google.common.collect.Lists; @@ -128,8 +126,8 @@ protected void assertImmediateAssignment(List regions, List existing, Set onlineServerSet = new TreeSet<>(servers); Set assignedRegions = new TreeSet<>(RegionInfo.COMPARATOR); for (Map.Entry> a : assignment.entrySet()) { - assertTrue("Region assigned to server that was not listed as online", - onlineServerSet.contains(a.getKey())); + assertTrue(onlineServerSet.contains(a.getKey()), + "Region assigned to server that was not listed as online"); for (RegionInfo r : a.getValue()) { assignedRegions.add(r); } @@ -173,8 +171,8 @@ protected void assertRetainedAssignment(Map existing, tableDescs.get(tableName).getRegionServerGroup().orElse(RSGroupInfo.DEFAULT_GROUP); assertTrue(StringUtils.isNotEmpty(groupName)); RSGroupInfo gInfo = getMockedGroupInfoManager().getRSGroup(groupName); - assertTrue("Region is not correctly assigned to group servers.", - gInfo.containsServer(currentServer.getAddress())); + assertTrue(gInfo.containsServer(currentServer.getAddress()), + "Region is not correctly assigned to group servers."); if ( oldAssignedServer != null && onlineHostNames.contains(oldAssignedServer.getHostname()) ) { @@ -232,7 +230,7 @@ protected String printStats(ArrayListMultimap groupBasedL } } List regions = serversMap.get(actual); - assertTrue("No load for " + actual, regions != null); + assertTrue(regions != null, "No load for " + actual); loadMap.put(gInfo.getName(), new ServerAndLoad(actual, regions.size())); } } @@ -389,31 +387,28 @@ protected static Map constructTableDesc(boolean hasB } protected static MasterServices getMockedMaster() throws IOException { - TableDescriptors tds = Mockito.mock(TableDescriptors.class); - Mockito.when(tds.get(tables[0])).thenReturn(tableDescs.get(tables[0])); - Mockito.when(tds.get(tables[1])).thenReturn(tableDescs.get(tables[1])); - Mockito.when(tds.get(tables[2])).thenReturn(tableDescs.get(tables[2])); - Mockito.when(tds.get(tables[3])).thenReturn(tableDescs.get(tables[3])); - MasterServices services = Mockito.mock(HMaster.class); - Mockito.when(services.getTableDescriptors()).thenReturn(tds); - AssignmentManager am = Mockito.mock(AssignmentManager.class); - Mockito.when(services.getAssignmentManager()).thenReturn(am); - Mockito.when(services.getConfiguration()).thenReturn(conf); + TableDescriptors tds = mock(TableDescriptors.class); + when(tds.get(tables[0])).thenReturn(tableDescs.get(tables[0])); + when(tds.get(tables[1])).thenReturn(tableDescs.get(tables[1])); + when(tds.get(tables[2])).thenReturn(tableDescs.get(tables[2])); + when(tds.get(tables[3])).thenReturn(tableDescs.get(tables[3])); + MasterServices services = mock(HMaster.class); + when(services.getTableDescriptors()).thenReturn(tds); + AssignmentManager am = mock(AssignmentManager.class); + when(services.getAssignmentManager()).thenReturn(am); + when(services.getConfiguration()).thenReturn(conf); RSGroupInfoManager manager = getMockedGroupInfoManager(); - Mockito.when(services.getRSGroupInfoManager()).thenReturn(manager); + when(services.getRSGroupInfoManager()).thenReturn(manager); return services; } protected static RSGroupInfoManager getMockedGroupInfoManager() throws IOException { - RSGroupInfoManager gm = Mockito.mock(RSGroupInfoManager.class); - Mockito.when(gm.getRSGroup(Mockito.any())).thenAnswer(new Answer() { - @Override - public RSGroupInfo answer(InvocationOnMock invocation) throws Throwable { - return groupMap.get(invocation.getArgument(0)); - } + RSGroupInfoManager gm = mock(RSGroupInfoManager.class); + when(gm.getRSGroup(any())).thenAnswer(invocation -> { + return groupMap.get(invocation.getArgument(0)); }); - Mockito.when(gm.listRSGroups()).thenReturn(Lists.newLinkedList(groupMap.values())); - Mockito.when(gm.isOnline()).thenReturn(true); + when(gm.listRSGroups()).thenReturn(Lists.newLinkedList(groupMap.values())); + when(gm.isOnline()).thenReturn(true); return gm; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBalancerStatusTagInJMXMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBalancerStatusTagInJMXMetrics.java index 38ef0a7c7765..c7c6abad74d3 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBalancerStatusTagInJMXMetrics.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestBalancerStatusTagInJMXMetrics.java @@ -17,34 +17,30 @@ */ package org.apache.hadoop.hbase.master.balancer; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.SingleProcessHBaseCluster; import org.apache.hadoop.hbase.master.HMaster; import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.metrics2.MetricsSource; import org.apache.hadoop.metrics2.MetricsTag; import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; -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(MiscTests.TAG) +@Tag(MediumTests.TAG) public class TestBalancerStatusTagInJMXMetrics extends BalancerTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestBalancerStatusTagInJMXMetrics.class); - private static final Logger LOG = LoggerFactory.getLogger(TestBalancerStatusTagInJMXMetrics.class); private static HBaseTestingUtil UTIL = new HBaseTestingUtil(); @@ -56,7 +52,7 @@ public class TestBalancerStatusTagInJMXMetrics extends BalancerTestBase { /** * Setup the environment for the test. */ - @BeforeClass + @BeforeAll public static void setupBeforeClass() throws Exception { conf = UTIL.getConfiguration(); Random rand = ThreadLocalRandom.current(); @@ -85,7 +81,7 @@ public static void setupBeforeClass() throws Exception { } } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { UTIL.shutdownMiniCluster(); } @@ -96,9 +92,9 @@ public static void tearDownAfterClass() throws Exception { @Test public void testJmxMetrics() throws Exception { - assertEquals(getStatus(), "true"); + assertEquals("true", getStatus()); master.getLoadBalancer().updateBalancerStatus(false); - assertEquals(getStatus(), "false"); + assertEquals("false", getStatus()); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestCacheAwareLoadBalancer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestCacheAwareLoadBalancer.java index ac62da5c3561..8b8fdbf11ad7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestCacheAwareLoadBalancer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestCacheAwareLoadBalancer.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.master.balancer; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -31,7 +31,6 @@ import java.util.concurrent.ThreadLocalRandom; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.ClusterMetrics; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.RegionMetrics; @@ -45,20 +44,16 @@ import org.apache.hadoop.hbase.master.RegionPlan; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.util.Bytes; -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; import org.apache.hbase.thirdparty.com.google.common.collect.Lists; -@Category({ LargeTests.class }) +@Tag(LargeTests.TAG) public class TestCacheAwareLoadBalancer extends BalancerTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestCacheAwareLoadBalancer.class); private static final Logger LOG = LoggerFactory.getLogger(TestCacheAwareLoadBalancer.class); @@ -115,7 +110,7 @@ private ServerMetrics mockServerMetricsWithRegionCacheInfo(ServerName server, return serverMetrics; } - @BeforeClass + @BeforeAll public static void beforeAllTests() throws Exception { servers = generateServers(3); tableDescs = constructTableDesc(false); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredNodeTableImport.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredNodeTableImport.java index 5f3f6b2667d1..05ef80b12114 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredNodeTableImport.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredNodeTableImport.java @@ -18,14 +18,13 @@ package org.apache.hadoop.hbase.master.balancer; import static org.apache.hadoop.hbase.favored.FavoredNodeAssignmentHelper.FAVORED_NODES_NUM; -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 java.util.List; import java.util.Set; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -40,10 +39,9 @@ import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Threads; -import org.junit.After; -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.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,13 +51,9 @@ * This case tests a scenario when a cluster with tables is moved from Stochastic Load Balancer * to FavoredStochasticLoadBalancer and the generation of favored nodes after switch. */ -@Category(MediumTests.class) +@Tag(MediumTests.TAG) public class TestFavoredNodeTableImport { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestFavoredNodeTableImport.class); - private static final Logger LOG = LoggerFactory.getLogger(TestFavoredNodeTableImport.class); private static final int SLAVES = 3; @@ -67,7 +61,7 @@ public class TestFavoredNodeTableImport { private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static final Configuration conf = UTIL.getConfiguration(); - @After + @AfterEach public void stopCluster() throws Exception { UTIL.shutdownMiniCluster(); } @@ -118,12 +112,12 @@ public void testTableCreation() throws Exception { assertNotNull(fnm); List fns = fnm.getFavoredNodes(rInfo); LOG.info("FNS {} {}", rInfo, fns); - assertNotNull(rInfo.toString(), fns); + assertNotNull(fns, rInfo.toString()); Set favNodes = Sets.newHashSet(fns); assertNotNull(favNodes); - assertEquals("Required no of favored nodes not found.", FAVORED_NODES_NUM, favNodes.size()); + assertEquals(FAVORED_NODES_NUM, favNodes.size(), "Required no of favored nodes not found."); for (ServerName fn : favNodes) { - assertEquals("StartCode invalid for:" + fn, ServerName.NON_STARTCODE, fn.getStartcode()); + assertEquals(ServerName.NON_STARTCODE, fn.getStartcode(), "StartCode invalid for:" + fn); } } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredStochasticBalancerPickers.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredStochasticBalancerPickers.java index 2cf706f1b9f0..a4acf8fa244a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredStochasticBalancerPickers.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredStochasticBalancerPickers.java @@ -17,10 +17,10 @@ */ package org.apache.hadoop.hbase.master.balancer; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.Arrays; @@ -30,7 +30,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.ClusterMetrics; import org.apache.hadoop.hbase.ClusterMetrics.Option; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -54,27 +53,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.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hbase.thirdparty.com.google.common.collect.Lists; import org.apache.hbase.thirdparty.com.google.common.collect.Maps; -@Category(LargeTests.class) +@Tag(LargeTests.TAG) public class TestFavoredStochasticBalancerPickers extends BalancerTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestFavoredStochasticBalancerPickers.class); - private static final Logger LOG = LoggerFactory.getLogger(TestFavoredStochasticBalancerPickers.class); @@ -86,10 +79,7 @@ public class TestFavoredStochasticBalancerPickers extends BalancerTestBase { private Admin admin; private SingleProcessHBaseCluster cluster; - @Rule - public TestName name = new TestName(); - - @BeforeClass + @BeforeAll public static void setupBeforeClass() throws Exception { conf = TEST_UTIL.getConfiguration(); // Enable favored nodes based load balancer @@ -100,7 +90,7 @@ public static void setupBeforeClass() throws Exception { conf.setBoolean("hbase.master.balancer.stochastic.execute.maxSteps", true); } - @Before + @BeforeEach public void startCluster() throws Exception { TEST_UTIL.startMiniCluster(SLAVES); TEST_UTIL.getDFSCluster().waitClusterUp(); @@ -110,15 +100,15 @@ public void startCluster() throws Exception { admin.balancerSwitch(false, true); } - @After + @AfterEach public void stopCluster() throws Exception { TEST_UTIL.cleanupTestDir(); TEST_UTIL.shutdownMiniCluster(); } @Test - public void testPickers() throws Exception { - TableName tableName = TableName.valueOf(name.getMethodName()); + public void testPickers(TestInfo testInfo) throws Exception { + TableName tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(HConstants.CATALOG_FAMILY).build(); TableDescriptor desc = @@ -216,7 +206,7 @@ public boolean evaluate() throws Exception { } } } - assertTrue("load picker did not pick expected regions in 100 iterations.", userRegionPicked); + assertTrue(userRegionPicked, "load picker did not pick expected regions in 100 iterations."); } /* diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredStochasticLoadBalancer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredStochasticLoadBalancer.java index dcaebbd84356..dee433bd444f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredStochasticLoadBalancer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestFavoredStochasticLoadBalancer.java @@ -18,11 +18,11 @@ package org.apache.hadoop.hbase.master.balancer; import static org.apache.hadoop.hbase.ServerName.NON_STARTCODE; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.EnumSet; @@ -33,7 +33,6 @@ import java.util.stream.Collectors; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.ClusterMetrics.Option; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; @@ -58,13 +57,12 @@ import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.JVMClusterUtil; -import org.junit.After; -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.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -72,14 +70,10 @@ import org.apache.hbase.thirdparty.com.google.common.collect.Maps; import org.apache.hbase.thirdparty.com.google.common.collect.Sets; -@Ignore // Disabled -@Category(MediumTests.class) +@Disabled +@Tag(MediumTests.TAG) public class TestFavoredStochasticLoadBalancer extends BalancerTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestFavoredStochasticLoadBalancer.class); - private static final Logger LOG = LoggerFactory.getLogger(TestFavoredStochasticLoadBalancer.class); @@ -91,7 +85,7 @@ public class TestFavoredStochasticLoadBalancer extends BalancerTestBase { private HMaster master; private SingleProcessHBaseCluster cluster; - @BeforeClass + @BeforeAll public static void setupBeforeClass() throws Exception { Configuration conf = TEST_UTIL.getConfiguration(); // Enable the favored nodes based load balancer @@ -99,7 +93,7 @@ public static void setupBeforeClass() throws Exception { LoadOnlyFavoredStochasticBalancer.class, LoadBalancer.class); } - @Before + @BeforeEach public void startCluster() throws Exception { TEST_UTIL.startMiniCluster(SLAVES); TEST_UTIL.getDFSCluster().waitClusterUp(); @@ -109,7 +103,7 @@ public void startCluster() throws Exception { admin.balancerSwitch(false, true); } - @After + @AfterEach public void stopCluster() throws Exception { TEST_UTIL.cleanupTestDir(); TEST_UTIL.shutdownMiniCluster(); @@ -133,18 +127,18 @@ public void testBasicBalance() throws Exception { // Now try to run balance, and verify no regions are moved to the 2 region servers recently // started. admin.balancerSwitch(true, true); - assertTrue("Balancer did not run", admin.balance()); + assertTrue(admin.balance(), "Balancer did not run"); TEST_UTIL.waitUntilNoRegionsInTransition(120000); List hris = admin.getRegions(rs1.getRegionServer().getServerName()); for (RegionInfo hri : hris) { - assertFalse("New RS contains regions belonging to table: " + tableName, - hri.getTable().equals(tableName)); + assertFalse(hri.getTable().equals(tableName), + "New RS contains regions belonging to table: " + tableName); } hris = admin.getRegions(rs2.getRegionServer().getServerName()); for (RegionInfo hri : hris) { - assertFalse("New RS contains regions belonging to table: " + tableName, - hri.getTable().equals(tableName)); + assertFalse(hri.getTable().equals(tableName), + "New RS contains regions belonging to table: " + tableName); } } @@ -168,7 +162,7 @@ public void testRoundRobinAssignment() throws Exception { for (List regionInfos : map.values()) { regions.removeAll(regionInfos); } - assertEquals("No region should be missed by balancer", 0, regions.size()); + assertEquals(0, regions.size(), "No region should be missed by balancer"); } @Test @@ -190,9 +184,10 @@ public void testBasicRegionPlacementAndReplicaLoad() throws Exception { Map> replicaLoadMap = fnm.getReplicaLoad(Lists.newArrayList( admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet())); - assertTrue("Not all replica load collected.", + assertTrue( admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().size() - == replicaLoadMap.size()); + == replicaLoadMap.size(), + "Not all replica load collected."); for (Entry> entry : replicaLoadMap.entrySet()) { assertTrue(entry.getValue().size() == FavoredNodeAssignmentHelper.FAVORED_NODES_NUM); assertTrue(entry.getValue().get(0) >= 0); @@ -204,9 +199,10 @@ public void testBasicRegionPlacementAndReplicaLoad() throws Exception { admin.deleteTable(TableName.valueOf(tableName)); replicaLoadMap = fnm.getReplicaLoad(Lists.newArrayList( admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().keySet())); - assertTrue("replica load found " + replicaLoadMap.size() + " instead of 0.", - replicaLoadMap.size() == admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)) - .getLiveServerMetrics().size()); + assertTrue( + replicaLoadMap.size() + == admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS)).getLiveServerMetrics().size(), + "replica load found " + replicaLoadMap.size() + " instead of 0."); } @Test @@ -223,7 +219,7 @@ public void testRandomAssignmentWithNoFavNodes() throws Exception { FavoredNodesManager fnm = master.getFavoredNodesManager(); fnm.deleteFavoredNodesForRegions(Lists.newArrayList(hri)); - assertNull("Favored nodes not found null after delete", fnm.getFavoredNodes(hri)); + assertNull(fnm.getFavoredNodes(hri), "Favored nodes not found null after delete"); LoadBalancer balancer = master.getLoadBalancer(); ServerName destination = balancer.randomAssignment(hri, @@ -238,7 +234,7 @@ public void testRandomAssignmentWithNoFavNodes() throws Exception { containsFN = true; } } - assertTrue("Destination server does not belong to favored nodes.", containsFN); + assertTrue(containsFN, "Destination server does not belong to favored nodes."); } @Test @@ -262,26 +258,26 @@ public void testBalancerWithoutFavoredNodes() throws Exception { admin.balancerSwitch(true, true); // Balancer should unassign the region - assertTrue("Balancer did not run", admin.balance()); + assertTrue(admin.balance(), "Balancer did not run"); TEST_UTIL.waitUntilNoRegionTransitScheduled(); - assertEquals("One region should be unassigned", 1, - master.getAssignmentManager().getRegionsInTransitionCount()); + assertEquals(1, master.getAssignmentManager().getRegionsInTransitionCount(), + "One region should be unassigned"); admin.assign(region.getEncodedNameAsBytes()); TEST_UTIL.waitUntilNoRegionsInTransition(60000); currentFN = fnm.getFavoredNodes(region); assertNotNull(currentFN); - assertEquals("Expected number of FN not present", FavoredNodeAssignmentHelper.FAVORED_NODES_NUM, - currentFN.size()); + assertEquals(FavoredNodeAssignmentHelper.FAVORED_NODES_NUM, currentFN.size(), + "Expected number of FN not present"); - assertTrue("Balancer did not run", admin.balance()); + assertTrue(admin.balance(), "Balancer did not run"); TEST_UTIL.waitUntilNoRegionsInTransition(60000); checkFavoredNodeAssignments(tableName, fnm, regionStates); } - @Ignore + @Disabled @Test public void testMisplacedRegions() throws Exception { TableName tableName = TableName.valueOf("testMisplacedRegions"); @@ -314,10 +310,11 @@ public void testMisplacedRegions() throws Exception { final RegionStates regionStates = master.getAssignmentManager().getRegionStates(); final ServerName current = regionStates.getRegionServerOfRegion(misplacedRegion); - assertNull("Misplaced region is still hosted on favored node, not expected.", - FavoredNodesPlan.getFavoredServerPosition(fnm.getFavoredNodes(misplacedRegion), current)); + assertNull( + FavoredNodesPlan.getFavoredServerPosition(fnm.getFavoredNodes(misplacedRegion), current), + "Misplaced region is still hosted on favored node, not expected."); admin.balancerSwitch(true, true); - assertTrue("Balancer did not run", admin.balance()); + assertTrue(admin.balance(), "Balancer did not run"); TEST_UTIL.waitFor(120000, 30000, new Waiter.Predicate() { @Override public boolean evaluate() throws Exception { @@ -357,15 +354,15 @@ public boolean evaluate() throws Exception { } }); - assertEquals("Not all regions are online", REGION_NUM, admin.getRegions(tableName).size()); + assertEquals(REGION_NUM, admin.getRegions(tableName).size(), "Not all regions are online"); admin.balancerSwitch(true, true); - assertTrue("Balancer did not run", admin.balance()); + assertTrue(admin.balance(), "Balancer did not run"); TEST_UTIL.waitUntilNoRegionsInTransition(60000); checkFavoredNodeAssignments(tableName, fnm, regionStates); } - @Ignore + @Disabled @Test public void testAllFavoredNodesDead() throws Exception { TableName tableName = TableName.valueOf("testAllFavoredNodesDead"); @@ -391,9 +388,8 @@ public boolean evaluate() throws Exception { return regionStates.getRegionState(region).isFailedOpen(); } }); - - assertTrue("Region: " + region + " should be RIT", - regionStates.getRegionState(region).isFailedOpen()); + assertTrue(regionStates.getRegionState(region).isFailedOpen(), + "Region: " + region + " should be RIT"); // Regenerate FN and assign, everything else should be fine List serversForNewFN = Lists.newArrayList(); @@ -419,16 +415,16 @@ public boolean evaluate() throws Exception { admin.assign(regionInfo.getEncodedNameAsBytes()); } TEST_UTIL.waitUntilNoRegionsInTransition(60000); - assertEquals("Not all regions are online", REGION_NUM, admin.getRegions(tableName).size()); + assertEquals(REGION_NUM, admin.getRegions(tableName).size(), "Not all regions are online"); admin.balancerSwitch(true, true); - assertTrue("Balancer did not run", admin.balance()); + assertTrue(admin.balance(), "Balancer did not run"); TEST_UTIL.waitUntilNoRegionsInTransition(60000); checkFavoredNodeAssignments(tableName, fnm, regionStates); } - @Ignore + @Disabled @Test public void testAllFavoredNodesDeadMasterRestarted() throws Exception { TableName tableName = TableName.valueOf("testAllFavoredNodesDeadMasterRestarted"); @@ -455,18 +451,18 @@ public boolean evaluate() throws Exception { } }); - assertTrue("Region: " + region + " should be RIT", - regionStatesBeforeMaster.getRegionState(region).isFailedOpen()); + assertTrue(regionStatesBeforeMaster.getRegionState(region).isFailedOpen(), + "Region: " + region + " should be RIT"); List rit = Lists.newArrayList(); for (RegionStateNode regionState : am.getRegionsInTransition()) { RegionInfo regionInfo = regionState.getRegionInfo(); LOG.debug("Region in transition after stopping FN's: " + regionInfo); rit.add(regionInfo); - assertTrue("Region: " + regionInfo + " should be RIT", - regionStatesBeforeMaster.getRegionState(regionInfo).isFailedOpen()); - assertEquals("Region: " + regionInfo + " does not belong to table: " + tableName, tableName, - regionInfo.getTable()); + assertTrue(regionStatesBeforeMaster.getRegionState(regionInfo).isFailedOpen(), + "Region: " + regionInfo + " should be RIT"); + assertEquals(tableName, regionInfo.getTable(), + "Region: " + regionInfo + " does not belong to table: " + tableName); } Configuration conf = cluster.getConf(); @@ -482,12 +478,12 @@ public boolean evaluate() throws Exception { fnm = master.getFavoredNodesManager(); RegionStates regionStates = master.getAssignmentManager().getRegionStates(); - assertTrue("Region: " + region + " should be RIT", - regionStates.getRegionState(region).isFailedOpen()); + assertTrue(regionStates.getRegionState(region).isFailedOpen(), + "Region: " + region + " should be RIT"); for (RegionInfo regionInfo : rit) { - assertTrue("Region: " + regionInfo + " should be RIT", - regionStates.getRegionState(regionInfo).isFailedOpen()); + assertTrue(regionStates.getRegionState(regionInfo).isFailedOpen(), + "Region: " + regionInfo + " should be RIT"); } // Regenerate FN and assign, everything else should be fine @@ -513,10 +509,10 @@ public boolean evaluate() throws Exception { admin.assign(regionInfo.getEncodedNameAsBytes()); } TEST_UTIL.waitUntilNoRegionsInTransition(60000); - assertEquals("Not all regions are online", REGION_NUM, admin.getRegions(tableName).size()); + assertEquals(REGION_NUM, admin.getRegions(tableName).size(), "Not all regions are online"); admin.balancerSwitch(true, true); - assertTrue("Balancer did not run", admin.balance()); + assertTrue(admin.balance(), "Balancer did not run"); TEST_UTIL.waitUntilNoRegionsInTransition(60000); checkFavoredNodeAssignments(tableName, fnm, regionStates); @@ -526,10 +522,9 @@ private void checkFavoredNodeAssignments(TableName tableName, FavoredNodesManage RegionStates regionStates) throws IOException { for (RegionInfo hri : admin.getRegions(tableName)) { ServerName host = regionStates.getRegionServerOfRegion(hri); - assertNotNull( + assertNotNull(FavoredNodesPlan.getFavoredServerPosition(fnm.getFavoredNodes(hri), host), "Region: " + hri.getEncodedName() + " not on FN, current: " + host + " FN list: " - + fnm.getFavoredNodes(hri), - FavoredNodesPlan.getFavoredServerPosition(fnm.getFavoredNodes(hri), host)); + + fnm.getFavoredNodes(hri)); } } @@ -552,8 +547,8 @@ public boolean evaluate() throws Exception { } }); - assertEquals("Not all servers killed", SLAVES - currentFN.size(), - cluster.getLiveRegionServerThreads().size()); + assertEquals(SLAVES - currentFN.size(), cluster.getLiveRegionServerThreads().size(), + "Not all servers killed"); } private void compactTable(TableName tableName) throws IOException { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestLoadBalancerStateStore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestLoadBalancerStateStore.java index ebe78f6f3acb..0a7f41c86db0 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestLoadBalancerStateStore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestLoadBalancerStateStore.java @@ -17,31 +17,26 @@ */ package org.apache.hadoop.hbase.master.balancer; -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 org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.master.MasterStateStoreTestBase; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.zookeeper.ZKUtil; -import org.junit.After; -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.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.generated.LoadBalancerProtos; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestLoadBalancerStateStore extends MasterStateStoreTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestLoadBalancerStateStore.class); - - @After + @AfterEach public void tearDown() throws Exception { cleanup(); ZKUtil.deleteNodeFailSilent(UTIL.getZooKeeperWatcher(), diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestMetaTableIsolationBalancerConditional.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestMetaTableIsolationBalancerConditional.java index 80f9728651e3..2dbda7ba0e7f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestMetaTableIsolationBalancerConditional.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestMetaTableIsolationBalancerConditional.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.master.balancer; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import java.io.IOException; import java.util.Collection; @@ -26,7 +26,6 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionLocation; @@ -41,30 +40,25 @@ import org.apache.hadoop.hbase.quotas.QuotaUtil; 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.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableSet; -@Category(LargeTests.class) +@Tag(LargeTests.TAG) public class TestMetaTableIsolationBalancerConditional { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMetaTableIsolationBalancerConditional.class); - private static final Logger LOG = LoggerFactory.getLogger(TestMetaTableIsolationBalancerConditional.class); private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static final int NUM_SERVERS = 3; - @Before + @BeforeEach public void setUp() throws Exception { TEST_UTIL.getConfiguration().setBoolean(BalancerConditionals.ISOLATE_META_TABLE_KEY, true); TEST_UTIL.getConfiguration().setBoolean(QuotaUtil.QUOTA_CONF_KEY, true); // for another table @@ -74,7 +68,7 @@ public void setUp() throws Exception { TEST_UTIL.startMiniCluster(NUM_SERVERS); } - @After + @AfterEach public void tearDown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -153,16 +147,16 @@ private static void validateRegionLocations(Map> tabl Set productServers = tableToServers.get(productTableName); if (shouldBeBalanced) { - assertNotEquals("Meta table and quota table should not share a server", metaServer, - quotaServer); + assertNotEquals(metaServer, quotaServer, + "Meta table and quota table should not share a server"); for (ServerName productServer : productServers) { - assertNotEquals("Meta table and product table should not share servers", productServer, - metaServer); + assertNotEquals(productServer, metaServer, + "Meta table and product table should not share servers"); } } else { - assertEquals("Quota table and product table must share servers", metaServer, quotaServer); + assertEquals(metaServer, quotaServer, "Quota table and product table must share servers"); for (ServerName server : productServers) { - assertEquals("Meta table and product table must share servers", server, metaServer); + assertEquals(server, metaServer, "Meta table and product table must share servers"); } } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancer.java index a64c2513dcd5..ed57c7a2211f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancer.java @@ -17,9 +17,9 @@ */ package org.apache.hadoop.hbase.master.balancer; -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.ArrayList; import java.util.Collections; @@ -30,7 +30,6 @@ import java.util.Map; import java.util.Set; import org.apache.commons.lang3.StringUtils; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; @@ -42,10 +41,9 @@ import org.apache.hadoop.hbase.rsgroup.RSGroupInfo; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.net.DNSToSwitchMapping; -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; @@ -54,15 +52,12 @@ /** * Test RSGroupBasedLoadBalancer with SimpleLoadBalancer as internal balancer */ -@Category(LargeTests.class) +@Tag(LargeTests.TAG) public class TestRSGroupBasedLoadBalancer extends RSGroupableBalancerTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRSGroupBasedLoadBalancer.class); private static final Logger LOG = LoggerFactory.getLogger(TestRSGroupBasedLoadBalancer.class); private static RSGroupBasedLoadBalancer loadBalancer; - @BeforeClass + @BeforeAll public static void beforeAllTests() throws Exception { servers = generateServers(7); groupMap = constructGroupInfo(servers, groups); @@ -122,8 +117,8 @@ public void testBulkAssignment() throws Exception { tableDescs.get(tableName).getRegionServerGroup().orElse(RSGroupInfo.DEFAULT_GROUP); assertTrue(StringUtils.isNotEmpty(groupName)); RSGroupInfo gInfo = getMockedGroupInfoManager().getRSGroup(groupName); - assertTrue("Region is not correctly assigned to group servers.", - gInfo.containsServer(sn.getAddress())); + assertTrue(gInfo.containsServer(sn.getAddress()), + "Region is not correctly assigned to group servers."); } } ArrayListMultimap loadMap = convertToGroupBasedMap(assignments); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancerWithCacheAwareLoadBalancerAsInternal.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancerWithCacheAwareLoadBalancerAsInternal.java index c92f1e5a205c..71154ebcb334 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancerWithCacheAwareLoadBalancerAsInternal.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancerWithCacheAwareLoadBalancerAsInternal.java @@ -17,9 +17,9 @@ */ package org.apache.hadoop.hbase.master.balancer; -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; @@ -36,7 +36,6 @@ import java.util.concurrent.Future; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.ClusterMetrics; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.ServerMetrics; @@ -49,26 +48,23 @@ import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.Pair; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.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.junit.jupiter.api.Timeout; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category(LargeTests.class) +@Tag(LargeTests.TAG) public class TestRSGroupBasedLoadBalancerWithCacheAwareLoadBalancerAsInternal extends RSGroupableBalancerTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule - .forClass(TestRSGroupBasedLoadBalancerWithCacheAwareLoadBalancerAsInternal.class); private static final Logger LOG = LoggerFactory.getLogger(TestRSGroupBasedLoadBalancerWithCacheAwareLoadBalancerAsInternal.class); private static RSGroupBasedLoadBalancer loadBalancer; - @BeforeClass + @BeforeAll public static void beforeAllTests() throws Exception { groups = new String[] { RSGroupInfo.DEFAULT_GROUP }; servers = generateServers(3); @@ -531,7 +527,8 @@ public void testRegionsPartiallyCachedOnOldServerAndCurrentServer() throws Excep assertTrue(targetServers.get(server1).containsAll(oldCachedRegions)); } - @Test(timeout = 60000) + @Timeout(60) + @Test public void testConfigUpdateDuringBalance() throws Exception { float expectedOldRatioThreshold = 0.8f; float expectedNewRatioThreshold = 0.95f; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancerWithStochasticLoadBalancerAsInternal.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancerWithStochasticLoadBalancerAsInternal.java index 67ef296da58b..cfb4c08ff6a9 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancerWithStochasticLoadBalancerAsInternal.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestRSGroupBasedLoadBalancerWithStochasticLoadBalancerAsInternal.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.master.balancer; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -30,7 +30,6 @@ import java.util.Set; import java.util.TreeMap; import org.apache.hadoop.hbase.ClusterMetrics; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.RegionMetrics; import org.apache.hadoop.hbase.ServerMetrics; import org.apache.hadoop.hbase.ServerName; @@ -43,23 +42,16 @@ import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.net.DNSToSwitchMapping; -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; -/** - * Test RSGroupBasedLoadBalancer with StochasticLoadBalancer as internal balancer - */ -@Category(LargeTests.class) +@Tag(LargeTests.TAG) public class TestRSGroupBasedLoadBalancerWithStochasticLoadBalancerAsInternal extends RSGroupableBalancerTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = HBaseClassTestRule - .forClass(TestRSGroupBasedLoadBalancerWithStochasticLoadBalancerAsInternal.class); private static RSGroupBasedLoadBalancer loadBalancer; - @BeforeClass + @BeforeAll public static void beforeAllTests() throws Exception { groups = new String[] { RSGroupInfo.DEFAULT_GROUP }; servers = generateServers(3); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestReplicaDistributionBalancerConditional.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestReplicaDistributionBalancerConditional.java index 0aae720f8384..12d1fe095604 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestReplicaDistributionBalancerConditional.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestReplicaDistributionBalancerConditional.java @@ -20,7 +20,6 @@ import static org.apache.hadoop.hbase.master.balancer.BalancerConditionalsTestUtil.validateAssertionsWithRetries; 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; @@ -34,21 +33,17 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.ServerRegionReplicaUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ LargeTests.class, MasterTests.class }) +@Tag(LargeTests.TAG) +@Tag(MasterTests.TAG) public class TestReplicaDistributionBalancerConditional { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicaDistributionBalancerConditional.class); - private static final Logger LOG = LoggerFactory.getLogger(TestReplicaDistributionBalancerConditional.class); private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); @@ -56,7 +51,7 @@ public class TestReplicaDistributionBalancerConditional { private static final int NUM_SERVERS = REPLICAS; private static final int REGIONS_PER_SERVER = 5; - @Before + @BeforeEach public void setUp() throws Exception { DistributeReplicasTestConditional .enableConditionalReplicaDistributionForTest(TEST_UTIL.getConfiguration()); @@ -74,7 +69,7 @@ public void setUp() throws Exception { TEST_UTIL.startMiniCluster(NUM_SERVERS); } - @After + @AfterEach public void tearDown() throws Exception { TEST_UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticBalancerJmxMetrics.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticBalancerJmxMetrics.java index 7cea8fdf47f7..722dcce8eb58 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticBalancerJmxMetrics.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticBalancerJmxMetrics.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.hbase.master.balancer; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.HashSet; @@ -36,7 +36,6 @@ import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.JMXListener; @@ -48,26 +47,22 @@ import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.util.Threads; import org.apache.hadoop.net.DNSToSwitchMapping; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.FixMethodOrder; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MiscTests.class, MediumTests.class }) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Ignore +@Tag(MiscTests.TAG) +@Tag(MediumTests.TAG) +@TestMethodOrder(MethodOrderer.MethodName.class) +@Disabled public class TestStochasticBalancerJmxMetrics extends BalancerTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestStochasticBalancerJmxMetrics.class); - private static final Logger LOG = LoggerFactory.getLogger(TestStochasticBalancerJmxMetrics.class); private static HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static int connectorPort = 61120; @@ -89,7 +84,7 @@ public class TestStochasticBalancerJmxMetrics extends BalancerTestBase { /** * Setup the environment for the test. */ - @BeforeClass + @BeforeAll public static void setupBeforeClass() throws Exception { conf = UTIL.getConfiguration(); @@ -120,7 +115,7 @@ public static void setupBeforeClass() throws Exception { } } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { UTIL.shutdownMiniCluster(); } @@ -150,8 +145,8 @@ public void testJmxMetrics_EnsembleMode() throws Exception { // assert that every expected is in the JMX for (String expected : expectedMetrics) { - assertTrue("Metric " + expected + " can not be found in JMX in ensemble mode.", - jmxMetrics.contains(expected)); + assertTrue(jmxMetrics.contains(expected), + "Metric " + expected + " can not be found in JMX in ensemble mode."); } } @@ -196,8 +191,8 @@ public void testJmxMetrics_PerTableMode() throws Exception { // assert that every expected is in the JMX for (String expected : expectedMetrics) { - assertTrue("Metric " + expected + " can not be found in JMX in per-table mode.", - jmxMetrics.contains(expected)); + assertTrue(jmxMetrics.contains(expected), + "Metric " + expected + " can not be found in JMX in per-table mode."); } } @@ -205,7 +200,9 @@ private Set readJmxMetricsWithRetry() throws IOException { final int count = 0; for (int i = 0; i < 10; i++) { Set metrics = readJmxMetrics(); - if (metrics != null) return metrics; + if (metrics != null) { + return metrics; + } LOG.warn("Failed to get jmxmetrics... sleeping, retrying; " + i + " of " + count + " times"); Threads.sleep(1000); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancerHeterogeneousCostRulesLoadFromHDFS.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancerHeterogeneousCostRulesLoadFromHDFS.java index 5cd9d1a3f20d..efe7d999b4dd 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancerHeterogeneousCostRulesLoadFromHDFS.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/balancer/TestStochasticLoadBalancerHeterogeneousCostRulesLoadFromHDFS.java @@ -18,41 +18,36 @@ package org.apache.hadoop.hbase.master.balancer; import static org.apache.hadoop.hbase.master.balancer.HeterogeneousCostRulesTestHelper.DEFAULT_RULES_FILE_NAME; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import org.apache.hadoop.conf.Configuration; 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.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.MiniDFSCluster; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestStochasticLoadBalancerHeterogeneousCostRulesLoadFromHDFS extends StochasticBalancerTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestStochasticLoadBalancerHeterogeneousCostRulesLoadFromHDFS.class); - private HeterogeneousRegionCountCostFunction costFunction; private static final HBaseTestingUtil HTU = new HBaseTestingUtil(); - @Before + @BeforeEach public void setUp() throws Exception { HTU.startMiniCluster(1); } - @After + @AfterEach public void tearDown() throws IOException { HTU.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestCleanerChore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestCleanerChore.java index d1a4f6dea055..15ee7ae272f3 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestCleanerChore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestCleanerChore.java @@ -20,10 +20,10 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.instanceOf; -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.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 java.io.IOException; import java.util.Map; @@ -39,7 +39,6 @@ import org.apache.hadoop.fs.FilterFileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.ChoreService; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.Stoppable; import org.apache.hadoop.hbase.testclassification.MasterTests; @@ -48,11 +47,10 @@ import org.apache.hadoop.hbase.util.CommonFSUtils; 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.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -61,25 +59,22 @@ import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap; -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestCleanerChore { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestCleanerChore.class); - private static final Logger LOG = LoggerFactory.getLogger(TestCleanerChore.class); private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static DirScanPool POOL; private static ChoreService SERVICE; - @BeforeClass + @BeforeAll public static void setup() { POOL = DirScanPool.getHFileCleanerScanPool(UTIL.getConfiguration()); SERVICE = new ChoreService("cleaner", 2, true); } - @AfterClass + @AfterAll public static void cleanup() throws Exception { SERVICE.shutdown(); UTIL.cleanupTestDir(); @@ -104,14 +99,14 @@ public void testSavesFilesOnRequest() throws Exception { fs.mkdirs(parent); // touch a new file fs.create(file).close(); - assertTrue("Test file didn't get created.", fs.exists(file)); + assertTrue(fs.exists(file), "Test file didn't get created."); // run the chore chore.chore(); // verify all the files were preserved - assertTrue("File shouldn't have been deleted", fs.exists(file)); - assertTrue("directory shouldn't have been deleted", fs.exists(parent)); + assertTrue(fs.exists(file), "File shouldn't have been deleted"); + assertTrue(fs.exists(parent), "directory shouldn't have been deleted"); } @Test @@ -126,7 +121,7 @@ public void retriesIOExceptionInStatus() throws Exception { Path file = new Path(child, "file"); fs.mkdirs(child); fs.create(file).close(); - assertTrue("test file didn't get created.", fs.exists(file)); + assertTrue(fs.exists(file), "test file didn't get created."); final AtomicBoolean fails = new AtomicBoolean(true); FilterFileSystem filtered = new FilterFileSystem(fs) { public FileStatus[] listStatus(Path f) throws IOException { @@ -149,8 +144,8 @@ public FileStatus[] listStatus(Path f) throws IOException { assertThat(e.getCause().getMessage(), containsString("whomp")); // verify that it couldn't clean the files. - assertTrue("test rig failed to inject failure.", fs.exists(file)); - assertTrue("test rig failed to inject failure.", fs.exists(child)); + assertTrue(fs.exists(file), "test rig failed to inject failure."); + assertTrue(fs.exists(child), "test rig failed to inject failure."); // filesystem is back fails.set(false); @@ -160,13 +155,13 @@ public FileStatus[] listStatus(Path f) throws IOException { // again. if (succFuture != errorFuture) { // verify that it accurately reported success. - assertTrue("chore should claim it succeeded.", succFuture.get()); + assertTrue(succFuture.get(), "chore should claim it succeeded."); break; } } // verify everything is gone. - assertFalse("file should have been destroyed.", fs.exists(file)); - assertFalse("directory should have been destroyed.", fs.exists(child)); + assertFalse(fs.exists(file), "file should have been destroyed."); + assertFalse(fs.exists(child), "directory should have been destroyed."); } finally { chore.cancel(); @@ -197,17 +192,17 @@ public void testDeletesEmptyDirectories() throws Exception { // also create a file in the top level directory Path topFile = new Path(testDir, "topFile"); fs.create(topFile).close(); - assertTrue("Test file didn't get created.", fs.exists(file)); - assertTrue("Test file didn't get created.", fs.exists(topFile)); + assertTrue(fs.exists(file), "Test file didn't get created."); + assertTrue(fs.exists(topFile), "Test file didn't get created."); // run the chore chore.chore(); // verify all the files got deleted - assertFalse("File didn't get deleted", fs.exists(topFile)); - assertFalse("File didn't get deleted", fs.exists(file)); - assertFalse("Empty directory didn't get deleted", fs.exists(child)); - assertFalse("Empty directory didn't get deleted", fs.exists(parent)); + assertFalse(fs.exists(topFile), "File didn't get deleted"); + assertFalse(fs.exists(file), "File didn't get deleted"); + assertFalse(fs.exists(child), "Empty directory didn't get deleted"); + assertFalse(fs.exists(parent), "Empty directory didn't get deleted"); } /** @@ -235,10 +230,10 @@ public void testDoesNotCheckDirectories() throws Exception { Path parent = new Path(testDir, "parent"); Path file = new Path(parent, "someFile"); fs.mkdirs(parent); - assertTrue("Test parent didn't get created.", fs.exists(parent)); + assertTrue(fs.exists(parent), "Test parent didn't get created."); // touch a new file fs.create(file).close(); - assertTrue("Test file didn't get created.", fs.exists(file)); + assertTrue(fs.exists(file), "Test file didn't get created."); FileStatus fStat = fs.getFileStatus(parent); chore.chore(); @@ -262,7 +257,7 @@ public void testStoppedCleanerDoesNotDeleteFiles() throws Exception { // also create a file in the top level directory Path topFile = new Path(testDir, "topFile"); fs.create(topFile).close(); - assertTrue("Test file didn't get created.", fs.exists(topFile)); + assertTrue(fs.exists(topFile), "Test file didn't get created."); // stop the chore stop.stop("testing stop"); @@ -271,7 +266,7 @@ public void testStoppedCleanerDoesNotDeleteFiles() throws Exception { chore.chore(); // test that the file still exists - assertTrue("File got deleted while chore was stopped", fs.exists(topFile)); + assertTrue(fs.exists(topFile), "File got deleted while chore was stopped"); } /** @@ -301,7 +296,7 @@ public void testCleanerDoesNotDeleteDirectoryWithLateAddedFiles() throws IOExcep fs.mkdirs(parent); // touch a new file fs.create(file).close(); - assertTrue("Test file didn't get created.", fs.exists(file)); + assertTrue(fs.exists(file), "Test file didn't get created."); final Path addedFile = new Path(parent, "addedFile"); // when we attempt to delete the original file, add another file in the same directory @@ -318,9 +313,9 @@ public Boolean answer(InvocationOnMock invocation) throws Throwable { chore.chore(); // make sure all the directories + added file exist, but the original file is deleted - assertTrue("Added file unexpectedly deleted", fs.exists(addedFile)); - assertTrue("Parent directory deleted unexpectedly", fs.exists(parent)); - assertFalse("Original file unexpectedly retained", fs.exists(file)); + assertTrue(fs.exists(addedFile), "Added file unexpectedly deleted"); + assertTrue(fs.exists(parent), "Parent directory deleted unexpectedly"); + assertFalse(fs.exists(file), "Original file unexpectedly retained"); Mockito.verify(spy, Mockito.times(1)).isFileDeletable(Mockito.any()); Mockito.reset(spy); } @@ -361,7 +356,7 @@ public void testNoExceptionFromDirectoryWithRacyChildren() throws Exception { fs.mkdirs(parent); // touch a new file fs.create(file).close(); - assertTrue("Test file didn't get created.", fs.exists(file)); + assertTrue(fs.exists(file), "Test file didn't get created."); final Path racyFile = new Path(parent, "addedFile"); // when we attempt to delete the original file, add another file in the same directory @@ -378,9 +373,9 @@ public Boolean answer(InvocationOnMock invocation) throws Throwable { chore.chore(); // make sure all the directories + added file exist, but the original file is deleted - assertTrue("Added file unexpectedly deleted", fs.exists(racyFile)); - assertTrue("Parent directory deleted unexpectedly", fs.exists(parent)); - assertFalse("Original file unexpectedly retained", fs.exists(file)); + assertTrue(fs.exists(racyFile), "Added file unexpectedly deleted"); + assertTrue(fs.exists(parent), "Parent directory deleted unexpectedly"); + assertFalse(fs.exists(file), "Original file unexpectedly retained"); Mockito.verify(spy, Mockito.times(1)).isFileDeletable(Mockito.any()); } @@ -407,15 +402,15 @@ public void testDeleteFileWithCleanerEnabled() throws Exception { // touch a new file fs.create(file).close(); - assertTrue("Test file didn't get created.", fs.exists(file)); + assertTrue(fs.exists(file), "Test file didn't get created."); // run the chore chore.chore(); // verify all the files got deleted - assertFalse("File didn't get deleted", fs.exists(file)); - assertFalse("Empty directory didn't get deleted", fs.exists(child)); - assertFalse("Empty directory didn't get deleted", fs.exists(parent)); + assertFalse(fs.exists(file), "File didn't get deleted"); + assertFalse(fs.exists(child), "Empty directory didn't get deleted"); + assertFalse(fs.exists(parent), "Empty directory didn't get deleted"); } @Test @@ -441,15 +436,15 @@ public void testDeleteFileWithCleanerDisabled() throws Exception { // touch a new file fs.create(file).close(); - assertTrue("Test file didn't get created.", fs.exists(file)); + assertTrue(fs.exists(file), "Test file didn't get created."); // run the chore chore.chore(); // verify all the files exist - assertTrue("File got deleted with cleaner disabled", fs.exists(file)); - assertTrue("Directory got deleted", fs.exists(child)); - assertTrue("Directory got deleted", fs.exists(parent)); + assertTrue(fs.exists(file), "File got deleted with cleaner disabled"); + assertTrue(fs.exists(child), "Directory got deleted"); + assertTrue(fs.exists(parent), "Directory got deleted"); } @Test diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestCleanerClearHFiles.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestCleanerClearHFiles.java index c747a14be1ae..82e0857659a7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestCleanerClearHFiles.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestCleanerClearHFiles.java @@ -24,7 +24,6 @@ import java.io.IOException; 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.Admin; @@ -36,23 +35,13 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.HFileArchiveUtil; import org.apache.hadoop.hdfs.DistributedFileSystem; -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(LargeTests.class) -public class TestCleanerClearHFiles { - - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestCleanerClearHFiles.class); +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; - @Rule - public TestName name = new TestName(); +@Tag(LargeTests.TAG) +public class TestCleanerClearHFiles { private static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static Configuration conf = TEST_UTIL.getConfiguration(); @@ -64,7 +53,7 @@ public class TestCleanerClearHFiles { private static final String TABLE2 = "table2"; private static final String DEFAULT_ARCHIVE_SUBDIRS_PREFIX = "data/default/"; - @BeforeClass + @BeforeAll public static void setupBeforeClass() throws Exception { conf.setStrings(HFileCleaner.HFILE_CLEANER_CUSTOM_PATHS, DEFAULT_ARCHIVE_SUBDIRS_PREFIX + TABLE1); @@ -77,7 +66,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/master/cleaner/TestHFileCleaner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileCleaner.java index ba16ec12daf2..bda9e0df43d8 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileCleaner.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileCleaner.java @@ -17,9 +17,10 @@ */ package org.apache.hadoop.hbase.master.cleaner; -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.List; @@ -30,7 +31,6 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.Server; @@ -45,22 +45,17 @@ import org.apache.hadoop.hbase.util.HFileArchiveUtil; import org.apache.hadoop.hbase.util.MockServer; import org.apache.hadoop.hbase.zookeeper.ZKWatcher; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestHFileCleaner { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestHFileCleaner.class); - private static final Logger LOG = LoggerFactory.getLogger(TestHFileCleaner.class); private final static HBaseTestingUtil UTIL = new HBaseTestingUtil(); @@ -70,14 +65,14 @@ public class TestHFileCleaner { private static String MOCK_ARCHIVED_HFILE_DIR = HConstants.HFILE_ARCHIVE_DIRECTORY + "/namespace/table/region"; - @BeforeClass + @BeforeAll public static void setupCluster() throws Exception { // have to use a minidfs cluster because the localfs doesn't modify file times correctly UTIL.startMiniDFSCluster(1); POOL = DirScanPool.getHFileCleanerScanPool(UTIL.getConfiguration()); } - @AfterClass + @AfterAll public static void shutdownCluster() throws IOException { UTIL.shutdownMiniDFSCluster(); POOL.shutdownNow(); @@ -90,15 +85,16 @@ public void testTTLCleaner() throws IOException { Path file = new Path(root, "file"); fs.createNewFile(file); long createTime = EnvironmentEdgeManager.currentTime(); - assertTrue("Test file not created!", fs.exists(file)); + assertTrue(fs.exists(file), "Test file not created!"); TimeToLiveHFileCleaner cleaner = new TimeToLiveHFileCleaner(); // update the time info for the file, so the cleaner removes it fs.setTimes(file, createTime - 100, -1); Configuration conf = UTIL.getConfiguration(); conf.setLong(TimeToLiveHFileCleaner.TTL_CONF_KEY, 100); cleaner.setConf(conf); - assertTrue("File not set deletable - check mod time:" + getFileStats(file, fs) - + " with create time:" + createTime, cleaner.isFileDeletable(fs.getFileStatus(file))); + assertTrue(cleaner.isFileDeletable(fs.getFileStatus(file)), + "File not set deletable - check mod time:" + getFileStats(file, fs) + " with create time:" + + createTime); } @Test @@ -112,12 +108,12 @@ public void testManualMobCleanerStopsMobRemoval() throws IOException { Path file = new Path(family, "someHFileThatWouldBeAUUID"); fs.createNewFile(file); - assertTrue("Test file not created!", fs.exists(file)); + assertTrue(fs.exists(file), "Test file not created!"); ManualMobMaintHFileCleaner cleaner = new ManualMobMaintHFileCleaner(); - assertFalse("Mob File shouldn't have been deletable. check path. '" + file + "'", - cleaner.isFileDeletable(fs.getFileStatus(file))); + assertFalse(cleaner.isFileDeletable(fs.getFileStatus(file)), + "Mob File shouldn't have been deletable. check path. '" + file + "'"); } @Test @@ -131,12 +127,12 @@ public void testManualMobCleanerLetsNonMobGo() throws IOException { Path file = new Path(family, "someHFileThatWouldBeAUUID"); fs.createNewFile(file); - assertTrue("Test file not created!", fs.exists(file)); + assertTrue(fs.exists(file), "Test file not created!"); ManualMobMaintHFileCleaner cleaner = new ManualMobMaintHFileCleaner(); - assertTrue("Non-Mob File should have been deletable. check path. '" + file + "'", - cleaner.isFileDeletable(fs.getFileStatus(file))); + assertTrue(cleaner.isFileDeletable(fs.getFileStatus(file)), + "Non-Mob File should have been deletable. check path. '" + file + "'"); } /** @@ -247,10 +243,10 @@ public void testRemovesEmptyDirectories() throws Exception { cleaner.chore(); // make sure all the parent directories get removed - assertFalse("family directory not removed for empty directory", fs.exists(family)); - assertFalse("region directory not removed for empty directory", fs.exists(region)); - assertFalse("table directory not removed for empty directory", fs.exists(table)); - assertTrue("archive directory", fs.exists(archivedHfileDir)); + assertFalse(fs.exists(family), "family directory not removed for empty directory"); + assertFalse(fs.exists(region), "region directory not removed for empty directory"); + assertFalse(fs.exists(table), "table directory not removed for empty directory"); + assertTrue(fs.exists(archivedHfileDir), "archive directory"); } static class DummyServer extends MockServer { @@ -293,7 +289,7 @@ public void testThreadCleanup() throws Exception { // wait awhile for thread to die Thread.sleep(100); for (Thread thread : cleaner.getCleanerThreads()) { - Assert.assertFalse(thread.isAlive()); + assertFalse(thread.isAlive()); } } @@ -320,8 +316,8 @@ public void testLargeSmallIsolation() throws Exception { // call cleanup cleaner.chore(); - Assert.assertEquals(LARGE_FILE_NUM, cleaner.getNumOfDeletedLargeFiles()); - Assert.assertEquals(SMALL_FILE_NUM, cleaner.getNumOfDeletedSmallFiles()); + assertEquals(LARGE_FILE_NUM, cleaner.getNumOfDeletedLargeFiles()); + assertEquals(SMALL_FILE_NUM, cleaner.getNumOfDeletedSmallFiles()); } @Test @@ -351,12 +347,12 @@ public void testOnConfigurationChange() throws Exception { // setup the cleaner FileSystem fs = UTIL.getDFSCluster().getFileSystem(); final HFileCleaner cleaner = new HFileCleaner(1000, server, conf, fs, archivedHfileDir, POOL); - Assert.assertEquals(ORIGINAL_THROTTLE_POINT, cleaner.getThrottlePoint()); - Assert.assertEquals(ORIGINAL_QUEUE_INIT_SIZE, cleaner.getLargeQueueInitSize()); - Assert.assertEquals(ORIGINAL_QUEUE_INIT_SIZE, cleaner.getSmallQueueInitSize()); - Assert.assertEquals(HFileCleaner.DEFAULT_HFILE_DELETE_THREAD_TIMEOUT_MSEC, + assertEquals(ORIGINAL_THROTTLE_POINT, cleaner.getThrottlePoint()); + assertEquals(ORIGINAL_QUEUE_INIT_SIZE, cleaner.getLargeQueueInitSize()); + assertEquals(ORIGINAL_QUEUE_INIT_SIZE, cleaner.getSmallQueueInitSize()); + assertEquals(HFileCleaner.DEFAULT_HFILE_DELETE_THREAD_TIMEOUT_MSEC, cleaner.getCleanerThreadTimeoutMsec()); - Assert.assertEquals(HFileCleaner.DEFAULT_HFILE_DELETE_THREAD_CHECK_INTERVAL_MSEC, + assertEquals(HFileCleaner.DEFAULT_HFILE_DELETE_THREAD_CHECK_INTERVAL_MSEC, cleaner.getCleanerThreadCheckIntervalMsec()); // clean up archive directory and create files for testing @@ -394,31 +390,29 @@ public void run() { cleaner.onConfigurationChange(newConf); // check values after change - Assert.assertEquals(UPDATE_THROTTLE_POINT, cleaner.getThrottlePoint()); - Assert.assertEquals(UPDATE_QUEUE_INIT_SIZE, cleaner.getLargeQueueInitSize()); - Assert.assertEquals(UPDATE_QUEUE_INIT_SIZE, cleaner.getSmallQueueInitSize()); - Assert.assertEquals(LARGE_THREAD_NUM + SMALL_THREAD_NUM, cleaner.getCleanerThreads().size()); - Assert.assertEquals(THREAD_TIMEOUT_MSEC, cleaner.getCleanerThreadTimeoutMsec()); - Assert.assertEquals(THREAD_CHECK_INTERVAL_MSEC, cleaner.getCleanerThreadCheckIntervalMsec()); + assertEquals(UPDATE_THROTTLE_POINT, cleaner.getThrottlePoint()); + assertEquals(UPDATE_QUEUE_INIT_SIZE, cleaner.getLargeQueueInitSize()); + assertEquals(UPDATE_QUEUE_INIT_SIZE, cleaner.getSmallQueueInitSize()); + assertEquals(LARGE_THREAD_NUM + SMALL_THREAD_NUM, cleaner.getCleanerThreads().size()); + assertEquals(THREAD_TIMEOUT_MSEC, cleaner.getCleanerThreadTimeoutMsec()); + assertEquals(THREAD_CHECK_INTERVAL_MSEC, cleaner.getCleanerThreadCheckIntervalMsec()); // make sure no cost when onConfigurationChange called with no change List oldThreads = cleaner.getCleanerThreads(); cleaner.onConfigurationChange(newConf); List newThreads = cleaner.getCleanerThreads(); - Assert.assertArrayEquals(oldThreads.toArray(), newThreads.toArray()); + assertArrayEquals(oldThreads.toArray(), newThreads.toArray()); // wait until clean done and check t.join(); LOG.debug("File deleted from large queue: " + cleaner.getNumOfDeletedLargeFiles() + "; from small queue: " + cleaner.getNumOfDeletedSmallFiles()); - Assert.assertTrue( + assertTrue(cleaner.getNumOfDeletedLargeFiles() > LARGE_FILE_NUM, "Should delete more than " + LARGE_FILE_NUM + " files from large queue but actually " - + cleaner.getNumOfDeletedLargeFiles(), - cleaner.getNumOfDeletedLargeFiles() > LARGE_FILE_NUM); - Assert.assertTrue( + + cleaner.getNumOfDeletedLargeFiles()); + assertTrue(cleaner.getNumOfDeletedSmallFiles() < SMALL_FILE_NUM, "Should delete less than " + SMALL_FILE_NUM + " files from small queue but actually " - + cleaner.getNumOfDeletedSmallFiles(), - cleaner.getNumOfDeletedSmallFiles() < SMALL_FILE_NUM); + + cleaner.getNumOfDeletedSmallFiles()); } private void createFilesForTesting(int largeFileNum, int smallFileNum, FileSystem fs, diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileLinkCleaner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileLinkCleaner.java index 62dc4a3e188b..9c6c6f95f862 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileLinkCleaner.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestHFileLinkCleaner.java @@ -17,16 +17,15 @@ */ package org.apache.hadoop.hbase.master.cleaner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.Server; import org.apache.hadoop.hbase.TableName; @@ -44,26 +43,21 @@ import org.apache.hadoop.hbase.util.HFileArchiveUtil; import org.apache.hadoop.hbase.util.MockServer; import org.apache.hadoop.hbase.zookeeper.ZKWatcher; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; /** * Test the HFileLink Cleaner. HFiles with links cannot be deleted until a link is present. */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestHFileLinkCleaner { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestHFileLinkCleaner.class); - private Configuration conf; private Path rootDir; private FileSystem fs; @@ -87,29 +81,26 @@ public class TestHFileLinkCleaner { private static DirScanPool POOL; private static final long TTL = 1000; - @Rule - public TestName name = new TestName(); - - @BeforeClass + @BeforeAll public static void setUp() { POOL = DirScanPool.getHFileCleanerScanPool(TEST_UTIL.getConfiguration()); } - @AfterClass + @AfterAll public static void tearDown() { POOL.shutdownNow(); } - @Before - public void configureDirectoriesAndLinks() throws IOException { + @BeforeEach + public void configureDirectoriesAndLinks(TestInfo testInfo) throws IOException { conf = TEST_UTIL.getConfiguration(); CommonFSUtils.setRootDir(conf, TEST_UTIL.getDataTestDir()); conf.set(HFileCleaner.MASTER_HFILE_CLEANER_PLUGINS, HFileLinkCleaner.class.getName()); rootDir = CommonFSUtils.getRootDir(conf); fs = FileSystem.get(conf); - tableName = TableName.valueOf(name.getMethodName()); - tableLinkName = TableName.valueOf(name.getMethodName() + "-link"); + tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); + tableLinkName = TableName.valueOf(testInfo.getTestMethod().get().getName() + "-link"); hfileName = "1234567890"; familyName = "cf"; @@ -154,21 +145,21 @@ private void createLink(StoreFileTracker sft, boolean createBackReference) throw linkBackRef = backRefs[0].getPath(); } - @After + @AfterEach public void cleanup() throws IOException, InterruptedException { // HFile can be removed Thread.sleep(TTL * 2); cleaner.chore(); - assertFalse("HFile should be deleted", fs.exists(hfilePath)); + assertFalse(fs.exists(hfilePath), "HFile should be deleted"); // Remove everything for (int i = 0; i < 4; ++i) { Thread.sleep(TTL * 2); cleaner.chore(); } - assertFalse("HFile should be deleted", - fs.exists(CommonFSUtils.getTableDir(archiveDir, tableName))); - assertFalse("Link should be deleted", - fs.exists(CommonFSUtils.getTableDir(archiveDir, tableLinkName))); + assertFalse(fs.exists(CommonFSUtils.getTableDir(archiveDir, tableName)), + "HFile should be deleted"); + assertFalse(fs.exists(CommonFSUtils.getTableDir(archiveDir, tableLinkName)), + "Link should be deleted"); } @Test @@ -183,7 +174,7 @@ public void testHFileLinkCleaning() throws Exception { fs.rename(CommonFSUtils.getTableDir(rootDir, tableLinkName), CommonFSUtils.getTableDir(archiveDir, tableLinkName)); cleaner.chore(); - assertFalse("Link should be deleted", fs.exists(linkBackRef)); + assertFalse(fs.exists(linkBackRef), "Link should be deleted"); } @Test @@ -196,16 +187,16 @@ public void testHFileLinkByRemovingReference() throws Exception { // simulate after removing the reference in data directory, the Link backref can be removed fs.delete(new Path(familyLinkPath, hfileLinkName), false); cleaner.chore(); - assertFalse("Link should be deleted", fs.exists(linkBackRef)); + assertFalse(fs.exists(linkBackRef), "Link should be deleted"); } @Test public void testHFileLinkEmptyBackReferenceDirectory() throws Exception { // simulate and remove the back reference fs.delete(linkBackRef, false); - assertTrue("back reference directory still exists", fs.exists(linkBackRefDir)); + assertTrue(fs.exists(linkBackRefDir), "back reference directory still exists"); cleaner.chore(); - assertFalse("back reference directory should be deleted", fs.exists(linkBackRefDir)); + assertFalse(fs.exists(linkBackRefDir), "back reference directory should be deleted"); } private static Path getFamilyDirPath(final Path rootDir, final TableName table, diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestLogsCleaner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestLogsCleaner.java index 8a05986f592a..2e05b7b876ca 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestLogsCleaner.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestLogsCleaner.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.hbase.master.cleaner; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -34,12 +34,10 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.Server; import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.TableNameTestRule; import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.client.AsyncClusterConnection; import org.apache.hadoop.hbase.client.TableDescriptor; @@ -61,25 +59,21 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.MockServer; import org.apache.hadoop.hbase.zookeeper.ZKWatcher; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.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; import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestLogsCleaner { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestLogsCleaner.class); - private static final Logger LOG = LoggerFactory.getLogger(TestLogsCleaner.class); private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); @@ -98,23 +92,20 @@ public class TestLogsCleaner { private ReplicationQueueStorage queueStorage; - @Rule - public final TableNameTestRule tableNameRule = new TableNameTestRule(); - - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { TEST_UTIL.startMiniCluster(); POOL = DirScanPool.getLogCleanerScanPool(TEST_UTIL.getConfiguration()); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL.shutdownMiniCluster(); POOL.shutdownNow(); } - @Before - public void beforeTest() throws Exception { + @BeforeEach + public void beforeTest(TestInfo testInfo) throws Exception { conf = TEST_UTIL.getConfiguration(); FileSystem fs = TEST_UTIL.getDFSCluster().getFileSystem(); @@ -124,7 +115,7 @@ public void beforeTest() throws Exception { // root directory fs.mkdirs(OLD_WALS_DIR); - TableName tableName = tableNameRule.getTableName(); + TableName tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); TableDescriptor td = ReplicationStorageFactory.createReplicationQueueTableDescriptor(tableName); TEST_UTIL.getAdmin().createTable(td); TEST_UTIL.waitTableAvailable(tableName); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestReplicationBarrierCleaner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestReplicationBarrierCleaner.java index 88d1a298aa48..675bd752050b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestReplicationBarrierCleaner.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestReplicationBarrierCleaner.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.master.cleaner; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyString; @@ -32,7 +32,6 @@ import java.util.Arrays; import java.util.Collections; 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.Stoppable; @@ -55,44 +54,36 @@ import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.junit.After; -import org.junit.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.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.hbase.thirdparty.com.google.common.collect.Lists; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestReplicationBarrierCleaner { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationBarrierCleaner.class); - - private static final Logger LOG = LoggerFactory.getLogger(TestHFileCleaner.class); + private static final Logger LOG = LoggerFactory.getLogger(TestReplicationBarrierCleaner.class); private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); - @Rule - public final TestName name = new TestName(); - - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { UTIL.startMiniCluster(1); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { UTIL.shutdownMiniCluster(); } - @After + @AfterEach public void tearDown() throws IOException { try (Table table = UTIL.getConnection().getTable(TableName.META_TABLE_NAME); ResultScanner scanner = table.getScanner(new Scan().addFamily(HConstants.CATALOG_FAMILY) @@ -176,8 +167,8 @@ public void testNothing() throws IOException { } @Test - public void testCleanNoPeers() throws IOException { - TableName tableName1 = TableName.valueOf(name.getMethodName() + "_1"); + public void testCleanNoPeers(TestInfo testInfo) throws IOException { + TableName tableName1 = TableName.valueOf(testInfo.getTestMethod().get().getName() + "_1"); RegionInfo region11 = RegionInfoBuilder.newBuilder(tableName1).setEndKey(Bytes.toBytes(1)).build(); addBarrier(region11, 10, 20, 30, 40, 50, 60); @@ -187,7 +178,7 @@ public void testCleanNoPeers() throws IOException { addBarrier(region12, 20, 30, 40, 50, 60, 70); fillCatalogFamily(region12); - TableName tableName2 = TableName.valueOf(name.getMethodName() + "_2"); + TableName tableName2 = TableName.valueOf(testInfo.getTestMethod().get().getName() + "_2"); RegionInfo region21 = RegionInfoBuilder.newBuilder(tableName2).setEndKey(Bytes.toBytes(1)).build(); addBarrier(region21, 100, 200, 300, 400); @@ -220,8 +211,8 @@ public void testCleanNoPeers() throws IOException { } @Test - public void testDeleteBarriers() throws IOException, ReplicationException { - TableName tableName = TableName.valueOf(name.getMethodName()); + public void testDeleteBarriers(TestInfo testInfo) throws IOException, ReplicationException { + TableName tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); RegionInfo region = RegionInfoBuilder.newBuilder(tableName).build(); addBarrier(region, 10, 20, 30, 40, 50, 60); // two peers @@ -260,8 +251,9 @@ public void testDeleteBarriers() throws IOException, ReplicationException { } @Test - public void testDeleteRowForDeletedRegion() throws IOException, ReplicationException { - TableName tableName = TableName.valueOf(name.getMethodName()); + public void testDeleteRowForDeletedRegion(TestInfo testInfo) + throws IOException, ReplicationException { + TableName tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); RegionInfo region = RegionInfoBuilder.newBuilder(tableName).build(); addBarrier(region, 40, 50, 60); fillCatalogFamily(region); @@ -290,8 +282,8 @@ public void testDeleteRowForDeletedRegion() throws IOException, ReplicationExcep } @Test - public void testDeleteRowForDeletedRegionNoPeers() throws IOException { - TableName tableName = TableName.valueOf(name.getMethodName()); + public void testDeleteRowForDeletedRegionNoPeers(TestInfo testInfo) throws IOException { + TableName tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); RegionInfo region = RegionInfoBuilder.newBuilder(tableName).build(); addBarrier(region, 40, 50, 60); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestReplicationHFileCleaner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestReplicationHFileCleaner.java index ab99c55e6255..1cffe08d7a20 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestReplicationHFileCleaner.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestReplicationHFileCleaner.java @@ -17,9 +17,9 @@ */ package org.apache.hadoop.hbase.master.cleaner; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.io.UncheckedIOException; @@ -31,7 +31,6 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.Server; @@ -53,25 +52,21 @@ import org.apache.hadoop.hbase.util.MockServer; import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.hbase.zookeeper.ZKWatcher; -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; import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap; -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestReplicationHFileCleaner { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestReplicationHFileCleaner.class); - private static final Logger LOG = LoggerFactory.getLogger(TestReplicationHFileCleaner.class); private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static Server server; @@ -84,7 +79,7 @@ public class TestReplicationHFileCleaner { private static Map params; private Path root; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { TEST_UTIL.startMiniCluster(); server = new DummyServer(); @@ -101,12 +96,12 @@ public static void setUpBeforeClass() throws Exception { fs = FileSystem.get(conf); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL.shutdownMiniCluster(); } - @Before + @BeforeEach public void setup() throws ReplicationException, IOException { root = TEST_UTIL.getDataTestDirOnTestFS(); rp.getPeerStorage().addPeer(peerId, @@ -114,7 +109,7 @@ public void setup() throws ReplicationException, IOException { true, SyncReplicationState.NONE); } - @After + @AfterEach public void cleanup() throws ReplicationException { try { fs.delete(root, true); @@ -139,19 +134,21 @@ public void testIsFileDeletable() throws IOException, ReplicationException { Path file = new Path(root, "testIsFileDeletableWithNoHFileRefs"); fs.createNewFile(file); // 2. Assert file is successfully created - assertTrue("Test file not created!", fs.exists(file)); + assertTrue(fs.exists(file), "Test file not created!"); ReplicationHFileCleaner cleaner = createCleaner(); // 3. Assert that file as is should be deletable - assertTrue("Cleaner should allow to delete this file as there is no hfile reference node " - + "for it in the queue.", cleaner.isFileDeletable(fs.getFileStatus(file))); + assertTrue(cleaner.isFileDeletable(fs.getFileStatus(file)), + "Cleaner should allow to delete this file as there is no hfile reference node " + + "for it in the queue."); List> files = new ArrayList<>(1); files.add(new Pair<>(null, file)); // 4. Add the file to hfile-refs queue rq.addHFileRefs(peerId, files); // 5. Assert file should not be deletable - assertFalse("Cleaner should not allow to delete this file as there is a hfile reference node " - + "for it in the queue.", cleaner.isFileDeletable(fs.getFileStatus(file))); + assertFalse(cleaner.isFileDeletable(fs.getFileStatus(file)), + "Cleaner should not allow to delete this file as there is a hfile reference node " + + "for it in the queue."); } @Test @@ -159,10 +156,10 @@ public void testGetDeletableFiles() throws Exception { // 1. Create two files and assert that they do not exist Path notDeletablefile = new Path(root, "testGetDeletableFiles_1"); fs.createNewFile(notDeletablefile); - assertTrue("Test file not created!", fs.exists(notDeletablefile)); + assertTrue(fs.exists(notDeletablefile), "Test file not created!"); Path deletablefile = new Path(root, "testGetDeletableFiles_2"); fs.createNewFile(deletablefile); - assertTrue("Test file not created!", fs.exists(deletablefile)); + assertTrue(fs.exists(deletablefile), "Test file not created!"); List files = new ArrayList<>(2); FileStatus f = new FileStatus(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestSnapshotCleanerChore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestSnapshotCleanerChore.java index 7933727a4e65..f31827f37be3 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestSnapshotCleanerChore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestSnapshotCleanerChore.java @@ -21,16 +21,14 @@ 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.Stoppable; import org.apache.hadoop.hbase.master.snapshot.SnapshotManager; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,13 +38,10 @@ /** * Tests for SnapshotsCleanerChore */ -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestSnapshotCleanerChore { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestSnapshotCleanerChore.class); - private static final Logger LOG = LoggerFactory.getLogger(TestSnapshotCleanerChore.class); private static final HBaseTestingUtil HBASE_TESTING_UTILITY = new HBaseTestingUtil(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestSnapshotFromMaster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestSnapshotFromMaster.java index 2fc267690c09..4e35a9160512 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestSnapshotFromMaster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestSnapshotFromMaster.java @@ -17,9 +17,10 @@ */ package org.apache.hadoop.hbase.master.cleaner; -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.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.util.Collection; @@ -31,7 +32,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -62,14 +62,12 @@ import org.apache.hadoop.hbase.util.CommonFSUtils; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -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.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -90,13 +88,10 @@ /** * Test the master-related aspects of a snapshot */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestSnapshotFromMaster { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestSnapshotFromMaster.class); - private static final Logger LOG = LoggerFactory.getLogger(TestSnapshotFromMaster.class); private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static final int NUM_RS = 2; @@ -115,7 +110,7 @@ public class TestSnapshotFromMaster { /** * Setup the config for the cluster */ - @BeforeClass + @BeforeAll public static void setupCluster() throws Exception { setupConf(UTIL.getConfiguration()); UTIL.startMiniCluster(NUM_RS); @@ -149,20 +144,20 @@ private static void setupConf(Configuration conf) { conf.setInt("hbase.master.cleaner.snapshot.interval", 500); } - @Before + @BeforeEach public void setup() throws Exception { UTIL.createTable(TABLE_NAME, TEST_FAM); master.getSnapshotManager().setSnapshotHandlerForTesting(TABLE_NAME, null); } - @After + @AfterEach public void tearDown() throws Exception { UTIL.deleteTable(TABLE_NAME); SnapshotTestingUtils.deleteAllSnapshots(UTIL.getAdmin()); SnapshotTestingUtils.deleteArchiveDirectory(UTIL); } - @AfterClass + @AfterAll public static void cleanupTest() throws Exception { try { UTIL.shutdownMiniCluster(); @@ -217,7 +212,7 @@ public void testIsDoneContract() throws Exception { builder.setSnapshot(desc); IsSnapshotDoneResponse response = master.getMasterRpcServices().isSnapshotDone(null, builder.build()); - assertTrue("Snapshot didn't complete when it should have.", response.getDone()); + assertTrue(response.getDone(), "Snapshot didn't complete when it should have."); // now try the case where we are looking for a snapshot we didn't take builder.setSnapshot(SnapshotDescription.newBuilder().setName("Not A Snapshot").build()); @@ -230,7 +225,7 @@ public void testIsDoneContract() throws Exception { builder.setSnapshot(desc); response = master.getMasterRpcServices().isSnapshotDone(null, builder.build()); - assertTrue("Completed, on-disk snapshot not found", response.getDone()); + assertTrue(response.getDone(), "Completed, on-disk snapshot not found"); } @Test @@ -239,7 +234,7 @@ public void testGetCompletedSnapshots() throws Exception { GetCompletedSnapshotsRequest request = GetCompletedSnapshotsRequest.newBuilder().build(); GetCompletedSnapshotsResponse response = master.getMasterRpcServices().getCompletedSnapshots(null, request); - assertEquals("Found unexpected number of snapshots", 0, response.getSnapshotsCount()); + assertEquals(0, response.getSnapshotsCount(), "Found unexpected number of snapshots"); // write one snapshot to the fs String snapshotName = "completed"; @@ -247,10 +242,10 @@ public void testGetCompletedSnapshots() throws Exception { // check that we get one snapshot response = master.getMasterRpcServices().getCompletedSnapshots(null, request); - assertEquals("Found unexpected number of snapshots", 1, response.getSnapshotsCount()); + assertEquals(1, response.getSnapshotsCount(), "Found unexpected number of snapshots"); List snapshots = response.getSnapshotsList(); List expected = Lists.newArrayList(snapshot); - assertEquals("Returned snapshots don't match created snapshots", expected, snapshots); + assertEquals(expected, snapshots, "Returned snapshots don't match created snapshots"); // write a second snapshot snapshotName = "completed_two"; @@ -259,9 +254,9 @@ public void testGetCompletedSnapshots() throws Exception { // check that we get one snapshot response = master.getMasterRpcServices().getCompletedSnapshots(null, request); - assertEquals("Found unexpected number of snapshots", 2, response.getSnapshotsCount()); + assertEquals(2, response.getSnapshotsCount(), "Found unexpected number of snapshots"); snapshots = response.getSnapshotsList(); - assertEquals("Returned snapshots don't match created snapshots", expected, snapshots); + assertEquals(expected, snapshots, "Returned snapshots don't match created snapshots"); } @Test @@ -297,7 +292,7 @@ public void testGetCompletedSnapshotsWithCleanup() throws Exception { GetCompletedSnapshotsRequest request = GetCompletedSnapshotsRequest.newBuilder().build(); GetCompletedSnapshotsResponse response = master.getMasterRpcServices().getCompletedSnapshots(null, request); - assertEquals("Found unexpected number of snapshots", 0, response.getSnapshotsCount()); + assertEquals(0, response.getSnapshotsCount(), "Found unexpected number of snapshots"); // NOTE: This is going to be flakey. Its timing based. For now made it more coarse // so more likely to pass though we have to hang around longer. @@ -308,13 +303,13 @@ public void testGetCompletedSnapshotsWithCleanup() throws Exception { // check that we get one snapshot response = master.getMasterRpcServices().getCompletedSnapshots(null, request); - assertEquals("Found unexpected number of snapshots", 2, response.getSnapshotsCount()); + assertEquals(2, response.getSnapshotsCount(), "Found unexpected number of snapshots"); // Check that 1 snapshot is auto cleaned after 5 sec of TTL expiration. Wait 10 seconds // just in case. Uninterruptibles.sleepUninterruptibly(10, TimeUnit.SECONDS); response = master.getMasterRpcServices().getCompletedSnapshots(null, request); - assertEquals("Found unexpected number of snapshots", 1, response.getSnapshotsCount()); + assertEquals(1, response.getSnapshotsCount(), "Found unexpected number of snapshots"); } @Test @@ -328,7 +323,7 @@ public void testGetCompletedSnapshotsWithoutCleanup() throws Exception { GetCompletedSnapshotsRequest request = GetCompletedSnapshotsRequest.newBuilder().build(); GetCompletedSnapshotsResponse response = master.getMasterRpcServices().getCompletedSnapshots(null, request); - assertEquals("Found unexpected number of snapshots", 0, response.getSnapshotsCount()); + assertEquals(0, response.getSnapshotsCount(), "Found unexpected number of snapshots"); // write one snapshot to the fs createSnapshotWithTtl("snapshot_02", 1L); @@ -336,12 +331,12 @@ public void testGetCompletedSnapshotsWithoutCleanup() throws Exception { // check that we get one snapshot response = master.getMasterRpcServices().getCompletedSnapshots(null, request); - assertEquals("Found unexpected number of snapshots", 2, response.getSnapshotsCount()); + assertEquals(2, response.getSnapshotsCount(), "Found unexpected number of snapshots"); // check that no snapshot is auto cleaned even after 1 sec of TTL expiration Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS); response = master.getMasterRpcServices().getCompletedSnapshots(null, request); - assertEquals("Found unexpected number of snapshots", 2, response.getSnapshotsCount()); + assertEquals(2, response.getSnapshotsCount(), "Found unexpected number of snapshots"); } @Test @@ -356,7 +351,7 @@ public void testSnapshotCleanupStatus() throws Exception { IsSnapshotCleanupEnabledRequest.newBuilder().build(); IsSnapshotCleanupEnabledResponse isSnapshotCleanupEnabledResponse = master.getMasterRpcServices().isSnapshotCleanupEnabled(null, isSnapshotCleanupEnabledRequest); - Assert.assertTrue(isSnapshotCleanupEnabledResponse.getEnabled()); + assertTrue(isSnapshotCleanupEnabledResponse.getEnabled()); // Disable auto snapshot cleanup for the cluster setSnapshotCleanupRequest = SetSnapshotCleanupRequest.newBuilder().setEnabled(false).build(); @@ -366,7 +361,7 @@ public void testSnapshotCleanupStatus() throws Exception { isSnapshotCleanupEnabledRequest = IsSnapshotCleanupEnabledRequest.newBuilder().build(); isSnapshotCleanupEnabledResponse = master.getMasterRpcServices().isSnapshotCleanupEnabled(null, isSnapshotCleanupEnabledRequest); - Assert.assertFalse(isSnapshotCleanupEnabledResponse.getEnabled()); + assertFalse(isSnapshotCleanupEnabledResponse.getEnabled()); } /** @@ -459,8 +454,8 @@ public void testSnapshotHFileArchiving() throws Exception { // and make sure that there is a proper subset for (String fileName : snapshotHFiles) { boolean exist = archives.contains(fileName) || hfiles.contains(fileName); - assertTrue("Archived hfiles " + archives + " and table hfiles " + hfiles - + " is missing snapshot file:" + fileName, exist); + assertTrue(exist, "Archived hfiles " + archives + " and table hfiles " + hfiles + + " is missing snapshot file:" + fileName); } // delete the existing snapshot diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestApiV1ClusterMetricsResource.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestApiV1ClusterMetricsResource.java index ac904dad30e7..bc2e89caa214 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestApiV1ClusterMetricsResource.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestApiV1ClusterMetricsResource.java @@ -22,16 +22,15 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.ConnectionRule; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.ConnectionExtension; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.MiniClusterRule; +import org.apache.hadoop.hbase.MiniClusterExtension; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.StartTestingClusterOption; import org.apache.hadoop.hbase.TableName; @@ -45,11 +44,13 @@ import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.ExternalResource; -import org.junit.rules.RuleChain; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.RegisterExtension; import org.apache.hbase.thirdparty.javax.ws.rs.NotAcceptableException; import org.apache.hbase.thirdparty.javax.ws.rs.client.Client; @@ -60,14 +61,13 @@ /** * Tests for the master api_v1 {@link ClusterMetricsResource}. */ -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestApiV1ClusterMetricsResource { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestApiV1ClusterMetricsResource.class); - - private static final MiniClusterRule miniClusterRule = MiniClusterRule.newBuilder() + @Order(1) + @RegisterExtension + private static final MiniClusterExtension miniClusterExtension = MiniClusterExtension.newBuilder() .setMiniClusterOption( StartTestingClusterOption.builder().numZkServers(3).numMasters(3).numDataNodes(3).build()) .setConfiguration(() -> { @@ -77,18 +77,25 @@ public class TestApiV1ClusterMetricsResource { conf.set("hbase.http.jersey.tracing.type", "ON_DEMAND"); return conf; }).build(); - private static final ConnectionRule connectionRule = - ConnectionRule.createAsyncConnectionRule(miniClusterRule::createAsyncConnection); - private static final ClassSetup classRule = new ClassSetup(connectionRule::getAsyncConnection); - private static final class ClassSetup extends ExternalResource { + @Order(2) + @RegisterExtension + private static final ConnectionExtension connectionExtension = + ConnectionExtension.createAsyncConnectionExtension(miniClusterExtension::createAsyncConnection); + + @Order(3) + @RegisterExtension + private static final ClassSetupExtension classRule = + new ClassSetupExtension(connectionExtension::getAsyncConnection); + + private static final class ClassSetupExtension implements BeforeAllCallback, AfterAllCallback { - private final Supplier connectionSupplier; private final TableName tableName; private AsyncAdmin admin; private WebTarget target; + private final Supplier connectionSupplier; - public ClassSetup(final Supplier connectionSupplier) { + public ClassSetupExtension(final Supplier connectionSupplier) { this.connectionSupplier = connectionSupplier; tableName = TableName.valueOf(TestApiV1ClusterMetricsResource.class.getSimpleName()); } @@ -98,12 +105,13 @@ public WebTarget getTarget() { } @Override - protected void before() throws Throwable { + public void beforeAll(ExtensionContext context) throws Exception { final AsyncConnection conn = connectionSupplier.get(); admin = conn.getAdmin(); + final ColumnFamilyDescriptorBuilder cfBuilder = + ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("c")); final TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName) - .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("c")).build()) - .setDurability(Durability.SKIP_WAL).build(); + .setColumnFamily(cfBuilder.build()).setDurability(Durability.SKIP_WAL).build(); admin.createTable(tableDescriptor).get(); final String baseUrl = @@ -114,7 +122,7 @@ protected void before() throws Throwable { } @Override - protected void after() { + public void afterAll(ExtensionContext context) { final TableName tableName = TableName.valueOf("test"); try { admin.tableExists(tableName).thenCompose(val -> { @@ -131,10 +139,6 @@ protected void after() { } } - @ClassRule - public static RuleChain ruleChain = - RuleChain.outerRule(miniClusterRule).around(connectionRule).around(classRule); - @Test public void testGetRoot() { final String response = classRule.getTarget().request(MediaType.APPLICATION_JSON_TYPE) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestHbckMetricsResource.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestHbckMetricsResource.java index 6ed5087ccbdb..fa57f2cf38a5 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestHbckMetricsResource.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestHbckMetricsResource.java @@ -23,7 +23,7 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -38,11 +38,10 @@ import java.util.function.Supplier; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.ConnectionRule; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.ConnectionExtension; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.MiniClusterRule; +import org.apache.hadoop.hbase.MiniClusterExtension; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.StartTestingClusterOption; import org.apache.hadoop.hbase.TableName; @@ -63,11 +62,13 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Pair; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.ExternalResource; -import org.junit.rules.RuleChain; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -81,7 +82,8 @@ /** * Tests for the {@link HbckMetricsResource}. */ -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestHbckMetricsResource { private static final Logger LOG = LoggerFactory.getLogger(TestHbckMetricsResource.class); @@ -132,11 +134,9 @@ public class TestHbckMetricsResource { private static final String hbckUnknownServers = quote + "hbck_unknown_servers" + quoteColon; private static final String hbckEmptyRegionInfo = quote + "hbck_empty_region_info" + quoteColon; - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestHbckMetricsResource.class); - - private static final MiniClusterRule miniClusterRule = MiniClusterRule.newBuilder() + @Order(1) + @RegisterExtension + private static final MiniClusterExtension miniClusterExtension = MiniClusterExtension.newBuilder() .setMiniClusterOption( StartTestingClusterOption.builder().numZkServers(3).numMasters(3).numDataNodes(3).build()) .setConfiguration(() -> { @@ -147,18 +147,24 @@ public class TestHbckMetricsResource { return conf; }).build(); - private static final ConnectionRule connectionRule = - ConnectionRule.createAsyncConnectionRule(miniClusterRule::createAsyncConnection); - private static final ClassSetup classRule = new ClassSetup(connectionRule::getAsyncConnection); + @Order(2) + @RegisterExtension + private static final ConnectionExtension connectionExtension = + ConnectionExtension.createAsyncConnectionExtension(miniClusterExtension::createAsyncConnection); + + @Order(3) + @RegisterExtension + private static final ClassSetupExtension classRule = + new ClassSetupExtension(connectionExtension::getAsyncConnection); - private static final class ClassSetup extends ExternalResource { + private static final class ClassSetupExtension implements BeforeAllCallback, AfterAllCallback { private final Supplier connectionSupplier; private final TableName tableName; private AsyncAdmin admin; private WebTarget target; - public ClassSetup(final Supplier connectionSupplier) { + public ClassSetupExtension(final Supplier connectionSupplier) { this.connectionSupplier = connectionSupplier; tableName = TableName.valueOf(TestHbckMetricsResource.class.getSimpleName()); } @@ -168,7 +174,7 @@ public WebTarget getTarget() { } @Override - protected void before() throws Throwable { + public void beforeAll(ExtensionContext context) throws Exception { final AsyncConnection conn = connectionSupplier.get(); admin = conn.getAdmin(); final TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName) @@ -176,7 +182,7 @@ protected void before() throws Throwable { .setDurability(Durability.SKIP_WAL).build(); admin.createTable(tableDescriptor).get(); - HMaster master = miniClusterRule.getTestingUtility().getMiniHBaseCluster().getMaster(); + HMaster master = miniClusterExtension.getTestingUtility().getMiniHBaseCluster().getMaster(); HbckChore hbckChore = mock(HbckChore.class); HbckReport hbckReport = mock(HbckReport.class); @@ -246,7 +252,7 @@ protected void before() throws Throwable { } @Override - protected void after() { + public void afterAll(ExtensionContext context) { final TableName tableName = TableName.valueOf("test"); try { admin.tableExists(tableName).thenCompose(val -> { @@ -263,10 +269,6 @@ protected void after() { } } - @ClassRule - public static RuleChain ruleChain = - RuleChain.outerRule(miniClusterRule).around(connectionRule).around(classRule); - @Test public void testGetRoot() { final String response = classRule.getTarget().request(MediaType.APPLICATION_JSON_TYPE) @@ -395,11 +397,11 @@ public void testGetUnkownServers() { containsString(regionId), containsString(tableName), containsString(serverName), containsString(serverName), containsString(port), containsString(startCode), containsString(metaRegionID), containsString(metaTableName), containsString(localhost1), - containsString(localhost2), containsString(port), containsString(startCode))); + containsString(localhost2), containsString(port), containsString(hostStartCode))); } @Test - public void testGetUnkownServersHtml() { + public void testGetUnknownServersHtml() { assertThrows(NotAcceptableException.class, () -> classRule.getTarget().path("unknown-servers") .request(MediaType.TEXT_HTML_TYPE).header("X-Jersey-Tracing-Accept", true).get(String.class)); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestMasterStatusPage.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestMasterStatusPage.java index a7496c78aa9a..ee6fe402f5c9 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestMasterStatusPage.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestMasterStatusPage.java @@ -17,9 +17,9 @@ */ package org.apache.hadoop.hbase.master.http; -import static org.junit.Assert.assertEquals; -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.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.net.URL; @@ -27,7 +27,6 @@ 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.LocalHBaseCluster; @@ -44,20 +43,14 @@ import org.apache.hadoop.hbase.util.CommonFSUtils; import org.apache.hadoop.hbase.util.TestServerHttpUtils; import org.apache.hadoop.hbase.util.VersionInfo; -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({ MasterTests.class, MediumTests.class }) -public class TestMasterStatusPage { +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterStatusPage.class); +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) +public class TestMasterStatusPage { private final static HBaseTestingUtil UTIL = new HBaseTestingUtil(); public static final String TEST_TABLE_NAME_1 = "TEST_TABLE_1"; @@ -65,10 +58,7 @@ public class TestMasterStatusPage { private static LocalHBaseCluster CLUSTER; - @Rule - public TestName name = new TestName(); - - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { Configuration conf = UTIL.getConfiguration(); UTIL.startMiniZKCluster(); @@ -91,7 +81,7 @@ public static void beforeClass() throws Exception { /** * Helper method to shut down the cluster (if running) */ - @AfterClass + @AfterAll public static void shutDownMiniCluster() throws Exception { if (CLUSTER != null) { CLUSTER.shutdown(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestMasterStatusUtil.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestMasterStatusUtil.java index 0ec94c917193..50f64c26a229 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestMasterStatusUtil.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestMasterStatusUtil.java @@ -17,10 +17,10 @@ */ package org.apache.hadoop.hbase.master.http; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import java.io.IOException; import java.util.ArrayList; @@ -30,7 +30,6 @@ import java.util.Map; import java.util.Optional; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableDescriptors; @@ -51,19 +50,15 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.zookeeper.ZKWatcher; import org.apache.hadoop.hbase.zookeeper.ZNodePaths; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestMasterStatusUtil { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterStatusUtil.class); - private HMaster master; private Configuration conf; @@ -74,7 +69,7 @@ public class TestMasterStatusUtil { static final RegionInfo FAKE_HRI = RegionInfoBuilder.newBuilder(FAKE_TABLE.getTableName()) .setStartKey(Bytes.toBytes("a")).setEndKey(Bytes.toBytes("b")).build(); - @Before + @BeforeEach public void setupBasicMocks() { conf = HBaseConfiguration.create(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestMetaBrowser.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestMetaBrowser.java index e2808d6234ad..0df11c7eef54 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestMetaBrowser.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestMetaBrowser.java @@ -28,12 +28,12 @@ import static org.mockito.Mockito.when; import java.util.List; +import java.util.Objects; import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; -import org.apache.hadoop.hbase.ClearUserNamespacesAndTablesRule; -import org.apache.hadoop.hbase.ConnectionRule; -import org.apache.hadoop.hbase.HBaseClassTestRule; -import org.apache.hadoop.hbase.MiniClusterRule; +import org.apache.hadoop.hbase.ConnectionExtension; +import org.apache.hadoop.hbase.MiniClusterExtension; import org.apache.hadoop.hbase.NamespaceDescriptor; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.AsyncAdmin; @@ -46,53 +46,63 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.RegionSplitter; -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.RuleChain; -import org.junit.rules.TestName; -import org.junit.rules.TestRule; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.extension.RegisterExtension; import org.apache.hbase.thirdparty.org.apache.commons.collections4.IterableUtils; /** * Cluster-backed correctness tests for the functionality provided by {@link MetaBrowser}. */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMetaBrowser { - @ClassRule - public static final HBaseClassTestRule testRule = - HBaseClassTestRule.forClass(TestMetaBrowser.class); - @ClassRule - public static final MiniClusterRule miniClusterRule = MiniClusterRule.newBuilder().build(); + @RegisterExtension + private static final MiniClusterExtension miniClusterExtension = + MiniClusterExtension.newBuilder().build(); - private final ConnectionRule connectionRule = - ConnectionRule.createAsyncConnectionRule(miniClusterRule::createAsyncConnection); - private final ClearUserNamespacesAndTablesRule clearUserNamespacesAndTablesRule = - new ClearUserNamespacesAndTablesRule(connectionRule::getAsyncConnection); - - @Rule - public TestRule rule = - RuleChain.outerRule(connectionRule).around(clearUserNamespacesAndTablesRule); - - @Rule - public TestName testNameRule = new TestName(); + @RegisterExtension + private static final ConnectionExtension connectionExtension = + ConnectionExtension.createAsyncConnectionExtension(miniClusterExtension::createAsyncConnection); private AsyncConnection connection; private AsyncAdmin admin; - @Before + @BeforeEach public void before() { - connection = connectionRule.getAsyncConnection(); + connection = connectionExtension.getAsyncConnection(); admin = connection.getAdmin(); + clearTablesAndNamespaces().join(); + } + + private CompletableFuture clearTablesAndNamespaces() { + return admin.listTableNames(false).thenApply(tableNames -> tableNames.stream() + .map( + tableName -> disableIfEnabled(tableName).thenCompose(_void -> admin.deleteTable(tableName))) + .toArray(CompletableFuture[]::new)).thenCompose(CompletableFuture::allOf) + .thenCompose(_void -> admin.listNamespaceDescriptors()) + .thenApply(nds -> nds.stream().map(NamespaceDescriptor::getName) + .filter(name -> !Objects.equals(name, NamespaceDescriptor.SYSTEM_NAMESPACE.getName())) + .filter(name -> !Objects.equals(name, NamespaceDescriptor.DEFAULT_NAMESPACE.getName())) + .collect(Collectors.toList())) + .thenCompose(namespaces -> CompletableFuture + .allOf(namespaces.stream().map(admin::deleteNamespace).toArray(CompletableFuture[]::new))); + } + + private CompletableFuture disableIfEnabled(final TableName tableName) { + return admin.isTableEnabled(tableName) + .thenCompose(isEnabled -> isEnabled + ? admin.disableTable(tableName) + : CompletableFuture.completedFuture(null)); } @Test public void noFilters() { - final String namespaceName = testNameRule.getMethodName(); + final String namespaceName = "noFilters"; final TableName a = TableName.valueOf("a"); final TableName b = TableName.valueOf(namespaceName, "b"); @@ -112,8 +122,8 @@ public void noFilters() { } @Test - public void limit() { - final String tableName = testNameRule.getMethodName(); + public void limit(TestInfo testInfo) { + final String tableName = testInfo.getTestMethod().get().getName(); createTable(TableName.valueOf(tableName), 8).join(); final HttpServletRequest request = new MockRequestBuilder().setLimit(5).build(); @@ -130,8 +140,8 @@ public void limit() { } @Test - public void regionStateFilter() { - final String namespaceName = testNameRule.getMethodName(); + public void regionStateFilter(TestInfo testInfo) { + final String namespaceName = testInfo.getTestMethod().get().getName(); final TableName foo = TableName.valueOf(namespaceName, "foo"); final TableName bar = TableName.valueOf(namespaceName, "bar"); @@ -152,8 +162,8 @@ public void regionStateFilter() { } @Test - public void scanTableFilter() { - final String namespaceName = testNameRule.getMethodName(); + public void scanTableFilter(TestInfo testInfo) { + final String namespaceName = testInfo.getTestMethod().get().getName(); final TableName a = TableName.valueOf("a"); final TableName b = TableName.valueOf(namespaceName, "b"); @@ -171,8 +181,8 @@ public void scanTableFilter() { } @Test - public void paginateWithReplicas() { - final String namespaceName = testNameRule.getMethodName(); + public void paginateWithReplicas(TestInfo testInfo) { + final String namespaceName = testInfo.getTestMethod().get().getName(); final TableName a = TableName.valueOf("a"); final TableName b = TableName.valueOf(namespaceName, "b"); @@ -202,8 +212,8 @@ public void paginateWithReplicas() { } @Test - public void paginateWithTableFilter() { - final String namespaceName = testNameRule.getMethodName(); + public void paginateWithTableFilter(TestInfo testInfo) { + final String namespaceName = testInfo.getTestMethod().get().getName(); final TableName a = TableName.valueOf("a"); final TableName b = TableName.valueOf(namespaceName, "b"); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestMetaBrowserNoCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestMetaBrowserNoCluster.java index 4bb60f4137e7..30dfbbf04353 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestMetaBrowserNoCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestMetaBrowserNoCluster.java @@ -20,40 +20,32 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import javax.servlet.http.HttpServletRequest; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.AsyncConnection; import org.apache.hadoop.hbase.master.RegionState; import org.apache.hadoop.hbase.master.http.TestMetaBrowser.MockRequestBuilder; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -/** - * Cluster-backed correctness tests for the functionality provided by {@link MetaBrowser}. - */ -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestMetaBrowserNoCluster { - @ClassRule - public static final HBaseClassTestRule testRule = - HBaseClassTestRule.forClass(TestMetaBrowserNoCluster.class); - @Mock private AsyncConnection connection; - @Before + @BeforeEach public void before() { - MockitoAnnotations.initMocks(this); + MockitoAnnotations.openMocks(this); } @Test diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestRegionVisualizer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestRegionVisualizer.java index b74fa9103676..0a0ede3e59c1 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestRegionVisualizer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/TestRegionVisualizer.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.hbase.master.http; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.lang.reflect.Method; import java.util.ArrayList; @@ -27,7 +27,6 @@ import java.util.Objects; import java.util.Random; import java.util.stream.Collectors; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.RegionMetrics; import org.apache.hadoop.hbase.RegionMetricsBuilder; import org.apache.hadoop.hbase.ServerName; @@ -37,26 +36,21 @@ import org.apache.hadoop.hbase.master.http.RegionVisualizer.RegionDetails; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.SmallTests; -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.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.apache.hbase.thirdparty.com.google.gson.Gson; import org.apache.hbase.thirdparty.com.google.gson.JsonObject; -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestRegionVisualizer { - @ClassRule - public static final HBaseClassTestRule testRule = - HBaseClassTestRule.forClass(TestRegionVisualizer.class); - private static final Random rand = new Random(); private static List regionMetricsBuilderLongValueSetters; - @BeforeClass + @BeforeAll public static void beforeClass() { regionMetricsBuilderLongValueSetters = Arrays.stream(RegionMetricsBuilder.class.getDeclaredMethods()) @@ -76,7 +70,6 @@ public void testRegionDetailsJsonSerialization() throws Exception { final Gson gson = RegionVisualizer.buildGson(); final JsonObject result = gson.fromJson(gson.toJson(regionDetails), JsonObject.class); - Assert.assertNotNull(result); assertEquals(serverName.toShortString(), result.get("server_name").getAsString()); assertEquals(tableName.getNameAsString(), result.get("table_name").getAsString()); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/gson/GsonFactoryTest.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/gson/GsonFactoryTest.java index ff3a5671b988..4ad54e7cfb2a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/gson/GsonFactoryTest.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/http/gson/GsonFactoryTest.java @@ -17,32 +17,27 @@ */ package org.apache.hadoop.hbase.master.http.gson; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Map; import java.util.TreeMap; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.Size; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.Bytes; -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.apache.hbase.thirdparty.com.google.gson.Gson; -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class GsonFactoryTest { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(GsonFactoryTest.class); - private static Gson gson; - @BeforeClass + @BeforeAll public static void beforeClass() { gson = GsonFactory.buildGson(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestCatalogJanitor.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestCatalogJanitor.java index 2ffc702a8c10..259ff1636bf9 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestCatalogJanitor.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestCatalogJanitor.java @@ -18,9 +18,9 @@ package org.apache.hadoop.hbase.master.janitor; import static org.apache.hadoop.hbase.util.HFileArchiveTestingUtil.assertArchiveEqualToOriginal; -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.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; @@ -40,7 +40,6 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MetaMockingUtil; @@ -70,49 +69,44 @@ import org.apache.hadoop.hbase.util.CommonFSUtils; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.HFileArchiveUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestCatalogJanitor { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestCatalogJanitor.class); - private static final Logger LOG = LoggerFactory.getLogger(TestCatalogJanitor.class); private static final HBaseTestingUtil HTU = new HBaseTestingUtil(); - @Rule - public final TestName name = new TestName(); + private String currentTestMethod; private MockMasterServices masterServices; private CatalogJanitor janitor; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ChunkCreator.initialize(MemStoreLAB.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null, MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_DEFAULT); } - @Before - public void setup() throws Exception { - setRootDirAndCleanIt(HTU, this.name.getMethodName()); + @BeforeEach + public void setup(TestInfo testInfo) throws Exception { + this.currentTestMethod = testInfo.getTestMethod().get().getName(); + setRootDirAndCleanIt(HTU, this.currentTestMethod); this.masterServices = new MockMasterServices(HTU.getConfiguration()); this.masterServices.start(10, null); this.janitor = new CatalogJanitor(masterServices); } - @After + @AfterEach public void teardown() { this.janitor.shutdown(true); this.masterServices.stop("DONE"); @@ -286,7 +280,7 @@ public void testCleanParent() throws IOException, InterruptedException { */ @Test public void testParentCleanedEvenIfDaughterGoneFirst() throws IOException, InterruptedException { - parentWithSpecifiedEndKeyCleanedEvenIfDaughterGoneFirst(this.name.getMethodName(), + parentWithSpecifiedEndKeyCleanedEvenIfDaughterGoneFirst(this.currentTestMethod, Bytes.toBytes("eee")); } @@ -297,7 +291,7 @@ public void testParentCleanedEvenIfDaughterGoneFirst() throws IOException, Inter @Test public void testLastParentCleanedEvenIfDaughterGoneFirst() throws IOException, InterruptedException { - parentWithSpecifiedEndKeyCleanedEvenIfDaughterGoneFirst(this.name.getMethodName(), new byte[0]); + parentWithSpecifiedEndKeyCleanedEvenIfDaughterGoneFirst(this.currentTestMethod, new byte[0]); } /** @@ -307,7 +301,7 @@ public void testLastParentCleanedEvenIfDaughterGoneFirst() private TableDescriptor createTableDescriptorForCurrentMethod() { ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder .newBuilder(Bytes.toBytes(MockMasterServices.DEFAULT_COLUMN_FAMILY_NAME)).build(); - return TableDescriptorBuilder.newBuilder(TableName.valueOf(this.name.getMethodName())) + return TableDescriptorBuilder.newBuilder(TableName.valueOf(this.currentTestMethod)) .setColumnFamily(columnFamilyDescriptor).build(); } @@ -574,8 +568,8 @@ public void testArchiveOldRegion() throws Exception { int index = 0; for (FileStatus file : storeFiles) { LOG.debug("Have store file:" + file.getPath()); - assertEquals("Got unexpected store file", mockFiles[index].getPath(), - storeFiles[index].getPath()); + assertEquals(mockFiles[index].getPath(), storeFiles[index].getPath(), + "Got unexpected store file"); index++; } @@ -693,7 +687,7 @@ public void testAlreadyRunningStatus() throws Exception { for (int i = 0; i < numberOfThreads; i++) { threads[i].join(); } - assertTrue("One janitor.scan() call should have returned -1", gcValues.contains(-1)); + assertTrue(gcValues.contains(-1), "One janitor.scan() call should have returned -1"); } private FileStatus[] addMockStoreFiles(int count, MasterServices services, Path storedir) @@ -711,7 +705,7 @@ private FileStatus[] addMockStoreFiles(int count, MasterServices services, Path LOG.debug("Adding " + count + " store files to the storedir:" + storedir); // make sure the mock store files are there FileStatus[] storeFiles = fs.listStatus(storedir); - assertEquals("Didn't have expected store files", count, storeFiles.length); + assertEquals(count, storeFiles.length, "Didn't have expected store files"); return storeFiles; } @@ -719,7 +713,9 @@ private String setRootDirAndCleanIt(final HBaseTestingUtil htu, final String sub throws IOException { Path testdir = htu.getDataTestDir(subdir); FileSystem fs = FileSystem.get(htu.getConfiguration()); - if (fs.exists(testdir)) assertTrue(fs.delete(testdir, true)); + if (fs.exists(testdir)) { + assertTrue(fs.delete(testdir, true)); + } CommonFSUtils.setRootDir(htu.getConfiguration(), testdir); return CommonFSUtils.getRootDir(htu.getConfiguration()).toString(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestCatalogJanitorCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestCatalogJanitorCluster.java index 58cef3b0465b..5f433e2290f5 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestCatalogJanitorCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestCatalogJanitorCluster.java @@ -17,17 +17,16 @@ */ package org.apache.hadoop.hbase.master.janitor; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.Arrays; import java.util.LinkedList; import java.util.List; import org.apache.hadoop.hbase.CatalogFamilyFormat; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MetaTableAccessor; @@ -42,27 +41,18 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.Pair; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestCatalogJanitorCluster { private static final Logger LOG = LoggerFactory.getLogger(TestCatalogJanitorCluster.class); - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestCatalogJanitorCluster.class); - - @Rule - public final TestName name = new TestName(); - private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static final TableName T1 = TableName.valueOf("t1"); private static final TableName T2 = TableName.valueOf("t2"); @@ -72,7 +62,7 @@ public class TestCatalogJanitorCluster { private static final TableName T6 = TableName.valueOf("t6"); private static final TableName T7 = TableName.valueOf("t7"); - @Before + @BeforeEach public void before() throws Exception { TEST_UTIL.startMiniCluster(); TEST_UTIL.createMultiRegionTable(T1, new byte[][] { HConstants.CATALOG_FAMILY }); @@ -92,7 +82,7 @@ public void before() throws Exception { TEST_UTIL.createMultiRegionTable(T7, new byte[][] { HConstants.CATALOG_FAMILY }); } - @After + @AfterEach public void after() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -260,11 +250,11 @@ private void fixHoles(CatalogJanitor janitor) throws IOException { janitor.scan(); CatalogJanitorReport report = janitor.getLastReport(); // Verify total number of holes, 2 in t1, t2, t6 each and one in t3 - assertEquals("Number of holes are not matching", 7, report.getHoles().size()); + assertEquals(7, report.getHoles().size(), "Number of holes are not matching"); metaFixer.fix(); janitor.scan(); report = janitor.getLastReport(); - assertEquals("Holes are not fixed", 0, report.getHoles().size()); + assertEquals(0, report.getHoles().size(), "Holes are not fixed"); } private void verifyMiddleHole(CatalogJanitor janitor) throws IOException { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestCatalogJanitorInMemoryStates.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestCatalogJanitorInMemoryStates.java index cf118260b401..7c0c72605fcb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestCatalogJanitorInMemoryStates.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestCatalogJanitorInMemoryStates.java @@ -17,23 +17,21 @@ */ package org.apache.hadoop.hbase.master.janitor; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutionException; import org.apache.hadoop.hbase.CatalogFamilyFormat; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.MetaMockingUtil; import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.TableNameTestRule; import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Connection; @@ -56,37 +54,30 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.PairOfSameType; 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.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestCatalogJanitorInMemoryStates { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestCatalogJanitorInMemoryStates.class); - private static final Logger LOG = LoggerFactory.getLogger(TestCatalogJanitorInMemoryStates.class); private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static byte[] FAMILY = Bytes.toBytes("testFamily"); - @Rule - public final TableNameTestRule name = new TableNameTestRule(); - - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { TEST_UTIL.startMiniCluster(1); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -95,7 +86,7 @@ public static void tearDownAfterClass() throws Exception { * Test clearing a split parent from memory. */ @Test - public void testInMemoryParentCleanup() + public void testInMemoryParentCleanup(TestInfo testInfo) throws IOException, InterruptedException, ExecutionException { HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); final AssignmentManager am = master.getAssignmentManager(); @@ -104,7 +95,7 @@ public void testInMemoryParentCleanup() Admin admin = TEST_UTIL.getAdmin(); admin.catalogJanitorSwitch(false); - final TableName tableName = name.getTableName(); + final TableName tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); Table t = TEST_UTIL.createTable(tableName, FAMILY); TEST_UTIL.loadTable(t, FAMILY, false); @@ -116,12 +107,13 @@ public void testInMemoryParentCleanup() List daughters = splitRegion(parent.getRegion()); LOG.info("Parent region: " + parent); LOG.info("Daughter regions: " + daughters); - assertNotNull("Should have found daughter regions for " + parent, daughters); + assertNotNull(daughters, "Should have found daughter regions for " + parent); - assertNotNull("Parent region should exist in RegionStates", - am.getRegionStates().getRegionStateNodeFromName(parent.getRegion().getRegionName())); - assertTrue("Parent region should exist in ServerManager", - sm.isRegionInServerManagerStates(parent.getRegion())); + assertNotNull( + am.getRegionStates().getRegionStateNodeFromName(parent.getRegion().getRegionName()), + "Parent region should exist in RegionStates"); + assertTrue(sm.isRegionInServerManagerStates(parent.getRegion()), + "Parent region should exist in ServerManager"); // clean the parent Result r = MetaMockingUtil.getMetaTableRowResult(parent.getRegion(), null, @@ -142,10 +134,10 @@ public boolean evaluate() throws Exception { } }); - assertNull("Parent region should have been removed from RegionStates", - am.getRegionStates().getRegionStateNodeFromName(parent.getRegion().getRegionName())); - assertFalse("Parent region should have been removed from ServerManager", - sm.isRegionInServerManagerStates(parent.getRegion())); + assertNull(am.getRegionStates().getRegionStateNodeFromName(parent.getRegion().getRegionName()), + "Parent region should have been removed from RegionStates"); + assertFalse(sm.isRegionInServerManagerStates(parent.getRegion()), + "Parent region should have been removed from ServerManager"); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestMetaFixer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestMetaFixer.java index 52bc8985f949..37b4ed284a54 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestMetaFixer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestMetaFixer.java @@ -17,9 +17,9 @@ */ package org.apache.hadoop.hbase.master.janitor; -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 java.io.IOException; import java.util.Collections; @@ -30,7 +30,6 @@ import org.apache.hadoop.hbase.Cell; 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.MetaTableAccessor; @@ -58,30 +57,24 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.Pair; 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; - -@Category({ MasterTests.class, LargeTests.class }) +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; + +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestMetaFixer { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMetaFixer.class); - @Rule - public TestName name = new TestName(); private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); - @BeforeClass + @BeforeAll public static void setupBeforeClass() throws Exception { TEST_UTIL.startMiniCluster(); } - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL.shutdownMiniCluster(); } @@ -113,12 +106,12 @@ private void testPlugsHolesWithReadReplicaInternal(final TableName tn, final int services.getAssignmentManager().getRegionStates().getRegionStates().size()); services.getCatalogJanitor().scan(); report = services.getCatalogJanitor().getLastReport(); - assertEquals(report.toString(), 3, report.getHoles().size()); + assertEquals(3, report.getHoles().size(), report.toString()); MetaFixer fixer = new MetaFixer(services); fixer.fixHoles(report); services.getCatalogJanitor().scan(); report = services.getCatalogJanitor().getLastReport(); - assertTrue(report.toString(), report.isEmpty()); + assertTrue(report.isEmpty(), report.toString()); assertEquals(initialSize, services.getAssignmentManager().getRegionStates().getRegionStates().size()); @@ -132,14 +125,14 @@ private void testPlugsHolesWithReadReplicaInternal(final TableName tn, final int } @Test - public void testPlugsHoles() throws Exception { - TableName tn = TableName.valueOf(this.name.getMethodName()); + public void testPlugsHoles(TestInfo testInfo) throws Exception { + TableName tn = TableName.valueOf(testInfo.getTestMethod().get().getName()); testPlugsHolesWithReadReplicaInternal(tn, 1); } @Test - public void testPlugsHolesWithReadReplica() throws Exception { - TableName tn = TableName.valueOf(this.name.getMethodName()); + public void testPlugsHolesWithReadReplica(TestInfo testInfo) throws Exception { + TableName tn = TableName.valueOf(testInfo.getTestMethod().get().getName()); testPlugsHolesWithReadReplicaInternal(tn, 3); } @@ -149,8 +142,8 @@ public void testPlugsHolesWithReadReplica() throws Exception { * (at least from a read of hbase:meta). */ @Test - public void testOneRegionTable() throws IOException { - TableName tn = TableName.valueOf(this.name.getMethodName()); + public void testOneRegionTable(TestInfo testInfo) throws IOException { + TableName tn = TableName.valueOf(testInfo.getTestMethod().get().getName()); TEST_UTIL.createTable(tn, HConstants.CATALOG_FAMILY); List ris = MetaTableAccessor.getTableRegions(TEST_UTIL.getConnection(), tn); MasterServices services = TEST_UTIL.getHBaseCluster().getMaster(); @@ -198,8 +191,8 @@ private void testOverlapCommon(final TableName tn) throws Exception { } @Test - public void testOverlap() throws Exception { - TableName tn = TableName.valueOf(this.name.getMethodName()); + public void testOverlap(TestInfo testInfo) throws Exception { + TableName tn = TableName.valueOf(testInfo.getTestMethod().get().getName()); testOverlapCommon(tn); HMaster services = TEST_UTIL.getHBaseCluster().getMaster(); HbckChore hbckChore = services.getHbckChore(); @@ -274,7 +267,7 @@ public void testMultipleTableOverlaps() throws Exception { services.getCatalogJanitor().scan(); report = services.getCatalogJanitor().getLastReport(); - assertEquals("Region overlaps count does not match.", 4, report.getOverlaps().size()); + assertEquals(4, report.getOverlaps().size(), "Region overlaps count does not match."); MetaFixer fixer = new MetaFixer(services); List longs = fixer.fixOverlaps(report); @@ -284,12 +277,12 @@ public void testMultipleTableOverlaps() throws Exception { // After fix, verify no overlaps are left. services.getCatalogJanitor().scan(); report = services.getCatalogJanitor().getLastReport(); - assertTrue("After fix there should not have been any overlaps.", report.isEmpty()); + assertTrue(report.isEmpty(), "After fix there should not have been any overlaps."); } @Test - public void testOverlapWithSmallMergeCount() throws Exception { - TableName tn = TableName.valueOf(this.name.getMethodName()); + public void testOverlapWithSmallMergeCount(TestInfo testInfo) throws Exception { + TableName tn = TableName.valueOf(testInfo.getTestMethod().get().getName()); try { testOverlapCommon(tn); HMaster services = TEST_UTIL.getHBaseCluster().getMaster(); @@ -376,8 +369,8 @@ public void testOverlapWithSmallMergeCount() throws Exception { * procedure, but no merge will happen. */ @Test - public void testMergeWithMergedChildRegion() throws Exception { - TableName tn = TableName.valueOf(this.name.getMethodName()); + public void testMergeWithMergedChildRegion(TestInfo testInfo) throws Exception { + TableName tn = TableName.valueOf(testInfo.getTestMethod().get().getName()); TEST_UTIL.createMultiRegionTable(tn, HConstants.CATALOG_FAMILY); List ris = MetaTableAccessor.getTableRegions(TEST_UTIL.getConnection(), tn); assertTrue(ris.size() > 5); @@ -438,8 +431,8 @@ public void testMergeWithMergedChildRegion() throws Exception { * can fix this condition. HBASE-24247 */ @Test - public void testOverlapWithMergeOfNonContiguous() throws Exception { - TableName tn = TableName.valueOf(this.name.getMethodName()); + public void testOverlapWithMergeOfNonContiguous(TestInfo testInfo) throws Exception { + TableName tn = TableName.valueOf(testInfo.getTestMethod().get().getName()); TEST_UTIL.createMultiRegionTable(tn, HConstants.CATALOG_FAMILY); List ris = MetaTableAccessor.getTableRegions(TEST_UTIL.getConnection(), tn); assertTrue(ris.size() > 5); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestMetaFixerNoCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestMetaFixerNoCluster.java index 614385ec04d6..589624e233ac 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestMetaFixerNoCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestMetaFixerNoCluster.java @@ -17,14 +17,13 @@ */ package org.apache.hadoop.hbase.master.janitor; -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.ArrayList; import java.util.List; import java.util.SortedSet; -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; @@ -32,18 +31,15 @@ import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Pair; -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; /** * Test small utility methods inside {@link MetaFixer}. For cluster tests see {@link TestMetaFixer} */ -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestMetaFixerNoCluster { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMetaFixerNoCluster.class); private static byte[] A = Bytes.toBytes("a"); private static byte[] B = Bytes.toBytes("b"); private static byte[] C = Bytes.toBytes("c"); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/locking/TestLockManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/locking/TestLockManager.java index 015afcc5e2dd..5104c2b53ee8 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/locking/TestLockManager.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/locking/TestLockManager.java @@ -17,13 +17,12 @@ */ package org.apache.hadoop.hbase.master.locking; -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.List; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.NamespaceDescriptor; import org.apache.hadoop.hbase.TableName; @@ -38,26 +37,18 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; 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.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestLockManager { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestLockManager.class); - - @Rule - public TestName testName = new TestName(); // crank this up if this test turns out to be flaky. private static final int LOCAL_LOCKS_TIMEOUT = 1000; @@ -75,7 +66,7 @@ private static void setupConf(Configuration conf) { conf.setInt(LockProcedure.LOCAL_MASTER_LOCKS_TIMEOUT_MS_CONF, LOCAL_LOCKS_TIMEOUT); } - @BeforeClass + @BeforeAll public static void setupCluster() throws Exception { setupConf(UTIL.getConfiguration()); UTIL.startMiniCluster(1); @@ -89,7 +80,7 @@ public static void setupCluster() throws Exception { regions.toArray(tableRegions); } - @AfterClass + @AfterAll public static void cleanupTest() throws Exception { try { UTIL.shutdownMiniCluster(); @@ -98,7 +89,7 @@ public static void cleanupTest() throws Exception { } } - @After + @AfterEach public void tearDown() throws Exception { for (Procedure proc : getMasterProcedureExecutor().getProcedures()) { if (proc instanceof LockProcedure) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/locking/TestLockProcedure.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/locking/TestLockProcedure.java index 8f5e5f599717..fbb2bdaa938f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/locking/TestLockProcedure.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/locking/TestLockProcedure.java @@ -17,9 +17,13 @@ */ package org.apache.hadoop.hbase.master.locking; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.StringStartsWith.startsWith; +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 java.util.ArrayList; import java.util.List; @@ -28,7 +32,6 @@ import java.util.concurrent.TimeoutException; 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.NamespaceDescriptor; @@ -46,18 +49,13 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.hamcrest.core.IsInstanceOf; -import org.hamcrest.core.StringStartsWith; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.ExpectedException; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,17 +67,10 @@ import org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockRequest; import org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockResponse; -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestLockProcedure { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestLockProcedure.class); - - @Rule - public final ExpectedException exception = ExpectedException.none(); - @Rule - public TestName testName = new TestName(); // crank this up if this test turns out to be flaky. private static final int HEARTBEAT_TIMEOUT = 2000; private static final int LOCAL_LOCKS_TIMEOUT = 4000; @@ -104,7 +95,7 @@ private static void setupConf(Configuration conf) { conf.setInt(LockProcedure.LOCAL_MASTER_LOCKS_TIMEOUT_MS_CONF, LOCAL_LOCKS_TIMEOUT); } - @BeforeClass + @BeforeAll public static void setupCluster() throws Exception { setupConf(UTIL.getConfiguration()); UTIL.startMiniCluster(1); @@ -121,7 +112,7 @@ public static void setupCluster() throws Exception { assert tableRegions2.size() > 0; } - @AfterClass + @AfterAll public static void cleanupTest() throws Exception { try { UTIL.shutdownMiniCluster(); @@ -130,13 +121,13 @@ public static void cleanupTest() throws Exception { } } - @Before - public void setup() throws Exception { + @BeforeEach + public void setup(TestInfo testInfo) throws Exception { ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false); - testMethodName = testName.getMethodName(); + testMethodName = testInfo.getTestMethod().get().getName(); } - @After + @AfterEach public void tearDown() throws Exception { ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false); // Kill all running procedures. @@ -164,12 +155,13 @@ private LockRequest getRegionLock(List regionInfos, String descripti private void validateLockRequestException(LockRequest lockRequest, String message) throws Exception { - exception.expect(ServiceException.class); - exception.expectCause(IsInstanceOf.instanceOf(DoNotRetryIOException.class)); - exception - .expectMessage(StringStartsWith.startsWith("org.apache.hadoop.hbase.DoNotRetryIOException: " - + "java.lang.IllegalArgumentException: " + message)); - masterRpcService.requestLock(null, lockRequest); + ServiceException serviceException = + assertThrows(ServiceException.class, () -> masterRpcService.requestLock(null, lockRequest)); + assertThat(serviceException.getCause(), instanceOf(DoNotRetryIOException.class)); + assertThat(serviceException.getMessage(), + startsWith( + "org.apache.hadoop.hbase.DoNotRetryIOException: java.lang.IllegalArgumentException: " + + message)); } @Test diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/migrate/TestInitializeStoreFileTracker.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/migrate/TestInitializeStoreFileTracker.java index 00b4c9975f77..9e061f0fad8b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/migrate/TestInitializeStoreFileTracker.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/migrate/TestInitializeStoreFileTracker.java @@ -17,12 +17,12 @@ */ package org.apache.hadoop.hbase.master.migrate; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.IOException; import org.apache.commons.lang3.StringUtils; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableDescriptors; @@ -34,18 +34,15 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; -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.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, MasterTests.class }) +@Tag(MediumTests.TAG) +@Tag(MasterTests.TAG) public class TestInitializeStoreFileTracker { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestInitializeStoreFileTracker.class); + private final static String[] tables = new String[] { "t1", "t2", "t3", "t4", "t5", "t6" }; private final static String famStr = "f1"; private final static byte[] fam = Bytes.toBytes(famStr); @@ -54,7 +51,7 @@ public class TestInitializeStoreFileTracker { private Configuration conf; private TableDescriptor tableDescriptor; - @Before + @BeforeEach public void setUp() throws Exception { conf = HBaseConfiguration.create(); // Speed up the launch of RollingUpgradeChore @@ -67,7 +64,7 @@ public void setUp() throws Exception { HTU.startMiniCluster(); } - @After + @AfterEach public void tearDown() throws Exception { HTU.shutdownMiniCluster(); } @@ -84,7 +81,7 @@ public void testMigrateStoreFileTracker() throws IOException, InterruptedExcepti for (int i = 0; i < tables.length; i++) { TableDescriptor tdAfterCreated = tableDescriptors.get(TableName.valueOf(tables[i])); // make sure that TRACKER_IMPL was set by default after tables have been created. - Assert.assertNotNull(tdAfterCreated.getValue(StoreFileTrackerFactory.TRACKER_IMPL)); + assertNotNull(tdAfterCreated.getValue(StoreFileTrackerFactory.TRACKER_IMPL)); // Remove StoreFileTracker impl from tableDescriptor TableDescriptor tdRemovedSFT = TableDescriptorBuilder.newBuilder(tdAfterCreated) .removeValue(StoreFileTrackerFactory.TRACKER_IMPL).build(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerManagerConfigurationObserver.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerManagerConfigurationObserver.java index d5763dfe6c95..82d35e208d07 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerManagerConfigurationObserver.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerManagerConfigurationObserver.java @@ -17,24 +17,22 @@ */ package org.apache.hadoop.hbase.master.normalizer; -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.regex.Matcher; import java.util.regex.Pattern; 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.conf.ConfigurationManager; import org.apache.hadoop.hbase.master.MasterServices; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -43,13 +41,10 @@ /** * Test that configuration changes are propagated to all children. */ -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestRegionNormalizerManagerConfigurationObserver { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionNormalizerManagerConfigurationObserver.class); - private static final HBaseTestingUtil testUtil = new HBaseTestingUtil(); private static final Pattern rateLimitPattern = Pattern.compile("RateLimiter\\[stableRate=(?.+)qps]"); @@ -67,7 +62,7 @@ public class TestRegionNormalizerManagerConfigurationObserver { private RegionNormalizerWorker worker; private ConfigurationManager configurationManager; - @Before + @BeforeEach public void before() { MockitoAnnotations.initMocks(this); conf = testUtil.getConfiguration(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerStateStore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerStateStore.java index 147192c12d26..8918270a3dc1 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerStateStore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerStateStore.java @@ -17,31 +17,26 @@ */ package org.apache.hadoop.hbase.master.normalizer; -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 org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.master.MasterStateStoreTestBase; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.zookeeper.ZKUtil; -import org.junit.After; -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.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionNormalizerProtos; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestRegionNormalizerStateStore extends MasterStateStoreTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionNormalizerStateStore.class); - - @After + @AfterEach public void tearDown() throws Exception { cleanup(); ZKUtil.deleteNodeFailSilent(UTIL.getZooKeeperWatcher(), diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerWorkQueue.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerWorkQueue.java index 088df7e7376e..29b499910fe2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerWorkQueue.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerWorkQueue.java @@ -21,8 +21,8 @@ import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.lessThanOrEqualTo; -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.util.ArrayList; import java.util.Arrays; @@ -39,30 +39,20 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import java.util.stream.IntStream; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; /** * Tests that {@link RegionNormalizerWorkQueue} implements the contract described in its docstring. */ -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestRegionNormalizerWorkQueue { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionNormalizerWorkQueue.class); - - @Rule - public TestName testName = new TestName(); - @Test public void testElementUniquenessAndFIFO() throws Exception { final RegionNormalizerWorkQueue queue = new RegionNormalizerWorkQueue<>(); @@ -173,7 +163,7 @@ public void testConcurrentPut() throws Exception { drainTo(queue, content); assertThat("at most `maxValue` items should be present.", content.size(), lessThanOrEqualTo(maxValue)); - assertEquals("all items should be unique.", content.size(), new HashSet<>(content).size()); + assertEquals(content.size(), new HashSet<>(content).size(), "all items should be unique."); } /** diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerWorker.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerWorker.java index c5f0a201cb0c..30be2b125741 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerWorker.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestRegionNormalizerWorker.java @@ -23,7 +23,7 @@ import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyLong; @@ -38,10 +38,8 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseCommonTestingUtil; import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.TableNameTestRule; import org.apache.hadoop.hbase.Waiter; import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.RegionInfoBuilder; @@ -53,18 +51,16 @@ import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.StringDescription; -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.junit.jupiter.api.extension.ExtendWith; import org.mockito.Answers; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder; @@ -75,21 +71,11 @@ * simple enough to use directly; for {@link MasterServices}, use a mock because, as of now, the * worker only invokes 4 methods. */ -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) +@ExtendWith(MockitoExtension.class) public class TestRegionNormalizerWorker { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestRegionNormalizerWorker.class); - - @Rule - public TestName testName = new TestName(); - @Rule - public TableNameTestRule tableName = new TableNameTestRule(); - - @Rule - public MockitoRule mockitoRule = MockitoJUnit.rule(); - @Mock(answer = Answers.RETURNS_DEEP_STUBS) private MasterServices masterServices; @Mock @@ -101,33 +87,36 @@ public class TestRegionNormalizerWorker { private final AtomicReference workerThreadThrowable = new AtomicReference<>(); - @Before - public void before() throws Exception { - MockitoAnnotations.initMocks(this); + private TableName tableName; + + @BeforeEach + public void before(TestInfo testInfo) throws Exception { + MockitoAnnotations.openMocks(this); when(masterServices.skipRegionManagementAction(any())).thenReturn(false); testingUtility = new HBaseCommonTestingUtil(); queue = new RegionNormalizerWorkQueue<>(); workerThreadThrowable.set(null); + tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); - final String threadNameFmt = - TestRegionNormalizerWorker.class.getSimpleName() + "-" + testName.getMethodName() + "-%d"; + final String threadNameFmt = TestRegionNormalizerWorker.class.getSimpleName() + "-" + + testInfo.getTestMethod().get().getName() + "-%d"; final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(threadNameFmt) .setDaemon(true).setUncaughtExceptionHandler((t, e) -> workerThreadThrowable.set(e)).build(); workerPool = Executors.newSingleThreadExecutor(threadFactory); } - @After + @AfterEach public void after() throws Exception { workerPool.shutdownNow(); // shutdownNow to interrupt the worker thread sitting on `take()` - assertTrue("timeout waiting for worker thread to terminate", - workerPool.awaitTermination(30, TimeUnit.SECONDS)); + assertTrue(workerPool.awaitTermination(30, TimeUnit.SECONDS), + "timeout waiting for worker thread to terminate"); final Throwable workerThrowable = workerThreadThrowable.get(); assertThat("worker thread threw unexpected exception", workerThrowable, nullValue()); } @Test public void testMergeCounter() throws Exception { - final TableName tn = tableName.getTableName(); + final TableName tn = tableName; final TableDescriptor tnDescriptor = TableDescriptorBuilder.newBuilder(tn).setNormalizationEnabled(true).build(); when(masterServices.getTableDescriptors().get(tn)).thenReturn(tnDescriptor); @@ -148,7 +137,7 @@ public void testMergeCounter() throws Exception { @Test public void testSplitCounter() throws Exception { - final TableName tn = tableName.getTableName(); + final TableName tn = tableName; final TableDescriptor tnDescriptor = TableDescriptorBuilder.newBuilder(tn).setNormalizationEnabled(true).build(); when(masterServices.getTableDescriptors().get(tn)).thenReturn(tnDescriptor); @@ -172,7 +161,7 @@ public void testSplitCounter() throws Exception { */ @Test public void testRateLimit() throws Exception { - final TableName tn = tableName.getTableName(); + final TableName tn = tableName; final TableDescriptor tnDescriptor = TableDescriptorBuilder.newBuilder(tn).setNormalizationEnabled(true).build(); final RegionInfo splitRegionInfo = RegionInfoBuilder.newBuilder(tn).build(); @@ -206,7 +195,7 @@ public void testRateLimit() throws Exception { @Test public void testPlansSizeLimit() throws Exception { - final TableName tn = tableName.getTableName(); + final TableName tn = tableName; final TableDescriptor tnDescriptor = TableDescriptorBuilder.newBuilder(tn).setNormalizationEnabled(true).build(); final RegionInfo splitRegionInfo = RegionInfoBuilder.newBuilder(tn).build(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizer.java index e931716e77ed..f474d795aa8b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizer.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizer.java @@ -35,9 +35,9 @@ import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.not; -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.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; @@ -54,13 +54,11 @@ import java.util.List; import java.util.Map; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.RegionMetrics; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.Size; import org.apache.hadoop.hbase.TableName; -import org.apache.hadoop.hbase.TableNameTestRule; import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.RegionInfoBuilder; import org.apache.hadoop.hbase.client.TableDescriptor; @@ -71,35 +69,30 @@ 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.Rule; -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.junit.jupiter.api.TestInfo; import org.mockito.Mockito; /** * Tests logic of {@link SimpleRegionNormalizer}. */ -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestSimpleRegionNormalizer { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestSimpleRegionNormalizer.class); - private Configuration conf; private SimpleRegionNormalizer normalizer; private MasterServices masterServices; private TableDescriptor tableDescriptor; + private TableName tableName; - @Rule - public TableNameTestRule name = new TableNameTestRule(); - - @Before - public void before() { + @BeforeEach + public void before(TestInfo testInfo) { conf = HBaseConfiguration.create(); - tableDescriptor = TableDescriptorBuilder.newBuilder(name.getTableName()).build(); + tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); + tableDescriptor = TableDescriptorBuilder.newBuilder(tableName).build(); } @Test @@ -116,7 +109,7 @@ public void testNoNormalizationForMetaTable() { @Test public void testNoNormalizationIfTooFewRegions() { - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 2); final Map regionSizes = createRegionSizesMap(regionInfos, 10, 15); setupMocksForNormalizer(regionSizes, regionInfos); @@ -127,7 +120,7 @@ public void testNoNormalizationIfTooFewRegions() { @Test public void testNoNormalizationOnNormalizedCluster() { - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 4); final Map regionSizes = createRegionSizesMap(regionInfos, 10, 15, 8, 10); setupMocksForNormalizer(regionSizes, regionInfos); @@ -137,7 +130,7 @@ public void testNoNormalizationOnNormalizedCluster() { } private void noNormalizationOnTransitioningRegions(final RegionState.State state) { - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 3); final Map regionSizes = createRegionSizesMap(regionInfos, 10, 1, 100); @@ -183,7 +176,7 @@ public void testNoNormalizationOnSplitRegions() { @Test public void testMergeOfSmallRegions() { - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 5); final Map regionSizes = createRegionSizesMap(regionInfos, 15, 5, 5, 15, 16); setupMocksForNormalizer(regionSizes, regionInfos); @@ -196,7 +189,7 @@ public void testMergeOfSmallRegions() { // Test for situation illustrated in HBASE-14867 @Test public void testMergeOfSecondSmallestRegions() { - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 6); final Map regionSizes = createRegionSizesMap(regionInfos, 1, 10000, 10000, 10000, 2700, 2700); @@ -209,7 +202,7 @@ public void testMergeOfSecondSmallestRegions() { @Test public void testMergeOfSmallNonAdjacentRegions() { - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 5); final Map regionSizes = createRegionSizesMap(regionInfos, 15, 5, 16, 15, 5); setupMocksForNormalizer(regionSizes, regionInfos); @@ -220,7 +213,7 @@ public void testMergeOfSmallNonAdjacentRegions() { @Test public void testSplitOfLargeRegion() { - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 4); final Map regionSizes = createRegionSizesMap(regionInfos, 8, 6, 10, 30); setupMocksForNormalizer(regionSizes, regionInfos); @@ -231,7 +224,7 @@ public void testSplitOfLargeRegion() { @Test public void testWithTargetRegionSize() throws Exception { - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 6); final Map regionSizes = createRegionSizesMap(regionInfos, 20, 40, 60, 80, 100, 120); @@ -255,7 +248,7 @@ public void testWithTargetRegionSize() throws Exception { @Test public void testSplitWithTargetRegionCount() throws Exception { - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 4); final Map regionSizes = createRegionSizesMap(regionInfos, 20, 40, 60, 80); setupMocksForNormalizer(regionSizes, regionInfos); @@ -276,7 +269,7 @@ public void testSplitWithTargetRegionCount() throws Exception { @Test public void testHonorsSplitEnabled() { conf.setBoolean(SPLIT_ENABLED_KEY, true); - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 5); final Map regionSizes = createRegionSizesMap(regionInfos, 5, 5, 20, 5, 5); setupMocksForNormalizer(regionSizes, regionInfos); @@ -291,7 +284,7 @@ public void testHonorsSplitEnabled() { @Test public void testHonorsSplitEnabledInTD() { conf.setBoolean(SPLIT_ENABLED_KEY, true); - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 5); final Map regionSizes = createRegionSizesMap(regionInfos, 5, 5, 20, 5, 5); setupMocksForNormalizer(regionSizes, regionInfos); @@ -313,7 +306,7 @@ public void testHonorsSplitEnabledInTD() { @Test public void testHonorsMergeEnabled() { conf.setBoolean(MERGE_ENABLED_KEY, true); - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 5); final Map regionSizes = createRegionSizesMap(regionInfos, 20, 5, 5, 20, 20); setupMocksForNormalizer(regionSizes, regionInfos); @@ -328,7 +321,7 @@ public void testHonorsMergeEnabled() { @Test public void testHonorsMergeEnabledInTD() { conf.setBoolean(MERGE_ENABLED_KEY, true); - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 5); final Map regionSizes = createRegionSizesMap(regionInfos, 20, 5, 5, 20, 20); setupMocksForNormalizer(regionSizes, regionInfos); @@ -362,7 +355,7 @@ public void testHonorsOldMinimumRegionCount() { private void honorsMinimumRegionCount(String confKey) { conf.setInt(confKey, 1); - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 3); // create a table topology that results in both a merge plan and a split plan. Assert that the // merge is only created when the when the number of table regions is above the region count @@ -401,7 +394,7 @@ public void testHonorsOldMinimumRegionCountInTD() { private void honorsOldMinimumRegionCountInTD(String confKey) { conf.setInt(confKey, 1); - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 3); // create a table topology that results in both a merge plan and a split plan. Assert that the // merge is only created when the when the number of table regions is above the region count @@ -424,7 +417,7 @@ private void honorsOldMinimumRegionCountInTD(String confKey) { @Test public void testHonorsMergeMinRegionAge() { conf.setInt(MERGE_MIN_REGION_AGE_DAYS_KEY, 7); - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 4); final Map regionSizes = createRegionSizesMap(regionInfos, 1, 1, 10, 10); setupMocksForNormalizer(regionSizes, regionInfos); @@ -445,7 +438,7 @@ public void testHonorsMergeMinRegionAge() { @Test public void testHonorsMergeMinRegionAgeInTD() { conf.setInt(MERGE_MIN_REGION_AGE_DAYS_KEY, 7); - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 4); final Map regionSizes = createRegionSizesMap(regionInfos, 1, 1, 10, 10); setupMocksForNormalizer(regionSizes, regionInfos); @@ -469,7 +462,7 @@ public void testHonorsMergeMinRegionAgeInTD() { @Test public void testHonorsMergeMinRegionSize() { conf.setBoolean(SPLIT_ENABLED_KEY, false); - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 5); final Map regionSizes = createRegionSizesMap(regionInfos, 1, 2, 0, 10, 10); setupMocksForNormalizer(regionSizes, regionInfos); @@ -489,7 +482,7 @@ public void testHonorsMergeMinRegionSize() { @Test public void testHonorsMergeMinRegionSizeInTD() { conf.setBoolean(SPLIT_ENABLED_KEY, false); - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 5); final Map regionSizes = createRegionSizesMap(regionInfos, 1, 2, 0, 10, 10); setupMocksForNormalizer(regionSizes, regionInfos); @@ -510,7 +503,7 @@ public void testHonorsMergeRequestMaxNumberOfRegionsCount() { conf.setInt(MERGE_MIN_REGION_COUNT_KEY, 1); conf.setInt(MERGE_MIN_REGION_SIZE_MB_KEY, 0); conf.setInt(MERGE_REQUEST_MAX_NUMBER_OF_REGIONS_COUNT_KEY, 3); - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 5); final Map regionSizes = createRegionSizesMap(regionInfos, 0, 1, 0, 1, 0); setupMocksForNormalizer(regionSizes, regionInfos); @@ -529,7 +522,7 @@ public void testHonorsMergeRequestMaxNumberOfRegionsCountDefault() { conf.setBoolean(SPLIT_ENABLED_KEY, false); conf.setInt(MERGE_MIN_REGION_COUNT_KEY, 1); conf.setInt(MERGE_MIN_REGION_SIZE_MB_KEY, 0); - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 3); final Map regionSizes = createRegionSizesMap(regionInfos, 0, 0, 0); setupMocksForNormalizer(regionSizes, regionInfos); @@ -543,7 +536,7 @@ public void testHonorsMergeRequestMaxNumberOfRegionsCountDefault() { public void testMergeEmptyRegions0() { conf.setBoolean(SPLIT_ENABLED_KEY, false); conf.setInt(MERGE_MIN_REGION_SIZE_MB_KEY, 0); - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 7); final Map regionSizes = createRegionSizesMap(regionInfos, 0, 1, 10, 0, 9, 10, 0); @@ -565,7 +558,7 @@ public void testMergeEmptyRegions0() { public void testMergeEmptyRegions1() { conf.setBoolean(SPLIT_ENABLED_KEY, false); conf.setInt(MERGE_MIN_REGION_SIZE_MB_KEY, 0); - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 8); final Map regionSizes = createRegionSizesMap(regionInfos, 0, 1, 10, 0, 9, 0, 10, 0); @@ -589,7 +582,7 @@ public void testMergeEmptyRegions1() { public void testMergeEmptyRegions2() { conf.setBoolean(SPLIT_ENABLED_KEY, false); conf.setInt(MERGE_MIN_REGION_SIZE_MB_KEY, 0); - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 8); final Map regionSizes = createRegionSizesMap(regionInfos, 0, 10, 1, 0, 9, 0, 10, 0); @@ -613,7 +606,7 @@ public void testMergeEmptyRegions2() { @Test public void testSplitAndMultiMerge() { conf.setInt(MERGE_MIN_REGION_SIZE_MB_KEY, 0); - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 8); final Map regionSizes = createRegionSizesMap(regionInfos, 3, 1, 1, 30, 9, 3, 1, 0); @@ -633,7 +626,7 @@ public void testSplitAndMultiMerge() { // This test is to make sure that normalizer is only going to merge adjacent regions. @Test public void testNormalizerCannotMergeNonAdjacentRegions() { - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; // create 5 regions with sizes to trigger merge of small regions. region ranges are: // [, "aa"), ["aa", "aa1"), ["aa1", "aa1!"), ["aa1!", "aa2"), ["aa2", ) // Region ["aa", "aa1") and ["aa1!", "aa2") are not adjacent, they are not supposed to @@ -652,7 +645,7 @@ public void testNormalizerCannotMergeNonAdjacentRegions() { @Test public void testSizeLimitShufflesPlans() { conf.setLong(CUMULATIVE_SIZE_LIMIT_MB_KEY, 10); - final TableName tableName = name.getTableName(); + final TableName tableName = this.tableName; final List regionInfos = createRegionInfos(tableName, 4); final Map regionSizes = createRegionSizesMap(regionInfos, 3, 3, 3, 3); setupMocksForNormalizer(regionSizes, regionInfos); @@ -696,7 +689,7 @@ private void setupMocksForNormalizer(Map regionSizes, } when(masterServices.isSplitOrMergeEnabled(any())).thenReturn(true); - when(tableDescriptor.getTableName()).thenReturn(name.getTableName()); + when(tableDescriptor.getTableName()).thenReturn(tableName); normalizer = new SimpleRegionNormalizer(); normalizer.setConf(conf); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizerOnCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizerOnCluster.java index adc8847e1cf6..b56bca4cdbee 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizerOnCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizerOnCluster.java @@ -21,10 +21,10 @@ import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.ArrayList; @@ -32,7 +32,6 @@ import java.util.Comparator; import java.util.List; import java.util.concurrent.TimeUnit; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.MatcherPredicate; @@ -64,39 +63,31 @@ import org.apache.hadoop.hbase.util.LoadTestKVGenerator; import org.hamcrest.Matcher; import org.hamcrest.Matchers; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Testing {@link SimpleRegionNormalizer} on minicluster. */ -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestSimpleRegionNormalizerOnCluster { private static final Logger LOG = LoggerFactory.getLogger(TestSimpleRegionNormalizerOnCluster.class); - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestSimpleRegionNormalizerOnCluster.class); - private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static final byte[] FAMILY_NAME = Bytes.toBytes("fam"); private static AsyncAdmin admin; private static HMaster master; - @Rule - public TestName name = new TestName(); - - @BeforeClass + @BeforeAll public static void beforeAllTests() throws Exception { // we will retry operations when PleaseHoldException is thrown TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 3); @@ -115,12 +106,12 @@ public static void beforeAllTests() throws Exception { assertNotNull(master); } - @AfterClass + @AfterAll public static void afterAllTests() throws Exception { TEST_UTIL.shutdownMiniCluster(); } - @Before + @BeforeEach public void before() throws Exception { // disable the normalizer ahead of time, let the test enable it when its ready. admin.normalizerSwitch(false).get(); @@ -140,10 +131,10 @@ public void testHonorsNormalizerSwitch() throws Exception { * and look for change in one and no change in the other. */ @Test - public void testHonorsNormalizerTableSetting() throws Exception { - final TableName tn1 = TableName.valueOf(name.getMethodName() + "1"); - final TableName tn2 = TableName.valueOf(name.getMethodName() + "2"); - final TableName tn3 = TableName.valueOf(name.getMethodName() + "3"); + public void testHonorsNormalizerTableSetting(TestInfo testInfo) throws Exception { + final TableName tn1 = TableName.valueOf(testInfo.getTestMethod().get().getName() + "1"); + final TableName tn2 = TableName.valueOf(testInfo.getTestMethod().get().getName() + "2"); + final TableName tn3 = TableName.valueOf(testInfo.getTestMethod().get().getName() + "3"); try { final int tn1RegionCount = createTableBegsSplit(tn1, true, false); @@ -160,8 +151,8 @@ public void testHonorsNormalizerTableSetting() throws Exception { // 1. split one region to two // 2. merge two regions into one // and hence, total number of regions for tn3 remains same - assertEquals(tn1 + " should have split.", tn1RegionCount + 1, getRegionCount(tn1)); - assertEquals(tn2 + " should not have split.", tn2RegionCount, getRegionCount(tn2)); + assertEquals(tn1RegionCount + 1, getRegionCount(tn1), tn1 + " should have split."); + assertEquals(tn2RegionCount, getRegionCount(tn2), tn2 + " should not have split."); LOG.debug("waiting for t3 to settle..."); waitForTableRegionCount(tn3, comparesEqualTo(tn3RegionCount)); } finally { @@ -172,21 +163,21 @@ public void testHonorsNormalizerTableSetting() throws Exception { } @Test - public void testRegionNormalizationSplitWithoutQuotaLimit() throws Exception { - testRegionNormalizationSplit(false); + public void testRegionNormalizationSplitWithoutQuotaLimit(TestInfo testInfo) throws Exception { + testRegionNormalizationSplit(false, testInfo); } @Test - public void testRegionNormalizationSplitWithQuotaLimit() throws Exception { - testRegionNormalizationSplit(true); + public void testRegionNormalizationSplitWithQuotaLimit(TestInfo testInfo) throws Exception { + testRegionNormalizationSplit(true, testInfo); } - void testRegionNormalizationSplit(boolean limitedByQuota) throws Exception { + void testRegionNormalizationSplit(boolean limitedByQuota, TestInfo testInfo) throws Exception { TableName tableName = null; try { tableName = limitedByQuota - ? buildTableNameForQuotaTest(name.getMethodName()) - : TableName.valueOf(name.getMethodName()); + ? buildTableNameForQuotaTest(testInfo.getTestMethod().get().getName()) + : TableName.valueOf(testInfo.getTestMethod().get().getName()); final int currentRegionCount = createTableBegsSplit(tableName, true, false); final long existingSkippedSplitCount = @@ -195,12 +186,12 @@ void testRegionNormalizationSplit(boolean limitedByQuota) throws Exception { assertTrue(admin.normalize().get()); if (limitedByQuota) { waitForSkippedSplits(master, existingSkippedSplitCount); - assertEquals(tableName + " should not have split.", currentRegionCount, - getRegionCount(tableName)); + assertEquals(currentRegionCount, getRegionCount(tableName), + tableName + " should not have split."); } else { waitForTableRegionCount(tableName, greaterThanOrEqualTo(currentRegionCount + 1)); - assertEquals(tableName + " should have split.", currentRegionCount + 1, - getRegionCount(tableName)); + assertEquals(currentRegionCount + 1, getRegionCount(tableName), + tableName + " should have split."); } } finally { dropIfExists(tableName); @@ -208,25 +199,25 @@ void testRegionNormalizationSplit(boolean limitedByQuota) throws Exception { } @Test - public void testRegionNormalizationMerge() throws Exception { - final TableName tableName = TableName.valueOf(name.getMethodName()); + public void testRegionNormalizationMerge(TestInfo testInfo) throws Exception { + final TableName tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); try { final int currentRegionCount = createTableBegsMerge(tableName); assertFalse(admin.normalizerSwitch(true).get()); assertTrue(admin.normalize().get()); waitForTableRegionCount(tableName, lessThanOrEqualTo(currentRegionCount - 1)); - assertEquals(tableName + " should have merged.", currentRegionCount - 1, - getRegionCount(tableName)); + assertEquals(currentRegionCount - 1, getRegionCount(tableName), + tableName + " should have merged."); } finally { dropIfExists(tableName); } } @Test - public void testHonorsNamespaceFilter() throws Exception { + public void testHonorsNamespaceFilter(TestInfo testInfo) throws Exception { final NamespaceDescriptor namespaceDescriptor = NamespaceDescriptor.create("ns").build(); - final TableName tn1 = TableName.valueOf("ns", name.getMethodName()); - final TableName tn2 = TableName.valueOf(name.getMethodName()); + final TableName tn1 = TableName.valueOf("ns", testInfo.getTestMethod().get().getName()); + final TableName tn2 = TableName.valueOf(testInfo.getTestMethod().get().getName()); try { admin.createNamespace(namespaceDescriptor).get(); @@ -241,7 +232,7 @@ public void testHonorsNamespaceFilter() throws Exception { // confirm that tn1 has (tn1RegionCount + 1) number of regions. // tn2 has tn2RegionCount number of regions because it's not a member of the target namespace. - assertEquals(tn1 + " should have split.", tn1RegionCount + 1, getRegionCount(tn1)); + assertEquals(tn1RegionCount + 1, getRegionCount(tn1), tn1 + " should have split."); waitForTableRegionCount(tn2, comparesEqualTo(tn2RegionCount)); } finally { dropIfExists(tn1); @@ -250,9 +241,9 @@ public void testHonorsNamespaceFilter() throws Exception { } @Test - public void testHonorsPatternFilter() throws Exception { - final TableName tn1 = TableName.valueOf(name.getMethodName() + "1"); - final TableName tn2 = TableName.valueOf(name.getMethodName() + "2"); + public void testHonorsPatternFilter(TestInfo testInfo) throws Exception { + final TableName tn1 = TableName.valueOf(testInfo.getTestMethod().get().getName() + "1"); + final TableName tn2 = TableName.valueOf(testInfo.getTestMethod().get().getName() + "2"); try { final int tn1RegionCount = createTableBegsSplit(tn1, true, false); @@ -266,7 +257,7 @@ public void testHonorsPatternFilter() throws Exception { // confirm that tn1 has (tn1RegionCount + 1) number of regions. // tn2 has tn2RegionCount number of regions because it fails filter. - assertEquals(tn1 + " should have split.", tn1RegionCount + 1, getRegionCount(tn1)); + assertEquals(tn1RegionCount + 1, getRegionCount(tn1), tn1 + " should have split."); waitForTableRegionCount(tn2, comparesEqualTo(tn2RegionCount)); } finally { dropIfExists(tn1); @@ -275,9 +266,9 @@ public void testHonorsPatternFilter() throws Exception { } @Test - public void testHonorsNameFilter() throws Exception { - final TableName tn1 = TableName.valueOf(name.getMethodName() + "1"); - final TableName tn2 = TableName.valueOf(name.getMethodName() + "2"); + public void testHonorsNameFilter(TestInfo testInfo) throws Exception { + final TableName tn1 = TableName.valueOf(testInfo.getTestMethod().get().getName() + "1"); + final TableName tn2 = TableName.valueOf(testInfo.getTestMethod().get().getName() + "2"); try { final int tn1RegionCount = createTableBegsSplit(tn1, true, false); @@ -291,7 +282,7 @@ public void testHonorsNameFilter() throws Exception { // confirm that tn1 has (tn1RegionCount + 1) number of regions. // tn2 has tn3RegionCount number of regions because it fails filter: - assertEquals(tn1 + " should have split.", tn1RegionCount + 1, getRegionCount(tn1)); + assertEquals(tn1RegionCount + 1, getRegionCount(tn1), tn1 + " should have split."); waitForTableRegionCount(tn2, comparesEqualTo(tn2RegionCount)); } finally { dropIfExists(tn1); @@ -304,8 +295,8 @@ public void testHonorsNameFilter() throws Exception { * expected behavior, only that some change is applied to the table. */ @Test - public void testTargetOfSplitAndMerge() throws Exception { - final TableName tn = TableName.valueOf(name.getMethodName()); + public void testTargetOfSplitAndMerge(TestInfo testInfo) throws Exception { + final TableName tn = TableName.valueOf(testInfo.getTestMethod().get().getName()); try { final int tnRegionCount = createTableTargetOfSplitAndMerge(tn); assertFalse(admin.normalizerSwitch(true).get()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/MasterRegionTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/MasterRegionTestBase.java index 9ea11f732310..d5cfb98d60f8 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/MasterRegionTestBase.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/MasterRegionTestBase.java @@ -38,8 +38,8 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.CommonFSUtils; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; public class MasterRegionTestBase { @@ -77,7 +77,7 @@ protected void configure(MasterRegionParams params) { protected void postSetUp() throws IOException { } - @Before + @BeforeEach public void setUp() throws IOException { htu = new HBaseCommonTestingUtil(); htu.getConfiguration().setBoolean(MemStoreLAB.USEMSLAB_KEY, false); @@ -119,7 +119,7 @@ protected final void createMasterRegion() throws IOException { postSetUp(); } - @After + @AfterEach public void tearDown() throws IOException { region.close(true); hfileCleanerPool.shutdownNow(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestChangeSFTForMasterRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestChangeSFTForMasterRegion.java index f69f6da6cccb..d31e88c4dd0a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestChangeSFTForMasterRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestChangeSFTForMasterRegion.java @@ -17,10 +17,9 @@ */ package org.apache.hadoop.hbase.master.region; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -29,29 +28,25 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; 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; /** * Make sure we do not loss data after changing SFT implementation */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestChangeSFTForMasterRegion { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestChangeSFTForMasterRegion.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); private static TableName NAME = TableName.valueOf("test"); private static byte[] FAMILY = Bytes.toBytes("family"); - @BeforeClass + @BeforeAll public static void setUp() throws Exception { UTIL.getConfiguration().set(MasterRegionFactory.TRACKER_IMPL, StoreFileTrackerFactory.Trackers.DEFAULT.name()); @@ -63,7 +58,7 @@ public static void setUp() throws Exception { UTIL.createTable(NAME, FAMILY).close(); } - @AfterClass + @AfterAll public static void tearDown() throws IOException { UTIL.shutdownMiniCluster(); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionCompaction.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionCompaction.java index 4eefddff16b1..7660367131e8 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionCompaction.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionCompaction.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.master.region; -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 java.io.FileNotFoundException; import java.io.IOException; @@ -26,7 +26,6 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.Stoppable; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.master.cleaner.HFileCleaner; @@ -37,17 +36,13 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.HFileArchiveUtil; -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({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterRegionCompaction extends MasterRegionTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterRegionCompaction.class); - private int compactMin = 4; private HFileCleaner hfileCleaner; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionFlush.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionFlush.java index b0f1a2027790..e7fbc2195eb8 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionFlush.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionFlush.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.master.region; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -31,7 +31,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Abortable; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.Waiter; @@ -40,19 +39,15 @@ import org.apache.hadoop.hbase.regionserver.HStore; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; -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({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterRegionFlush { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterRegionFlush.class); - private Configuration conf; private HRegion region; @@ -65,7 +60,7 @@ public class TestMasterRegionFlush { private AtomicLong memstoreOffHeapSize; - @Before + @BeforeEach public void setUp() throws IOException { conf = HBaseConfiguration.create(); region = mock(HRegion.class); @@ -80,15 +75,21 @@ public void setUp() throws IOException { when(region.getMemStoreHeapSize()).thenAnswer(invocation -> memstoreHeapSize.get()); when(region.getMemStoreOffHeapSize()).thenAnswer(invocation -> memstoreOffHeapSize.get()); when(region.flush(anyBoolean())).thenAnswer(invocation -> { - assertTrue(invocation.getArgument(0)); + assertTrue(invocation.getArgument(0, Boolean.class)); memstoreHeapSize.set(0); memstoreOffHeapSize.set(0); flushCalled.incrementAndGet(); - return null; + // Return a mock FlushResult since FlushResultImpl constructor is package-private + HRegion.FlushResult mockResult = mock(HRegion.FlushResult.class); + when(mockResult.getResult()) + .thenReturn(HRegion.FlushResult.Result.FLUSHED_NO_COMPACTION_NEEDED); + when(mockResult.isFlushSucceeded()).thenReturn(true); + when(mockResult.isCompactionNeeded()).thenReturn(false); + return mockResult; }); } - @After + @AfterEach public void tearDown() { if (flusher != null) { flusher.close(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionInitialize.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionInitialize.java index 8b6f46707322..b3e732db3ebd 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionInitialize.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionInitialize.java @@ -17,15 +17,14 @@ */ package org.apache.hadoop.hbase.master.region; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.TableDescriptor; @@ -37,17 +36,13 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.CommonFSUtils; import org.apache.hadoop.hbase.util.FSTableDescriptors; -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({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterRegionInitialize extends MasterRegionTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterRegionInitialize.class); - @Test public void testUpgrade() throws IOException { Path rootDir = new Path(htu.getDataTestDir(), REGION_DIR_NAME); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionOnTwoFileSystems.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionOnTwoFileSystems.java index 80792d4b276d..75157294b9d3 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionOnTwoFileSystems.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionOnTwoFileSystems.java @@ -59,13 +59,13 @@ import org.apache.hadoop.hbase.util.CommonFSUtils; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.HFileArchiveUtil; -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.AfterEach; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -144,7 +144,7 @@ public void setUpBeforeTest() throws IOException { ServerName.valueOf("localhost", 12345, EnvironmentEdgeManager.currentTime())); } - @After + @AfterEach public void tearDownAfterTest() { region.close(true); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionRpcTimeout.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionRpcTimeout.java index 66cdaf4cc76d..3cfe5e460d50 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionRpcTimeout.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionRpcTimeout.java @@ -17,12 +17,11 @@ */ package org.apache.hadoop.hbase.master.region; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.IOException; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.ipc.RpcCall; import org.apache.hadoop.hbase.ipc.RpcServer; @@ -30,20 +29,16 @@ import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -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; /** * Make sure that we will not get rpc timeout when updating master region. */ -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterRegionRpcTimeout extends MasterRegionTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterRegionRpcTimeout.class); - @Test public void testRpcTimeout() throws IOException { RpcCall call = mock(RpcCall.class); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionWALCleaner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionWALCleaner.java index 6a596a6f138c..7ff130833ee2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionWALCleaner.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionWALCleaner.java @@ -17,16 +17,15 @@ */ package org.apache.hadoop.hbase.master.region; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.Stoppable; import org.apache.hadoop.hbase.client.Put; @@ -35,17 +34,13 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterRegionWALCleaner extends MasterRegionTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterRegionWALCleaner.class); - private static long TTL_MS = 5000; private LogCleaner logCleaner; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionWALRecovery.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionWALRecovery.java index 738f6fbed913..d7bc397342f5 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionWALRecovery.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionWALRecovery.java @@ -17,9 +17,9 @@ */ package org.apache.hadoop.hbase.master.region; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -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.assertTrue; import java.io.IOException; import java.util.Arrays; @@ -29,7 +29,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.HConstants; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Put; @@ -37,20 +36,16 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterRegionWALRecovery extends MasterRegionTestBase { private static final Logger LOG = LoggerFactory.getLogger(TestMasterRegionWALRecovery.class); - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterRegionWALRecovery.class); - private Path masterRegionDir; @Override diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionWALSyncTimeoutIOException.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionWALSyncTimeoutIOException.java index 02cad9d8c4bd..a6c76ab58d47 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionWALSyncTimeoutIOException.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/region/TestMasterRegionWALSyncTimeoutIOException.java @@ -17,7 +17,7 @@ */ package org.apache.hadoop.hbase.master.region; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; @@ -28,7 +28,6 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Abortable; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.io.asyncfs.monitor.StreamSlowMonitor; import org.apache.hadoop.hbase.regionserver.wal.AbstractFSWAL; @@ -42,20 +41,16 @@ import org.apache.hadoop.hbase.wal.AsyncFSWALProvider; import org.apache.hadoop.hbase.wal.WALFactory; import org.apache.hadoop.hbase.wal.WALProvider; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.apache.hbase.thirdparty.io.netty.channel.Channel; import org.apache.hbase.thirdparty.io.netty.channel.EventLoopGroup; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestMasterRegionWALSyncTimeoutIOException extends MasterRegionTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMasterRegionWALSyncTimeoutIOException.class); - private static final Duration WAL_SYNC_TIMEOUT = Duration.ofSeconds(3); private static volatile boolean testWalTimeout = false; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotCleanupStateStore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotCleanupStateStore.java index 3ae8656d204c..6249b0ed9e29 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotCleanupStateStore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotCleanupStateStore.java @@ -17,31 +17,26 @@ */ package org.apache.hadoop.hbase.master.snapshot; -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 org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.master.MasterStateStoreTestBase; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.zookeeper.ZKUtil; -import org.junit.After; -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.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotCleanupProtos; -@Category({ MasterTests.class, MediumTests.class }) +@Tag(MasterTests.TAG) +@Tag(MediumTests.TAG) public class TestSnapshotCleanupStateStore extends MasterStateStoreTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestSnapshotCleanupStateStore.class); - - @After + @AfterEach public void tearDown() throws Exception { cleanup(); ZKUtil.deleteNodeFailSilent(UTIL.getZooKeeperWatcher(), diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCache.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCache.java index 5a9b7fcd8330..25826bb3b6ba 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCache.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCache.java @@ -17,9 +17,9 @@ */ package org.apache.hadoop.hbase.master.snapshot; -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; @@ -34,7 +34,6 @@ import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils; @@ -43,12 +42,11 @@ import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.util.CommonFSUtils; -import org.junit.After; -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.AfterEach; +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; @@ -60,13 +58,10 @@ /** * Test that we correctly reload the cache, filter directories, etc. */ -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestSnapshotFileCache { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestSnapshotFileCache.class); - protected static final Logger LOG = LoggerFactory.getLogger(TestSnapshotFileCache.class); protected static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); // don't refresh the cache unless we tell it to @@ -86,19 +81,19 @@ protected static void initCommon() throws Exception { conf = UTIL.getConfiguration(); } - @BeforeClass + @BeforeAll public static void startCluster() throws Exception { initCommon(); workingDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(rootDir, conf); workingFs = workingDir.getFileSystem(conf); } - @AfterClass + @AfterAll public static void stopCluster() throws Exception { UTIL.shutdownMiniDFSCluster(); } - @After + @AfterEach public void cleanupFiles() throws Exception { // cleanup the snapshot directory fs.delete(snapshotDir, true); @@ -256,8 +251,8 @@ private void createAndTestSnapshot(final SnapshotFileCache cache, if (tmp) { // We should be able to find all the files while the snapshot creation is in-progress CommonFSUtils.logFileSystemState(fs, rootDir, LOG); - assertFalse("Cache didn't find " + filePath, - contains(getNonSnapshotFiles(cache, filePath), filePath)); + assertFalse(contains(getNonSnapshotFiles(cache, filePath), filePath), + "Cache didn't find " + filePath); } files.add(filePath); } @@ -274,7 +269,7 @@ private void createAndTestSnapshot(final SnapshotFileCache cache, // Make sure that all files are still present for (Path path : files) { - assertFalse("Cache didn't find " + path, contains(getNonSnapshotFiles(cache, path), path)); + assertFalse(contains(getNonSnapshotFiles(cache, path), path), "Cache didn't find " + path); } CommonFSUtils.logFileSystemState(fs, rootDir, LOG); @@ -287,8 +282,8 @@ private void createAndTestSnapshot(final SnapshotFileCache cache, cache.triggerCacheRefreshForTesting(); // and not it shouldn't find those files for (Path filePath : files) { - assertTrue("Cache found '" + filePath + "', but it shouldn't have.", - contains(getNonSnapshotFiles(cache, filePath), filePath)); + assertTrue(contains(getNonSnapshotFiles(cache, filePath), filePath), + "Cache found '" + filePath + "', but it shouldn't have."); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCacheWithDifferentWorkingDir.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCacheWithDifferentWorkingDir.java index 0cd8c3f48759..c78e6e2e17be 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCacheWithDifferentWorkingDir.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotFileCacheWithDifferentWorkingDir.java @@ -22,30 +22,25 @@ import java.util.UUID; import org.apache.commons.io.FileUtils; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; /** * Test that we correctly reload the cache, filter directories, etc. while the temporary directory * is on a different file system than the root directory */ -@Category({ MasterTests.class, LargeTests.class }) +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestSnapshotFileCacheWithDifferentWorkingDir extends TestSnapshotFileCache { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestSnapshotFileCacheWithDifferentWorkingDir.class); - protected static String TEMP_DIR = Paths.get(".", UUID.randomUUID().toString()).toAbsolutePath().toString(); - @BeforeClass + @BeforeAll public static void startCluster() throws Exception { initCommon(); @@ -56,7 +51,7 @@ public static void startCluster() throws Exception { workingFs = workingDir.getFileSystem(conf); } - @AfterClass + @AfterAll public static void stopCluster() throws Exception { UTIL.shutdownMiniDFSCluster(); FileUtils.deleteDirectory(new File(TEMP_DIR)); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotHFileCleaner.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotHFileCleaner.java index b3b36cbaad46..c1e93e1a3c0d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotHFileCleaner.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotHFileCleaner.java @@ -17,8 +17,8 @@ */ package org.apache.hadoop.hbase.master.snapshot; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.Collection; @@ -26,7 +26,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -38,24 +37,19 @@ import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.CommonFSUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; /** * Test that the snapshot hfile cleaner finds hfiles referenced in a snapshot */ -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestSnapshotHFileCleaner { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestSnapshotHFileCleaner.class); - private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private static final String TABLE_NAME_STR = "testSnapshotManifest"; private static final String SNAPSHOT_NAME_STR = "testSnapshotManifest-snapshot"; @@ -63,27 +57,24 @@ public class TestSnapshotHFileCleaner { private static FileSystem fs; private static Configuration conf; - @Rule - public TestName name = new TestName(); - /** * Setup the test environment */ - @BeforeClass + @BeforeAll public static void setup() throws Exception { conf = TEST_UTIL.getConfiguration(); rootDir = CommonFSUtils.getRootDir(conf); fs = FileSystem.get(conf); } - @AfterClass + @AfterAll public static void cleanup() throws IOException { // cleanup fs.delete(rootDir, true); } @Test - public void testFindsSnapshotFilesWhenCleaning() throws IOException { + public void testFindsSnapshotFilesWhenCleaning(TestInfo testInfo) throws IOException { CommonFSUtils.setRootDir(conf, TEST_UTIL.getDataTestDir()); Path rootDir = CommonFSUtils.getRootDir(conf); Path archivedHfileDir = @@ -95,7 +86,7 @@ public void testFindsSnapshotFilesWhenCleaning() throws IOException { // write an hfile to the snapshot directory String snapshotName = "snapshot"; - final TableName tableName = TableName.valueOf(name.getMethodName()); + final TableName tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir); RegionInfo mockRegion = RegionInfoBuilder.newBuilder(tableName).build(); Path regionSnapshotDir = new Path(snapshotDir, mockRegion.getEncodedName()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotManager.java index 4b1e4b1d3f58..adeeace48394 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotManager.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotManager.java @@ -17,17 +17,16 @@ */ package org.apache.hadoop.hbase.master.snapshot; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.Stoppable; import org.apache.hadoop.hbase.TableName; @@ -52,27 +51,21 @@ import org.apache.hadoop.hbase.util.CommonFSUtils; import org.apache.hadoop.hbase.util.HFileArchiveUtil; import org.apache.zookeeper.KeeperException; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.TestName; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.mockito.Mockito; /** * Test basic snapshot manager functionality */ -@Category({ MasterTests.class, SmallTests.class }) +@Tag(MasterTests.TAG) +@Tag(SmallTests.TAG) public class TestSnapshotManager { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestSnapshotManager.class); - private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); - @Rule - public TestName name = new TestName(); + private String currentTestName; MasterServices services = Mockito.mock(MasterServices.class); ProcedureCoordinator coordinator = Mockito.mock(ProcedureCoordinator.class); @@ -106,23 +99,24 @@ private SnapshotManager getNewManager(Configuration conf, int intervalSeconds) } @Test - public void testCleanFinishedHandler() throws Exception { - TableName tableName = TableName.valueOf(name.getMethodName()); + public void testCleanFinishedHandler(TestInfo testInfo) throws Exception { + currentTestName = testInfo.getTestMethod().get().getName(); + TableName tableName = TableName.valueOf(currentTestName); Configuration conf = UTIL.getConfiguration(); try { conf.setLong(SnapshotManager.HBASE_SNAPSHOT_SENTINELS_CLEANUP_TIMEOUT_MILLIS, 5 * 1000L); SnapshotManager manager = getNewManager(conf, 1); TakeSnapshotHandler handler = Mockito.mock(TakeSnapshotHandler.class); - assertFalse("Manager is in process when there is no current handler", - manager.isTakingSnapshot(tableName)); + assertFalse(manager.isTakingSnapshot(tableName), + "Manager is in process when there is no current handler"); manager.setSnapshotHandlerForTesting(tableName, handler); Mockito.when(handler.isFinished()).thenReturn(false); assertTrue(manager.isTakingAnySnapshot()); - assertTrue("Manager isn't in process when handler is running", - manager.isTakingSnapshot(tableName)); + assertTrue(manager.isTakingSnapshot(tableName), + "Manager isn't in process when handler is running"); Mockito.when(handler.isFinished()).thenReturn(true); - assertFalse("Manager is process when handler isn't running", - manager.isTakingSnapshot(tableName)); + assertFalse(manager.isTakingSnapshot(tableName), + "Manager is process when handler isn't running"); assertTrue(manager.isTakingAnySnapshot()); Thread.sleep(6 * 1000); assertFalse(manager.isTakingAnySnapshot()); @@ -132,19 +126,20 @@ public void testCleanFinishedHandler() throws Exception { } @Test - public void testInProcess() throws KeeperException, IOException { - final TableName tableName = TableName.valueOf(name.getMethodName()); + public void testInProcess(TestInfo testInfo) throws KeeperException, IOException { + currentTestName = testInfo.getTestMethod().get().getName(); + final TableName tableName = TableName.valueOf(currentTestName); SnapshotManager manager = getNewManager(); TakeSnapshotHandler handler = Mockito.mock(TakeSnapshotHandler.class); - assertFalse("Manager is in process when there is no current handler", - manager.isTakingSnapshot(tableName)); + assertFalse(manager.isTakingSnapshot(tableName), + "Manager is in process when there is no current handler"); manager.setSnapshotHandlerForTesting(tableName, handler); Mockito.when(handler.isFinished()).thenReturn(false); - assertTrue("Manager isn't in process when handler is running", - manager.isTakingSnapshot(tableName)); + assertTrue(manager.isTakingSnapshot(tableName), + "Manager isn't in process when handler is running"); Mockito.when(handler.isFinished()).thenReturn(true); - assertFalse("Manager is process when handler isn't running", - manager.isTakingSnapshot(tableName)); + assertFalse(manager.isTakingSnapshot(tableName), + "Manager is process when handler isn't running"); } /** @@ -155,19 +150,19 @@ public void testSnapshotSupportConfiguration() throws Exception { // No configuration (no cleaners, not enabled): snapshot feature disabled Configuration conf = new Configuration(); SnapshotManager manager = getNewManager(conf); - assertFalse("Snapshot should be disabled with no configuration", isSnapshotSupported(manager)); + assertFalse(isSnapshotSupported(manager), "Snapshot should be disabled with no configuration"); // force snapshot feature to be enabled conf = new Configuration(); conf.setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, true); manager = getNewManager(conf); - assertTrue("Snapshot should be enabled", isSnapshotSupported(manager)); + assertTrue(isSnapshotSupported(manager), "Snapshot should be enabled"); // force snapshot feature to be disabled conf = new Configuration(); conf.setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, false); manager = getNewManager(conf); - assertFalse("Snapshot should be disabled", isSnapshotSupported(manager)); + assertFalse(isSnapshotSupported(manager), "Snapshot should be disabled"); // force snapshot feature to be disabled, even if cleaners are present conf = new Configuration(); @@ -175,15 +170,15 @@ public void testSnapshotSupportConfiguration() throws Exception { HFileLinkCleaner.class.getName()); conf.setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, false); manager = getNewManager(conf); - assertFalse("Snapshot should be disabled", isSnapshotSupported(manager)); + assertFalse(isSnapshotSupported(manager), "Snapshot should be disabled"); // cleaners are present, but missing snapshot enabled property conf = new Configuration(); conf.setStrings(HFileCleaner.MASTER_HFILE_CLEANER_PLUGINS, SnapshotHFileCleaner.class.getName(), HFileLinkCleaner.class.getName()); manager = getNewManager(conf); - assertTrue("Snapshot should be enabled, because cleaners are present", - isSnapshotSupported(manager)); + assertTrue(isSnapshotSupported(manager), + "Snapshot should be enabled, because cleaners are present"); // Create a "test snapshot" Path rootDir = UTIL.getDataTestDir(); @@ -204,7 +199,8 @@ public void testSnapshotSupportConfiguration() throws Exception { } @Test - public void testDisableSnapshotAndNotDeleteBackReference() throws Exception { + public void testDisableSnapshotAndNotDeleteBackReference(TestInfo testInfo) throws Exception { + currentTestName = testInfo.getTestMethod().get().getName(); Configuration conf = new Configuration(); conf.setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, false); SnapshotManager manager = getNewManager(conf); @@ -213,8 +209,8 @@ public void testDisableSnapshotAndNotDeleteBackReference() throws Exception { Path rootDir = UTIL.getDataTestDir(); CommonFSUtils.setRootDir(conf, rootDir); - TableName tableName = TableName.valueOf(name.getMethodName()); - TableName tableLinkName = TableName.valueOf(name.getMethodName() + "-link"); + TableName tableName = TableName.valueOf(currentTestName); + TableName tableLinkName = TableName.valueOf(currentTestName + "-link"); String hfileName = "1234567890"; String familyName = "cf"; RegionInfo hri = RegionInfoBuilder.newBuilder(tableName).build(); @@ -254,10 +250,10 @@ public void testDisableSnapshotAndNotDeleteBackReference() throws Exception { CommonFSUtils.getTableDir(archiveDir, tableLinkName)); // Link backref can be removed cleaner.choreForTesting(); - assertFalse("Link should be deleted", fs.exists(linkBackRef)); + assertFalse(fs.exists(linkBackRef), "Link should be deleted"); // HFile can be removed cleaner.choreForTesting(); - assertFalse("HFile should be deleted", fs.exists(hfilePath)); + assertFalse(fs.exists(hfilePath), "HFile should be deleted"); } private Path getFamilyDirPath(final Path rootDir, final TableName table, final String region, diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotStats.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotStats.java index 155d24ae20e4..296afbf4319a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotStats.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestSnapshotStats.java @@ -17,12 +17,11 @@ */ package org.apache.hadoop.hbase.master.snapshot; -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.Optional; -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; @@ -34,33 +33,27 @@ import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.util.Bytes; -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; - -@Category({ MasterTests.class, LargeTests.class }) +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; + +@Tag(MasterTests.TAG) +@Tag(LargeTests.TAG) public class TestSnapshotStats { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestSnapshotStats.class); - private final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); private Admin admin; + private String currentTestName; - @Rule - public TestName name = new TestName(); - - @Before - public void setup() throws Exception { + @BeforeEach + public void setup(TestInfo testInfo) throws Exception { + currentTestName = testInfo.getTestMethod().get().getName(); TEST_UTIL.startMiniCluster(1); admin = TEST_UTIL.getAdmin(); } - @After + @AfterEach public void tearDown() throws IOException { admin.close(); TEST_UTIL.shutdownMiniCluster(); @@ -69,8 +62,7 @@ public void tearDown() throws IOException { @Test public void testSnapshotTableWithoutAnyData() throws IOException { - // Create a table without any data - TableName tableName = TableName.valueOf(name.getMethodName()); + TableName tableName = TableName.valueOf(currentTestName); TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tableName); ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("info")).build(); @@ -78,7 +70,7 @@ public void testSnapshotTableWithoutAnyData() throws IOException { admin.createTable(tableDescriptorBuilder.build()); assertTrue(admin.tableExists(tableName)); - String snapshotName = "snapshot_" + name.getMethodName(); + String snapshotName = "snapshot_" + currentTestName; admin.snapshot(snapshotName, tableName); Optional optional = @@ -98,7 +90,7 @@ public void testSnapshotTableWithoutAnyData() throws IOException { @Test public void testSnapshotMobTableWithoutAnyData() throws IOException { // Create a MOB table without any data - TableName tableName = TableName.valueOf(name.getMethodName()); + TableName tableName = TableName.valueOf(currentTestName); TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tableName); ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("info")).setMobEnabled(true).build(); @@ -106,7 +98,7 @@ public void testSnapshotMobTableWithoutAnyData() throws IOException { admin.createTable(tableDescriptorBuilder.build()); assertTrue(admin.tableExists(tableName)); - String snapshotName = "snapshot_" + name.getMethodName(); + String snapshotName = "snapshot_" + currentTestName; admin.snapshot(snapshotName, tableName); Optional optional = diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestTakeSnapshotHandler.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestTakeSnapshotHandler.java index 5f4e55b80602..d597b838ab8d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestTakeSnapshotHandler.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/snapshot/TestTakeSnapshotHandler.java @@ -17,11 +17,11 @@ */ package org.apache.hadoop.hbase.master.snapshot; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.HashMap; import java.util.Map; -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; @@ -32,13 +32,11 @@ import org.apache.hadoop.hbase.snapshot.SnapshotTTLExpiredException; import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.util.Bytes; -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; /** * Unfortunately, couldn't test TakeSnapshotHandler using mocks, because it relies on TableLock, @@ -46,27 +44,22 @@ * prevents us from mocking its behaviour. Looks like an overkill having to emulate a whole cluster * run for such a small optional property behaviour. */ -@Category({ MediumTests.class }) +@Tag(MediumTests.TAG) public class TestTakeSnapshotHandler { private static HBaseTestingUtil UTIL; + private String currentTestName; - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestTakeSnapshotHandler.class); - - @Rule - public TestName name = new TestName(); - - @Before - public void setup() { + @BeforeEach + public void setup(TestInfo testInfo) { + currentTestName = testInfo.getTestMethod().get().getName(); UTIL = new HBaseTestingUtil(); } public TableDescriptor createTableInsertDataAndTakeSnapshot(Map snapshotProps) throws Exception { TableDescriptor descriptor = - TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName())) + TableDescriptorBuilder.newBuilder(TableName.valueOf(currentTestName)) .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("f")).build()) .build(); UTIL.getConnection().getAdmin().createTable(descriptor); @@ -74,9 +67,9 @@ public TableDescriptor createTableInsertDataAndTakeSnapshot(Map Put put = new Put(Bytes.toBytes("1")); put.addColumn(Bytes.toBytes("f"), Bytes.toBytes("1"), Bytes.toBytes("v1")); table.put(put); - String snapName = "snap" + name.getMethodName(); + String snapName = "snap" + currentTestName; UTIL.getAdmin().snapshot(snapName, descriptor.getTableName(), snapshotProps); - TableName cloned = TableName.valueOf(name.getMethodName() + "clone"); + TableName cloned = TableName.valueOf(currentTestName + "clone"); UTIL.getAdmin().cloneSnapshot(snapName, cloned); return descriptor; } @@ -87,7 +80,7 @@ public void testPreparePreserveMaxFileSizeEnabled() throws Exception { Map snapshotProps = new HashMap<>(); snapshotProps.put(TableDescriptorBuilder.MAX_FILESIZE, Long.parseLong("21474836480")); TableDescriptor descriptor = createTableInsertDataAndTakeSnapshot(snapshotProps); - TableName cloned = TableName.valueOf(name.getMethodName() + "clone"); + TableName cloned = TableName.valueOf(currentTestName + "clone"); assertEquals(-1, UTIL.getAdmin().getDescriptor(descriptor.getTableName()).getMaxFileSize()); assertEquals(21474836480L, UTIL.getAdmin().getDescriptor(cloned).getMaxFileSize()); } @@ -96,20 +89,22 @@ public void testPreparePreserveMaxFileSizeEnabled() throws Exception { public void testPreparePreserveMaxFileSizeDisabled() throws Exception { UTIL.startMiniCluster(); TableDescriptor descriptor = createTableInsertDataAndTakeSnapshot(null); - TableName cloned = TableName.valueOf(name.getMethodName() + "clone"); + TableName cloned = TableName.valueOf(currentTestName + "clone"); assertEquals(-1, UTIL.getAdmin().getDescriptor(descriptor.getTableName()).getMaxFileSize()); assertEquals(-1, UTIL.getAdmin().getDescriptor(cloned).getMaxFileSize()); } - @Test(expected = SnapshotTTLExpiredException.class) + @Test public void testSnapshotEarlyExpiration() throws Exception { UTIL.startMiniCluster(); Map snapshotProps = new HashMap<>(); snapshotProps.put("TTL", 1L); - createTableInsertDataAndTakeSnapshot(snapshotProps); + assertThrows(SnapshotTTLExpiredException.class, () -> { + createTableInsertDataAndTakeSnapshot(snapshotProps); + }); } - @After + @AfterEach public void shutdown() throws Exception { UTIL.shutdownMiniCluster(); }