From f4f5049036d9cd7114dfef532bea3782c217a1f3 Mon Sep 17 00:00:00 2001 From: Duo Zhang Date: Sat, 18 Apr 2026 23:58:19 +0800 Subject: [PATCH] HBASE-30091 Rewrite CloneSnapshotFromClientTestBase and its sub classes --- ...romClientAfterSplittingRegionTestBase.java | 36 ++++++++----- ...omClientCloneLinksAfterDeleteTestBase.java | 8 +-- .../CloneSnapshotFromClientErrorTestBase.java | 18 +++++-- ...CloneSnapshotFromClientNormalTestBase.java | 12 +++-- .../CloneSnapshotFromClientTestBase.java | 51 ++++++++++--------- ...napshotFromClientAfterSplittingRegion.java | 36 +++++-------- ...apshotFromClientCloneLinksAfterDelete.java | 42 +++++++-------- .../TestCloneSnapshotFromClientCustomSFT.java | 26 ++++++---- .../TestCloneSnapshotFromClientError.java | 36 +++++-------- .../TestCloneSnapshotFromClientNormal.java | 36 +++++-------- ...napshotFromClientAfterSplittingRegion.java | 22 ++++---- ...apshotFromClientCloneLinksAfterDelete.java | 30 +++++------ .../TestMobCloneSnapshotFromClientError.java | 21 ++++---- .../TestMobCloneSnapshotFromClientNormal.java | 21 ++++---- 14 files changed, 195 insertions(+), 200 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientAfterSplittingRegionTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientAfterSplittingRegionTestBase.java index 7f1b7bd445c3..ffdbdfb297a0 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientAfterSplittingRegionTestBase.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientAfterSplittingRegionTestBase.java @@ -17,10 +17,12 @@ */ package org.apache.hadoop.hbase.client; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.IOException; +import java.time.Duration; import java.util.List; import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.TableName; @@ -28,12 +30,17 @@ import org.apache.hadoop.hbase.master.assignment.RegionStates; import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.junit.Test; +import org.junit.jupiter.api.TestTemplate; public class CloneSnapshotFromClientAfterSplittingRegionTestBase extends CloneSnapshotFromClientTestBase { + protected CloneSnapshotFromClientAfterSplittingRegionTestBase(int numReplicas) { + super(numReplicas); + } + private void splitRegion() throws IOException { + int numRegions = admin.getRegions(tableName).size(); try (Table k = TEST_UTIL.getConnection().getTable(tableName); ResultScanner scanner = k.getScanner(new Scan())) { // Split on the second row to make sure that the snapshot contains reference files. @@ -41,13 +48,17 @@ private void splitRegion() throws IOException { scanner.next(); admin.split(tableName, scanner.next().getRow()); } + await().atMost(Duration.ofSeconds(30)) + .untilAsserted(() -> assertEquals(numRegions + 1, admin.getRegions(tableName).size())); } - @Test + @TestTemplate public void testCloneSnapshotAfterSplittingRegion() throws IOException, InterruptedException { // Turn off the CatalogJanitor admin.catalogJanitorSwitch(false); + TableName clonedTableName = + TableName.valueOf(getValidMethodName() + "-" + EnvironmentEdgeManager.currentTime()); try { List regionInfos = admin.getRegions(tableName); RegionReplicaUtil.removeNonDefaultRegions(regionInfos); @@ -59,8 +70,6 @@ public void testCloneSnapshotAfterSplittingRegion() throws IOException, Interrup admin.snapshot(snapshotName2, tableName); // Clone the snapshot to another table - TableName clonedTableName = - TableName.valueOf(getValidMethodName() + "-" + EnvironmentEdgeManager.currentTime()); admin.cloneSnapshot(snapshotName2, clonedTableName); SnapshotTestingUtils.waitForTableToBeOnline(TEST_UTIL, clonedTableName); @@ -90,26 +99,26 @@ public void testCloneSnapshotAfterSplittingRegion() throws IOException, Interrup assertNotNull(daughter); } } - - TEST_UTIL.deleteTable(clonedTableName); } finally { + if (admin.tableExists(clonedTableName)) { + TEST_UTIL.deleteTable(clonedTableName); + } admin.catalogJanitorSwitch(true); } } - @Test + @TestTemplate public void testCloneSnapshotBeforeSplittingRegionAndDroppingTable() throws IOException, InterruptedException { // Turn off the CatalogJanitor admin.catalogJanitorSwitch(false); - + TableName clonedTableName = + TableName.valueOf(getValidMethodName() + "-" + EnvironmentEdgeManager.currentTime()); try { // Take a snapshot admin.snapshot(snapshotName2, tableName); // Clone the snapshot to another table - TableName clonedTableName = - TableName.valueOf(getValidMethodName() + "-" + EnvironmentEdgeManager.currentTime()); admin.cloneSnapshot(snapshotName2, clonedTableName); SnapshotTestingUtils.waitForTableToBeOnline(TEST_UTIL, clonedTableName); @@ -129,6 +138,9 @@ public void testCloneSnapshotBeforeSplittingRegionAndDroppingTable() verifyRowCount(TEST_UTIL, clonedTableName, snapshot1Rows); } finally { + if (admin.tableExists(clonedTableName)) { + TEST_UTIL.deleteTable(clonedTableName); + } admin.catalogJanitorSwitch(true); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientCloneLinksAfterDeleteTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientCloneLinksAfterDeleteTestBase.java index 60f0c64cc22d..2dffd502bab2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientCloneLinksAfterDeleteTestBase.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientCloneLinksAfterDeleteTestBase.java @@ -20,16 +20,18 @@ import java.io.IOException; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.junit.Test; public class CloneSnapshotFromClientCloneLinksAfterDeleteTestBase extends CloneSnapshotFromClientTestBase { + protected CloneSnapshotFromClientCloneLinksAfterDeleteTestBase(int numReplicas) { + super(numReplicas); + } + /** * Verify that tables created from the snapshot are still alive after source table deletion. */ - @Test - public void testCloneLinksAfterDelete() throws IOException, InterruptedException { + protected void testCloneLinksAfterDelete0() throws IOException, InterruptedException { // Clone a table from the first snapshot final TableName clonedTableName = TableName.valueOf(getValidMethodName() + "1-" + EnvironmentEdgeManager.currentTime()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientErrorTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientErrorTestBase.java index ac4d1d5c3a3f..887b410491e7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientErrorTestBase.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientErrorTestBase.java @@ -17,26 +17,34 @@ */ package org.apache.hadoop.hbase.client; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.io.IOException; import org.apache.hadoop.hbase.NamespaceNotFoundException; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.junit.Test; +import org.junit.jupiter.api.TestTemplate; public class CloneSnapshotFromClientErrorTestBase extends CloneSnapshotFromClientTestBase { - @Test(expected = SnapshotDoesNotExistException.class) + protected CloneSnapshotFromClientErrorTestBase(int numReplicas) { + super(numReplicas); + } + + @TestTemplate public void testCloneNonExistentSnapshot() throws IOException, InterruptedException { String snapshotName = "random-snapshot-" + EnvironmentEdgeManager.currentTime(); final TableName tableName = TableName.valueOf(getValidMethodName() + "-" + EnvironmentEdgeManager.currentTime()); - admin.cloneSnapshot(snapshotName, tableName); + assertThrows(SnapshotDoesNotExistException.class, + () -> admin.cloneSnapshot(snapshotName, tableName)); } - @Test(expected = NamespaceNotFoundException.class) + @TestTemplate public void testCloneOnMissingNamespace() throws IOException, InterruptedException { final TableName clonedTableName = TableName.valueOf("unknownNS:" + getValidMethodName()); - admin.cloneSnapshot(snapshotName1, clonedTableName); + assertThrows(NamespaceNotFoundException.class, + () -> admin.cloneSnapshot(snapshotName1, clonedTableName)); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientNormalTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientNormalTestBase.java index a3205875a306..38f0acd18915 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientNormalTestBase.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientNormalTestBase.java @@ -22,11 +22,15 @@ import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.junit.Test; +import org.junit.jupiter.api.TestTemplate; public class CloneSnapshotFromClientNormalTestBase extends CloneSnapshotFromClientTestBase { - @Test + protected CloneSnapshotFromClientNormalTestBase(int numReplicas) { + super(numReplicas); + } + + @TestTemplate public void testCloneSnapshot() throws IOException, InterruptedException { TableName clonedTableName = TableName.valueOf(getValidMethodName() + "-" + EnvironmentEdgeManager.currentTime()); @@ -46,10 +50,10 @@ private void testCloneSnapshot(TableName tableName, String snapshotName, int sna } private void verifyReplicasCameOnline(TableName tableName) throws IOException { - SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); + SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, numReplicas); } - @Test + @TestTemplate public void testCloneSnapshotCrossNamespace() throws IOException, InterruptedException { String nsName = getValidMethodName() + "_ns_" + EnvironmentEdgeManager.currentTime(); admin.createNamespace(NamespaceDescriptor.create(nsName).build()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientTestBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientTestBase.java index 26d93e27507b..4b2ac715c96f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientTestBase.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/CloneSnapshotFromClientTestBase.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hbase.client; import java.io.IOException; +import java.util.stream.Stream; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -25,12 +26,11 @@ import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.params.provider.Arguments; /** * Base class for testing clone snapsot @@ -50,8 +50,17 @@ public class CloneSnapshotFromClientTestBase { protected int snapshot1Rows; protected Admin admin; - @Rule - public TestName name = new TestName(); + protected int numReplicas; + + private String testName; + + protected CloneSnapshotFromClientTestBase(int numReplicas) { + this.numReplicas = numReplicas; + } + + public static Stream parameters() { + return Stream.of(Arguments.of(1), Arguments.of(3)); + } protected static void setupConfiguration() { TEST_UTIL.getConfiguration().setBoolean(SnapshotManager.HBASE_SNAPSHOT_ENABLED, true); @@ -63,19 +72,13 @@ protected static void setupConfiguration() { TEST_UTIL.getConfiguration().setBoolean("hbase.regionserver.compaction.enabled", false); } - @BeforeClass - public static void setUpBeforeClass() throws Exception { - setupConfiguration(); - TEST_UTIL.startMiniCluster(3); - } - - @AfterClass + @AfterAll public static void tearDownAfterClass() throws Exception { TEST_UTIL.shutdownMiniCluster(); } protected final String getValidMethodName() { - return name.getMethodName().replaceAll("[^0-9A-Za-z_]", "_"); + return testName; } /** @@ -83,10 +86,12 @@ protected final String getValidMethodName() { * snapshotName1) of different states. The tableName, snapshotNames and the number of rows in the * snapshot are initialized. */ - @Before - public void setup() throws Exception { + @BeforeEach + public void setUp(TestInfo testInfo) throws Exception { this.admin = TEST_UTIL.getAdmin(); long tid = EnvironmentEdgeManager.currentTime(); + testName = testInfo.getTestMethod().get().getName() + + testInfo.getDisplayName().replaceAll("[^0-9A-Za-z_]", "_"); tableName = TableName.valueOf(getValidMethodName() + tid); emptySnapshot = "emptySnaptb-" + tid; snapshotName0 = "snaptb0-" + tid; @@ -97,7 +102,7 @@ public void setup() throws Exception { } protected void createTable() throws IOException, InterruptedException { - SnapshotTestingUtils.createTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY); + SnapshotTestingUtils.createTable(TEST_UTIL, tableName, numReplicas, FAMILY); } protected int numRowsToLoad() { @@ -105,7 +110,7 @@ protected int numRowsToLoad() { } protected int countRows(Table table) throws IOException { - return TEST_UTIL.countRows(table); + return HBaseTestingUtil.countRows(table); } private void createTableAndSnapshots() throws Exception { @@ -142,16 +147,12 @@ private void createTableAndSnapshots() throws Exception { admin.enableTable(tableName); } - protected int getNumReplicas() { - return 1; - } - protected void verifyRowCount(final HBaseTestingUtil util, final TableName tableName, long expectedRows) throws IOException { SnapshotTestingUtils.verifyRowCount(util, tableName, expectedRows); } - @After + @AfterEach public void tearDown() throws Exception { if (admin.tableExists(tableName)) { TEST_UTIL.deleteTable(tableName); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientAfterSplittingRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientAfterSplittingRegion.java index 2a1eedcd3b70..4f037866758e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientAfterSplittingRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientAfterSplittingRegion.java @@ -17,37 +17,25 @@ */ package org.apache.hadoop.hbase.client; -import java.util.Arrays; -import java.util.List; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; import org.apache.hadoop.hbase.testclassification.ClientTests; import org.apache.hadoop.hbase.testclassification.LargeTests; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; -@RunWith(Parameterized.class) -@Category({ LargeTests.class, ClientTests.class }) +@Tag(LargeTests.TAG) +@Tag(ClientTests.TAG) +@HBaseParameterizedTestTemplate(name = "{index}: regionReplication={0}") public class TestCloneSnapshotFromClientAfterSplittingRegion extends CloneSnapshotFromClientAfterSplittingRegionTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestCloneSnapshotFromClientAfterSplittingRegion.class); - - @Parameter - public int numReplicas; - - @Parameters(name = "{index}: regionReplication={0}") - public static List params() { - return Arrays.asList(new Object[] { 1 }, new Object[] { 3 }); + public TestCloneSnapshotFromClientAfterSplittingRegion(int numReplicas) { + super(numReplicas); } - @Override - protected int getNumReplicas() { - return numReplicas; + @BeforeAll + public static void setUpBeforeClass() throws Exception { + setupConfiguration(); + TEST_UTIL.startMiniCluster(3); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientCloneLinksAfterDelete.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientCloneLinksAfterDelete.java index c70c58513c65..c6bab38cdbd8 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientCloneLinksAfterDelete.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientCloneLinksAfterDelete.java @@ -17,38 +17,32 @@ */ package org.apache.hadoop.hbase.client; -import java.util.Arrays; -import java.util.List; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import java.io.IOException; +import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; import org.apache.hadoop.hbase.testclassification.ClientTests; import org.apache.hadoop.hbase.testclassification.LargeTests; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.TestTemplate; -@RunWith(Parameterized.class) -@Category({ LargeTests.class, ClientTests.class }) +@Tag(LargeTests.TAG) +@Tag(ClientTests.TAG) +@HBaseParameterizedTestTemplate(name = "{index}: regionReplication={0}") public class TestCloneSnapshotFromClientCloneLinksAfterDelete extends CloneSnapshotFromClientCloneLinksAfterDeleteTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestCloneSnapshotFromClientCloneLinksAfterDelete.class); - - @Parameter - public int numReplicas; - - @Parameters(name = "{index}: regionReplication={0}") - public static List params() { - return Arrays.asList(new Object[] { 1 }, new Object[] { 3 }); + public TestCloneSnapshotFromClientCloneLinksAfterDelete(int numReplicas) { + super(numReplicas); } - @Override - protected int getNumReplicas() { - return numReplicas; + @BeforeAll + public static void setUpBeforeClass() throws Exception { + setupConfiguration(); + TEST_UTIL.startMiniCluster(3); } + @TestTemplate + public void testCloneLinksAfterDelete() throws IOException, InterruptedException { + testCloneLinksAfterDelete0(); + } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientCustomSFT.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientCustomSFT.java index f64b75a02ae5..7ac7052724c4 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientCustomSFT.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientCustomSFT.java @@ -17,26 +17,32 @@ */ package org.apache.hadoop.hbase.client; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; -import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory; import org.apache.hadoop.hbase.testclassification.ClientTests; import org.apache.hadoop.hbase.testclassification.LargeTests; 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.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; -@Category({ LargeTests.class, ClientTests.class }) +@Tag(LargeTests.TAG) +@Tag(ClientTests.TAG) public class TestCloneSnapshotFromClientCustomSFT extends CloneSnapshotFromClientTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestCloneSnapshotFromClientCustomSFT.class); + protected TestCloneSnapshotFromClientCustomSFT() { + super(1); + } + + @BeforeAll + public static void setUpBeforeClass() throws Exception { + setupConfiguration(); + TEST_UTIL.startMiniCluster(3); + } public static final String CLONE_SFT = "FILE"; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientError.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientError.java index ea02b7ee0ab8..00fe89004051 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientError.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientError.java @@ -17,36 +17,24 @@ */ package org.apache.hadoop.hbase.client; -import java.util.Arrays; -import java.util.List; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; import org.apache.hadoop.hbase.testclassification.ClientTests; import org.apache.hadoop.hbase.testclassification.LargeTests; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; -@RunWith(Parameterized.class) -@Category({ LargeTests.class, ClientTests.class }) +@Tag(LargeTests.TAG) +@Tag(ClientTests.TAG) +@HBaseParameterizedTestTemplate(name = "{index}: regionReplication={0}") public class TestCloneSnapshotFromClientError extends CloneSnapshotFromClientErrorTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestCloneSnapshotFromClientError.class); - - @Parameter - public int numReplicas; - - @Parameters(name = "{index}: regionReplication={0}") - public static List params() { - return Arrays.asList(new Object[] { 1 }, new Object[] { 3 }); + public TestCloneSnapshotFromClientError(int numReplicas) { + super(numReplicas); } - @Override - protected int getNumReplicas() { - return numReplicas; + @BeforeAll + public static void setUpBeforeClass() throws Exception { + setupConfiguration(); + TEST_UTIL.startMiniCluster(3); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientNormal.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientNormal.java index d52d7a2ce53c..1acb63c47651 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientNormal.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestCloneSnapshotFromClientNormal.java @@ -17,36 +17,24 @@ */ package org.apache.hadoop.hbase.client; -import java.util.Arrays; -import java.util.List; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; import org.apache.hadoop.hbase.testclassification.ClientTests; import org.apache.hadoop.hbase.testclassification.LargeTests; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameter; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; -@RunWith(Parameterized.class) -@Category({ LargeTests.class, ClientTests.class }) +@Tag(LargeTests.TAG) +@Tag(ClientTests.TAG) +@HBaseParameterizedTestTemplate(name = "{index}: regionReplication={0}") public class TestCloneSnapshotFromClientNormal extends CloneSnapshotFromClientNormalTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestCloneSnapshotFromClientNormal.class); - - @Parameter - public int numReplicas; - - @Parameters(name = "{index}: regionReplication={0}") - public static List params() { - return Arrays.asList(new Object[] { 1 }, new Object[] { 3 }); + public TestCloneSnapshotFromClientNormal(int numReplicas) { + super(numReplicas); } - @Override - protected int getNumReplicas() { - return numReplicas; + @BeforeAll + public static void setUpBeforeClass() throws Exception { + setupConfiguration(); + TEST_UTIL.startMiniCluster(3); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobCloneSnapshotFromClientAfterSplittingRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobCloneSnapshotFromClientAfterSplittingRegion.java index 9c7cbd8380dd..96f7f5490e4b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobCloneSnapshotFromClientAfterSplittingRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobCloneSnapshotFromClientAfterSplittingRegion.java @@ -18,32 +18,34 @@ package org.apache.hadoop.hbase.client; import java.io.IOException; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; import org.apache.hadoop.hbase.master.cleaner.TimeToLiveHFileCleaner; import org.apache.hadoop.hbase.mob.MobConstants; import org.apache.hadoop.hbase.snapshot.MobSnapshotTestingUtils; import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; import org.apache.hadoop.hbase.testclassification.ClientTests; import org.apache.hadoop.hbase.testclassification.LargeTests; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; -@Category({ LargeTests.class, ClientTests.class }) +@Tag(LargeTests.TAG) +@Tag(ClientTests.TAG) +@HBaseParameterizedTestTemplate(name = "{index}: regionReplication={0}") public class TestMobCloneSnapshotFromClientAfterSplittingRegion extends CloneSnapshotFromClientAfterSplittingRegionTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMobCloneSnapshotFromClientAfterSplittingRegion.class); + public TestMobCloneSnapshotFromClientAfterSplittingRegion(int numReplicas) { + super(numReplicas); + } protected static void setupConfiguration() { CloneSnapshotFromClientTestBase.setupConfiguration(); + TEST_UTIL.getConfiguration().setLong(TimeToLiveHFileCleaner.TTL_CONF_KEY, 0); TEST_UTIL.getConfiguration().setInt(MobConstants.MOB_FILE_CACHE_SIZE_KEY, 0); } - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { setupConfiguration(); TEST_UTIL.startMiniCluster(3); @@ -52,7 +54,7 @@ public static void setUpBeforeClass() throws Exception { @Override protected void createTable() throws IOException, InterruptedException { MobSnapshotTestingUtils.createMobTable(TEST_UTIL, tableName, - SnapshotTestingUtils.getSplitKeys(), getNumReplicas(), FAMILY); + SnapshotTestingUtils.getSplitKeys(), numReplicas, FAMILY); } @Override diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobCloneSnapshotFromClientCloneLinksAfterDelete.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobCloneSnapshotFromClientCloneLinksAfterDelete.java index e50be218747c..34cc3a179db6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobCloneSnapshotFromClientCloneLinksAfterDelete.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobCloneSnapshotFromClientCloneLinksAfterDelete.java @@ -20,7 +20,7 @@ import java.io.IOException; import java.io.InterruptedIOException; import java.util.Optional; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.TableName; @@ -38,18 +38,19 @@ import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -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.TestTemplate; -@Category({ LargeTests.class, ClientTests.class }) +@Tag(LargeTests.TAG) +@Tag(ClientTests.TAG) +@HBaseParameterizedTestTemplate(name = "{index}: regionReplication={0}") public class TestMobCloneSnapshotFromClientCloneLinksAfterDelete extends CloneSnapshotFromClientCloneLinksAfterDeleteTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMobCloneSnapshotFromClientCloneLinksAfterDelete.class); + public TestMobCloneSnapshotFromClientCloneLinksAfterDelete(int numReplicas) { + super(numReplicas); + } private static boolean delayFlush = false; @@ -87,7 +88,7 @@ protected static void setupConfiguration() { TEST_UTIL.getConfiguration().setInt(MobConstants.MOB_FILE_CACHE_SIZE_KEY, 0); } - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { setupConfiguration(); TEST_UTIL.startMiniCluster(3); @@ -96,7 +97,7 @@ public static void setUpBeforeClass() throws Exception { @Override protected void createTable() throws IOException, InterruptedException { MobSnapshotTestingUtils.createMobTable(TEST_UTIL, tableName, - SnapshotTestingUtils.getSplitKeys(), getNumReplicas(), + SnapshotTestingUtils.getSplitKeys(), numReplicas, StoreFileTrackerFactory.Trackers.DEFAULT.name(), DelayFlushCoprocessor.class.getName(), FAMILY); } @@ -111,8 +112,7 @@ protected int countRows(Table table) throws IOException { return MobSnapshotTestingUtils.countMobRows(table); } - @Test - @Override + @TestTemplate public void testCloneLinksAfterDelete() throws IOException, InterruptedException { // delay the flush to make sure delayFlush = true; @@ -120,7 +120,7 @@ public void testCloneLinksAfterDelete() throws IOException, InterruptedException long tid = EnvironmentEdgeManager.currentTime(); String snapshotName3 = "snaptb3-" + tid; TableName clonedTableName3 = - TableName.valueOf(name.getMethodName() + EnvironmentEdgeManager.currentTime()); + TableName.valueOf(getValidMethodName() + EnvironmentEdgeManager.currentTime()); admin.snapshot(snapshotName3, tableName); delayFlush = false; int snapshot3Rows = -1; @@ -129,7 +129,7 @@ public void testCloneLinksAfterDelete() throws IOException, InterruptedException } admin.cloneSnapshot(snapshotName3, clonedTableName3); admin.deleteSnapshot(snapshotName3); - super.testCloneLinksAfterDelete(); + testCloneLinksAfterDelete0(); verifyRowCount(TEST_UTIL, clonedTableName3, snapshot3Rows); admin.disableTable(clonedTableName3); admin.deleteTable(clonedTableName3); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobCloneSnapshotFromClientError.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobCloneSnapshotFromClientError.java index 0de32ddf4f5c..54b7bb3ab5b2 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobCloneSnapshotFromClientError.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobCloneSnapshotFromClientError.java @@ -18,23 +18,24 @@ package org.apache.hadoop.hbase.client; import java.io.IOException; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; import org.apache.hadoop.hbase.master.cleaner.TimeToLiveHFileCleaner; import org.apache.hadoop.hbase.mob.MobConstants; import org.apache.hadoop.hbase.snapshot.MobSnapshotTestingUtils; import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; import org.apache.hadoop.hbase.testclassification.ClientTests; import org.apache.hadoop.hbase.testclassification.LargeTests; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; -@Category({ LargeTests.class, ClientTests.class }) +@Tag(LargeTests.TAG) +@Tag(ClientTests.TAG) +@HBaseParameterizedTestTemplate(name = "{index}: regionReplication={0}") public class TestMobCloneSnapshotFromClientError extends CloneSnapshotFromClientErrorTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMobCloneSnapshotFromClientError.class); + public TestMobCloneSnapshotFromClientError(int numReplicas) { + super(numReplicas); + } protected static void setupConfiguration() { CloneSnapshotFromClientTestBase.setupConfiguration(); @@ -42,7 +43,7 @@ protected static void setupConfiguration() { TEST_UTIL.getConfiguration().setInt(MobConstants.MOB_FILE_CACHE_SIZE_KEY, 0); } - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { setupConfiguration(); TEST_UTIL.startMiniCluster(3); @@ -51,7 +52,7 @@ public static void setUpBeforeClass() throws Exception { @Override protected void createTable() throws IOException, InterruptedException { MobSnapshotTestingUtils.createMobTable(TEST_UTIL, tableName, - SnapshotTestingUtils.getSplitKeys(), getNumReplicas(), FAMILY); + SnapshotTestingUtils.getSplitKeys(), numReplicas, FAMILY); } @Override diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobCloneSnapshotFromClientNormal.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobCloneSnapshotFromClientNormal.java index c5a33eedd034..8133718b2b53 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobCloneSnapshotFromClientNormal.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMobCloneSnapshotFromClientNormal.java @@ -18,7 +18,7 @@ package org.apache.hadoop.hbase.client; import java.io.IOException; -import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; import org.apache.hadoop.hbase.HBaseTestingUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.master.cleaner.TimeToLiveHFileCleaner; @@ -27,16 +27,17 @@ import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; import org.apache.hadoop.hbase.testclassification.ClientTests; import org.apache.hadoop.hbase.testclassification.LargeTests; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; -@Category({ LargeTests.class, ClientTests.class }) +@Tag(LargeTests.TAG) +@Tag(ClientTests.TAG) +@HBaseParameterizedTestTemplate(name = "{index}: regionReplication={0}") public class TestMobCloneSnapshotFromClientNormal extends CloneSnapshotFromClientNormalTestBase { - @ClassRule - public static final HBaseClassTestRule CLASS_RULE = - HBaseClassTestRule.forClass(TestMobCloneSnapshotFromClientNormal.class); + public TestMobCloneSnapshotFromClientNormal(int numReplicas) { + super(numReplicas); + } protected static void setupConfiguration() { CloneSnapshotFromClientTestBase.setupConfiguration(); @@ -44,7 +45,7 @@ protected static void setupConfiguration() { TEST_UTIL.getConfiguration().setInt(MobConstants.MOB_FILE_CACHE_SIZE_KEY, 0); } - @BeforeClass + @BeforeAll public static void setUpBeforeClass() throws Exception { setupConfiguration(); TEST_UTIL.startMiniCluster(3); @@ -53,7 +54,7 @@ public static void setUpBeforeClass() throws Exception { @Override protected void createTable() throws IOException, InterruptedException { MobSnapshotTestingUtils.createMobTable(TEST_UTIL, tableName, - SnapshotTestingUtils.getSplitKeys(), getNumReplicas(), FAMILY); + SnapshotTestingUtils.getSplitKeys(), numReplicas, FAMILY); } @Override