Skip to content

Commit 2d12633

Browse files
committed
HBASE-30190 Upgrade hbase-server to use junit5 Part21
1 parent 2eb5a34 commit 2d12633

68 files changed

Lines changed: 897 additions & 1246 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-common/src/test/java/org/apache/hadoop/hbase/TableNameTestExtension.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public TableName getTableName() {
4545
return tableName;
4646
}
4747

48+
public TableName getTableName(String suffix) {
49+
return TableName.valueOf(tableName.getNameAsString() + suffix);
50+
}
51+
4852
@Override
4953
public void beforeEach(ExtensionContext context) {
5054
tableName = TableName.valueOf(cleanUpTestName(context.getRequiredTestMethod().getName()));

hbase-mapreduce/src/test/java/org/apache/hadoop/hbase/replication/VerifyReplicationTestBase.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ public void setUp() throws Exception {
8080

8181
@BeforeAll
8282
public static void setUpBeforeClass() throws Exception {
83-
8483
TableDescriptor peerTable =
8584
TableDescriptorBuilder.newBuilder(peerTableName)
8685
.setColumnFamily(

hbase-server/src/test/java/org/apache/hadoop/hbase/replication/ReplicationDroppedTablesTestBase.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
package org.apache.hadoop.hbase.replication;
1919

2020
import static org.apache.hadoop.hbase.replication.regionserver.HBaseInterClusterReplicationEndpoint.REPLICATION_DROP_ON_DELETED_TABLE_KEY;
21-
import static org.junit.Assert.fail;
21+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
22+
import static org.junit.jupiter.api.Assertions.fail;
2223

2324
import java.io.IOException;
2425
import java.util.concurrent.ThreadLocalRandom;
@@ -37,14 +38,13 @@
3738
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
3839
import org.apache.hadoop.hbase.ipc.RpcServer;
3940
import org.apache.hadoop.hbase.util.Bytes;
40-
import org.junit.Assert;
4141
import org.slf4j.Logger;
4242
import org.slf4j.LoggerFactory;
4343

4444
/**
4545
* Base class for testing replication for dropped tables.
4646
*/
47-
public class ReplicationDroppedTablesTestBase extends TestReplicationBase {
47+
public class ReplicationDroppedTablesTestBase extends TestReplicationBaseNoBeforeAll {
4848

4949
private static final Logger LOG = LoggerFactory.getLogger(ReplicationDroppedTablesTestBase.class);
5050

@@ -149,7 +149,7 @@ private boolean peerHasAllNormalRows() throws IOException {
149149
return false;
150150
}
151151
for (int i = 0; i < results.length; i++) {
152-
Assert.assertArrayEquals(generateRowKey(i), results[i].getRow());
152+
assertArrayEquals(generateRowKey(i), results[i].getRow());
153153
}
154154
return true;
155155
}

hbase-server/src/test/java/org/apache/hadoop/hbase/replication/ReplicationKillRSTestBase.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static org.junit.jupiter.api.Assertions.fail;
2121

2222
import org.apache.hadoop.hbase.HBaseTestingUtil;
23-
import org.apache.hadoop.hbase.UnknownScannerException;
2423
import org.apache.hadoop.hbase.client.Connection;
2524
import org.apache.hadoop.hbase.client.ConnectionFactory;
2625
import org.apache.hadoop.hbase.client.Result;
@@ -60,7 +59,7 @@ protected void loadTableAndKillRS(HBaseTestingUtil util) throws Exception {
6059
try (ResultScanner scanner = table.getScanner(new Scan())) {
6160
res = scanner.next(initialCount);
6261
break;
63-
} catch (UnknownScannerException ex) {
62+
} catch (Exception ex) {
6463
LOG.info("Cluster wasn't ready yet, restarting scanner");
6564
}
6665
}
@@ -87,6 +86,10 @@ protected void loadTableAndKillRS(HBaseTestingUtil util) throws Exception {
8786
Result[] res2;
8887
try (ResultScanner scanner = table.getScanner(new Scan())) {
8988
res2 = scanner.next(initialCount * 2);
89+
} catch (Exception e) {
90+
LOG.warn("Cluster wasn't ready yet, sleep and retry later");
91+
Thread.sleep(SLEEP_TIME * 2);
92+
continue;
9093
}
9194
if (res2.length < initialCount) {
9295
if (lastCount < res2.length) {
@@ -113,7 +116,7 @@ private static Thread killARegionServer(final HBaseTestingUtil utility, final lo
113116
public void run() {
114117
try {
115118
Thread.sleep(timeout);
116-
utility.getHBaseCluster().getRegionServer(rs).stop("Stopping as part of the test");
119+
utility.getHBaseCluster().getRegionServer(rs).abort("Stopping as part of the test");
117120
} catch (Exception e) {
118121
LOG.error("Couldn't kill a region server", e);
119122
}

hbase-server/src/test/java/org/apache/hadoop/hbase/replication/SerialReplicationTestBase.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
*/
1818
package org.apache.hadoop.hbase.replication;
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.IOException;
2424
import java.io.UncheckedIOException;
@@ -28,6 +28,7 @@
2828
import org.apache.hadoop.hbase.HBaseTestingUtil;
2929
import org.apache.hadoop.hbase.HConstants;
3030
import org.apache.hadoop.hbase.TableName;
31+
import org.apache.hadoop.hbase.TableNameTestExtension;
3132
import org.apache.hadoop.hbase.Waiter.ExplainingPredicate;
3233
import org.apache.hadoop.hbase.client.Admin;
3334
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
@@ -41,11 +42,10 @@
4142
import org.apache.hadoop.hbase.wal.WALFactory;
4243
import org.apache.hadoop.hbase.wal.WALProvider;
4344
import org.apache.hadoop.hbase.wal.WALStreamReader;
44-
import org.junit.After;
45-
import org.junit.AfterClass;
46-
import org.junit.BeforeClass;
47-
import org.junit.Rule;
48-
import org.junit.rules.TestName;
45+
import org.junit.jupiter.api.AfterAll;
46+
import org.junit.jupiter.api.AfterEach;
47+
import org.junit.jupiter.api.BeforeAll;
48+
import org.junit.jupiter.api.extension.RegisterExtension;
4949

5050
/**
5151
* Base class for testing serial replication.
@@ -66,14 +66,14 @@ public class SerialReplicationTestBase {
6666

6767
protected static WALProvider.Writer WRITER;
6868

69-
@Rule
70-
public final TestName name = new TestName();
69+
@RegisterExtension
70+
protected final TableNameTestExtension tableNameExt = new TableNameTestExtension();
7171

7272
protected Path logPath;
7373

7474
public static final class LocalReplicationEndpoint extends BaseReplicationEndpoint {
7575

76-
private static final UUID PEER_UUID = UTIL.getRandomUUID();
76+
private static final UUID PEER_UUID = HBaseTestingUtil.getRandomUUID();
7777

7878
@Override
7979
public UUID getPeerUUID() {
@@ -121,7 +121,7 @@ public boolean canReplicateToSameCluster() {
121121
}
122122
}
123123

124-
@BeforeClass
124+
@BeforeAll
125125
public static void setUpBeforeClass() throws Exception {
126126
UTIL.getConfiguration().setInt("replication.source.nb.capacity", 10);
127127
UTIL.getConfiguration().setLong("replication.sleep.before.failover", 1000);
@@ -134,12 +134,12 @@ public static void setUpBeforeClass() throws Exception {
134134
FS.mkdirs(LOG_DIR);
135135
}
136136

137-
@AfterClass
137+
@AfterAll
138138
public static void tearDownAfterClass() throws Exception {
139139
UTIL.shutdownMiniCluster();
140140
}
141141

142-
@After
142+
@AfterEach
143143
public void tearDown() throws Exception {
144144
Admin admin = UTIL.getAdmin();
145145
for (ReplicationPeerDescription pd : admin.listReplicationPeers()) {
@@ -188,7 +188,7 @@ public String explainFailure() throws Exception {
188188
}
189189

190190
protected final void setupWALWriter() throws IOException {
191-
logPath = new Path(LOG_DIR, name.getMethodName());
191+
logPath = new Path(LOG_DIR, tableNameExt.getTableName().getNameAsString());
192192
WRITER = WALFactory.createWALWriter(FS, logPath, UTIL.getConfiguration());
193193
}
194194

@@ -235,9 +235,8 @@ protected final void checkOrder(int expectedEntries) throws IOException {
235235
if (entry == null) {
236236
break;
237237
}
238-
assertTrue(
239-
"Sequence id go backwards from " + seqId + " to " + entry.getKey().getSequenceId(),
240-
entry.getKey().getSequenceId() >= seqId);
238+
assertTrue(entry.getKey().getSequenceId() >= seqId,
239+
"Sequence id go backwards from " + seqId + " to " + entry.getKey().getSequenceId());
241240
seqId = entry.getKey().getSequenceId();
242241
count++;
243242
}
@@ -246,7 +245,7 @@ protected final void checkOrder(int expectedEntries) throws IOException {
246245
}
247246

248247
protected final TableName createTable() throws IOException, InterruptedException {
249-
TableName tableName = TableName.valueOf(name.getMethodName());
248+
TableName tableName = tableNameExt.getTableName();
250249
UTIL.getAdmin().createTable(
251250
TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(ColumnFamilyDescriptorBuilder
252251
.newBuilder(CF).setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build()).build());

hbase-server/src/test/java/org/apache/hadoop/hbase/replication/SyncReplicationActiveTestBase.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020
import static org.hamcrest.CoreMatchers.containsString;
2121
import static org.hamcrest.MatcherAssert.assertThat;
22-
import static org.junit.Assert.assertFalse;
23-
import static org.junit.Assert.assertTrue;
24-
import static org.junit.Assert.fail;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertFalse;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
25+
import static org.junit.jupiter.api.Assertions.fail;
2526

2627
import java.util.concurrent.CompletableFuture;
2728
import java.util.concurrent.ExecutionException;
@@ -41,12 +42,12 @@
4142
import org.apache.hadoop.hbase.wal.NoEOFWALStreamReader;
4243
import org.apache.hadoop.hbase.wal.WAL.Entry;
4344
import org.apache.hadoop.hbase.wal.WALStreamReader;
44-
import org.junit.Assert;
45-
import org.junit.Test;
46-
import org.junit.experimental.categories.Category;
45+
import org.junit.jupiter.api.Tag;
46+
import org.junit.jupiter.api.Test;
4747

48-
@Category({ ReplicationTests.class, LargeTests.class })
49-
public class SyncReplicationActiveTestBase extends SyncReplicationTestBase {
48+
@Tag(ReplicationTests.TAG)
49+
@Tag(LargeTests.TAG)
50+
public class SyncReplicationActiveTestBase extends SyncReplicationTestBaseNoBeforeAll {
5051

5152
@Test
5253
public void testActive() throws Exception {
@@ -115,14 +116,14 @@ private void verifyNoClusterIdInRemoteLog(HBaseTestingUtil utility, Path remoteD
115116
throws Exception {
116117
FileSystem fs2 = utility.getTestFileSystem();
117118
FileStatus[] files = fs2.listStatus(new Path(remoteDir, peerId));
118-
Assert.assertTrue(files.length > 0);
119+
assertTrue(files.length > 0);
119120
for (FileStatus file : files) {
120121
try (WALStreamReader reader =
121122
NoEOFWALStreamReader.create(fs2, file.getPath(), utility.getConfiguration())) {
122123
Entry entry = reader.next();
123-
Assert.assertTrue(entry != null);
124+
assertTrue(entry != null);
124125
while (entry != null) {
125-
Assert.assertEquals(entry.getKey().getClusterIds().size(), 0);
126+
assertEquals(entry.getKey().getClusterIds().size(), 0);
126127
entry = reader.next();
127128
}
128129
}

hbase-server/src/test/java/org/apache/hadoop/hbase/replication/SyncReplicationStandbyTestBase.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import static org.hamcrest.Matchers.containsString;
2222
import static org.hamcrest.Matchers.either;
2323
import static org.hamcrest.Matchers.instanceOf;
24-
import static org.junit.Assert.assertFalse;
25-
import static org.junit.Assert.assertThrows;
26-
import static org.junit.Assert.assertTrue;
24+
import static org.junit.jupiter.api.Assertions.assertFalse;
25+
import static org.junit.jupiter.api.Assertions.assertThrows;
26+
import static org.junit.jupiter.api.Assertions.assertTrue;
2727

2828
import java.io.IOException;
2929
import java.util.Arrays;
@@ -40,10 +40,9 @@
4040
import org.apache.hadoop.hbase.client.Table;
4141
import org.apache.hadoop.hbase.master.MasterFileSystem;
4242
import org.apache.hadoop.hbase.util.Bytes;
43-
import org.junit.Assert;
44-
import org.junit.Test;
43+
import org.junit.jupiter.api.Test;
4544

46-
public class SyncReplicationStandbyTestBase extends SyncReplicationTestBase {
45+
public class SyncReplicationStandbyTestBase extends SyncReplicationTestBaseNoBeforeAll {
4746

4847
@FunctionalInterface
4948
private interface TableAction {
@@ -88,12 +87,12 @@ public void testStandby() throws Exception {
8887

8988
// Remove the peers in ACTIVE & STANDBY cluster.
9089
FileSystem fs2 = REMOTE_WAL_DIR2.getFileSystem(UTIL2.getConfiguration());
91-
Assert.assertTrue(fs2.exists(getRemoteWALDir(REMOTE_WAL_DIR2, PEER_ID)));
90+
assertTrue(fs2.exists(getRemoteWALDir(REMOTE_WAL_DIR2, PEER_ID)));
9291

9392
UTIL2.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID,
9493
SyncReplicationState.DOWNGRADE_ACTIVE);
95-
Assert.assertFalse(fs2.exists(getRemoteWALDir(REMOTE_WAL_DIR2, PEER_ID)));
96-
Assert.assertFalse(fs2.exists(getReplayRemoteWALs(REMOTE_WAL_DIR2, PEER_ID)));
94+
assertFalse(fs2.exists(getRemoteWALDir(REMOTE_WAL_DIR2, PEER_ID)));
95+
assertFalse(fs2.exists(getReplayRemoteWALs(REMOTE_WAL_DIR2, PEER_ID)));
9796

9897
UTIL1.getAdmin().removeReplicationPeer(PEER_ID);
9998
verifyRemovedPeer(PEER_ID, REMOTE_WAL_DIR1, UTIL1);
@@ -103,8 +102,8 @@ public void testStandby() throws Exception {
103102
// whether the removeReplicationPeer would remove the remoteWAL dir.
104103
fs2.create(getRemoteWALDir(REMOTE_WAL_DIR2, PEER_ID));
105104
fs2.create(getReplayRemoteWALs(REMOTE_WAL_DIR2, PEER_ID));
106-
Assert.assertTrue(fs2.exists(getRemoteWALDir(REMOTE_WAL_DIR2, PEER_ID)));
107-
Assert.assertTrue(fs2.exists(getReplayRemoteWALs(REMOTE_WAL_DIR2, PEER_ID)));
105+
assertTrue(fs2.exists(getRemoteWALDir(REMOTE_WAL_DIR2, PEER_ID)));
106+
assertTrue(fs2.exists(getReplayRemoteWALs(REMOTE_WAL_DIR2, PEER_ID)));
108107
UTIL2.getAdmin().removeReplicationPeer(PEER_ID);
109108
verifyRemovedPeer(PEER_ID, REMOTE_WAL_DIR2, UTIL2);
110109
}

hbase-server/src/test/java/org/apache/hadoop/hbase/replication/SyncReplicationTestBase.java

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

20-
import org.junit.BeforeClass;
2120
import org.junit.jupiter.api.BeforeAll;
2221

2322
/**
@@ -26,7 +25,6 @@
2625
public class SyncReplicationTestBase extends SyncReplicationTestBaseNoBeforeAll {
2726

2827
@BeforeAll
29-
@BeforeClass
3028
public static void setUp() throws Exception {
3129
startClusters();
3230
}

hbase-server/src/test/java/org/apache/hadoop/hbase/replication/SyncReplicationTestBaseNoBeforeAll.java

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

2020
import static org.hamcrest.CoreMatchers.instanceOf;
2121
import static org.hamcrest.MatcherAssert.assertThat;
22-
import static org.junit.Assert.assertEquals;
23-
import static org.junit.Assert.assertFalse;
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.assertFalse;
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;
@@ -55,7 +55,6 @@
5555
import org.apache.hadoop.hbase.wal.WALEdit;
5656
import org.apache.hadoop.hbase.wal.WALKeyImpl;
5757
import org.apache.hadoop.ipc.RemoteException;
58-
import org.junit.AfterClass;
5958
import org.junit.jupiter.api.AfterAll;
6059

6160
import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap;
@@ -155,7 +154,6 @@ private static void shutdown(HBaseTestingUtil util) throws Exception {
155154
}
156155

157156
@AfterAll
158-
@AfterClass
159157
public static void tearDown() throws Exception {
160158
shutdown(UTIL1);
161159
shutdown(UTIL2);

hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestAddToSerialReplicationPeer.java

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

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

2222
import java.io.IOException;
2323
import java.util.Collections;
2424
import org.apache.hadoop.fs.Path;
25-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2625
import org.apache.hadoop.hbase.TableName;
2726
import org.apache.hadoop.hbase.Waiter.ExplainingPredicate;
2827
import org.apache.hadoop.hbase.client.Put;
@@ -39,24 +38,20 @@
3938
import org.apache.hadoop.hbase.util.Bytes;
4039
import org.apache.hadoop.hbase.util.CommonFSUtils.StreamLacksCapabilityException;
4140
import org.apache.hadoop.hbase.wal.AbstractFSWALProvider;
42-
import org.junit.Before;
43-
import org.junit.ClassRule;
44-
import org.junit.Test;
45-
import org.junit.experimental.categories.Category;
41+
import org.junit.jupiter.api.BeforeEach;
42+
import org.junit.jupiter.api.Tag;
43+
import org.junit.jupiter.api.Test;
4644

4745
import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap;
4846

4947
/**
5048
* Testcase for HBASE-20147.
5149
*/
52-
@Category({ ReplicationTests.class, LargeTests.class })
50+
@Tag(ReplicationTests.TAG)
51+
@Tag(LargeTests.TAG)
5352
public class TestAddToSerialReplicationPeer extends SerialReplicationTestBase {
5453

55-
@ClassRule
56-
public static final HBaseClassTestRule CLASS_RULE =
57-
HBaseClassTestRule.forClass(TestAddToSerialReplicationPeer.class);
58-
59-
@Before
54+
@BeforeEach
6055
public void setUp() throws IOException, StreamLacksCapabilityException {
6156
setupWALWriter();
6257
}

0 commit comments

Comments
 (0)