Skip to content

Commit 5d5c0f1

Browse files
authored
HBASE-30136 Upgrade hbase-server to use junit5 Part15 (#8283)
Signed-off-by: Duo Zhang <zhangduo@apache.org> (cherry picked from commit c3ff57d)
1 parent 0101e3a commit 5d5c0f1

56 files changed

Lines changed: 1169 additions & 1416 deletions

File tree

Some content is hidden

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

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestAtomicOperation.java

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919

2020
import static org.apache.hadoop.hbase.HBaseTestingUtility.fam1;
2121
import static org.apache.hadoop.hbase.HBaseTestingUtility.fam2;
22-
import static org.junit.Assert.assertEquals;
23-
import static org.junit.Assert.assertNotNull;
24-
import static org.junit.Assert.assertTrue;
25-
import static org.junit.Assert.fail;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertNotNull;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
25+
import static org.junit.jupiter.api.Assertions.fail;
2626

2727
import java.io.IOException;
2828
import java.util.ArrayList;
@@ -38,7 +38,6 @@
3838
import org.apache.hadoop.hbase.Cell;
3939
import org.apache.hadoop.hbase.CellUtil;
4040
import org.apache.hadoop.hbase.CompareOperator;
41-
import org.apache.hadoop.hbase.HBaseClassTestRule;
4241
import org.apache.hadoop.hbase.HBaseTestingUtility;
4342
import org.apache.hadoop.hbase.HColumnDescriptor;
4443
import org.apache.hadoop.hbase.HConstants;
@@ -69,29 +68,23 @@
6968
import org.apache.hadoop.hbase.testclassification.VerySlowRegionServerTests;
7069
import org.apache.hadoop.hbase.util.Bytes;
7170
import org.apache.hadoop.hbase.wal.WAL;
72-
import org.junit.After;
73-
import org.junit.Before;
74-
import org.junit.ClassRule;
75-
import org.junit.Rule;
76-
import org.junit.Test;
77-
import org.junit.experimental.categories.Category;
78-
import org.junit.rules.TestName;
71+
import org.junit.jupiter.api.AfterEach;
72+
import org.junit.jupiter.api.BeforeEach;
73+
import org.junit.jupiter.api.Tag;
74+
import org.junit.jupiter.api.Test;
75+
import org.junit.jupiter.api.TestInfo;
7976
import org.slf4j.Logger;
8077
import org.slf4j.LoggerFactory;
8178

8279
/**
8380
* Testing of HRegion.incrementColumnValue, HRegion.increment, and HRegion.append
8481
*/
85-
@Category({ VerySlowRegionServerTests.class, LargeTests.class }) // Starts 100 threads
82+
@Tag(VerySlowRegionServerTests.TAG)
83+
@Tag(LargeTests.TAG) // Starts 100 threads
8684
public class TestAtomicOperation {
8785

88-
@ClassRule
89-
public static final HBaseClassTestRule CLASS_RULE =
90-
HBaseClassTestRule.forClass(TestAtomicOperation.class);
91-
9286
private static final Logger LOG = LoggerFactory.getLogger(TestAtomicOperation.class);
93-
@Rule
94-
public TestName name = new TestName();
87+
private String name;
9588

9689
HRegion region = null;
9790
private HBaseTestingUtility TEST_UTIL = HBaseTestingUtility.createLocalHTU();
@@ -106,12 +99,13 @@ public class TestAtomicOperation {
10699
static final byte[] row = Bytes.toBytes("rowA");
107100
static final byte[] row2 = Bytes.toBytes("rowB");
108101

109-
@Before
110-
public void setup() {
111-
tableName = Bytes.toBytes(name.getMethodName());
102+
@BeforeEach
103+
public void setup(TestInfo testInfo) {
104+
this.name = testInfo.getTestMethod().get().getName();
105+
tableName = Bytes.toBytes(name);
112106
}
113107

114-
@After
108+
@AfterEach
115109
public void teardown() throws IOException {
116110
if (region != null) {
117111
CacheConfig cacheConfig = region.getStores().get(0).getCacheConfig();
@@ -132,11 +126,11 @@ public void teardown() throws IOException {
132126

133127
/**
134128
* Test basic append operation. More tests in
135-
* @see org.apache.hadoop.hbase.client.TestFromClientSide#testAppend()
129+
* {@link org.apache.hadoop.hbase.client.FromClientSideTest5#testAppend()}.
136130
*/
137131
@Test
138132
public void testAppend() throws IOException {
139-
initHRegion(tableName, name.getMethodName(), fam1);
133+
initHRegion(tableName, name, fam1);
140134
String v1 =
141135
"Ultimate Answer to the Ultimate Question of Life," + " The Universe, and Everything";
142136
String v2 = " is... 42.";
@@ -156,7 +150,7 @@ public void testAppend() throws IOException {
156150
@Test
157151
public void testAppendWithMultipleFamilies() throws IOException {
158152
final byte[] fam3 = Bytes.toBytes("colfamily31");
159-
initHRegion(tableName, name.getMethodName(), fam1, fam2, fam3);
153+
initHRegion(tableName, name, fam1, fam2, fam3);
160154
String v1 = "Appended";
161155
String v2 = "Value";
162156

@@ -165,8 +159,8 @@ public void testAppendWithMultipleFamilies() throws IOException {
165159
a.addColumn(fam1, qual1, Bytes.toBytes(v1));
166160
a.addColumn(fam2, qual2, Bytes.toBytes(v2));
167161
Result result = region.append(a, HConstants.NO_NONCE, HConstants.NO_NONCE);
168-
assertTrue("Expected an empty result but result contains " + result.size() + " keys",
169-
result.isEmpty());
162+
assertTrue(result.isEmpty(),
163+
"Expected an empty result but result contains " + result.size() + " keys");
170164

171165
a = new Append(row);
172166
a.addColumn(fam2, qual2, Bytes.toBytes(v1));
@@ -181,10 +175,10 @@ public void testAppendWithMultipleFamilies() throws IOException {
181175
byte[] actualValue3 = result.getValue(fam3, qual3);
182176
byte[] actualValue4 = result.getValue(fam1, qual2);
183177

184-
assertNotNull("Value1 should bot be null", actualValue1);
185-
assertNotNull("Value2 should bot be null", actualValue2);
186-
assertNotNull("Value3 should bot be null", actualValue3);
187-
assertNotNull("Value4 should bot be null", actualValue4);
178+
assertNotNull(actualValue1, "Value1 should bot be null");
179+
assertNotNull(actualValue2, "Value2 should bot be null");
180+
assertNotNull(actualValue3, "Value3 should bot be null");
181+
assertNotNull(actualValue4, "Value4 should bot be null");
188182
assertEquals(0, Bytes.compareTo(Bytes.toBytes(v1 + v2), actualValue1));
189183
assertEquals(0, Bytes.compareTo(Bytes.toBytes(v2 + v1), actualValue2));
190184
assertEquals(0, Bytes.compareTo(Bytes.toBytes(v2), actualValue3));
@@ -193,7 +187,7 @@ public void testAppendWithMultipleFamilies() throws IOException {
193187

194188
@Test
195189
public void testAppendWithNonExistingFamily() throws IOException {
196-
initHRegion(tableName, name.getMethodName(), fam1);
190+
initHRegion(tableName, name, fam1);
197191
final String v1 = "Value";
198192
final Append a = new Append(row);
199193
a.addColumn(fam1, qual1, Bytes.toBytes(v1));
@@ -211,7 +205,7 @@ public void testAppendWithNonExistingFamily() throws IOException {
211205

212206
@Test
213207
public void testIncrementWithNonExistingFamily() throws IOException {
214-
initHRegion(tableName, name.getMethodName(), fam1);
208+
initHRegion(tableName, name, fam1);
215209
final Increment inc = new Increment(row);
216210
inc.addColumn(fam1, qual1, 1);
217211
inc.addColumn(fam2, qual2, 1);
@@ -236,7 +230,7 @@ public void testIncrementMultiThreads() throws IOException {
236230
boolean fast = true;
237231
LOG.info("Starting test testIncrementMultiThreads");
238232
// run a with mixed column families (1 and 3 versions)
239-
initHRegion(tableName, name.getMethodName(), new int[] { 1, 3 }, fam1, fam2);
233+
initHRegion(tableName, name, new int[] { 1, 3 }, fam1, fam2);
240234

241235
// Create 100 threads, each will increment by its own quantity. All 100 threads update the
242236
// same row over two column families.
@@ -339,8 +333,8 @@ public void run() {
339333
Bytes.toLong(result.getValue(fam1, qual2)));
340334
long fam1Increment = Bytes.toLong(result.getValue(fam1, qual1)) * 3;
341335
long fam2Increment = Bytes.toLong(result.getValue(fam2, qual3));
342-
assertEquals("fam1=" + fam1Increment + ", fam2=" + fam2Increment, fam1Increment,
343-
fam2Increment);
336+
assertEquals(fam1Increment, fam2Increment,
337+
"fam1=" + fam1Increment + ", fam2=" + fam2Increment);
344338
}
345339
} catch (IOException e) {
346340
e.printStackTrace();
@@ -353,7 +347,7 @@ public void run() {
353347
public void testAppendMultiThreads() throws IOException {
354348
LOG.info("Starting test testAppendMultiThreads");
355349
// run a with mixed column families (1 and 3 versions)
356-
initHRegion(tableName, name.getMethodName(), new int[] { 1, 3 }, fam1, fam2);
350+
initHRegion(tableName, name, new int[] { 1, 3 }, fam1, fam2);
357351

358352
int numThreads = 100;
359353
int opsPerThread = 100;
@@ -417,7 +411,7 @@ public void run() {
417411
@Test
418412
public void testRowMutationMultiThreads() throws IOException {
419413
LOG.info("Starting test testRowMutationMultiThreads");
420-
initHRegion(tableName, name.getMethodName(), fam1);
414+
initHRegion(tableName, name, fam1);
421415

422416
// create 10 threads, each will alternate between adding and
423417
// removing a column
@@ -508,7 +502,7 @@ public void run() {
508502
public void testMultiRowMutationMultiThreads() throws IOException {
509503

510504
LOG.info("Starting test testMultiRowMutationMultiThreads");
511-
initHRegion(tableName, name.getMethodName(), fam1);
505+
initHRegion(tableName, name, fam1);
512506

513507
// create 10 threads, each will alternate between adding and
514508
// removing a column
@@ -634,8 +628,8 @@ private enum TestStep {
634628
public void testPutAndCheckAndPutInParallel() throws Exception {
635629
Configuration conf = TEST_UTIL.getConfiguration();
636630
conf.setClass(HConstants.REGION_IMPL, MockHRegion.class, HeapSize.class);
637-
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName()))
638-
.addFamily(new HColumnDescriptor(family));
631+
HTableDescriptor htd =
632+
new HTableDescriptor(TableName.valueOf(name)).addFamily(new HColumnDescriptor(family));
639633
this.region = TEST_UTIL.createLocalHRegion(htd, null, null);
640634
Put[] puts = new Put[1];
641635
Put put = new Put(Bytes.toBytes("r1"));

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBlocksRead.java

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

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

2323
import java.io.IOException;
2424
import java.util.ArrayList;
@@ -28,7 +28,6 @@
2828
import org.apache.hadoop.fs.Path;
2929
import org.apache.hadoop.hbase.Cell;
3030
import org.apache.hadoop.hbase.CellUtil;
31-
import org.apache.hadoop.hbase.HBaseClassTestRule;
3231
import org.apache.hadoop.hbase.HBaseTestingUtility;
3332
import org.apache.hadoop.hbase.TableName;
3433
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
@@ -47,26 +46,26 @@
4746
import org.apache.hadoop.hbase.testclassification.SmallTests;
4847
import org.apache.hadoop.hbase.util.Bytes;
4948
import org.apache.hadoop.hbase.util.EnvironmentEdgeManagerTestHelper;
50-
import org.junit.AfterClass;
51-
import org.junit.BeforeClass;
52-
import org.junit.ClassRule;
53-
import org.junit.Rule;
54-
import org.junit.Test;
55-
import org.junit.experimental.categories.Category;
56-
import org.junit.rules.TestName;
49+
import org.junit.jupiter.api.AfterAll;
50+
import org.junit.jupiter.api.BeforeAll;
51+
import org.junit.jupiter.api.BeforeEach;
52+
import org.junit.jupiter.api.Tag;
53+
import org.junit.jupiter.api.Test;
54+
import org.junit.jupiter.api.TestInfo;
5755
import org.slf4j.Logger;
5856
import org.slf4j.LoggerFactory;
5957

60-
@Category({ RegionServerTests.class, SmallTests.class })
58+
@Tag(RegionServerTests.TAG)
59+
@Tag(SmallTests.TAG)
6160
public class TestBlocksRead {
6261

63-
@ClassRule
64-
public static final HBaseClassTestRule CLASS_RULE =
65-
HBaseClassTestRule.forClass(TestBlocksRead.class);
66-
6762
private static final Logger LOG = LoggerFactory.getLogger(TestBlocksRead.class);
68-
@Rule
69-
public TestName testName = new TestName();
63+
private String testName;
64+
65+
@BeforeEach
66+
public void setTestName(TestInfo testInfo) {
67+
this.testName = testInfo.getTestMethod().get().getName();
68+
}
7069

7170
static final BloomType[] BLOOM_TYPE =
7271
new BloomType[] { BloomType.ROWCOL, BloomType.ROW, BloomType.NONE };
@@ -76,13 +75,13 @@ public class TestBlocksRead {
7675
private final String DIR = TEST_UTIL.getDataTestDir("TestBlocksRead").toString();
7776
private Configuration conf = TEST_UTIL.getConfiguration();
7877

79-
@BeforeClass
78+
@BeforeAll
8079
public static void setUp() throws Exception {
8180
// disable compactions in this test.
8281
TEST_UTIL.getConfiguration().setInt("hbase.hstore.compactionThreshold", 10000);
8382
}
8483

85-
@AfterClass
84+
@AfterAll
8685
public static void tearDown() throws Exception {
8786
EnvironmentEdgeManagerTestHelper.reset();
8887
}
@@ -164,8 +163,8 @@ private Cell[] getData(String family, String row, List<String> columns, int expB
164163
kvs = region.get(get).rawCells();
165164
long blocksEnd = getBlkAccessCount(cf);
166165
if (expBlocks[i] != -1) {
167-
assertEquals("Blocks Read Check for Bloom: " + bloomType, expBlocks[i],
168-
blocksEnd - blocksStart);
166+
assertEquals(expBlocks[i], blocksEnd - blocksStart,
167+
"Blocks Read Check for Bloom: " + bloomType);
169168
}
170169
System.out.println("Blocks Read for Bloom: " + bloomType + " = " + (blocksEnd - blocksStart)
171170
+ "Expected = " + expBlocks[i]);
@@ -194,11 +193,11 @@ private void deleteFamily(String family, String row, long version) throws IOExce
194193

195194
private static void verifyData(Cell kv, String expectedRow, String expectedCol,
196195
long expectedVersion) {
197-
assertTrue("RowCheck", CellUtil.matchingRows(kv, Bytes.toBytes(expectedRow)));
198-
assertTrue("ColumnCheck", CellUtil.matchingQualifier(kv, Bytes.toBytes(expectedCol)));
199-
assertEquals("TSCheck", expectedVersion, kv.getTimestamp());
200-
assertTrue("ValueCheck",
201-
CellUtil.matchingValue(kv, genValue(expectedRow, expectedCol, expectedVersion)));
196+
assertTrue(CellUtil.matchingRows(kv, Bytes.toBytes(expectedRow)), "RowCheck");
197+
assertTrue(CellUtil.matchingQualifier(kv, Bytes.toBytes(expectedCol)), "ColumnCheck");
198+
assertEquals(expectedVersion, kv.getTimestamp(), "TSCheck");
199+
assertTrue(CellUtil.matchingValue(kv, genValue(expectedRow, expectedCol, expectedVersion)),
200+
"ValueCheck");
202201
}
203202

204203
private static long getBlkAccessCount(byte[] cf) {
@@ -213,7 +212,7 @@ public void testBlocksRead() throws Exception {
213212
byte[] TABLE = Bytes.toBytes("testBlocksRead");
214213
String FAMILY = "cf1";
215214
Cell[] kvs;
216-
this.region = initHRegion(TABLE, testName.getMethodName(), conf, FAMILY);
215+
this.region = initHRegion(TABLE, testName, conf, FAMILY);
217216

218217
try {
219218
putData(FAMILY, "row", "col1", 1);
@@ -267,7 +266,7 @@ public void testLazySeekBlocksRead() throws Exception {
267266
byte[] TABLE = Bytes.toBytes("testLazySeekBlocksRead");
268267
String FAMILY = "cf1";
269268
Cell[] kvs;
270-
this.region = initHRegion(TABLE, testName.getMethodName(), conf, FAMILY);
269+
this.region = initHRegion(TABLE, testName, conf, FAMILY);
271270

272271
try {
273272
// File 1
@@ -373,7 +372,7 @@ public void testBlocksStoredWhenCachingDisabled() throws Exception {
373372
String FAMILY = "cf1";
374373

375374
BlockCache blockCache = BlockCacheFactory.createBlockCache(conf);
376-
this.region = initHRegion(TABLE, testName.getMethodName(), conf, FAMILY, blockCache);
375+
this.region = initHRegion(TABLE, testName, conf, FAMILY, blockCache);
377376

378377
try {
379378
putData(FAMILY, "row", "col1", 1);
@@ -417,7 +416,7 @@ public void testLazySeekBlocksReadWithDelete() throws Exception {
417416
byte[] TABLE = Bytes.toBytes("testLazySeekBlocksReadWithDelete");
418417
String FAMILY = "cf1";
419418
Cell[] kvs;
420-
this.region = initHRegion(TABLE, testName.getMethodName(), conf, FAMILY);
419+
this.region = initHRegion(TABLE, testName, conf, FAMILY);
421420
try {
422421
deleteFamily(FAMILY, "row", 200);
423422
for (int i = 0; i < 100; i++) {

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBlocksScanned.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818
package org.apache.hadoop.hbase.regionserver;
1919

2020
import static org.apache.hadoop.hbase.HTestConst.addContent;
21-
import static org.junit.Assert.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
2222

2323
import java.util.ArrayList;
2424
import java.util.List;
2525
import org.apache.hadoop.conf.Configuration;
2626
import org.apache.hadoop.fs.Path;
2727
import org.apache.hadoop.hbase.Cell;
28-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2928
import org.apache.hadoop.hbase.HBaseTestingUtility;
3029
import org.apache.hadoop.hbase.HColumnDescriptor;
3130
import org.apache.hadoop.hbase.HTableDescriptor;
@@ -43,19 +42,15 @@
4342
import org.apache.hadoop.hbase.testclassification.RegionServerTests;
4443
import org.apache.hadoop.hbase.testclassification.SmallTests;
4544
import org.apache.hadoop.hbase.util.Bytes;
46-
import org.junit.Before;
47-
import org.junit.ClassRule;
48-
import org.junit.Test;
49-
import org.junit.experimental.categories.Category;
45+
import org.junit.jupiter.api.BeforeEach;
46+
import org.junit.jupiter.api.Tag;
47+
import org.junit.jupiter.api.Test;
5048

5149
@SuppressWarnings("deprecation")
52-
@Category({ RegionServerTests.class, SmallTests.class })
50+
@Tag(RegionServerTests.TAG)
51+
@Tag(SmallTests.TAG)
5352
public class TestBlocksScanned {
5453

55-
@ClassRule
56-
public static final HBaseClassTestRule CLASS_RULE =
57-
HBaseClassTestRule.forClass(TestBlocksScanned.class);
58-
5954
private static byte[] FAMILY = Bytes.toBytes("family");
6055
private static byte[] COL = Bytes.toBytes("col");
6156
private static byte[] START_KEY = Bytes.toBytes("aaa");
@@ -66,7 +61,7 @@ public class TestBlocksScanned {
6661
private Configuration conf;
6762
private Path testDir;
6863

69-
@Before
64+
@BeforeEach
7065
public void setUp() throws Exception {
7166
TEST_UTIL = new HBaseTestingUtility();
7267
conf = TEST_UTIL.getConfiguration();

0 commit comments

Comments
 (0)