Skip to content

Commit d430f2a

Browse files
authored
HBASE-30063 Upgrade hbase-server to use junit5 Part7 (#8031)
Signed-off-by: Duo Zhang <zhangduo@apache.org>
1 parent b316753 commit d430f2a

79 files changed

Lines changed: 1074 additions & 1445 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/master/AbstractTestDLS.java

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
import static org.apache.hadoop.hbase.HConstants.HBASE_SPLIT_WAL_MAX_SPLITTER;
2121
import static org.apache.hadoop.hbase.SplitLogCounters.tot_mgr_wait_for_zk_delete;
22-
import static org.junit.Assert.assertEquals;
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.assertTrue;
24+
import static org.junit.jupiter.api.Assertions.fail;
2525

2626
import java.io.IOException;
2727
import java.util.ArrayList;
@@ -69,13 +69,12 @@
6969
import org.apache.hadoop.hbase.wal.WALEditInternalHelper;
7070
import org.apache.hadoop.hbase.wal.WALKeyImpl;
7171
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
72-
import org.junit.After;
73-
import org.junit.AfterClass;
74-
import org.junit.Before;
75-
import org.junit.BeforeClass;
76-
import org.junit.Rule;
77-
import org.junit.Test;
78-
import org.junit.rules.TestName;
72+
import org.junit.jupiter.api.AfterAll;
73+
import org.junit.jupiter.api.AfterEach;
74+
import org.junit.jupiter.api.BeforeAll;
75+
import org.junit.jupiter.api.BeforeEach;
76+
import org.junit.jupiter.api.Test;
77+
import org.junit.jupiter.api.TestInfo;
7978
import org.slf4j.Logger;
8079
import org.slf4j.LoggerFactory;
8180

@@ -94,18 +93,12 @@ public abstract class AbstractTestDLS {
9493
private static final int NUM_RS = 5;
9594
private static byte[] COLUMN_FAMILY = Bytes.toBytes("family");
9695

97-
@Rule
98-
public TestName testName = new TestName();
99-
10096
private TableName tableName;
10197
private SingleProcessHBaseCluster cluster;
10298
private HMaster master;
10399
private Configuration conf;
104100

105-
@Rule
106-
public TestName name = new TestName();
107-
108-
@BeforeClass
101+
@BeforeAll
109102
public static void setup() throws Exception {
110103
// Uncomment the following line if more verbosity is needed for
111104
// debugging (see HBASE-12285 for details).
@@ -114,7 +107,7 @@ public static void setup() throws Exception {
114107
TEST_UTIL.startMiniDFSCluster(3);
115108
}
116109

117-
@AfterClass
110+
@AfterAll
118111
public static void tearDown() throws Exception {
119112
TEST_UTIL.shutdownMiniCluster();
120113
}
@@ -147,13 +140,13 @@ public boolean evaluate() throws Exception {
147140
});
148141
}
149142

150-
@Before
151-
public void before() throws Exception {
143+
@BeforeEach
144+
public void before(TestInfo testInfo) throws Exception {
152145
conf = TEST_UTIL.getConfiguration();
153-
tableName = TableName.valueOf(testName.getMethodName());
146+
tableName = TableName.valueOf(testInfo.getTestMethod().get().getName());
154147
}
155148

156-
@After
149+
@AfterEach
157150
public void after() throws Exception {
158151
TEST_UTIL.shutdownMiniHBaseCluster();
159152
TEST_UTIL.getTestFileSystem().delete(CommonFSUtils.getRootDir(TEST_UTIL.getConfiguration()),
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.master;
19+
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
22+
import java.util.concurrent.atomic.AtomicBoolean;
23+
import java.util.concurrent.atomic.AtomicInteger;
24+
import org.apache.hadoop.hbase.HBaseTestingUtil;
25+
import org.apache.hadoop.hbase.HConstants;
26+
import org.apache.hadoop.hbase.ServerName;
27+
import org.apache.hadoop.hbase.SingleProcessHBaseCluster;
28+
import org.apache.hadoop.hbase.StartTestingClusterOption;
29+
import org.apache.hadoop.hbase.TableName;
30+
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
31+
import org.apache.hadoop.hbase.client.TableDescriptor;
32+
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
33+
import org.apache.hadoop.hbase.master.hbck.HbckChore;
34+
import org.apache.hadoop.hbase.master.hbck.HbckReport;
35+
import org.apache.hadoop.hbase.regionserver.HRegion;
36+
import org.apache.hadoop.hbase.util.Bytes;
37+
import org.junit.jupiter.api.BeforeEach;
38+
import org.junit.jupiter.api.Test;
39+
import org.junit.jupiter.api.TestInfo;
40+
import org.slf4j.Logger;
41+
import org.slf4j.LoggerFactory;
42+
43+
import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos;
44+
45+
public abstract class AbstractTestMasterRegionMutation {
46+
47+
private static final Logger LOG = LoggerFactory.getLogger(AbstractTestMasterRegionMutation.class);
48+
49+
protected static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
50+
protected static ServerName rs0;
51+
52+
protected static final AtomicBoolean ERROR_OUT = new AtomicBoolean(false);
53+
protected static final AtomicInteger ERROR_COUNTER = new AtomicInteger(0);
54+
protected static final AtomicBoolean FIRST_TIME_ERROR = new AtomicBoolean(true);
55+
56+
protected static void setUpBeforeClass(int numMasters, Class<? extends HRegion> regionImplClass)
57+
throws Exception {
58+
TEST_UTIL.getConfiguration().setClass(HConstants.REGION_IMPL, regionImplClass, HRegion.class);
59+
StartTestingClusterOption.Builder builder = StartTestingClusterOption.builder();
60+
builder.numMasters(numMasters).numRegionServers(3);
61+
TEST_UTIL.startMiniCluster(builder.build());
62+
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
63+
rs0 = cluster.getRegionServer(0).getServerName();
64+
TEST_UTIL.getAdmin().balancerSwitch(false, true);
65+
}
66+
67+
protected static void tearDownAfterClass() throws Exception {
68+
TEST_UTIL.shutdownMiniCluster();
69+
}
70+
71+
@BeforeEach
72+
protected void setUp(TestInfo testInfo) throws Exception {
73+
TableName tableName = TableName.valueOf(testInfo.getTestMethod().orElseThrow().getName());
74+
TableDescriptor tableDesc = TableDescriptorBuilder.newBuilder(tableName)
75+
.setColumnFamily(ColumnFamilyDescriptorBuilder.of("fam1")).build();
76+
int startKey = 0;
77+
int endKey = 80000;
78+
TEST_UTIL.getAdmin().createTable(tableDesc, Bytes.toBytes(startKey), Bytes.toBytes(endKey), 9);
79+
}
80+
81+
@Test
82+
protected void testMasterRegionMutations() throws Exception {
83+
HbckChore hbckChore = new HbckChore(TEST_UTIL.getHBaseCluster().getMaster());
84+
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
85+
86+
int numRegions0 = cluster.getRegionServer(0).getNumberOfOnlineRegions();
87+
int numRegions1 = cluster.getRegionServer(1).getNumberOfOnlineRegions();
88+
int numRegions2 = cluster.getRegionServer(2).getNumberOfOnlineRegions();
89+
90+
hbckChore.choreForTesting();
91+
HbckReport hbckReport = hbckChore.getLastReport();
92+
assertEquals(0, hbckReport.getInconsistentRegions().size());
93+
assertEquals(0, hbckReport.getOrphanRegionsOnFS().size());
94+
assertEquals(0, hbckReport.getOrphanRegionsOnRS().size());
95+
96+
ERROR_OUT.set(true);
97+
TEST_UTIL.getAdmin().move(
98+
cluster.getRegionServer(1).getRegions().get(0).getRegionInfo().getEncodedNameAsBytes(), rs0);
99+
100+
ERROR_OUT.set(true);
101+
TEST_UTIL.getAdmin().move(
102+
cluster.getRegionServer(2).getRegions().get(0).getRegionInfo().getEncodedNameAsBytes(), rs0);
103+
104+
HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
105+
106+
TEST_UTIL.waitFor(5000, 1000, () -> {
107+
LOG.info("numRegions0: {} , numRegions1: {} , numRegions2: {}", numRegions0, numRegions1,
108+
numRegions2);
109+
LOG.info("Online regions - server0 : {} , server1: {} , server2: {}",
110+
cluster.getRegionServer(0).getNumberOfOnlineRegions(),
111+
cluster.getRegionServer(1).getNumberOfOnlineRegions(),
112+
cluster.getRegionServer(2).getNumberOfOnlineRegions());
113+
LOG.info("Num of successfully completed procedures: {} , num of all procedures: {}",
114+
master.getMasterProcedureExecutor().getProcedures().stream()
115+
.filter(masterProcedureEnvProcedure -> masterProcedureEnvProcedure.getState()
116+
== ProcedureProtos.ProcedureState.SUCCESS)
117+
.count(),
118+
master.getMasterProcedureExecutor().getProcedures().size());
119+
return (numRegions0 + numRegions1 + numRegions2)
120+
== (cluster.getRegionServer(0).getNumberOfOnlineRegions()
121+
+ cluster.getRegionServer(1).getNumberOfOnlineRegions()
122+
+ cluster.getRegionServer(2).getNumberOfOnlineRegions())
123+
&& master.getMasterProcedureExecutor().getProcedures().stream()
124+
.filter(masterProcedureEnvProcedure -> masterProcedureEnvProcedure.getState()
125+
== ProcedureProtos.ProcedureState.SUCCESS)
126+
.count() == master.getMasterProcedureExecutor().getProcedures().size();
127+
});
128+
129+
TEST_UTIL.waitFor(5000, 1000, () -> {
130+
HbckChore hbck = new HbckChore(TEST_UTIL.getHBaseCluster().getMaster());
131+
hbck.choreForTesting();
132+
HbckReport report = hbck.getLastReport();
133+
return report.getInconsistentRegions().isEmpty() && report.getOrphanRegionsOnFS().isEmpty()
134+
&& report.getOrphanRegionsOnRS().isEmpty();
135+
});
136+
}
137+
}

hbase-server/src/test/java/org/apache/hadoop/hbase/master/AbstractTestRestartCluster.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import org.apache.hadoop.hbase.HConstants;
2222
import org.apache.hadoop.hbase.TableName;
2323
import org.apache.hadoop.hbase.util.Bytes;
24-
import org.junit.After;
25-
import org.junit.Before;
24+
import org.junit.jupiter.api.AfterEach;
25+
import org.junit.jupiter.api.BeforeEach;
2626
import org.slf4j.Logger;
2727
import org.slf4j.LoggerFactory;
2828

@@ -39,15 +39,15 @@ public abstract class AbstractTestRestartCluster {
3939

4040
protected abstract boolean splitWALCoordinatedByZk();
4141

42-
@Before
42+
@BeforeEach
4343
public void setUp() {
4444
boolean splitWALCoordinatedByZk = splitWALCoordinatedByZk();
4545
LOG.info("WAL splitting coordinated by zk {}", splitWALCoordinatedByZk);
4646
UTIL.getConfiguration().setBoolean(HConstants.HBASE_SPLIT_WAL_COORDINATED_BY_ZK,
4747
splitWALCoordinatedByZk);
4848
}
4949

50-
@After
50+
@AfterEach
5151
public void tearDown() throws Exception {
5252
UTIL.shutdownMiniCluster();
5353
}

hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestActiveMasterManager.java

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

20-
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertFalse;
22-
import static org.junit.Assert.assertNotNull;
23-
import static org.junit.Assert.assertTrue;
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.assertNotNull;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
2424
import static org.mockito.ArgumentMatchers.any;
2525
import static org.mockito.Mockito.when;
2626

@@ -30,7 +30,6 @@
3030
import java.util.List;
3131
import java.util.concurrent.Semaphore;
3232
import org.apache.hadoop.conf.Configuration;
33-
import org.apache.hadoop.hbase.HBaseClassTestRule;
3433
import org.apache.hadoop.hbase.HBaseTestingUtil;
3534
import org.apache.hadoop.hbase.ServerName;
3635
import org.apache.hadoop.hbase.keymeta.KeyManagementService;
@@ -47,34 +46,30 @@
4746
import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
4847
import org.apache.hadoop.hbase.zookeeper.ZNodePaths;
4948
import org.apache.zookeeper.KeeperException;
50-
import org.junit.AfterClass;
51-
import org.junit.BeforeClass;
52-
import org.junit.ClassRule;
53-
import org.junit.Test;
54-
import org.junit.experimental.categories.Category;
49+
import org.junit.jupiter.api.AfterAll;
50+
import org.junit.jupiter.api.BeforeAll;
51+
import org.junit.jupiter.api.Tag;
52+
import org.junit.jupiter.api.Test;
5553
import org.mockito.Mockito;
5654
import org.slf4j.Logger;
5755
import org.slf4j.LoggerFactory;
5856

5957
/**
6058
* Test the {@link ActiveMasterManager}.
6159
*/
62-
@Category({ MasterTests.class, MediumTests.class })
60+
@Tag(MasterTests.TAG)
61+
@Tag(MediumTests.TAG)
6362
public class TestActiveMasterManager {
6463

65-
@ClassRule
66-
public static final HBaseClassTestRule CLASS_RULE =
67-
HBaseClassTestRule.forClass(TestActiveMasterManager.class);
68-
6964
private final static Logger LOG = LoggerFactory.getLogger(TestActiveMasterManager.class);
7065
private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
7166

72-
@BeforeClass
67+
@BeforeAll
7368
public static void setUpBeforeClass() throws Exception {
7469
TEST_UTIL.startMiniZKCluster();
7570
}
7671

77-
@AfterClass
72+
@AfterAll
7873
public static void tearDownAfterClass() throws Exception {
7974
TEST_UTIL.shutdownMiniZKCluster();
8075
}

hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestAlwaysStandByHMaster.java

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

20-
import static junit.framework.TestCase.assertTrue;
21-
import static org.junit.Assert.assertEquals;
22-
import static org.junit.Assert.assertFalse;
23-
import static org.junit.Assert.assertNotNull;
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.assertNotNull;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
2424

25-
import org.apache.hadoop.hbase.HBaseClassTestRule;
2625
import org.apache.hadoop.hbase.HBaseTestingUtil;
27-
import org.apache.hadoop.hbase.MiniClusterRule;
26+
import org.apache.hadoop.hbase.MiniClusterExtension;
2827
import org.apache.hadoop.hbase.StartTestingClusterOption;
2928
import org.apache.hadoop.hbase.testclassification.MasterTests;
3029
import org.apache.hadoop.hbase.testclassification.MediumTests;
31-
import org.junit.ClassRule;
32-
import org.junit.Test;
33-
import org.junit.experimental.categories.Category;
30+
import org.junit.jupiter.api.Tag;
31+
import org.junit.jupiter.api.Test;
32+
import org.junit.jupiter.api.extension.RegisterExtension;
3433

35-
@Category({ MediumTests.class, MasterTests.class })
34+
@Tag(MediumTests.TAG)
35+
@Tag(MasterTests.TAG)
3636
public class TestAlwaysStandByHMaster {
3737

38-
@ClassRule
39-
public static final HBaseClassTestRule CLASS_RULE =
40-
HBaseClassTestRule.forClass(TestAlwaysStandByHMaster.class);
41-
4238
private static final StartTestingClusterOption OPTION = StartTestingClusterOption.builder()
4339
.numAlwaysStandByMasters(1).numMasters(1).numRegionServers(1).build();
4440

45-
@ClassRule
46-
public static final MiniClusterRule miniClusterRule =
47-
MiniClusterRule.newBuilder().setMiniClusterOption(OPTION).build();
41+
@RegisterExtension
42+
public static final MiniClusterExtension miniClusterExtension =
43+
MiniClusterExtension.newBuilder().setMiniClusterOption(OPTION).build();
4844

4945
/**
5046
* Tests that the AlwaysStandByHMaster does not transition to active state even if no active
5147
* master exists.
5248
*/
5349
@Test
5450
public void testAlwaysStandBy() throws Exception {
55-
HBaseTestingUtil testUtil = miniClusterRule.getTestingUtility();
51+
HBaseTestingUtil testUtil = miniClusterExtension.getTestingUtility();
5652
// Make sure there is an active master.
5753
assertNotNull(testUtil.getMiniHBaseCluster().getMaster());
5854
assertEquals(2, testUtil.getMiniHBaseCluster().getMasterThreads().size());

0 commit comments

Comments
 (0)