Skip to content

Commit eb3986a

Browse files
authored
HBASE-30082 Upgrade hbase-server to use junit5 Part12 (#8190) (#8253) (#8267)
(cherry picked from commit 61e78cd) Signed-off-by: Xiao Liu <liuxiaocs@apache.org>
1 parent 9ca4d53 commit eb3986a

173 files changed

Lines changed: 4770 additions & 5487 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/client/AbstractTestAsyncTableRegionReplicasRead.java

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

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

2222
import java.io.IOException;
23-
import java.util.Arrays;
2423
import java.util.List;
2524
import java.util.Optional;
2625
import java.util.concurrent.ConcurrentHashMap;
2726
import java.util.concurrent.ConcurrentMap;
2827
import java.util.concurrent.ForkJoinPool;
2928
import java.util.concurrent.atomic.AtomicInteger;
3029
import java.util.function.Supplier;
30+
import java.util.stream.Stream;
3131
import org.apache.hadoop.hbase.Cell;
3232
import org.apache.hadoop.hbase.HBaseTestingUtility;
3333
import org.apache.hadoop.hbase.TableName;
@@ -38,12 +38,9 @@
3838
import org.apache.hadoop.hbase.regionserver.HRegion;
3939
import org.apache.hadoop.hbase.util.Bytes;
4040
import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread;
41-
import org.junit.AfterClass;
42-
import org.junit.Rule;
43-
import org.junit.Test;
44-
import org.junit.rules.TestName;
45-
import org.junit.runners.Parameterized.Parameter;
46-
import org.junit.runners.Parameterized.Parameters;
41+
import org.junit.jupiter.api.AfterAll;
42+
import org.junit.jupiter.api.TestTemplate;
43+
import org.junit.jupiter.params.provider.Arguments;
4744

4845
import org.apache.hbase.thirdparty.com.google.common.io.Closeables;
4946

@@ -65,25 +62,24 @@ public abstract class AbstractTestAsyncTableRegionReplicasRead {
6562

6663
protected static AsyncConnection ASYNC_CONN;
6764

68-
@Rule
69-
public TestName testName = new TestName();
65+
protected Supplier<AsyncTable<?>> getTable;
7066

71-
@Parameter
72-
public Supplier<AsyncTable<?>> getTable;
67+
public static Stream<Arguments> parameters() {
68+
return Stream.of(
69+
Arguments.of((Supplier<AsyncTable<?>>) AbstractTestAsyncTableRegionReplicasRead::getRawTable),
70+
Arguments.of((Supplier<AsyncTable<?>>) AbstractTestAsyncTableRegionReplicasRead::getTable));
71+
}
7372

74-
private static AsyncTable<?> getRawTable() {
75-
return ASYNC_CONN.getTable(TABLE_NAME);
73+
protected AbstractTestAsyncTableRegionReplicasRead(Supplier<AsyncTable<?>> getTable) {
74+
this.getTable = getTable;
7675
}
7776

78-
private static AsyncTable<?> getTable() {
79-
return ASYNC_CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool());
77+
protected static AsyncTable<?> getRawTable() {
78+
return ASYNC_CONN.getTable(TABLE_NAME);
8079
}
8180

82-
@Parameters
83-
public static List<Object[]> params() {
84-
return Arrays.asList(
85-
new Supplier<?>[] { AbstractTestAsyncTableRegionReplicasRead::getRawTable },
86-
new Supplier<?>[] { AbstractTestAsyncTableRegionReplicasRead::getTable });
81+
protected static AsyncTable<?> getTable() {
82+
return ASYNC_CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool());
8783
}
8884

8985
protected static volatile boolean FAIL_PRIMARY_GET = false;
@@ -151,7 +147,7 @@ protected static void waitUntilAllReplicasHaveRow(byte[] row) throws IOException
151147
TEST_UTIL.waitFor(30000, () -> allReplicasHaveRow(row));
152148
}
153149

154-
@AfterClass
150+
@AfterAll
155151
public static void tearDownAfterClass() throws Exception {
156152
Closeables.close(ASYNC_CONN, true);
157153
TEST_UTIL.shutdownMiniCluster();
@@ -171,7 +167,7 @@ protected static int getPrimaryGetCount() {
171167
// replicaId = -1 means do not set replica
172168
protected abstract void readAndCheck(AsyncTable<?> table, int replicaId) throws Exception;
173169

174-
@Test
170+
@TestTemplate
175171
public void testNoReplicaRead() throws Exception {
176172
FAIL_PRIMARY_GET = false;
177173
REPLICA_ID_TO_COUNT.clear();
@@ -183,7 +179,7 @@ public void testNoReplicaRead() throws Exception {
183179
assertEquals(0, getSecondaryGetCount());
184180
}
185181

186-
@Test
182+
@TestTemplate
187183
public void testReplicaRead() throws Exception {
188184
// fail the primary get request
189185
FAIL_PRIMARY_GET = true;
@@ -198,7 +194,7 @@ public void testReplicaRead() throws Exception {
198194
assertEquals(count, getPrimaryGetCount());
199195
}
200196

201-
@Test
197+
@TestTemplate
202198
public void testReadSpecificReplica() throws Exception {
203199
FAIL_PRIMARY_GET = false;
204200
REPLICA_ID_TO_COUNT.clear();

hbase-server/src/test/java/org/apache/hadoop/hbase/client/AbstractTestCIOperationTimeout.java

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

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

2222
import java.io.IOException;
2323
import java.net.SocketTimeoutException;
2424
import org.apache.hadoop.hbase.TableName;
25-
import org.junit.Before;
26-
import org.junit.Test;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
2727
import org.slf4j.Logger;
2828
import org.slf4j.LoggerFactory;
2929

@@ -36,9 +36,9 @@ public abstract class AbstractTestCIOperationTimeout extends AbstractTestCITimeo
3636

3737
private TableName tableName;
3838

39-
@Before
39+
@BeforeEach
4040
public void setUp() throws IOException {
41-
tableName = TableName.valueOf(name.getMethodName());
41+
tableName = name.getTableName();
4242
TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName)
4343
.setCoprocessor(SleepAndFailFirstTime.class.getName())
4444
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAM_NAM)).build();

hbase-server/src/test/java/org/apache/hadoop/hbase/client/AbstractTestCIRpcTimeout.java

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

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

2222
import java.io.IOException;
2323
import org.apache.hadoop.conf.Configuration;
2424
import org.apache.hadoop.hbase.HConstants;
2525
import org.apache.hadoop.hbase.TableName;
26-
import org.junit.Before;
27-
import org.junit.Test;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
2828
import org.slf4j.Logger;
2929
import org.slf4j.LoggerFactory;
3030

@@ -37,9 +37,9 @@ public abstract class AbstractTestCIRpcTimeout extends AbstractTestCITimeout {
3737

3838
private TableName tableName;
3939

40-
@Before
40+
@BeforeEach
4141
public void setUp() throws IOException {
42-
tableName = TableName.valueOf(name.getMethodName());
42+
tableName = name.getTableName();
4343
TableDescriptor htd =
4444
TableDescriptorBuilder.newBuilder(tableName).setCoprocessor(SleepCoprocessor.class.getName())
4545
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAM_NAM)).build();

hbase-server/src/test/java/org/apache/hadoop/hbase/client/AbstractTestCITimeout.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@
2525
import org.apache.hadoop.hbase.Cell;
2626
import org.apache.hadoop.hbase.HBaseTestingUtility;
2727
import org.apache.hadoop.hbase.HConstants;
28+
import org.apache.hadoop.hbase.TableNameTestExtension;
2829
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
2930
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessor;
3031
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
3132
import org.apache.hadoop.hbase.coprocessor.RegionObserver;
3233
import org.apache.hadoop.hbase.util.Bytes;
3334
import org.apache.hadoop.hbase.util.Threads;
3435
import org.apache.hadoop.hbase.wal.WALEdit;
35-
import org.junit.AfterClass;
36-
import org.junit.BeforeClass;
37-
import org.junit.Rule;
38-
import org.junit.rules.TestName;
36+
import org.junit.jupiter.api.AfterAll;
37+
import org.junit.jupiter.api.BeforeAll;
38+
import org.junit.jupiter.api.extension.RegisterExtension;
3939

4040
/**
4141
* Based class for testing timeout logic for {@link ConnectionImplementation}.
@@ -46,8 +46,8 @@ public abstract class AbstractTestCITimeout {
4646

4747
protected static final byte[] FAM_NAM = Bytes.toBytes("f");
4848

49-
@Rule
50-
public final TestName name = new TestName();
49+
@RegisterExtension
50+
protected final TableNameTestExtension name = new TableNameTestExtension();
5151

5252
/**
5353
* This copro sleeps 20 second. The first call it fails. The second time, it works.
@@ -146,7 +146,7 @@ public void preDelete(final ObserverContext<RegionCoprocessorEnvironment> e,
146146
}
147147
}
148148

149-
@BeforeClass
149+
@BeforeAll
150150
public static void setUpBeforeClass() throws Exception {
151151
TEST_UTIL.getConfiguration().setBoolean(HConstants.STATUS_PUBLISHED, true);
152152
// Up the handlers; this test needs more than usual.
@@ -157,7 +157,7 @@ public static void setUpBeforeClass() throws Exception {
157157

158158
}
159159

160-
@AfterClass
160+
@AfterAll
161161
public static void tearDownAfterClass() throws Exception {
162162
TEST_UTIL.shutdownMiniCluster();
163163
}

hbase-server/src/test/java/org/apache/hadoop/hbase/client/AbstractTestRegionLocator.java

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

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

2323
import java.io.IOException;
2424
import java.util.Collections;
@@ -32,8 +32,8 @@
3232
import org.apache.hadoop.hbase.security.User;
3333
import org.apache.hadoop.hbase.util.Bytes;
3434
import org.apache.hadoop.hbase.util.Pair;
35-
import org.junit.After;
36-
import org.junit.Test;
35+
import org.junit.jupiter.api.AfterEach;
36+
import org.junit.jupiter.api.Test;
3737

3838
public abstract class AbstractTestRegionLocator {
3939

@@ -66,7 +66,7 @@ protected static void startClusterAndCreateTable() throws Exception {
6666
UTIL.getAdmin().balancerSwitch(false, true);
6767
}
6868

69-
@After
69+
@AfterEach
7070
public void tearDownAfterTest() throws IOException {
7171
clearCache(TABLE_NAME);
7272
clearCache(TableName.META_TABLE_NAME);

hbase-server/src/test/java/org/apache/hadoop/hbase/client/AbstractTestResultScannerCursor.java

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

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

2424
import java.io.IOException;
25-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
2626

2727
public abstract class AbstractTestResultScannerCursor extends AbstractTestScanCursor {
2828

hbase-server/src/test/java/org/apache/hadoop/hbase/client/AbstractTestScanCursor.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import org.apache.hadoop.hbase.regionserver.StoreScanner;
3434
import org.apache.hadoop.hbase.util.Bytes;
3535
import org.apache.hadoop.hbase.util.Threads;
36-
import org.junit.AfterClass;
37-
import org.junit.BeforeClass;
3836

3937
public abstract class AbstractTestScanCursor {
4038

@@ -62,8 +60,7 @@ public abstract class AbstractTestScanCursor {
6260

6361
protected static final int TIMEOUT = 4000;
6462

65-
@BeforeClass
66-
public static void setUpBeforeClass() throws Exception {
63+
protected static void startCluster() throws Exception {
6764
Configuration conf = TEST_UTIL.getConfiguration();
6865

6966
conf.setInt(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, TIMEOUT);
@@ -97,8 +94,7 @@ private static List<Put> createPuts(byte[][] rows, byte[][] families, byte[][] q
9794
return puts;
9895
}
9996

100-
@AfterClass
101-
public static void tearDownAfterClass() throws Exception {
97+
protected static void stopCluster() throws Exception {
10298
TEST_UTIL.shutdownMiniCluster();
10399
}
104100

hbase-server/src/test/java/org/apache/hadoop/hbase/client/ClientPushbackTestBase.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
package org.apache.hadoop.hbase.client;
1919

2020
import static org.apache.hadoop.hbase.client.MetricsConnection.CLIENT_SIDE_METRICS_ENABLED_KEY;
21-
import static org.junit.Assert.assertEquals;
22-
import static org.junit.Assert.assertNotEquals;
23-
import static org.junit.Assert.assertNotNull;
24-
import static org.junit.Assert.assertTrue;
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
23+
import static org.junit.jupiter.api.Assertions.assertNotNull;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
2525

2626
import java.io.IOException;
2727
import java.util.concurrent.CountDownLatch;
@@ -39,9 +39,9 @@
3939
import org.apache.hadoop.hbase.regionserver.Region;
4040
import org.apache.hadoop.hbase.util.Bytes;
4141
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
42-
import org.junit.AfterClass;
43-
import org.junit.BeforeClass;
44-
import org.junit.Test;
42+
import org.junit.jupiter.api.AfterAll;
43+
import org.junit.jupiter.api.BeforeAll;
44+
import org.junit.jupiter.api.Test;
4545
import org.slf4j.Logger;
4646
import org.slf4j.LoggerFactory;
4747

@@ -58,7 +58,7 @@ public abstract class ClientPushbackTestBase {
5858
private static final byte[] qualifier = Bytes.toBytes("q");
5959
private static final long flushSizeBytes = 512;
6060

61-
@BeforeClass
61+
@BeforeAll
6262
public static void setupCluster() throws Exception {
6363
Configuration conf = UTIL.getConfiguration();
6464
// enable backpressure
@@ -77,7 +77,7 @@ public static void setupCluster() throws Exception {
7777
UTIL.createTable(tableName, family);
7878
}
7979

80-
@AfterClass
80+
@AfterAll
8181
public static void cleanupCluster() throws Exception {
8282
UTIL.shutdownMiniCluster();
8383
}
@@ -112,23 +112,23 @@ public void testClientTracksServerPushback() throws Exception {
112112

113113
// get the stats for the region hosting our table
114114
ClientBackoffPolicy backoffPolicy = getBackoffPolicy();
115-
assertTrue("Backoff policy is not correctly configured",
116-
backoffPolicy instanceof ExponentialClientBackoffPolicy);
115+
assertTrue(backoffPolicy instanceof ExponentialClientBackoffPolicy,
116+
"Backoff policy is not correctly configured");
117117

118118
ServerStatisticTracker stats = getStatisticsTracker();
119-
assertNotNull("No stats configured for the client!", stats);
119+
assertNotNull(stats, "No stats configured for the client!");
120120
// get the names so we can query the stats
121121
ServerName server = rs.getServerName();
122122
byte[] regionName = region.getRegionInfo().getRegionName();
123123

124124
// check to see we found some load on the memstore
125125
ServerStatistics serverStats = stats.getStats(server);
126126
ServerStatistics.RegionStatistics regionStats = serverStats.getStatsForRegion(regionName);
127-
assertEquals("We did not find some load on the memstore", load,
128-
regionStats.getMemStoreLoadPercent());
127+
assertEquals(load, regionStats.getMemStoreLoadPercent(),
128+
"We did not find some load on the memstore");
129129
// check that the load reported produces a nonzero delay
130130
long backoffTime = backoffPolicy.getBackoffTime(server, regionName, serverStats);
131-
assertNotEquals("Reported load does not produce a backoff", 0, backoffTime);
131+
assertNotEquals(0, backoffTime, "Reported load does not produce a backoff");
132132
LOG.debug("Backoff calculated for " + region.getRegionInfo().getRegionNameAsString() + " @ "
133133
+ server + " is " + backoffTime);
134134

@@ -153,12 +153,12 @@ public void testClientTracksServerPushback() throws Exception {
153153

154154
assertEquals(1, runnerStats.delayRunners.getCount());
155155
assertEquals(1, runnerStats.normalRunners.getCount());
156-
assertEquals("", runnerStats.delayIntevalHist.getSnapshot().getMean(), (double) backoffTime,
157-
0.1);
156+
assertEquals(runnerStats.delayIntevalHist.getSnapshot().getMean(), (double) backoffTime, 0.1,
157+
"");
158158

159159
latch.await(backoffTime * 2, TimeUnit.MILLISECONDS);
160-
assertNotEquals("AsyncProcess did not submit the work time", 0, endTime.get());
161-
assertTrue("AsyncProcess did not delay long enough", endTime.get() - startTime >= backoffTime);
160+
assertNotEquals(0, endTime.get(), "AsyncProcess did not submit the work time");
161+
assertTrue(endTime.get() - startTime >= backoffTime, "AsyncProcess did not delay long enough");
162162
}
163163

164164
@Test
@@ -173,7 +173,7 @@ public void testMutateRowStats() throws IOException {
173173
mutateRow(mutations);
174174

175175
ServerStatisticTracker stats = getStatisticsTracker();
176-
assertNotNull("No stats configured for the client!", stats);
176+
assertNotNull(stats, "No stats configured for the client!");
177177
// get the names so we can query the stats
178178
ServerName server = rs.getServerName();
179179
byte[] regionName = region.getRegionInfo().getRegionName();

0 commit comments

Comments
 (0)