Skip to content

Commit 881a714

Browse files
authored
HBASE-30011 Upgrade hbase-server to use junit5 Part1 (#8091)
Signed-off-by: Duo Zhang <zhangduo@apache.org> (cherry picked from commit aedef59) (cherry picked from commit f5f745a)
1 parent d8cd864 commit 881a714

File tree

64 files changed

+2678
-2984
lines changed

Some content is hidden

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

64 files changed

+2678
-2984
lines changed

hbase-server/src/test/java/org/apache/hadoop/hbase/filter/FilterTestingCluster.java

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

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

2424
import java.io.IOException;
2525
import java.util.ArrayList;
@@ -35,41 +35,36 @@
3535
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
3636
import org.apache.hadoop.hbase.client.Admin;
3737
import org.apache.hadoop.hbase.client.Table;
38-
import org.apache.hadoop.hbase.testclassification.FilterTests;
39-
import org.apache.hadoop.hbase.testclassification.MediumTests;
4038
import org.apache.hadoop.hbase.util.Bytes;
41-
import org.junit.AfterClass;
42-
import org.junit.BeforeClass;
43-
import org.junit.experimental.categories.Category;
39+
import org.junit.jupiter.api.AfterAll;
4440

4541
/**
4642
* By using this class as the super class of a set of tests you will have a HBase testing cluster
4743
* available that is very suitable for writing tests for scanning and filtering against.
4844
*/
49-
@Category({ FilterTests.class, MediumTests.class })
50-
public class FilterTestingCluster {
45+
public abstract class FilterTestingCluster {
5146
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
5247
private static Admin admin = null;
5348
private static List<TableName> createdTables = new ArrayList<>();
5449

5550
protected static void createTable(TableName tableName, String columnFamilyName) {
56-
assertNotNull("HBaseAdmin is not initialized successfully.", admin);
51+
assertNotNull(admin, "HBaseAdmin is not initialized successfully.");
5752
HTableDescriptor desc = new HTableDescriptor(tableName);
5853
HColumnDescriptor colDef = new HColumnDescriptor(Bytes.toBytes(columnFamilyName));
5954
desc.addFamily(colDef);
6055

6156
try {
6257
admin.createTable(desc);
6358
createdTables.add(tableName);
64-
assertTrue("Fail to create the table", admin.tableExists(tableName));
59+
assertTrue(admin.tableExists(tableName), "Fail to create the table");
6560
} catch (IOException e) {
66-
assertNull("Exception found while creating table", e);
61+
assertNull(e, "Exception found while creating table");
6762
}
6863
}
6964

7065
protected static Table openTable(TableName tableName) throws IOException {
7166
Table table = TEST_UTIL.getConnection().getTable(tableName);
72-
assertTrue("Fail to create the table", admin.tableExists(tableName));
67+
assertTrue(admin.tableExists(tableName), "Fail to create the table");
7368
return table;
7469
}
7570

@@ -82,7 +77,7 @@ private static void deleteTables() {
8277
admin.deleteTable(tableName);
8378
}
8479
} catch (IOException e) {
85-
assertNull("Exception found deleting the table", e);
80+
assertNull(e, "Exception found deleting the table");
8681
}
8782
}
8883
}
@@ -94,21 +89,20 @@ private static void initialize(Configuration conf) {
9489
try {
9590
admin = TEST_UTIL.getAdmin();
9691
} catch (MasterNotRunningException e) {
97-
assertNull("Master is not running", e);
92+
assertNull(e, "Master is not running");
9893
} catch (ZooKeeperConnectionException e) {
99-
assertNull("Cannot connect to ZooKeeper", e);
94+
assertNull(e, "Cannot connect to ZooKeeper");
10095
} catch (IOException e) {
101-
assertNull("IOException", e);
96+
assertNull(e, "IOException");
10297
}
10398
}
10499

105-
@BeforeClass
106100
public static void setUp() throws Exception {
107101
TEST_UTIL.startMiniCluster(1);
108102
initialize(TEST_UTIL.getConfiguration());
109103
}
110104

111-
@AfterClass
105+
@AfterAll
112106
public static void tearDown() throws Exception {
113107
deleteTables();
114108
TEST_UTIL.shutdownMiniCluster();

hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestBigDecimalComparator.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,45 @@
1717
*/
1818
package org.apache.hadoop.hbase.filter;
1919

20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
24+
2025
import java.math.BigDecimal;
21-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2226
import org.apache.hadoop.hbase.testclassification.FilterTests;
2327
import org.apache.hadoop.hbase.testclassification.SmallTests;
2428
import org.apache.hadoop.hbase.util.Bytes;
25-
import org.junit.Assert;
26-
import org.junit.ClassRule;
27-
import org.junit.Test;
28-
import org.junit.experimental.categories.Category;
29+
import org.junit.jupiter.api.Tag;
30+
import org.junit.jupiter.api.Test;
2931

30-
@Category({ FilterTests.class, SmallTests.class })
32+
@Tag(FilterTests.TAG)
33+
@Tag(SmallTests.TAG)
3134
public class TestBigDecimalComparator {
3235

33-
@ClassRule
34-
public static final HBaseClassTestRule CLASS_RULE =
35-
HBaseClassTestRule.forClass(TestBigDecimalComparator.class);
36-
3736
@Test
3837
public void testObjectEquals() {
3938
BigDecimal bd = new BigDecimal(Double.MIN_VALUE);
4039
// Check that equals returns true for identical objects
4140
final BigDecimalComparator bdc = new BigDecimalComparator(bd);
42-
Assert.assertTrue(bdc.equals(bdc));
43-
Assert.assertEquals(bdc.hashCode(), bdc.hashCode());
41+
assertTrue(bdc.equals(bdc));
42+
assertEquals(bdc.hashCode(), bdc.hashCode());
4443

4544
// Check that equals returns true for the same object
4645
final BigDecimalComparator bdc1 = new BigDecimalComparator(bd);
4746
final BigDecimalComparator bdc2 = new BigDecimalComparator(bd);
48-
Assert.assertTrue(bdc1.equals(bdc2));
49-
Assert.assertEquals(bdc1.hashCode(), bdc2.hashCode());
47+
assertTrue(bdc1.equals(bdc2));
48+
assertEquals(bdc1.hashCode(), bdc2.hashCode());
5049

5150
// Check that equals returns false for different objects
5251
final BigDecimalComparator bdc3 = new BigDecimalComparator(bd);
5352
final BigDecimalComparator bdc4 = new BigDecimalComparator(new BigDecimal(Long.MIN_VALUE));
54-
Assert.assertFalse(bdc3.equals(bdc4));
55-
Assert.assertNotEquals(bdc3.hashCode(), bdc4.hashCode());
53+
assertFalse(bdc3.equals(bdc4));
54+
assertNotEquals(bdc3.hashCode(), bdc4.hashCode());
5655

5756
// Check that equals returns false for a different type
5857
final BigDecimalComparator bdc5 = new BigDecimalComparator(bd);
59-
Assert.assertFalse(bdc5.equals(0));
58+
assertFalse(bdc5.equals(0));
6059
}
6160

6261
@Test
@@ -74,8 +73,8 @@ public void testEqualsValue() {
7473
int comp2 = comparator2.compareTo(value2);
7574

7675
// then
77-
Assert.assertEquals(0, comp1);
78-
Assert.assertEquals(0, comp2);
76+
assertEquals(0, comp1);
77+
assertEquals(0, comp2);
7978
}
8079

8180
@Test
@@ -93,9 +92,9 @@ public void testGreaterThanValue() {
9392
int comp3 = comparator.compareTo(val3);
9493

9594
// then
96-
Assert.assertEquals(1, comp1);
97-
Assert.assertEquals(1, comp2);
98-
Assert.assertEquals(1, comp3);
95+
assertEquals(1, comp1);
96+
assertEquals(1, comp2);
97+
assertEquals(1, comp3);
9998
}
10099

101100
@Test
@@ -113,9 +112,9 @@ public void testLessThanValue() {
113112
int comp3 = comparator.compareTo(val3);
114113

115114
// then
116-
Assert.assertEquals(-1, comp1);
117-
Assert.assertEquals(-1, comp2);
118-
Assert.assertEquals(-1, comp3);
115+
assertEquals(-1, comp1);
116+
assertEquals(-1, comp2);
117+
assertEquals(-1, comp3);
119118
}
120119

121120
}

hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestBitComparator.java

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

20-
import static org.junit.Assert.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
2121

2222
import java.nio.ByteBuffer;
23-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2423
import org.apache.hadoop.hbase.testclassification.FilterTests;
2524
import org.apache.hadoop.hbase.testclassification.SmallTests;
26-
import org.junit.ClassRule;
27-
import org.junit.Test;
28-
import org.junit.experimental.categories.Category;
25+
import org.junit.jupiter.api.Tag;
26+
import org.junit.jupiter.api.Test;
2927

3028
/**
3129
* Tests for the bit comparator
3230
*/
33-
@Category({ FilterTests.class, SmallTests.class })
31+
@Tag(FilterTests.TAG)
32+
@Tag(SmallTests.TAG)
3433
public class TestBitComparator {
3534

36-
@ClassRule
37-
public static final HBaseClassTestRule CLASS_RULE =
38-
HBaseClassTestRule.forClass(TestBitComparator.class);
39-
4035
private static byte[] zeros = new byte[] { 0, 0, 0, 0, 0, 0 };
4136
private static ByteBuffer zeros_bb = ByteBuffer.wrap(zeros);
4237
private static byte[] ones = new byte[] { 1, 1, 1, 1, 1, 1 };

hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestColumnPaginationFilter.java

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

20-
import static org.junit.Assert.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2121

22-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2322
import org.apache.hadoop.hbase.KeyValue;
2423
import org.apache.hadoop.hbase.testclassification.FilterTests;
2524
import org.apache.hadoop.hbase.testclassification.SmallTests;
2625
import org.apache.hadoop.hbase.util.Bytes;
27-
import org.junit.Before;
28-
import org.junit.ClassRule;
29-
import org.junit.Test;
30-
import org.junit.experimental.categories.Category;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Tag;
28+
import org.junit.jupiter.api.Test;
3129

3230
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
3331
import org.apache.hadoop.hbase.shaded.protobuf.generated.FilterProtos;
@@ -37,13 +35,10 @@
3735
* filter. More test functionality can be found within
3836
* {@link org.apache.hadoop.hbase.filter.TestFilter#testColumnPaginationFilter()}
3937
*/
40-
@Category({ FilterTests.class, SmallTests.class })
38+
@Tag(FilterTests.TAG)
39+
@Tag(SmallTests.TAG)
4140
public class TestColumnPaginationFilter {
4241

43-
@ClassRule
44-
public static final HBaseClassTestRule CLASS_RULE =
45-
HBaseClassTestRule.forClass(TestColumnPaginationFilter.class);
46-
4742
private static final byte[] ROW = Bytes.toBytes("row_1_test");
4843
private static final byte[] COLUMN_FAMILY = Bytes.toBytes("test");
4944
private static final byte[] VAL_1 = Bytes.toBytes("a");
@@ -52,7 +47,7 @@ public class TestColumnPaginationFilter {
5247
private Filter columnPaginationFilterOffset;
5348
private Filter columnPaginationFilter;
5449

55-
@Before
50+
@BeforeEach
5651
public void setUp() throws Exception {
5752
columnPaginationFilter = getColumnPaginationFilter();
5853
columnPaginationFilterOffset = getColumnPaginationFilterOffset();
@@ -79,7 +74,7 @@ private Filter serializationTest(Filter filter) throws Exception {
7974
*/
8075
private void basicFilterTests(ColumnPaginationFilter filter) throws Exception {
8176
KeyValue c = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_1);
82-
assertTrue("basicFilter1", filter.filterCell(c) == Filter.ReturnCode.INCLUDE_AND_NEXT_COL);
77+
assertTrue(filter.filterCell(c) == Filter.ReturnCode.INCLUDE_AND_NEXT_COL, "basicFilter1");
8378
}
8479

8580
/**

hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestColumnPrefixFilter.java

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

20-
import static org.junit.Assert.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
2121

2222
import java.io.IOException;
2323
import java.util.ArrayList;
@@ -27,7 +27,6 @@
2727
import java.util.Map;
2828
import java.util.Set;
2929
import org.apache.hadoop.hbase.Cell;
30-
import org.apache.hadoop.hbase.HBaseClassTestRule;
3130
import org.apache.hadoop.hbase.HBaseTestingUtility;
3231
import org.apache.hadoop.hbase.HColumnDescriptor;
3332
import org.apache.hadoop.hbase.HRegionInfo;
@@ -43,28 +42,21 @@
4342
import org.apache.hadoop.hbase.testclassification.FilterTests;
4443
import org.apache.hadoop.hbase.testclassification.SmallTests;
4544
import org.apache.hadoop.hbase.util.Bytes;
46-
import org.junit.ClassRule;
47-
import org.junit.Rule;
48-
import org.junit.Test;
49-
import org.junit.experimental.categories.Category;
50-
import org.junit.rules.TestName;
45+
import org.junit.jupiter.api.Tag;
46+
import org.junit.jupiter.api.Test;
47+
import org.junit.jupiter.api.TestInfo;
5148

52-
@Category({ FilterTests.class, SmallTests.class })
49+
@Tag(FilterTests.TAG)
50+
@Tag(SmallTests.TAG)
5351
public class TestColumnPrefixFilter {
5452

55-
@ClassRule
56-
public static final HBaseClassTestRule CLASS_RULE =
57-
HBaseClassTestRule.forClass(TestColumnPrefixFilter.class);
58-
5953
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
6054

61-
@Rule
62-
public TestName name = new TestName();
63-
6455
@Test
65-
public void testColumnPrefixFilter() throws IOException {
56+
public void testColumnPrefixFilter(TestInfo testInfo) throws IOException {
6657
String family = "Family";
67-
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
58+
HTableDescriptor htd =
59+
new HTableDescriptor(TableName.valueOf(testInfo.getTestMethod().get().getName()));
6860
htd.addFamily((new HColumnDescriptor(family)).setMaxVersions(3));
6961
HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
7062
HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(),
@@ -123,9 +115,10 @@ public void testColumnPrefixFilter() throws IOException {
123115
}
124116

125117
@Test
126-
public void testColumnPrefixFilterWithFilterList() throws IOException {
118+
public void testColumnPrefixFilterWithFilterList(TestInfo testInfo) throws IOException {
127119
String family = "Family";
128-
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
120+
HTableDescriptor htd =
121+
new HTableDescriptor(TableName.valueOf(testInfo.getTestMethod().get().getName()));
129122
htd.addFamily((new HColumnDescriptor(family)).setMaxVersions(3));
130123
HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false);
131124
HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.getDataTestDir(),

0 commit comments

Comments
 (0)