Skip to content

Commit 1474ebc

Browse files
authored
HBASE-25475: Improve UT added as part of HBASE-25445 in TestSplitWALManager (#2855)
Signed-off-by: Wellington Chevreuil <[email protected]>
1 parent 9b670a4 commit 1474ebc

File tree

1 file changed

+32
-69
lines changed

1 file changed

+32
-69
lines changed

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

Lines changed: 32 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@
3131
import org.apache.hadoop.hbase.HConstants;
3232
import org.apache.hadoop.hbase.ServerName;
3333
import org.apache.hadoop.hbase.TableName;
34-
import org.apache.hadoop.hbase.client.Admin;
35-
import org.apache.hadoop.hbase.client.Put;
36-
import org.apache.hadoop.hbase.client.RegionInfo;
37-
import org.apache.hadoop.hbase.client.ResultScanner;
38-
import org.apache.hadoop.hbase.client.Scan;
39-
import org.apache.hadoop.hbase.client.Table;
40-
import org.apache.hadoop.hbase.master.assignment.SplitTableRegionProcedure;
41-
import org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure;
4234
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
4335
import org.apache.hadoop.hbase.master.procedure.ServerProcedureInterface;
4436
import org.apache.hadoop.hbase.procedure2.Procedure;
@@ -98,58 +90,6 @@ public void teardown() throws Exception {
9890
TEST_UTIL.shutdownMiniCluster();
9991
}
10092

101-
@Test
102-
public void testWALArchiveWithDifferentWalAndRootFS() throws Exception{
103-
HBaseTestingUtility test_util_2 = new HBaseTestingUtility();
104-
Path dir = TEST_UTIL.getDataTestDirOnTestFS("testWalDir");
105-
test_util_2.getConfiguration().set(CommonFSUtils.HBASE_WAL_DIR, dir.toString());
106-
CommonFSUtils.setWALRootDir(test_util_2.getConfiguration(), dir);
107-
test_util_2.startMiniCluster(3);
108-
HMaster master2 = test_util_2.getHBaseCluster().getMaster();
109-
LOG.info("The Master FS is pointing to: " + master2.getMasterFileSystem()
110-
.getFileSystem().getUri());
111-
LOG.info("The WAL FS is pointing to: " + master2.getMasterFileSystem()
112-
.getWALFileSystem().getUri());
113-
Table table = test_util_2.createTable(TABLE_NAME, FAMILY);
114-
test_util_2.waitTableAvailable(TABLE_NAME);
115-
Admin admin = test_util_2.getAdmin();
116-
MasterProcedureEnv env = test_util_2.getMiniHBaseCluster().getMaster()
117-
.getMasterProcedureExecutor().getEnvironment();
118-
final ProcedureExecutor<MasterProcedureEnv> executor = test_util_2.getMiniHBaseCluster()
119-
.getMaster().getMasterProcedureExecutor();
120-
List<RegionInfo> regionInfos = admin.getRegions(TABLE_NAME);
121-
SplitTableRegionProcedure splitProcedure = new SplitTableRegionProcedure(
122-
env, regionInfos.get(0), Bytes.toBytes("row5"));
123-
// Populate some rows in the table
124-
LOG.info("Beginning put data to the table: " + TABLE_NAME.toString());
125-
int rowCount = 5;
126-
for (int i = 0; i < rowCount; i++) {
127-
byte[] row = Bytes.toBytes("row" + i);
128-
Put put = new Put(row);
129-
put.addColumn(FAMILY, FAMILY, FAMILY);
130-
table.put(put);
131-
}
132-
executor.submitProcedure(splitProcedure);
133-
LOG.info("Submitted SplitProcedure.");
134-
test_util_2.waitFor(30000, () -> executor.getProcedures().stream()
135-
.filter(p -> p instanceof TransitRegionStateProcedure)
136-
.map(p -> (TransitRegionStateProcedure) p)
137-
.anyMatch(p -> TABLE_NAME.equals(p.getTableName())));
138-
test_util_2.getMiniHBaseCluster().killRegionServer(
139-
test_util_2.getMiniHBaseCluster().getRegionServer(0).getServerName());
140-
test_util_2.getMiniHBaseCluster().startRegionServer();
141-
test_util_2.waitUntilNoRegionsInTransition();
142-
Scan scan = new Scan();
143-
ResultScanner results = table.getScanner(scan);
144-
int scanRowCount = 0;
145-
while (results.next() != null) {
146-
scanRowCount++;
147-
}
148-
Assert.assertEquals("Got " + scanRowCount + " rows when " + rowCount +
149-
" were expected.", rowCount, scanRowCount);
150-
test_util_2.shutdownMiniCluster();
151-
}
152-
15393
@Test
15494
public void testAcquireAndRelease() throws Exception {
15595
List<FakeServerProcedure> testProcedures = new ArrayList<>();
@@ -272,16 +212,22 @@ public void testGetWALsToSplit() throws Exception {
272212
Assert.assertEquals(0, metaWals.size());
273213
}
274214

275-
@Test
276-
public void testSplitLogs() throws Exception {
277-
TEST_UTIL.createTable(TABLE_NAME, FAMILY, TEST_UTIL.KEYS_FOR_HBA_CREATE_TABLE);
215+
private void splitLogsTestHelper(HBaseTestingUtility testUtil) throws Exception {
216+
HMaster hmaster = testUtil.getHBaseCluster().getMaster();
217+
SplitWALManager splitWALManager = hmaster.getSplitWALManager();
218+
LOG.info("The Master FS is pointing to: " + hmaster.getMasterFileSystem()
219+
.getFileSystem().getUri());
220+
LOG.info("The WAL FS is pointing to: " + hmaster.getMasterFileSystem()
221+
.getWALFileSystem().getUri());
222+
223+
testUtil.createTable(TABLE_NAME, FAMILY, testUtil.KEYS_FOR_HBA_CREATE_TABLE);
278224
// load table
279-
TEST_UTIL.loadTable(TEST_UTIL.getConnection().getTable(TABLE_NAME), FAMILY);
280-
ProcedureExecutor<MasterProcedureEnv> masterPE = master.getMasterProcedureExecutor();
281-
ServerName metaServer = TEST_UTIL.getHBaseCluster().getServerHoldingMeta();
282-
ServerName testServer = TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream()
283-
.map(rs -> rs.getRegionServer().getServerName()).filter(rs -> rs != metaServer).findAny()
284-
.get();
225+
testUtil.loadTable(testUtil.getConnection().getTable(TABLE_NAME), FAMILY);
226+
ProcedureExecutor<MasterProcedureEnv> masterPE = hmaster.getMasterProcedureExecutor();
227+
ServerName metaServer = testUtil.getHBaseCluster().getServerHoldingMeta();
228+
ServerName testServer = testUtil.getHBaseCluster().getRegionServerThreads().stream()
229+
.map(rs -> rs.getRegionServer().getServerName()).filter(rs -> rs != metaServer).findAny()
230+
.get();
285231
List<Procedure> procedures = splitWALManager.splitWALs(testServer, false);
286232
Assert.assertEquals(1, procedures.size());
287233
ProcedureTestingUtility.submitAndWait(masterPE, procedures.get(0));
@@ -294,6 +240,23 @@ public void testSplitLogs() throws Exception {
294240
Assert.assertEquals(1, splitWALManager.getWALsToSplit(metaServer, false).size());
295241
}
296242

243+
@Test
244+
public void testSplitLogs() throws Exception {
245+
splitLogsTestHelper(TEST_UTIL);
246+
}
247+
248+
@Test
249+
public void testSplitLogsWithDifferentWalAndRootFS() throws Exception{
250+
HBaseTestingUtility testUtil2 = new HBaseTestingUtility();
251+
testUtil2.getConfiguration().setInt(HBASE_SPLIT_WAL_MAX_SPLITTER, 1);
252+
Path dir = TEST_UTIL.getDataTestDirOnTestFS("testWalDir");
253+
testUtil2.getConfiguration().set(CommonFSUtils.HBASE_WAL_DIR, dir.toString());
254+
CommonFSUtils.setWALRootDir(testUtil2.getConfiguration(), dir);
255+
testUtil2.startMiniCluster(3);
256+
splitLogsTestHelper(testUtil2);
257+
testUtil2.shutdownMiniCluster();
258+
}
259+
297260
@Test
298261
public void testWorkerReloadWhenMasterRestart() throws Exception {
299262
List<FakeServerProcedure> testProcedures = new ArrayList<>();

0 commit comments

Comments
 (0)