Skip to content

Commit 8d89599

Browse files
authored
HBASE-29967 Upgrade hbase-backup to use junit5 (#7859)
Signed-off-by: Duo Zhang <zhangduo@apache.org>
1 parent 531f91c commit 8d89599

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+432
-652
lines changed

hbase-backup/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,6 @@
177177
<artifactId>junit-jupiter-params</artifactId>
178178
<scope>test</scope>
179179
</dependency>
180-
<dependency>
181-
<groupId>org.junit.vintage</groupId>
182-
<artifactId>junit-vintage-engine</artifactId>
183-
<scope>test</scope>
184-
</dependency>
185180
</dependencies>
186181
<build>
187182
<plugins>

hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/IncrementalBackupRestoreTestBase.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.apache.hadoop.hbase.util.Bytes;
3939
import org.apache.hadoop.hbase.util.CommonFSUtils;
4040
import org.apache.hadoop.hbase.util.HFileTestUtil;
41-
import org.junit.jupiter.api.BeforeAll;
4241

4342
import org.apache.hbase.thirdparty.com.google.common.base.Throwables;
4443

@@ -47,10 +46,8 @@ public class IncrementalBackupRestoreTestBase extends TestBackupBase {
4746
private static final byte[] BULKLOAD_START_KEY = new byte[] { 0x00 };
4847
private static final byte[] BULKLOAD_END_KEY = new byte[] { Byte.MAX_VALUE };
4948

50-
@BeforeAll
51-
public static void setUp() throws Exception {
49+
static {
5250
provider = "multiwal";
53-
TestBackupBase.setUp();
5451
}
5552

5653
protected void checkThrowsCFMismatch(IOException ex, List<TableName> tables) {

hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestBackupBase.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@
6666
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
6767
import org.apache.hadoop.hbase.wal.AbstractFSWALProvider;
6868
import org.apache.hadoop.hbase.wal.WALFactory;
69-
import org.junit.AfterClass;
70-
import org.junit.Before;
71-
import org.junit.BeforeClass;
7269
import org.junit.jupiter.api.AfterAll;
7370
import org.junit.jupiter.api.BeforeAll;
7471
import org.junit.jupiter.api.BeforeEach;
@@ -120,7 +117,6 @@ public IncrementalTableBackupClientForTest(Connection conn, String backupId,
120117
}
121118

122119
@BeforeEach
123-
@Before
124120
public void ensurePreviousBackupTestsAreCleanedUp() throws Exception {
125121
// Every operation here may not be necessary for any given test,
126122
// some often being no-ops. the goal is to help ensure atomicity
@@ -348,7 +344,6 @@ public static void setUpHelper() throws Exception {
348344
* @throws Exception if starting the mini cluster or setting up the tables fails
349345
*/
350346
@BeforeAll
351-
@BeforeClass
352347
public static void setUp() throws Exception {
353348
TEST_UTIL = new HBaseTestingUtil();
354349
conf1 = TEST_UTIL.getConfiguration();
@@ -366,7 +361,6 @@ private static void populateFromMasterConfig(Configuration masterConf, Configura
366361
}
367362

368363
@AfterAll
369-
@AfterClass
370364
public static void tearDown() throws Exception {
371365
try {
372366
SnapshotTestingUtils.deleteAllSnapshots(TEST_UTIL.getAdmin());

hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestBackupBoundaryTests.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,22 @@
1717
*/
1818
package org.apache.hadoop.hbase.backup;
1919

20+
import static org.junit.jupiter.api.Assertions.assertThrows;
21+
2022
import java.io.IOException;
2123
import java.util.List;
22-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2324
import org.apache.hadoop.hbase.TableName;
2425
import org.apache.hadoop.hbase.testclassification.LargeTests;
25-
import org.junit.ClassRule;
26-
import org.junit.Test;
27-
import org.junit.experimental.categories.Category;
26+
import org.junit.jupiter.api.Tag;
27+
import org.junit.jupiter.api.Test;
2828
import org.slf4j.Logger;
2929
import org.slf4j.LoggerFactory;
3030

3131
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
3232

33-
@Category(LargeTests.class)
33+
@Tag(LargeTests.TAG)
3434
public class TestBackupBoundaryTests extends TestBackupBase {
3535

36-
@ClassRule
37-
public static final HBaseClassTestRule CLASS_RULE =
38-
HBaseClassTestRule.forClass(TestBackupBoundaryTests.class);
39-
4036
private static final Logger LOG = LoggerFactory.getLogger(TestBackupBoundaryTests.class);
4137

4238
/**
@@ -66,33 +62,39 @@ public void testFullBackupMultipleEmpty() throws Exception {
6662
* Verify that full backup fails on a single table that does not exist.
6763
* @throws Exception if doing the full backup fails
6864
*/
69-
@Test(expected = IOException.class)
65+
@Test
7066
public void testFullBackupSingleDNE() throws Exception {
71-
LOG.info("test full backup fails on a single table that does not exist");
72-
List<TableName> tables = toList("tabledne");
73-
fullTableBackup(tables);
67+
assertThrows(IOException.class, () -> {
68+
LOG.info("test full backup fails on a single table that does not exist");
69+
List<TableName> tables = toList("tabledne");
70+
fullTableBackup(tables);
71+
});
7472
}
7573

7674
/**
7775
* Verify that full backup fails on multiple tables that do not exist.
7876
* @throws Exception if doing the full backup fails
7977
*/
80-
@Test(expected = IOException.class)
78+
@Test
8179
public void testFullBackupMultipleDNE() throws Exception {
82-
LOG.info("test full backup fails on multiple tables that do not exist");
83-
List<TableName> tables = toList("table1dne", "table2dne");
84-
fullTableBackup(tables);
80+
assertThrows(IOException.class, () -> {
81+
LOG.info("test full backup fails on multiple tables that do not exist");
82+
List<TableName> tables = toList("table1dne", "table2dne");
83+
fullTableBackup(tables);
84+
});
8585
}
8686

8787
/**
8888
* Verify that full backup fails on tableset containing real and fake tables.
8989
* @throws Exception if doing the full backup fails
9090
*/
91-
@Test(expected = IOException.class)
91+
@Test
9292
public void testFullBackupMixExistAndDNE() throws Exception {
93-
LOG.info("create full backup fails on tableset containing real and fake table");
93+
assertThrows(IOException.class, () -> {
94+
LOG.info("create full backup fails on tableset containing real and fake table");
9495

95-
List<TableName> tables = toList(table1.getNameAsString(), "tabledne");
96-
fullTableBackup(tables);
96+
List<TableName> tables = toList(table1.getNameAsString(), "tabledne");
97+
fullTableBackup(tables);
98+
});
9799
}
98100
}

hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestBackupCommandLineTool.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,22 @@
1717
*/
1818
package org.apache.hadoop.hbase.backup;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

2323
import java.io.ByteArrayOutputStream;
2424
import java.io.PrintStream;
2525
import org.apache.hadoop.conf.Configuration;
26-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2726
import org.apache.hadoop.hbase.HBaseConfiguration;
2827
import org.apache.hadoop.hbase.testclassification.SmallTests;
2928
import org.apache.hadoop.util.ToolRunner;
30-
import org.junit.Before;
31-
import org.junit.ClassRule;
32-
import org.junit.Test;
33-
import org.junit.experimental.categories.Category;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Tag;
31+
import org.junit.jupiter.api.Test;
3432

35-
@Category(SmallTests.class)
33+
@Tag(SmallTests.TAG)
3634
public class TestBackupCommandLineTool {
3735

38-
@ClassRule
39-
public static final HBaseClassTestRule CLASS_RULE =
40-
HBaseClassTestRule.forClass(TestBackupCommandLineTool.class);
41-
4236
private final static String USAGE_DESCRIBE = "Usage: hbase backup describe <backup_id>";
4337
private final static String USAGE_CREATE = "Usage: hbase backup create";
4438
private final static String USAGE_HISTORY = "Usage: hbase backup history";
@@ -50,7 +44,7 @@ public class TestBackupCommandLineTool {
5044

5145
Configuration conf;
5246

53-
@Before
47+
@BeforeEach
5448
public void setUpBefore() throws Exception {
5549
conf = HBaseConfiguration.create();
5650
conf.setBoolean(BackupRestoreConstants.BACKUP_ENABLE_KEY, true);

hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDelete.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,32 @@
1717
*/
1818
package org.apache.hadoop.hbase.backup;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
22+
import static org.junit.jupiter.api.Assertions.fail;
2223

2324
import java.io.ByteArrayOutputStream;
2425
import java.io.PrintStream;
2526
import java.util.List;
2627
import org.apache.hadoop.fs.FileSystem;
2728
import org.apache.hadoop.fs.Path;
28-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2929
import org.apache.hadoop.hbase.TableName;
3030
import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
3131
import org.apache.hadoop.hbase.testclassification.LargeTests;
3232
import org.apache.hadoop.hbase.util.EnvironmentEdge;
3333
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
3434
import org.apache.hadoop.util.ToolRunner;
35-
import org.junit.Assert;
36-
import org.junit.ClassRule;
37-
import org.junit.Test;
38-
import org.junit.experimental.categories.Category;
35+
import org.junit.jupiter.api.Tag;
36+
import org.junit.jupiter.api.Test;
3937
import org.slf4j.Logger;
4038
import org.slf4j.LoggerFactory;
4139

4240
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
4341
import org.apache.hbase.thirdparty.com.google.common.collect.Sets;
4442

45-
@Category(LargeTests.class)
43+
@Tag(LargeTests.TAG)
4644
public class TestBackupDelete extends TestBackupBase {
4745

48-
@ClassRule
49-
public static final HBaseClassTestRule CLASS_RULE =
50-
HBaseClassTestRule.forClass(TestBackupDelete.class);
51-
5246
private static final Logger LOG = LoggerFactory.getLogger(TestBackupDelete.class);
5347

5448
/**
@@ -138,7 +132,7 @@ public long currentTime() {
138132
assertTrue(ret == 0);
139133
} catch (Exception e) {
140134
LOG.error("failed", e);
141-
Assert.fail(e.getMessage());
135+
fail(e.getMessage());
142136
}
143137
String output = baos.toString();
144138
LOG.info(baos.toString());
@@ -154,7 +148,7 @@ public long currentTime() {
154148
assertTrue(ret == 0);
155149
} catch (Exception e) {
156150
LOG.error("failed", e);
157-
Assert.fail(e.getMessage());
151+
fail(e.getMessage());
158152
}
159153
output = baos.toString();
160154
LOG.info(baos.toString());

hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDeleteRestore.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,27 @@
1717
*/
1818
package org.apache.hadoop.hbase.backup;
1919

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

2323
import java.util.List;
24-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2524
import org.apache.hadoop.hbase.TableName;
2625
import org.apache.hadoop.hbase.backup.util.BackupUtils;
2726
import org.apache.hadoop.hbase.client.Admin;
2827
import org.apache.hadoop.hbase.client.Delete;
2928
import org.apache.hadoop.hbase.client.Table;
3029
import org.apache.hadoop.hbase.testclassification.LargeTests;
3130
import org.apache.hadoop.hbase.util.Bytes;
32-
import org.junit.ClassRule;
33-
import org.junit.Test;
34-
import org.junit.experimental.categories.Category;
31+
import org.junit.jupiter.api.Tag;
32+
import org.junit.jupiter.api.Test;
3533
import org.slf4j.Logger;
3634
import org.slf4j.LoggerFactory;
3735

3836
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
3937

40-
@Category(LargeTests.class)
38+
@Tag(LargeTests.TAG)
4139
public class TestBackupDeleteRestore extends TestBackupBase {
4240

43-
@ClassRule
44-
public static final HBaseClassTestRule CLASS_RULE =
45-
HBaseClassTestRule.forClass(TestBackupDeleteRestore.class);
46-
4741
private static final Logger LOG = LoggerFactory.getLogger(TestBackupDeleteRestore.class);
4842

4943
/**

hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDeleteWithFailures.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717
*/
1818
package org.apache.hadoop.hbase.backup;
1919

20-
import static org.junit.Assert.assertNull;
21-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertNull;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

2323
import java.io.IOException;
2424
import java.util.ArrayList;
2525
import java.util.List;
2626
import java.util.Optional;
2727
import org.apache.hadoop.fs.FileSystem;
2828
import org.apache.hadoop.fs.Path;
29-
import org.apache.hadoop.hbase.HBaseClassTestRule;
3029
import org.apache.hadoop.hbase.HBaseTestingUtil;
3130
import org.apache.hadoop.hbase.HConstants;
3231
import org.apache.hadoop.hbase.TableName;
@@ -42,10 +41,9 @@
4241
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
4342
import org.apache.hadoop.hbase.testclassification.LargeTests;
4443
import org.apache.hadoop.util.ToolRunner;
45-
import org.junit.BeforeClass;
46-
import org.junit.ClassRule;
47-
import org.junit.Test;
48-
import org.junit.experimental.categories.Category;
44+
import org.junit.jupiter.api.BeforeAll;
45+
import org.junit.jupiter.api.Tag;
46+
import org.junit.jupiter.api.Test;
4947
import org.slf4j.Logger;
5048
import org.slf4j.LoggerFactory;
5149

@@ -56,13 +54,9 @@
5654
* TestBackupSmallTests is where tests that don't require bring machines up/down should go All other
5755
* tests should have their own classes and extend this one
5856
*/
59-
@Category(LargeTests.class)
57+
@Tag(LargeTests.TAG)
6058
public class TestBackupDeleteWithFailures extends TestBackupBase {
6159

62-
@ClassRule
63-
public static final HBaseClassTestRule CLASS_RULE =
64-
HBaseClassTestRule.forClass(TestBackupDeleteWithFailures.class);
65-
6660
private static final Logger LOG = LoggerFactory.getLogger(TestBackupDeleteWithFailures.class);
6761

6862
public enum Failure {
@@ -117,7 +111,7 @@ public void postDeleteSnapshot(ObserverContext<MasterCoprocessorEnvironment> ctx
117111
* Setup Cluster with appropriate configurations before running tests.
118112
* @throws Exception if starting the mini cluster or setting up the tables fails
119113
*/
120-
@BeforeClass
114+
@BeforeAll
121115
public static void setUp() throws Exception {
122116
TEST_UTIL = new HBaseTestingUtil();
123117
conf1 = TEST_UTIL.getConfiguration();

hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDescribe.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,28 @@
1717
*/
1818
package org.apache.hadoop.hbase.backup;
1919

20-
import static org.junit.Assert.assertNotEquals;
21-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2222

2323
import java.io.ByteArrayOutputStream;
2424
import java.io.PrintStream;
2525
import java.util.List;
26-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2726
import org.apache.hadoop.hbase.TableName;
2827
import org.apache.hadoop.hbase.backup.BackupInfo.BackupState;
2928
import org.apache.hadoop.hbase.backup.impl.BackupCommands;
3029
import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
3130
import org.apache.hadoop.hbase.testclassification.LargeTests;
3231
import org.apache.hadoop.util.ToolRunner;
33-
import org.junit.ClassRule;
34-
import org.junit.Test;
35-
import org.junit.experimental.categories.Category;
32+
import org.junit.jupiter.api.Tag;
33+
import org.junit.jupiter.api.Test;
3634
import org.slf4j.Logger;
3735
import org.slf4j.LoggerFactory;
3836

3937
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
4038

41-
@Category(LargeTests.class)
39+
@Tag(LargeTests.TAG)
4240
public class TestBackupDescribe extends TestBackupBase {
4341

44-
@ClassRule
45-
public static final HBaseClassTestRule CLASS_RULE =
46-
HBaseClassTestRule.forClass(TestBackupDescribe.class);
47-
4842
private static final Logger LOG = LoggerFactory.getLogger(TestBackupDescribe.class);
4943

5044
/**

0 commit comments

Comments
 (0)